-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-messages.sh
executable file
·65 lines (58 loc) · 1.54 KB
/
process-messages.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
#!/bin/sh
#
# 2024 Eric Radman <[email protected]>
#
# Process new messages to allow users to manage mailing list membership
# using simple OpenSMPTD tables.
: ${READ_MESSAGE:="/usr/local/libexec/smtpd/read_message.awk"}
: ${MEMBERS:="/etc/mail/members"}
: ${ALIASES:="/etc/mail/aliases"}
: ${MAILDIR:="mail"}
: ${PROJECT:="rset"}
: ${LIST_NAME:="dev"}
: ${LIST_EMAIL:="[email protected]"}
: ${ADMIN_EMAIL:="[email protected]"}
function commit {
doas cp tmp/members.new $MEMBERS
doas rsub $ALIASES <<-CONF
$LIST_NAME: /var/www/archive/$PROJECT-$LIST_NAME-$(date +%Y).mbox,marc,$(paste -sd ',' $MEMBERS)
CONF
rm -f tmp/members.new rsub_*
doas smtpctl update table aliases
doas smtpctl update table members
}
function send_status {
reply_to=$1
if egrep -xq $reply_to $MEMBERS; then
msg="You are subscribed to $LIST_EMAIL"
else
msg="You are not subscribed to $LIST_EMAIL"
fi
echo "$msg" | mail -r $ADMIN_EMAIL -s "Re: status $LIST_NAME" $reply_to
}
# backup
cp $MEMBERS etc/members.$(md5 -q $MEMBERS)
export LIST_NAME
export IFS="|"
$READ_MESSAGE $(find $MAILDIR/new -type f -name "*.*.*") /dev/null \
| while read -r list email action msgfile
do
case $action in
subscribe)
egrep -xv $email $MEMBERS > tmp/members.new
echo $email >> tmp/members.new
commit
;;
unsubscribe)
egrep -xv $email $MEMBERS > tmp/members.new
commit
;;
status)
send_status $email
;;
esac
mv $msgfile $MAILDIR/cur/
done
# wait for incoming messages
echo $MAILDIR/new | entr -zpnd true
[ $? -eq 0 -o $? -eq 2 ] && exec $0 $*