Solved

Using Procmail to *modify* MIME Attachments

Posted on 2006-07-21
4
1,108 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
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:

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

Accepted Solution

by:
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.

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

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

Author Comment

by:todd_e_bryant
ID: 17160997
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access_log 17 119
AWS CLI - Issue with name display 2 71
nagios 4 php error after installation 6 90
how to print sub line with  sed /awk /perl in bash file 11 23
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 …
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
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.

785 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