Discussion:
Modifying body content before delivering
(too old to reply)
Alex
2010-05-19 11:50:21 UTC
Permalink
Hi,

Where can I go to find information on how to modify the content of the
body of an email before delivering?

I would like to experiment with changing "curse words" or removing
URLs like "<a href=....>" ?

I realize there are all kinds of problems with doing this, such as
modifying the signature and size of messages, but it's acceptable
tradeoff for now.

I'd really like to be able to do this with a perl script rather than
having to install some additional program like amavisd. Maybe
something like alterMIME?

Thanks,
Alex
Noel Jones
2010-05-19 12:37:21 UTC
Permalink
Post by Alex
Hi,
Where can I go to find information on how to modify the content of the
body of an email before delivering?
I would like to experiment with changing "curse words" or removing
URLs like "<a href=....>" ?
I realize there are all kinds of problems with doing this, such as
modifying the signature and size of messages, but it's acceptable
tradeoff for now.
I'd really like to be able to do this with a perl script rather than
having to install some additional program like amavisd. Maybe
something like alterMIME?
Thanks,
Alex
You can use smtp_header_checks and smtp_body_checks with the
REPLACE action to make minor changes to mail content during
delivery. These are rather simple tools by design, best
suited for easily defined transformations.

IIRC altermime is better suited for removing attachments or
adding disclaimers. I don't think it will help with replacing
words or URLs.

There are some regexp based milters that may give you more
control.

Enjoy your experiment, but in the end you're much better off
rejecting messages with content you don't like rather than
trying to fix it.


-- Noel Jones
Alex
2010-05-19 20:30:52 UTC
Permalink
Hi,
You can use smtp_header_checks and smtp_body_checks with the REPLACE action
to make minor changes to mail content during delivery.  These are rather
simple tools by design, best suited for easily defined transformations.
Thanks for the notes. If I were to do it the right way, how would I go about it?

Is it possible to strip the entire HTML content and pass only the
text? Perhaps the right way to say it would be to pass only the MIME
text and strip everything else?

Thanks again,
Alex
Noel Jones
2010-05-19 21:39:54 UTC
Permalink
Post by Alex
Hi,
You can use smtp_header_checks and smtp_body_checks with the REPLACE action
to make minor changes to mail content during delivery. These are rather
simple tools by design, best suited for easily defined transformations.
Thanks for the notes. If I were to do it the right way, how would I go about it?
Is it possible to strip the entire HTML content and pass only the
text? Perhaps the right way to say it would be to pass only the MIME
text and strip everything else?
Yes, you can probably do something like that with MIMEDefang.

-- Noel Jones
Jeroen Geilman
2010-05-19 23:08:50 UTC
Permalink
Post by Alex
Hi,
You can use smtp_header_checks and smtp_body_checks with the REPLACE action
to make minor changes to mail content during delivery. These are rather
simple tools by design, best suited for easily defined transformations.
Thanks for the notes. If I were to do it the right way, how would I go about it?
Is it possible to strip the entire HTML content and pass only the
text? Perhaps the right way to say it would be to pass only the MIME
text and strip everything else?
Thanks again,
Alex
I found this fantastic little util called "mailtextbody" - it does just
that: strips off all non-text parts and leaves a clean, text-only message.
Really, content processing should be left to non-MTA programs.
Ansgar Wiechers
2010-05-20 07:31:17 UTC
Permalink
Post by Jeroen Geilman
Post by Alex
Is it possible to strip the entire HTML content and pass only the
text? Perhaps the right way to say it would be to pass only the MIME
text and strip everything else?
I found this fantastic little util called "mailtextbody" - it does
just that: strips off all non-text parts and leaves a clean,
text-only message.
Sounds interesting, but how does it handle html-only mails (i.e. mails
with no text/plain MIME part) or mails that are declared text/plain, but
contain HTML nonetheless?

Regards
Ansgar Wiechers
--
"Abstractions save us time working, but they don't save us time learning."
--Joel Spolsky
Jeroen Geilman
2010-05-21 19:33:51 UTC
Permalink
Post by Ansgar Wiechers
Post by Jeroen Geilman
Post by Alex
Is it possible to strip the entire HTML content and pass only the
text? Perhaps the right way to say it would be to pass only the MIME
text and strip everything else?
I found this fantastic little util called "mailtextbody" - it does
just that: strips off all non-text parts and leaves a clean,
text-only message.
Sounds interesting, but how does it handle html-only mails (i.e. mails
with no text/plain MIME part) or mails that are declared text/plain, but
contain HTML nonetheless?
Regards
Ansgar Wiechers
Good point ;)

Mail that does not contain a text-only representation of the content may
safely be dropped, since it violates the RFCs.

Malformed messages (yes, I'm looking at you M$ Outhouse) are anotehr
matter, and will almost always cause problems - anywhere.

I'm not saying "use this, it's foolproof".

I am saying I found it, it does what it advertises, it's simple, and a
lot less hassle to configure and maintain than the various MIME* solutions.

One possible application (one we use it for, incidentally) would be to
strip out the mailtextbody and send it over a smaller medium, such as
SMS or Twitter, and keep the original mail separately.

YMMV

Gr.,

J.
Victor Duchovni
2010-05-21 19:45:55 UTC
Permalink
Post by Jeroen Geilman
Mail that does not contain a text-only representation of the content may
safely be dropped, since it violates the RFCs.
This is false. No RFC requires a text/plain message body.
--
Viktor.

P.S. Morgan Stanley is looking for a New York City based, Senior Unix
system/email administrator to architect and sustain our perimeter email
environment. If you are interested, please drop me a note.
Continue reading on narkive:
Loading...