On Mon, Jul 1, 2013 at 10:04 PM, Noel Jones <[email protected]> wrote:

> On 7/1/2013 1:09 PM, Daniel L. Miller wrote:
> > On 6/28/2013 4:34 PM, Noel Jones wrote:
> >> On 6/28/2013 5:39 PM, Daniel L. Miller wrote:
> >>> Does anyone know of a tool that will let me modify the subject line
> >>> of all emails that pass through it?  I would call it via a transport
> >>> map.
> >>>
> >>> My application - we just switched to a new email-to-fax service.  As
> >>> part of their security implementation (THEIRS, not mine!) they
> >>> require all emails sent to them to contain our own fax number.  I
> >>> want to automate this step so I don't have to hear from my users.
> >>>
> >>
> >> http://www.postfix.org/postconf.5.html#smtp_header_checks
> >>
> >> Add this to master.cf something like this:
> >> (or if you already use a custom master.cf transport, add the -o
> >> override to that entry)
> >>
> >> # master.cf
> >> # fax_service is a copy of the smtp...smtp transport
> >> fax_service ... smtp
> >>    -o smtp_header_checks=pcre:/etc/postfix/smtp_fax_header
> >>
> >> # smtp_fax_header
> >> /^Subject: / REPLACE Subject: fax from 555-1212
> >>
> >
> > That ALMOST works - thanks!  The problem - I have to have SOMETHING
> > in the subject otherwise it doesn't happen with this matching rule.
> > Is it possible to ADD a Subject: header when none is present?
> >
>
>
> Postfix header_checks cannot detect a missing header.  To add a
> Subject: header when it's missing requires a milter or content
> filter of some type.
>
> Since this isn't real email, it might be sufficient to always add a
> Subject header, even if one already exists.  And maybe throw away
> the existing Subject too.
>
> I'm pretty sure postfix will only add one header, despite this rule
> matching multiple headers. If it does add multiple headers, you can
> try matching /^Message-ID: / or /^From: /, but those aren't required
> headers either and may not always be present (or just ignore the
> ugliness -- multiple identical Subject: headers probably won't break
> anything).
>
> Order doesn't matter here, header_checks won't delete a header added
> by itself.
>
> # smtp_fax_header
> # delete existing subject line, if any
> /^Subject: /  IGNORE
> # add a subject line
> /^/  PREPEND Subject: fax from ......
>
>
>
>
>   -- Noel Jones
>

I guess you need to configure a different SMTP for that fax destination
(based on transport maps) and pass the email to a script which should
modify your fax messages addressed to @fax-provider and reinject the
message back to postfix:
sed "s/^Subject:\(.*)/^Subject:\1 text-for fax here/" || awk '/^To:/ {print
"Subject: text-for fax here"}1;'

If there is a subject, sed will modify it. If sed fails in finding and
replacing the pattern, awk will insert a Subject line above To.

Reply via email to