File: fetchmail

package info (click to toggle)
popa3d 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: ansic: 2,334; sh: 106; makefile: 61
file content (68 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash

set -e

cd $AUTOPKGTEST_TMP
export HOME_ETC=$(pwd)

log () { echo "+++ $*"; }
fail () { echo Error: "$*" >&2; exit 1; }
fail_if_not () { "$@" || fail "$?: $*"; }

pw="bloggs"
user="fred"
connect="localhost"
subject="nothing"
content="Hello!"

fail_if_not service inetutils-syslogd start
fail_if_not service popa3d start
log "Started popa3d"

trap "{ service popa3d stop 2>/dev/null || true; tail -n20 /var/log/{syslog,auth.log} || true; }" EXIT
fail_if_not adduser --disabled-login --shell /usr/bin/bash --comment "$user" $user
log "Created user"

printf "%s" $pw | passwd -s $user || fail "setting password";
getent passwd $user
getent shadow $user
log "Set password"

cat >message <<EOF
$content
EOF
cat >.fetchmailrc <<EOF
poll $connect protocol pop3 keep sslproto ''
EOF
cat >.netrc <<EOF
machine $connect
login $user
password $pw
EOF
chmod 0600 .fetchmailrc .netrc
head -n20 .fetchmailrc .netrc message
log "Written files"

mail -s $subject fred < message
log "Sent mail"

tail -f /var/log/exim4/mainlog | grep -q 'Completed'
cat /var/log/exim4/mainlog
log "Delivered mail"

fail_if_not service popa3d status
ret=0
fetchmail -vvv -N --bsmtp out --username $user 2>&1 || ret=$?
tail -n10 /var/log/{syslog,auth.log} || true
[ $ret -eq 0 ] || fail "fetchmail($ret)"
log "Fetched mail"

cat out
fail_if_not grep -Eq "^Subject: $subject" out
fail_if_not grep -q "$content" out
log "Validated mail"

fail_if_not service popa3d stop
log "All checks suceeded!"

trap - EXIT