-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail2irc-daemon.sh
executable file
·45 lines (37 loc) · 997 Bytes
/
mail2irc-daemon.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
#!/bin/bash
# FILE mail2irc-daemon.sh
# AUTHOR MDrights
# DATE 2020-01-05
SELF_PATH=$(dirname $0)
MAILBOX=$HOME/Maildir
LOG_FILE=/tmp/csobot-mail2irc.log
while true; do
NEW_MAIL=$(find ${MAILBOX}/new -type f)
if [[ -z $NEW_MAIL ]]; then
echo "No new mail found. Cheers."
echo "" > $LOG_FILE
#continue
else
for NM in $(echo "$NEW_MAIL"); do
SUB=$(grep "Subject:" $NM)
FROM=$(grep "From:" $NM)
DATE=$(grep "Date:" $NM)
echo " ==== $DATE ====
$FROM
$SUB
" >> $LOG_FILE
mv $NM ${MAILBOX}/cur/
done
fi
# Send the results
if [[ -n $LOG_FILE ]]; then
python2 $SELF_PATH/irc-send-oftc.py $LOG_FILE
if [[ $? -eq 0 ]] ; then
echo "The mail has been sent." |tee -a $LOG_FILE
echo "" > $LOG_FILE
fi
else
echo "No new mail, do not send." |tee -a $LOG_FILE
fi
sleep 60
done