Using Procmail to *modify* MIME Attachments

Posted on 2006-07-21
Last Modified: 2013-12-16
I want to use procmail to MODIFY an incoming MIME attachment.  Specifically, I want to rewrite .ics attachments from Apple iCal so they can be read by Microsoft Outlook.

I can set up the procmail recipes to detect the matching email, but I haven't been able to find examples of how I can MODIFY attachments (detach, modify, re-attach), so the resulting MIME email is still valid.  Because the content is encoded, I don't want to process the raw MIME data, but want to use some MIME scripts to process the attachments.

Does anyone have examples doing this kind of procmail-based transcoding of attachments?  I've heard of people deleting attachments, but I actually want to modify them.

Question by:todd_e_bryant
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 22

Expert Comment

ID: 17159745
Outlook 2003 can 'import' ics documents, but this is a fairly complex process, and not really suited to Procmail!

However, the ability to 'strip out' attachments and 'rebuild' the email \can be done with a utility called reformime:

This is the tool I use to extract attachments from emails in order to AV scan them, before they are allowed to be passed on.

(   (()
(`-' _\
 ''  ''

Author Comment

ID: 17160622
Thanks pjedmond,

This looks like an interesting tool.  As I understand it, it allows you to copy different attachments from the MIME email message to standard output, or to a file.

But, I'm not completely clear how to reassemble a new message, containing a modified attachment.

My mission is to:

(1) Pull out the .ics iCalendar attachment from an incoming event notification email using procmail and other tools.
(2) Rewrite the .ics file to make Apple iCal invites compatible with Outlook 2003 (basically changing timezone formats)
(3) Replace the email with a new email that is identical, except it has the new .ics file attachment.
(4) The modified email gets dumped into my IMAP folder and read by Outlook normally.

It looks like I can get the .ics attachment using the -e option.  But I'm unclear if this helps me recreate a new MIME email message that contains the new attachment, or if I have to do that from scratch?

Thoughts if this might be relevant to my mission!
LVL 22

Accepted Solution

pjedmond earned 250 total points
ID: 17160947
I'm sure that I wil be corrected on this, but as far as I'm aware, if you modify a 'mime' attachment and put it back in, the email becomes invalid due to the various 'hashes that exist. You would have to use 'reformime' to take the email completely to pieces, and then rebuild it from scratch. Many MTAs, including Sendmail support the 'putting back together process'.

Due to the complexity of what you are trying to do, I think that you need to look at the mechanism used for delivery of mail, and then use a Perl script of some sort to take the mime attachments apart completely. MIME-tools appears to fit the bill for taking apart and rebuilding the email completely.

(   (()
(`-' _\
 ''  ''

Author Comment

ID: 17160997

The MIME-tools package looks interesting.  Better yet, it's in perl, so I don't have to have any compilation struggles.  I'm going to give this a try, and give you the points for this recommendation.

I'm not sure that most MIME messages have checksums/hashes (I think MIME usually has well-defined text strings to define partitions between entities in most cases), but there may well be special cases and magic headers I need to worry about.  Hopefully MIME-tools will hide most of these details from me!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apache LDAP Authentication 20 52
Redhat upgrade 1 48
Unix Help with:  mailx -s 17 57
exchange, squid, proxy, linux 6 34
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question