Steve's blog
   


Steve About
Steve's blog,
The Words of the Sledge
steve@einval.com

Subscribe
Subscribe to the RSS feed.

Links

  • Home
  • Debian
  • PlanetDebian
  • Search PlanetDebian
  • Friends

  • Matthew Garrett
  • Jonathan McDowell
  • Jo McIntyre
  • Martin Michlmayr
  • Andrew Mobbs
  • Mike Pitt
  • Daniel Silverstone
  • Andy Simpkins
  • Neil Williams

  •        

    Sunday, 12 June 2011

    How to not embarrass yourself with missing attachments in mutt

    I keep on seeing people sending messages saying "see attached file" or similar in their emails, but then forgetting to actually attach the file. I used to do it myself lots, but then with the help of some ideas I found on the net I wrote the following script to use with mutt. To use it, use the setting "set sendmail=" to point at it.


    #!/bin/bash
    #
    # mutt-sendmail
    # helper script to reduce embarrassment with mutt :-)
    #
    # Copyright 2011 Steve McIntyre 
    # GPL v2
    
    ###
    # save msg in file to re-use it for multiple tests
    ###
    TMPFILE=`mktemp -p ~/tmp -t mutt.XXXXXX` || exit 2
    cat > $TMPFILE
    
    ## Attachment keywords that the message body will be searched for:
    KEYWORDS='attach|patch'
    
    ## Define test for multipart message.
    function multipart {
        grep -q '^Content-Type: multipart' "$TMPFILE"
    }
    
    ## Define test for keyword search.
    function word-attach {
        grep -v '^>' "$TMPFILE" | grep -v "^X-attached:" | grep -E -i -q "$KEYWORDS"
    }
    
    ## Header override.
    function header-override {
        grep -i -E "^X-attached: *none *$" "$TMPFILE"
    }
    
    ###
    # FINAL DECISION:
    # chain series of functions, use ! || && for logic connections,
    ###
    if multipart || ! word-attach || header-override; then
        formail -I bcc < $TMPFILE | /usr/lib/sendmail -oi -oem "$@"
        status=$?
    else
        echo "No file was attached but a search of the message text suggests there"
        echo "should be one.  Add a header \"X-attached: none\" to override this"
        echo "check if no attachment is intended."
        status=1
    fi
    rm -f $TMPFILE
    exit $status
    
    

    15:31 :: # :: /debian/mutt :: 6 comments

    Comments

    Re: How to not embarrass yourself with missing attachments in mutt
    Paul Csanyi wrote on Fri, 28 Dec 2012 06:42

    OK, the script works but then in Mutt, how can I actually add the header X-attached: none ??


    Reply

    Your Comment

     
    Name:
    URL/Email: [http://... or mailto:you@wherever] (optional)
    Title: (optional)
    Comment:
    Anti-spam:Select the first of the following words and enter it in the "Human" box
    creaks crack chi casino courting casing crevice colleens collier cramped
    Human:
    Save my Name and URL/Email for next time