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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now