File: t.operation

package info (click to toggle)
fetchmail 6.5.6-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,596 kB
  • sloc: ansic: 19,190; sh: 7,108; python: 2,395; perl: 564; yacc: 447; lex: 286; makefile: 260; awk: 124; lisp: 84; exp: 43; sed: 17
file content (65 lines) | stat: -rwxr-xr-x 1,771 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
#!/bin/sh

###########################
### Test fetching email ###
###########################

set -e

# skip test if python3 not present
python3 -V || exit 77

POP3_SERVER=127.0.0.1
POP3_PORT=11110
USER=${USER:-user}
PASSWORD=ubuntu
WORKDIR=$(mktemp -d)
SERVER_PID=
trap 'set +e ; test -z $SERVER_PID || kill $SERVER_PID ; rm -rf $WORKDIR' 0 INT QUIT ABRT PIPE TERM

LOG="${WORKDIR}/fetchmail.log"
MBOX="${WORKDIR}/test-mbox-$(date +%''s_%N)"
CONFIG="${WORKDIR}/fetchmailrc"
STARTMARKER="${WORKDIR}/started"

echo "Configuring a functional local mail system"

export STARTMARKER
rm -f "${STARTMARKER}"
python3 "$(dirname ${0})/t.operation.mock-pop3-server.py" &
SERVER_PID=$!
running=0
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  echo >&2 "waiting for server to start... $i"
  sleep 1
  if test -r "${STARTMARKER}" ; then
    running=1
    break
  fi
done
[ $running -eq 1 ] || { echo >&2 "mock-pop3-server.py has not started, skipping test." ; SERVER_PID= ; exit 77 ; }
kill -0 $SERVER_PID || { echo >&2 "mock-pop3-server.py has gone away, skipping test." ; SERVER_PID= ; exit 77 ; }

# Configure fetchmail
cat > "${CONFIG}" <<EOF
poll ${POP3_SERVER} port ${POP3_PORT} no uidl with protocol POP3:
  auth password
  user '${USER}' there with password '${PASSWORD}'
  is ${USER} here
  sslproto ''
  mda "/bin/sh -c 'cat > ${MBOX}'"
EOF
chmod 700 "${CONFIG}"

# Run fetchmail
echo "Checking fetchmail operates"
unset LANG LANGUAGE
LC_ALL=C FETCHMAILHOME=${WORKDIR} FETCHMAILUSER="" ./fetchmail -d0 -vvv -f "${CONFIG}" "${POP3_SERVER}"

# TODO: Verify the test email was delivered to expected destination
echo "Checking test email was received"
grep "Received: from " "${MBOX}"

kill ${SERVER_PID} || exit 77
SERVER_PID= # blank so trap doesn't re-kill
echo "OK"