In a scenario on which we have a local network with Outlook/Thunderbird clients and sendmail on a Linux server: it is possible to use some sendmail's milter to modify the incoming mail to add the signature of the sender to the mail he/she sends? it may be useful to centralize the signatures in the server.

The steps would be something like this:

1) The user composes a mail and sends it. The MUA set some "signature" magic text to be replaced later, i.e.: "x-replace-signature-x", so the MUA must be configured to add that signature on the place the user wants (below the quoted text or below the reply)

2) Mail arrives to sendmail's MSP queue

3) Sendmail takes the user name from the "From" header, i.e. user1@domain.tld

4) Sendmail looks in the filesystem for the signature of that user in html (with possibly embedded images), i.e. /var/lib/sendmail/signatures/user1.html

5) The milter looks for "x-replace-signature-x" and replaces that line with the contents of /var/lib/sendmail/signatures/user.html

6) sendmail's MTA sends out the mail (in my case to a smarthost).

I don't know such capability, so that's why I'm thinking about a milter with regex match.

  • 2
    You could do this with e.g. MIMEDefang but I'm not sure the complexity and potential for bugs is worth the benefit of some sort of centralized signature thingy. – thrig Feb 25 '17 at 17:01

As suggested by @thrig, MIMEDefang is the way to go, heavy duty but well worth the effort IMHO.

Within filter_end() most people will use one of the functions:

append_text_boilerplate($entity, $boilerplate, $all)  
append_html_boilerplate($entity, $boilerplate, $all)  

though these append text rather than replace it. To do exactly what you specify you could use the filter_part() handler. One way to do this is to call action_external_filter() on the part(s) you want to modify (the first text/plain and text/html parts with no MIME disposition are usually a good bet). This filters the part through an external command. To add images to HTML you'll need to add those as new parts, then refer to them (by CID).

The normal way to modify a message though is to call replace_entire_message() in filter_end().This is not as simple as it sounds, you will need to copy the current message as a MIME::Entity, modify the part body, and replace the entire message body with a new MIME::Entity.

This should get you started: https://stuff.mit.edu/~jik/software/mailman_mimedefang/

Alternatively, a low-tech solution would be to have sendmail spool (-odd deferred delivery) instead of immediate delivery, modify the queued df file (treating it as plaintext may work sometimes, but to be thorough you need to treat it as MIME), move the qf/df pair to a new normally run spool (with re-mqueue.pl perhaps).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.