]> git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blame - mutt_check_attachment
wrapper_display + LICENSE
[perso/Immae/Projets/Scripts/Public.git] / mutt_check_attachment
CommitLineData
5172ecf8
IB
1#!/bin/bash
2
3## Original script adapted from source: http://wiki.mutt.org/?ConfigTricks/CheckAttach
4##
5## Adapted by Ismaël Bouya (http://www.normalesup.org/~bouya/) to make it so
6## that retrying to send the email shortly after will work
7##
8## Edit muttrc to have this line:
9## set sendmail = "/usr/local/bin/mutt_check_attachment_before_send.sh /usr/lib/sendmail -oem -oi"
10##
11
12
13## Attachment keywords that the message body will be searched for:
14KEYWORDS='attach|joint|voici|voil'
15
16## Check that sendmail or other program is supplied as first argument.
17if [ ! -x "$1" ]; then
18 echo "Usage: $0 </path/to/mailprog> <args> ..."
19 echo "e.g.: $0 /usr/sbin/sendmail -oem -oi"
20 exit 2
21fi
22
23## Save msg in file to re-use it for multiple tests.
24TMPFILE=`mktemp -t mutt_checkattach.XXXXXX` || exit 2
25cat > "$TMPFILE"
26
27## Define test for multipart message.
28function multipart {
29# grep -q '^Content-Type: multipart' "$TMPFILE"
30 grep -q '^Content-Disposition: attachment' "$TMPFILE"
31}
32
33## Define test for keyword search.
34function word-attach {
35 grep -v '^>' "$TMPFILE" | grep -E -i -q "$KEYWORDS"
36}
37
38## Header override.
39function header-override {
40 grep -i -E "^X-attached: *none *$" "$TMPFILE"
41}
42
43function ask {
44 terminal=`tty`
45 dialog --yesno "Envoyer malgré la pièce jointe manquante ?" 5 30 < $terminal > $terminal
46 }
47
48#Verifie qu'on a essayé de l'envoyer y'a moins d'une minute
49function file_last {
50 if [ ! -e $HOME/.mutt_attach ]; then
51 return 0
52 fi
53 valeur=`echo \`date +%s\`-\`stat -c %Y $HOME/.mutt_attach\`'<60' | bc`
54 return $valeur
55}
56## FINAL DECISION:
57if multipart || ! word-attach || header-override || ! file_last ; then
58 "$@" < "$TMPFILE"
59 EXIT_STATUS=$?
60 if [ ! -s $HOME/.mutt_attach ]; then
61 rm -f $HOME/.mutt_attach
62 fi
63else
64 echo "No file was attached but a search of the message text suggests there should be one. Add a header \"X-attached: none\" to override this check if no attachment is intended."
65 echo "You can also send the email again in the next minute."
66 EXIT_STATUS=1
67 touch $HOME/.mutt_attach
68fi
69
70## Delete the temporary file.
71rm -f "$TMPFILE"
72
73## That's all folks.
74exit $EXIT_STATUS
75