Mailing List Archive

Remove & Replace Message Body Content
Hello,

I would like to create a filter that removes and replaces all HTML
hyperlinks in received messages.  In doing some initial testing, I made
the following conditional filter to test how Exim processes the
$message_body variable:

*if $message_body contains "href="**
**then**
**    headers add "X-Links: Yes"**
**endif*

However, it appears that the $message_body variable doesn't analyze the
source HTML of the message, but instead just looks at the plain text
produced by the HTML output.  Is Exim capable of analyzing the source
HTML of a message and then when certain criteria is matched, replacing
those parts of the message before delivery?

HTML Message Example:

*<html>**
**<head>**
**<meta charset="utf-8">**
**<title>Untitled Document</title>**
**</head>**
**
**<body>**
**    <a href="http://www.example.com">my-link</a>**
**</body>**
**</html>*

Thanks for any guidance,

Patrick


--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Remove & Replace Message Body Content [ In reply to ]
On 02/10/2020 17:26, Patrick Porteous via Exim-users wrote:
> However, it appears that the $message_body variable doesn't analyze the
> source HTML of the message, but instead just looks at the plain text
> produced by the HTML output.  Is Exim capable of analyzing the source
> HTML

No. $message_body is the raw body content. You probably had
a mime multipart message, with both text and HTML alternate
parts. You'd be having to use a MIME ACL to pull those apart.

You're getting into a world of complexity here.
--
Cheers,
Jeremy

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Remove & Replace Message Body Content [ In reply to ]
Hi, Patrick -

I'll chip in with my usual caution of: Be careful! Doing this will
invalidate any digital signatures that the incoming message has been signed
with.

If you're planning to do this only for locally originated messages being
created by MUAs, or for messages for local delivery that have already
passed your anti-spam measures, then you might get away with it. But if
they're messages your other MTAs have created and signed, or are messages
you might be forwarding on to one of your user's onward addresses, then
you're going to cause problems — by breaking its digital signature you
could make the onward copy undeliverable as many sites check DKIM
signatures now as they receive an email.

Cheers,
Mike B-)

On Fri, 2 Oct 2020 at 17:34, Patrick Porteous via Exim-users <
exim-users@exim.org> wrote:

> Hello,
>
> I would like to create a filter that removes and replaces all HTML
> hyperlinks in received messages. In doing some initial testing, I made
> the following conditional filter to test how Exim processes the
> $message_body variable:
>
> *if $message_body contains "href="**
> **then**
> ** headers add "X-Links: Yes"**
> **endif*
>
> However, it appears that the $message_body variable doesn't analyze the
> source HTML of the message, but instead just looks at the plain text
> produced by the HTML output. Is Exim capable of analyzing the source
> HTML of a message and then when certain criteria is matched, replacing
> those parts of the message before delivery?
>
> HTML Message Example:
>
> *<html>**
> **<head>**
> **<meta charset="utf-8">**
> **<title>Untitled Document</title>**
> **</head>**
> **
> **<body>**
> ** <a href="http://www.example.com">my-link</a>**
> **</body>**
> **</html>*
>
> Thanks for any guidance,
>
> Patrick
>
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>


--
*My normal working days are Tuesdays, Wednesdays and Thursdays.*

Systems Administrator working in Teaching & Learning
IT Services, University of York, Heslington, York YO10 5DD, UK
Tel: +44-(0)1904-323811
Email Disclaimer: www.york.ac.uk/about/legal-statements/email-disclaimer/

Web: www.york.ac.uk/it-services
Disclaimer: www.york.ac.uk/docs/disclaimer/email.htm
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/