Extract Email Attachments With Procmail and Munpack

I regularly use the Marquette University PrintWise Canon copiers to scan paper documents into PDF files. These files are delivered to me via email where I manually save each PDF attachment, rename it, and move it to the appropriate directory. Using Procmail and Munpack, I was able to eliminate some of the tedium of this problem.

I inserted the following block of code into my .procmailrc file. It looks for emails that were sent from me and to me by a Canon copier. When it finds one, it copes the email and pipes it to Munpack which extracts the attachments into my attachments directory.

ATTACH=`echo $HOME/attachments`
:0 c
* ^To:.*[email protected]
* ^From:.*[email protected]
* ^X-Mailer: Canon imageRUNNER
| munpack -q -C $ATTACH

After the attachment has been extracted, I can rename it and move it to the appropriate directory, and I still receive the email in my inbox so I know I have attachments to deal with.