Solved

Using Procmail to *modify* MIME Attachments

Posted on 2006-07-21
4
1,102 Views
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.

Wisdom?
0
Comment
Question by:todd_e_bryant
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:pjedmond
Comment Utility
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:

http://www.courier-mta.org/?reformime.html

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.

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

Author Comment

by:todd_e_bryant
Comment Utility
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!
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 250 total points
Comment Utility
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.

http://www.zeegee.com/code/perl/MIME-tools/

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

Author Comment

by:todd_e_bryant
Comment Utility
pjedmond,

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!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

771 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