procmail
[Top] [All Lists]

Re: Procmail and attachments

1996-12-06 22:56:54
o Jason Tang had asked for a method of decoding mime base64-encoded emails.

o The Doctor(_at_)netcom(_dot_)com provided the following procmail script:
    :0 HBw
    * ^Content-Transfer-Encoding:.*base64
    {
            :0 cw
            | munpack
    
            :0 Hhw
            | formail -zcI"Status: O" -I"X-Unpacked: to Mail" >>$DEFAULT
    }

I tried to understand this succinct script, and, well, er, this is the best 
I can interpret it so far. Can anyone correct my explanation below?

Summary, I think:
 +-----------------------------------------------------------------------+
 | Automatically decode all mime base64-encoded emails _before_ they get |
 | to your mail spool directory and send to your spool directory _only_  |
 | the tiny mail header information along with special additional header |
 | lines informing you that the original message contained an attachment |
 | which was automatically decoded into your default decoding location.  |
 +-----------------------------------------------------------------------+
 (This is the first time I've seen "formail" without a pipe to "$SENDMAIL" 
  in a procmail script.)

More specifically, the script, I believe, translate directly into:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
o Begin a recipe & filter based on data in both the header and body (:0 HB),
o Wait for the filter to finish, and check its exit code for errors (w)
  before processing the next email (even if the next email arrives before
  this filter is finished),
o Begin a condition (*),
o Look for a line starting with "Content-Transfer-Encoding:" followed
  by any character (.), and any number of those characters (*) and 
  then the word "base64" (^Content-Transfer-Encoding:.*base64),
o Begin a nesting block ({) where everything up till the closing brace will
  depend on the conditions specified for this recipe,
o Search the header of the message (:0),
o Generate a carbon copy of the message by cloning the running procmail 
  process and allowing the parent to jump across the nesting block (c), 
  (huh?)
o Again, wait for the filter to finish (the w flag prevents any lockfile from 
  being removed before the work is done and therefore is a simple way of 
  keeping your mailfile from being trashed),
o Pipe the message to the UNIX command "munpack" (| munpack),
o Begin another recipe and feed just the header (not the body) to the 
  upcoming pipe, including a blank line delimiting the header (:0 Hh),
o Wait for this to finish, and check its exit code for errors (w),
o Send just this header to the UNIX command "formail", passing 
  formail additional header lines stating the mail was decoded
  (-zcI"Status: O" -I"X-Unpacked: to Mail" >>$DEFAULT") where $DEFAULT is 
  typically your mail spool file /var/spool/mail/yourLogin or, on Solaris, 
  /var/mail/yourLogin. 
o Note: The closing brace exists merely to delimit the block (}).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Is this interpretation correct? Where is it lacking?

Thanks,
John

<Prev in Thread] Current Thread [Next in Thread>
  • Re: Procmail and attachments, John Gianni <=