-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
114 lines (99 loc) · 1.26 KB
/
test.sh
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
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2019-2022 Junjiro R. Okajima
tmp=/tmp/$$
prefix=xoauth2-pipe
set -eu
TEST_USER=${TEST_USER:-Debian-exim}
cmd=$1
sender=$2
recipient=$3
cat << EOF > $tmp.body
From: $sender
To: $recipient
Subject: $prefix, $sender --> $recipient
test
EOF
{
cat << EOF
w
EHLO your.domain
w
MAIL FROM: <$sender>
w
RCPT TO: <$recipient>
w
DATA
w
EOF
cat $tmp.body
cat << EOF
.
w
QUIT
w
EOF
} > $tmp
wait_for_server() # pipe_server
{
local stopme=0
local server
while [ $stopme -eq 0 ]
do
read server < $1
echo "$server"
case "$(echo $server | cut -f1 -d' ')" in
[0-9][0-9][0-9])
stopme=1
;;
esac
done
}
conversation() # input pipe_server
{
local i
while read i
do
case "$i" in
w)
wait_for_server $2 1>&2
;;
*)
echo "$i" 1>&2
echo "$i\r"
;;
esac
done < $1
}
stdalone()
{
rm -f $tmp.p
mknod -m 600 $tmp.p p
conversation $tmp $tmp.p |
{
set -x
sudo -u $TEST_USER xoauth2-pipe.sh smtp >> $tmp.p
}
}
exim()
{
set -x
{
cat $tmp.body
echo by exim
} |
/usr/sbin/exim -odf -v -f $sender $recipient
}
mail()
{
set -x
{
tail -1 $tmp.body
echo by mail
} |
/usr/bin/mail -r $sender \
-s "$(grep '^Subject:' $tmp.body | cut -f2- -d:)" \
$recipient
}
$cmd
rm -f $tmp $tmp.*