Search code examples
linuxemailprocmailfetchmail

Procmail/munpack: Extracting headers similar to text and attachments?


I currently have set up fetchmail to transfer mail to procmail and a .procmailrc file with the following content:

FILE_DIR=$HOME/incoming
:0
* 
| munpack -q -C "$FILE_DIR"

If I receive emails with attachments, munpack will create a file123.ext and a file123.desc, the latter containing the text of the email. However, the headers are lost. Is there a way to save the headers of the email to a file123.headers file or something like that or, better yet, make munpack save the whole message - including headers - in the .desc file?


Solution

  • You can easily save the headers separately, but of course you can't predict which file name munpack will assign to the extracted message.

    :0hc
    headers
    
    :0
    | munpack -q -C "$FILE_DIR"
    

    This simply writes the headers to headers. Perhaps you could add some logic around this to create a new directory for each incoming message, or something like that.

    (Notice also how you simply omit the condition line if you want to deliver unconditionally.)

    Maybe a better solution would be to switch to a tool which extracts the headers as well. I vaguely recall ripmime would be somewhat more flexible than munpack.