views:

82

answers:

3

Hi,

I am looking for a solution that will enable me to connect to a mailbox, obtain an email, apply specific modifications to the email body (for example, change the content), and then forward the newly modified email to a new email address. The trick is that such modification must not destroy the format and headers of the original email and I must not lose any attachments that were in the original email.

The sort of manipulation that will be performed will need to be done by an external process that knows the logic of my application.

The solution I am looking for can be an external software that can invoke some API for processing the content of the emails, or even API by itself that my code will invoke.

Our solution is currently based on PHP, but any other solution is also acceptable.

I started working with the Zend Mail library but I am running into problem having to understand the inner-workings of email formats. I wouldn't want to start messing around with the mime objects in the email format. I only want to alter the textual content of the message and keep the rest untouched.

A: 

http://php.net/manual/en/book.imap.php - functions that let you manipulate email systems.

Galen
I know. But using it I must handle all the MIME parsing by myself. It is way too risky and complicated. I want something that can easily let me grab just the text or HTML body of the message, change it and forward the message to somewhere else, while any other property of the message is left untouched.
sagi
A: 

What mail server are you using? In qmail its easy to process any incomming email. You can put any script in any language to process the lines of the email.

If you have IMAP access to your server you can use the php IMAP lib. http://www.php.net/manual/en/book.imap.php

Carlos
A: 

I wrote a library as part of a larger open source app that may help you a bit. Its an object orientated wrapper around the PHP imap functions and can be found at google code.

Unfortunately this doesn't do exactly what you want. What in the message are you trying to change? I may be possible to just grab a raw version and specifically search out what you want to change, ignoring the whole mimetype processing altogether, and then just send the whole message along again.

Resending the email is simple enough, and this (small tutorial)* on sending email with attachments can refresh you on the basics (although most of what is in there you can skip as the attachments and mimetypes will already be built).

* I can't post the link because my reputation isn't high enough for two links in a single post, so I'll add it in a comment.

tedivm
The tutorial is here - http://www.webcheatsheet.com/php/send_email_text_html_attachment.php
tedivm