]> git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blame - mutt_check_attachment
Update save-gif script
[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
2d8938f6
IB
13# Feel like tipping/donating? https://www.immae.eu/licenses_and_tipping
14
15
5172ecf8
IB
16## Attachment keywords that the message body will be searched for:
17KEYWORDS='attach|joint|voici|voil'
18
19## Check that sendmail or other program is supplied as first argument.
20if [ ! -x "$1" ]; then
21 echo "Usage: $0 </path/to/mailprog> <args> ..."
22 echo "e.g.: $0 /usr/sbin/sendmail -oem -oi"
23 exit 2
24fi
25
26## Save msg in file to re-use it for multiple tests.
27TMPFILE=`mktemp -t mutt_checkattach.XXXXXX` || exit 2
28cat > "$TMPFILE"
29
30## Define test for multipart message.
31function multipart {
32# grep -q '^Content-Type: multipart' "$TMPFILE"
33 grep -q '^Content-Disposition: attachment' "$TMPFILE"
34}
35
36## Define test for keyword search.
37function word-attach {
38 grep -v '^>' "$TMPFILE" | grep -E -i -q "$KEYWORDS"
39}
40
41## Header override.
42function header-override {
43 grep -i -E "^X-attached: *none *$" "$TMPFILE"
44}
45
46function ask {
47 terminal=`tty`
48 dialog --yesno "Envoyer malgré la pièce jointe manquante ?" 5 30 < $terminal > $terminal
49 }
50
51#Verifie qu'on a essayé de l'envoyer y'a moins d'une minute
52function file_last {
53 if [ ! -e $HOME/.mutt_attach ]; then
54 return 0
55 fi
56 valeur=`echo \`date +%s\`-\`stat -c %Y $HOME/.mutt_attach\`'<60' | bc`
57 return $valeur
58}
59## FINAL DECISION:
60if multipart || ! word-attach || header-override || ! file_last ; then
61 "$@" < "$TMPFILE"
62 EXIT_STATUS=$?
63 if [ ! -s $HOME/.mutt_attach ]; then
64 rm -f $HOME/.mutt_attach
65 fi
66else
67 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."
68 echo "You can also send the email again in the next minute."
69 EXIT_STATUS=1
70 touch $HOME/.mutt_attach
71fi
72
73## Delete the temporary file.
74rm -f "$TMPFILE"
75
76## That's all folks.
77exit $EXIT_STATUS
78