Loading ...
Sorry, an error occurred while loading the content.

Modify subject based on recipient

Expand Messages
  • Daniel L. Miller
    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 -
    Message 1 of 13 , Jun 28, 2013
    • 0 Attachment
      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.

      --
      Daniel
    • Noel Jones
      ... 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,
      Message 2 of 13 , Jun 28, 2013
      • 0 Attachment
        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




        -- Noel Jones
      • Daniel L. Miller
        ... 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
        Message 3 of 13 , Jul 1 11:09 AM
        • 0 Attachment
          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?

          --
          Daniel
        • Jeroen Geilman
          ... Again, in header_checks: ! /^Subject:/ Subject: This message had no subject so I m adding one. -- J.
          Message 4 of 13 , Jul 1 11:15 AM
          • 0 Attachment
            On 07/01/2013 08: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?
            >
            Again, in header_checks:

            ! /^Subject:/ Subject: This message had no subject so I'm
            adding one.



            --
            J.
          • Jeroen Geilman
            ... Oops - would that add a Subject header for every header that isn t Subject ? -- J.
            Message 5 of 13 , Jul 1 11:16 AM
            • 0 Attachment
              On 07/01/2013 08:15 PM, Jeroen Geilman wrote:
              > On 07/01/2013 08: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?
              >>
              > Again, in header_checks:
              >
              > ! /^Subject:/ Subject: This message had no subject so I'm
              > adding one.
              >
              >
              >

              Oops - would that add a Subject header for every header that isn't Subject ?


              --
              J.
            • Daniel L. Miller
              ... Yes it does! Not quite what I m looking for... -- Daniel
              Message 6 of 13 , Jul 1 11:20 AM
              • 0 Attachment
                On 7/1/2013 11:16 AM, Jeroen Geilman wrote:
                > On 07/01/2013 08:15 PM, Jeroen Geilman wrote:
                >> On 07/01/2013 08: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?
                >>>
                >> Again, in header_checks:
                >>
                >> ! /^Subject:/ Subject: This message had no subject so I'm
                >> adding one.
                >>
                >>
                >>
                >
                > Oops - would that add a Subject header for every header that isn't
                > Subject ?
                >
                >
                Yes it does! Not quite what I'm looking for...

                --
                Daniel
              • Noel Jones
                ... 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
                Message 7 of 13 , Jul 1 12:04 PM
                • 0 Attachment
                  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
                • Marius Gologan
                  ... 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
                  Message 8 of 13 , Jul 1 12:22 PM
                  • 0 Attachment
                    On Mon, Jul 1, 2013 at 10:04 PM, Noel Jones <njones@...> 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.
                  • Wietse Venema
                    Noel Jones: [Setting the subject to fax from 555-1212 ] ... It s easy enough to ignore existing Subject: lines, but adding exactly one requires care. The bad
                    Message 9 of 13 , Jul 1 12:51 PM
                    • 0 Attachment
                      Noel Jones:
                      [Setting the subject to "fax from 555-1212"]
                      > 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).

                      It's easy enough to ignore existing Subject: lines, but adding
                      exactly one requires care. The bad news is that PREPEND action (in
                      access, header_checks, body_checks) will prepend text for each match.

                      Adding text once robustly requires changes to Postfix, without
                      entering the slippery slope that ends with a Turing-complete language.

                      Of all the alternatives that I could think of, EOH pseudo pattern,
                      match count options in the regexp/pcre implementation, the only
                      change that seems reasonably implementable is to apply header_checks
                      to an empty line to signal the end of the message header (which
                      means Postfix would have to supply this line when none exists).

                      /^$/ PREPEND Subject: fax from 555-1212

                      Then, new safety code would have to be added so that REPLACE, IGNORE,
                      etc., won't remove an existing blank line from the input stream.

                      Wietse
                    • Noel Jones
                      ... Maybe a PREPENDONCE action that only fires once per message? At any rate, this new feature doesn t seem to be worth spending much time on. -- Noel Jones
                      Message 10 of 13 , Jul 1 1:57 PM
                      • 0 Attachment
                        On 7/1/2013 2:51 PM, Wietse Venema wrote:
                        > Noel Jones:
                        > [Setting the subject to "fax from 555-1212"]
                        >> 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).
                        >
                        > It's easy enough to ignore existing Subject: lines, but adding
                        > exactly one requires care. The bad news is that PREPEND action (in
                        > access, header_checks, body_checks) will prepend text for each match.
                        >
                        > Adding text once robustly requires changes to Postfix, without
                        > entering the slippery slope that ends with a Turing-complete language.
                        >
                        > Of all the alternatives that I could think of, EOH pseudo pattern,
                        > match count options in the regexp/pcre implementation, the only
                        > change that seems reasonably implementable is to apply header_checks
                        > to an empty line to signal the end of the message header (which
                        > means Postfix would have to supply this line when none exists).
                        >
                        > /^$/ PREPEND Subject: fax from 555-1212
                        >
                        > Then, new safety code would have to be added so that REPLACE, IGNORE,
                        > etc., won't remove an existing blank line from the input stream.
                        >
                        > Wietse
                        >


                        Maybe a PREPENDONCE action that only fires once per message? At any
                        rate, this new feature doesn't seem to be worth spending much time on.



                        -- Noel Jones
                      • LuKreme
                        ... Perhaps procmail/formail then (with procmail is easiest) ... * ^TO_faxservice@faxcompany .com { ... } I invoke procmail like this /etc/postfix/main.cf
                        Message 11 of 13 , Jul 1 2:33 PM
                        • 0 Attachment
                          On 01 Jul 2013, at 12:09 , Daniel L. Miller <dmiller@...> 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?

                          Perhaps procmail/formail then

                          (with procmail is easiest)

                          :0
                          * ^TO_faxservice@faxcompany\.com
                          {
                          SUBJECT=|formail-xSubject:

                          :0 hfw
                          | formail -i "Subject: 555-1234 $SUBJECT"
                          }


                          I invoke procmail like this

                          /etc/postfix/main.cf
                          virtual_transport = procmail

                          /etc/postfix/master.cf
                          procmail unix - n n - - pipe -o
                          flags=uhFORD
                          user=vpopmail argv=/usr/local/bin/procmail -t -m USER=${recipient} EXTENSION=${extension} /usr/local/etc/procmailrc.common

                          But it shouldn't be much of a trick to fire it with a custom recipe file on the outbound mail. It might be a little expensive, however.

                          --
                          Stone circles were common enough everywhere in the mountains. Druids
                          built them as weather computers, and since it was always cheaper to
                          build a new 33-Megalith circle than to upgrade an old slow one, there
                          were generally plenty of ancient ones around --Lords and Ladies
                        • Wietse Venema
                          ... This is what I call match counts, and rejected for the following reason. How would this be implemented with Postfix lookup tables? There is no interface
                          Message 12 of 13 , Jul 1 2:59 PM
                          • 0 Attachment
                            Noel Jones:
                            > > It's easy enough to ignore existing Subject: lines, but adding
                            > > exactly one requires care. The bad news is that PREPEND action (in
                            > > access, header_checks, body_checks) will prepend text for each match.
                            > >
                            > > Adding text once robustly requires changes to Postfix, without
                            > > entering the slippery slope that ends with a Turing-complete language.
                            > >
                            > > Of all the alternatives that I could think of, EOH pseudo pattern,
                            > > match count options in the regexp/pcre implementation, the only
                            > > change that seems reasonably implementable is to apply header_checks
                            > > to an empty line to signal the end of the message header (which
                            > > means Postfix would have to supply this line when none exists).
                            > >
                            > > /^$/ PREPEND Subject: fax from 555-1212
                            > >
                            > > Then, new safety code would have to be added so that REPLACE, IGNORE,
                            > > etc., won't remove an existing blank line from the input stream.
                            >
                            > Maybe a PREPENDONCE action that only fires once per message? At any
                            > rate, this new feature doesn't seem to be worth spending much time on.

                            This is what I call match counts, and rejected for the following
                            reason. How would this be implemented with Postfix lookup tables?
                            There is no interface in Postfix such that the table lookup routine
                            (regexp, cidr map, hash table, SQL lookup) can know what the
                            lookup result will be used for, let alone that a right-hand-side
                            action has already been used. There also is no interface in Postfix
                            such that the right-hand-side action routine can tell the table
                            lookup routine (regexp, cidr map, hash table, SQL lookup, ...) to
                            skip a match.

                            There is no such conflict with the empty-line (or EOH) header event.
                            Apart from that, neither the empty line nor the EOH pseudo event
                            generalizes to end-of-body conditions.

                            Wietse
                          • Gaby L
                            I resolve same problem: 1 Use header checks in main.cf header_checks=regexp:/etc/postfix/header_checks 2. Edit and map header_checks file with line:
                            Message 13 of 13 , Jul 2 1:22 AM
                            • 0 Attachment
                              I resolve same problem:
                               
                              1 Use header checks in main.cf
                                 header_checks=regexp:/etc/postfix/header_checks
                              2. Edit and map header_checks file  with line:
                                  /^Subject:.*(fax...)/  FILTER filter_fax:dummy
                              3.Edit master.cf with filter_fax line:
                                 filter_fax   unix   -       n        n      -       15      pipe
                                   flags=Rq user=faxfilter null_sender=
                                  argv=/var/spool/filter/faxfilter -f fax@... -- ${recipient}
                              4.Create one user for filter files
                              5.Create faxfilter file owned by create user in /var/spool/filter
                              6.Edit faxfilter file with
                                 sed -e 's/^From:.*/From:<fax@...>/g' -e 's/^Subject:.*fax....../Subject:Fax newname/g' in.$$ | $SENDMAIL "$@"
                               
                              The key for solve this problem is the sed command,this is command for best replace
                               
                              Gaby 
                            Your message has been successfully submitted and would be delivered to recipients shortly.