On Tue, Jul 12, 2011 at 12:45:43AM +0200, Eric Smith wrote:
If I add an Attach: heder with an invalid filename causing a failure to attach the file, is it possible to have mutt disable mail send.This often occurs when quickly exiting the editor and pressing "y" without noticing the failure.
I don't think what you're specifically asking for is possible without code changes to mutt.
I use two approaches which deal with 99% of the "intended to attach a file but didn't" problem for me.
First I use vim to compose messages, and use a function that prompts me to attach a file if I use the words 'attach' or 'patch' in the message. It adds Attach: headers, but allows me to find the file with tab completion, so it's very rare for me to get the file name wrong.
I then use a script as a pass-through to sendmail. It looks for the same keywords. If it finds them, but doesn't find an attachment, it exits without sending the message, leaving an error message on the screen instead.
I've attached my mutt check-for-attachments script (refined from the version on http://wiki.mutt.org/?ConfigTricks/CheckAttach) and my vim function script.
-- Ed Blackman
#!/bin/bash ## ## Script: muttCheckAttach ## ## Original source: http://wiki.mutt.org/?ConfigTricks/CheckAttach ## Refinements by Ed Blackman <[email protected]> ## ## Edit muttrc to have this line: ## set sendmail = "/path/to/muttCheckAttach /usr/lib/sendmail -oem -oi" ## ## Attachment keywords that the message body will be searched for: KEYWORDS='attach|patch' ## Check that sendmail or other program is supplied as first argument. if [ ! -x "$1" ]; then echo "Usage: $0 </path/to/mailprog> <args> ..." echo "e.g.: $0 /usr/sbin/sendmail -oem -oi" exit 2 fi ## Save msg in file to re-use it for multiple tests. TMPFILE=`mktemp -t mutt_checkattach.XXXXXX` || exit 2 cat > "$TMPFILE" ## Define test for multipart message. ## Can't just be "multipart", as in the original, since GPG signed messages ## are multipart/signed, but signature shouldn't be treated as an attachment function multipart { grep -q '^Content-Type: multipart/mixed' "$TMPFILE" } ## Define test for keyword search. ## Ignore keywords in quoted body lines, response Subjects, and ## Content-Disposition MIME headers function word-attach { grep -E -v '^>|Content-Disposition|^Subject: Re:' "$TMPFILE" | grep -E -i -q "$KEYWORDS" } ## Header override. ## Also allow mutt "bounce"s (with header Resent-From) through without check. function header-override { grep -i -E "^(X-attached: *none|Resent-From: )" "$TMPFILE" } ## FINAL DECISION: if multipart || ! word-attach || header-override; then "$@" < "$TMPFILE" EXIT_STATUS=$? else 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." EXIT_STATUS=1 fi ## Delete the temporary file. rm -f "$TMPFILE" ## That's all folks. exit $EXIT_STATUS
" To install, copy into existing ~/.vim/after/ftplugin/mail.vim, " or save it into ~/.vim/plugin/mail/ and edit ~/.vim/after/ftplugin/mail.vim " to have this line: "runtime mail/muttAttach.vim" " " Script: muttAttach.vim " Author: Ed Blackman " Email: [email protected] " " This file was modified from a version from Brian Medley " <[email protected]>, which was modified from Cedric Duval's version. " http://cedricduval.free.fr/download/vimrc/mail " " Description: " This function creates a file-write hook that looks for key words that " indicate the user wishes to attach a file, and prompts for the file, " then causes it to be attached using the Mutt Attach: pseudo-header. " " If the user responds to the prompt with 'none', add the X-Attached: none " header to indicate that other attachment processing scripts shouldn't " expect to find an attachment despite the prescence of key words. " ------------------------------------------------ " Check Attachments " ------------------------------------------------ if !exists("CheckAttach") function! CheckAttach() let check='attach,patch' let oldPos=getpos('.') let ans=1 let val = join(split(escape(check,' \.+*'), ','),'\|') 1 let s:ignorecase_save=&ignorecase set ignorecase if search('\%('.val.'\)','W') let ans=input("Attach file?: (leave empty to abort): ", "", "file") while (ans != '') normal magg}- if ans != 'none' call append(line('.'), 'Attach: '.ans) else call append(line('.'), 'X-Attached: '.ans) endif redraw let ans=input("Attach another file?: (leave empty to abort): ", "", "file") endwhile endif exe ":write ". expand("<amatch>") let &ignorecase=s:ignorecase_save call setpos('.', oldPos) endfu augroup script au! au BufWriteCmd,FileWriteCmd mutt* :call CheckAttach() augroup END endif
signature.txt
Description: Digital signature
