-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemlv-report
executable file
·123 lines (108 loc) · 2.27 KB
/
gemlv-report
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
#!/bin/bash
LF=$'\n'
type=$1
shift
if [ -z "$GEMLV_UNDER_XTERM" ]
then
if [ -x ~/.local/share/gemlv/report-$type ]
then
exec ~/.local/share/gemlv/report-$type "$@"
fi
if [ -x /etc/gemlv/report-$type ]
then
exec /etc/gemlv/report-$type "$@"
fi
GEMLV_EMAIL_FILE=$1
export GEMLV_EMAIL_FILE
GEMLV_UNDER_XTERM=yes
export GEMLV_UNDER_XTERM
GEMLV_REPORT_TYPE=$type
export GEMLV_REPORT_TYPE
exec xterm -hold -e "gemlv-report-$type"
else
if zenity --question --no-markup --text "Report ${GEMLV_REPORT_TYPE^}?$LF$GEMLV_EMAIL_FILE" --title "Report ${GEMLV_REPORT_TYPE^}"
then
pids=()
case "$GEMLV_REPORT_TYPE" in
spam)
commands=("razor-report -d -f" "pyzor-files -d report --" "bogofilter -s -v -B")
;;
ham)
commands=("razor-revoke -d -f" "pyzor-files -d whitelist --" "bogofilter -n -v -B")
;;
*)
echo "unknown: $GEMLV_REPORT_TYPE" >&2
exit -1
;;
esac
for cmd in "${commands[@]}"
do
command $cmd "$GEMLV_EMAIL_FILE" &
pids+=($!)
done
all_ok=1
codes=()
for pid in "${pids[@]}"
do
wait $pid
code=$?
codes+=($code)
if [ $code != 0 ]
then
all_ok=0
fi
done
if [ $all_ok != 1 ]
then
n=0
highest_code=0
for code in "${codes[@]}"
do
if [ $code != 0 ]
then
echo "$0: $GEMLV_EMAIL_FILE: [1m$GEMLV_REPORT_TYPE report error $code[m at command '${commands[$n]}'" >&2
if [ $highest_code -lt $code ]
then
highest_code=$code
fi
fi
n=$[n+1]
done
exit $highest_code
fi
# Move to 'Spam/' folder
path=`readlink -f "$GEMLV_EMAIL_FILE"`
dirpath=`dirname "$path"`
dirname=`basename "$dirpath"`
ask_move=no
case "$GEMLV_REPORT_TYPE" in
spam)
prep=into
if [ "$dirname" != Spam ]
then
ask_move=yes
fi
;;
ham)
prep="out from"
if [ "$dirname" = Spam ]
then
ask_move=yes
fi
;;
esac
if [ $ask_move = yes ] && zenity --question --no-markup --text "Move $prep Spam folder?$LF$GEMLV_EMAIL_FILE" --title "Move Email $prep Spam"
then
case "$GEMLV_REPORT_TYPE" in
spam)
mkdir -p "$dirpath/Spam/"
mv "$GEMLV_EMAIL_FILE" "$dirpath/Spam/"
;;
ham)
mv "$GEMLV_EMAIL_FILE" "$dirpath/../"
;;
esac
fi
echo "$0: $GEMLV_EMAIL_FILE: [1mdone marked as $GEMLV_REPORT_TYPE[m" >&2
fi
fi