File: functions.in

package info (click to toggle)
nullmailer 1:2.2-3
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 1,228 kB
  • sloc: cpp: 6,785; sh: 504; makefile: 221; perl: 184
file content (155 lines) | stat: -rw-r--r-- 3,043 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
srcdir=@SRCDIR@
builddir=@BUILDDIR@
tmpdir=$builddir/test-tmp
export NULLMAILER_TEST_PREFIX=$tmpdir
SYSCONFDIR=$tmpdir/conf
QUEUEDIR=$tmpdir/queue
rm -rf $tmpdir
mkdir -p \
    $tmpdir/protocols \
    $QUEUEDIR/{failed,queue,tmp} \
    $SYSCONFDIR
mknod $QUEUEDIR/trigger p
ln -s $builddir/src $tmpdir/sbin
ln -s $builddir/src $tmpdir/bin
ln -s $builddir/protocols/* $tmpdir/protocols/

exit_cleanup() {
    local exit=$?
    svc -dx $tmpdir/service/* > /dev/null 2>&1 || :
    # Remove all temporary files on success
    if [ $exit -eq 0 ]
    then
        wait
        rm -rf $tmpdir
    fi
}
trap exit_cleanup EXIT

fail() {
    echo "$*"
    exit 1
}
start() {
    local name=$1
    shift
    mkdir -p $tmpdir/service/$name
    {
	echo '#!/bin/sh'
	echo exec "$@"
    } >$tmpdir/service/$name/run
    chmod +x $tmpdir/service/$name/run
    supervise $tmpdir/service/$name </dev/null >$tmpdir/service/${name}-log 2>&1 &
    sleep 1
}
stop() {
    for name in $*; do
	svc -dx $tmpdir/service/$name >/dev/null 2>&1
	wait
    done
}
catch-port() {
    local name=$1
    port=$( head -n 1 $tmpdir/service/${name}-log )
}

#not() { if "$@"; then return 1; else return 0; fi }
not() { ! safe "$@"; }
safe() { set +e; "$@"; result=$?; set -e; return $result; }
error() {
  local code=$1
  shift
  if "$@"; then
    echo "Result was 0, should be $code."
    return 1
  else
    result=$?
    if test $result -eq $code; then
      return 0
    else
      echo "Result was $result, should be $code."
      return 1
    fi
  fi
}

inject() { ../src/nullmailer-inject "$@"; }
mailq() { ../src/mailq "$@"; }
smtpd() { ../src/nullmailer-smtpd "$@"; }
queue() {
    (
        echo "$1"
        shift
        while [ x"$1" != x ]
        do
            echo "$1"
            shift
        done
        echo
        echo "Subject: test"
    ) | ../src/nullmailer-queue > $tmpdir/queue-out 2> $tmpdir/queue-err
}
injectlines() {
  for line in "$@"; do
    echo "$line"
  done | inject -n
  return $?
}
injectfield() {
  local field=$1
  shift
  injectlines "$@" | grep -i "^$field:" | cut -d: -f2-
}
protocol() {
    local p=$1
    local opts=""
    shift
    while [ $# -gt 0 -a x"$1" != x-- ]
    do
        opts="$opts $1"
        shift
    done
    shift || :
    for line in "$@"
    do
        echo "$line"
    done > $tmpdir/protocol-in
    ../protocols/$p $opts < $tmpdir/protocol-in > $tmpdir/protocol-log 2>&1
}

# Split an input on blank lines
splitblank() {
  local fn=$1
  local n=1
  while read line
  do
    if [ x"$line" = x ]
    then
      n=$(( $n + 1 ))
    else
      echo "$line" >> ${fn}.$n
    fi
  done
}

make-testmail() {
    testmail=$tmpdir/testmail
    rm -f $testmail
    cat >$testmail <<EOF
bruce@untroubled.org
bruce@untroubled.org

From: <bruce@untroubled.org>
To: <bruce@untroubled.org>
Subject: Nullmailer automated test message

Just testing, please ignore
EOF
}

export PATH=/bin:/usr/bin:/usr/local/bin
rm -f $SYSCONFDIR/*
echo f.q.d.n >$SYSCONFDIR/../mailname
echo q.d.n >$SYSCONFDIR/defaultdomain
set -e