Content filter - reijnect message back into queue

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Content filter - reijnect message back into queue

Rafael Azevedo-4
Hi there,

I'm trying to build my own content filter so I can actually filter outgoing messages and take appropriated actions upon spam messages.

After some time I was able to make postfix send messages to the content filter.

The documentation says that content_filter expects a "transport:maps" response.

The content_filter configuration parameter expects a value of the form transport:destination. The transport name specifies the first field of a mail delivery agent definition in master.cf; the syntax of the next-hop destination is described in the manual page of the corresponding delivery agent.

My script just returns "ACCEPT" as the content_filter action.

The thing is that the messages are then gone after the content_filter receives it.

Looking my log files:

Jan  4 13:58:19 lab postfix/pipe[2025749]: 193EA13DB044: to=<xxx@xxx>, orig_to=<xxx@xxx>, relay=post_queue_content_filter, delay=0.11, delays=0.09/0/0/0.02, dsn=2.0.0, status=sent (delivered via post_queue_content_filter service (action=PERMIT))

After that, the message is gone.

So I kindly ask you guys how can I re-inject message back into queue.

Another question is how to postpone a specific message when re-injecting it to queue. For example: the filter will accept the message but hold it for 5 minutes before delivering it to final destination.


smtp      inet  n       -       n       -       30      smtpd
  -o content_filter=post_queue_content_filter:dummy 
 
post_queue_content_filter    unix    -       n       n       -       -       pipe
        user=iagente argv=/home/postfix/app/tools/contentFilter.php
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Note that I've added at the last line a sendmail call. That was copied from another server running spamassassin (which ijnects message back to queue after content analysis). I'm still trying to understand the right way to do it.

Any help would be much appreciated.

Thanks in advance.

BR,

Rafael
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Viktor Dukhovni


> On Jan 4, 2019, at 11:54 AM, Rafael Azevedo <[hidden email]> wrote:
>
> So I kindly ask you guys how can I re-inject message back into queue.

http://www.postfix.org/FILTER_README.html

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
Hi Viktor,

Thanks for the tip.

I did my best within my knowledges to archive that goal.

After reading that document so many times this was the farther I could go.

Another tip would be much appreciated.

BR,

Em sex, 4 de jan de 2019 às 15:28, Viktor Dukhovni <[hidden email]> escreveu:


> On Jan 4, 2019, at 11:54 AM, Rafael Azevedo <[hidden email]> wrote:
>
> So I kindly ask you guys how can I re-inject message back into queue.

http://www.postfix.org/FILTER_README.html

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Viktor Dukhovni
Viktor,

After doing as explained @ http://www.postfix.org/FILTER_README.html, I'm still having same behavior.

Jan  4 15:23:16 zimuslab postfix/pipe[2026324]: 90FAD13DE3B1: to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07, delays=0.04/0/0/0.02, dsn=2.0.0, status=sent (delivered via post_queue_content_filter service (action=PERMIT))

After changing my script to simply "return" the situation persists.

Jan  4 15:33:27 zimuslab postfix/pipe[2026361]: 7751713DE600: to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07, delays=0.04/0/0/0.02, dsn=2.0.0, status=sent (delivered via post_queue_content_filter service)

BR,
Rafael

Em sex, 4 de jan de 2019 às 15:28, Viktor Dukhovni <[hidden email]> escreveu:


> On Jan 4, 2019, at 11:54 AM, Rafael Azevedo <[hidden email]> wrote:
>
> So I kindly ask you guys how can I re-inject message back into queue.

http://www.postfix.org/FILTER_README.html

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

RE: Content filter - reijnect message back into queue

luistkd4
Try create another postfix instance and force your filter send message to it.



De: [hidden email] <[hidden email]> em nome de Rafael Azevedo <[hidden email]>
Enviado: sexta-feira, 4 de janeiro de 2019 16:21
Para: Postfix users
Assunto: Re: Content filter - reijnect message back into queue
 
Viktor,

After doing as explained @ http://www.postfix.org/FILTER_README.html, I'm still having same behavior.

Jan  4 15:23:16 zimuslab postfix/pipe[2026324]: 90FAD13DE3B1: to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07, delays=0.04/0/0/0.02, dsn=2.0.0, status=sent (delivered via post_queue_content_filter service (action=PERMIT))

After changing my script to simply "return" the situation persists.

Jan  4 15:33:27 zimuslab postfix/pipe[2026361]: 7751713DE600: to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07, delays=0.04/0/0/0.02, dsn=2.0.0, status=sent (delivered via post_queue_content_filter service)

BR,
Rafael

Em sex, 4 de jan de 2019 às 15:28, Viktor Dukhovni <[hidden email]> escreveu:


> On Jan 4, 2019, at 11:54 AM, Rafael Azevedo <[hidden email]> wrote:
>
> So I kindly ask you guys how can I re-inject message back into queue.

http://www.postfix.org/FILTER_README.html

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Wietse Venema
In reply to this post by Rafael Azevedo-4
Rafael Azevedo:
> Looking my log files:
>
> Jan  4 13:58:19 lab postfix/pipe[2025749]: 193EA13DB044: to=<xxx@xxx>,
> > orig_to=<xxx@xxx>, relay=post_queue_content_filter, delay=0.11,
> > delays=0.09/0/0/0.02, dsn=2.0.0, status=sent (delivered via
> > post_queue_content_filter service (action=PERMIT))
>
> After that, the message is gone.

You forgot to send it back into Postfix.

BTW what is that "action=PERMIT" stuff? There is no such feature
with Postfix filters. Are you confusing SMTPD_POLICY_README and
FILTER_README?

> So I kindly ask you guys how can I re-inject message back into queue.

FILTER_README gives multiple examples for doing exactly that. One
approach uses /usr/sbin/sendmail, and one uses SMTP.

SMTPD_POLICY_README is about sending name=value pairs and receiving
a response with action=(PERMIT or some other action).

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
Hi Wietse,

Thanks for your help.

> You forgot to send it back into Postfix.

Would you please tell me how to send it back to POSTFIX ?

> BTW what is that "action=PERMIT" stuff? There is no such feature
> with Postfix filters. Are you confusing SMTPD_POLICY_README and
> FILTER_README?

Yes, I tried to use same syntax of "check_policy_service" but had no success.

Thanks a lot.

BR,

Rafael
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Wietse Venema
Digging on FILTER_README, I've noticed that:

&gt; The content_filter setting has lower precedence than a FILTER
action that is specified in an access(5), header_checks(5) or
body_checks(5) table.

Even using OK, PREPEND, the message could not go back into queue.

JIT:

ACCEPT ACTIONS
       OK     Accept the address etc. that matches the pattern.

       all-numerical
              An  all-numerical result is treated as OK. This format is gener-
              ated  by  address-based  relay  authorization  schemes  such  as
              pop-before-smtp.

       For other accept actions, see "OTHER ACTIONS" below.

REJECT ACTIONS
       Postfix  version 2.3 and later support enhanced status codes as defined
       in RFC 3463.  When no code is specified at the beginning  of  the  text
       below, Postfix inserts a default enhanced status code of "5.7.1" in the
       case of reject actions, and "4.7.1" in the case of defer  actions.  See
       "ENHANCED STATUS CODES" below.

       4NN text

       5NN text
              Reject  the  address  etc. that matches the pattern, and respond
              with the numerical three-digit code and  text.  4NN  means  "try
              again later", while 5NN means "do not try again".

              The  following  responses  have  special meaning for the Postfix
              SMTP server:

              421 text (Postfix 2.3 and later)

              521 text (Postfix 2.6 and later)
                     After responding with the numerical three-digit code  and
                     text,  disconnect immediately from the SMTP client.  This
                     frees up SMTP server resources so that they can  be  made
                     available to another SMTP client.

                     Note: The "521" response should be used only with botnets
                     and other malware where interoperability is  of  no  con-
                     cern.   The  "send  521  and  disconnect" behavior is NOT
                     defined in the SMTP standard.

       REJECT optional text...
              Reject the address etc. that matches  the  pattern.  Reply  with
              "$access_map_reject_code  optional  text..."  when  the optional
              text is specified, otherwise reply with a generic error response
              message.

       DEFER optional text...
              Reject  the  address  etc.  that matches the pattern. Reply with
              "$access_map_defer_code optional text..." when the optional text
              is specified, otherwise reply with a generic error response mes-
              sage.

              This feature is available in Postfix 2.6 and later.

       DEFER_IF_REJECT optional text...
              Defer the request if some later restriction would  result  in  a
              REJECT action. Reply with "$access_map_defer_code 4.7.1 optional
              text..." when the optional text is  specified,  otherwise  reply
              with a generic error response message.

              Prior to Postfix 2.6, the SMTP reply code is 450.

              This feature is available in Postfix 2.1 and later.

       DEFER_IF_PERMIT optional text...
              Defer the request if some later restriction would result in a an
              explicit   or    implicit    PERMIT    action.     Reply    with
              "$access_map_defer_code   4.7.1    optional  text..."  when  the
              optional text is specified, otherwise reply with a generic error
              response message.

              Prior to Postfix 2.6, the SMTP reply code is 450.

              This feature is available in Postfix 2.1 and later.

       For other reject actions, see "OTHER ACTIONS" below.

OTHER ACTIONS
       restriction...
              Apply    the   named   UCE   restriction(s)   (permit,   reject,
              reject_unauth_destination, and so on).

       BCC user@domain
              Send one copy of the message to the specified recipient.

              If multiple BCC actions are specified within the same SMTP  MAIL
              transaction, with Postfix 3.0 only the last action will be used.

              This feature is available in Postfix 3.0 and later.

       DISCARD optional text...
              Claim successful delivery and silently discard the message.  Log
              the optional text if specified, otherwise log a generic message.

              Note: this action currently affects all recipients of  the  mes-
              sage.   To  discard  only  one  recipient without discarding the
              entire message, use the transport(5) table to direct mail to the
              discard(8) service.

              This feature is available in Postfix 2.0 and later.

       DUNNO  Pretend that the lookup key was not found. This prevents Postfix
              from trying substrings of the lookup key (such  as  a  subdomain
              name, or a network address subnetwork).

              This feature is available in Postfix 2.0 and later.

       FILTER transport:destination
              After the message is queued, send the entire message through the
              specified external content filter. The transport name  specifies
              the  first  field  of  a  mail delivery agent definition in mas-
              ter.cf; the syntax of the next-hop destination is  described  in
              the  manual  page  of  the  corresponding  delivery agent.  More
              information about external content filters  is  in  the  Postfix
              FILTER_README file.

              Note  1: do not use $number regular expression substitutions for
              transport or destination unless you know  that  the  information
              has a trusted origin.

              Note  2:  this  action overrides the main.cf content_filter set-
              ting, and affects all recipients of the  message.  In  the  case
              that  multiple  FILTER  actions  fire, only the last one is exe-
              cuted.

              Note 3: the purpose of the FILTER command is to override message
              routing.   To  override  the  recipient's  transport but not the
              next-hop destination, specify an empty filter destination (Post-
              fix  2.7  and  later),  or  specify a transport:destination that
              delivers through a different Postfix instance (Postfix  2.6  and
              earlier). Other options are using the recipient-dependent trans-
              port_maps  or  the  sender-dependent   sender_dependent_default-
              _transport_maps features.

              This feature is available in Postfix 2.0 and later.

       HOLD optional text...
              Place  the  message  on  the hold queue, where it will sit until
              someone either deletes it or releases it for delivery.  Log  the
              optional text if specified, otherwise log a generic message.

              Mail  that is placed on hold can be examined with the postcat(1)
              command, and can be destroyed or released with the  postsuper(1)
              command.

              Note:  use  "postsuper -r" to release mail that was kept on hold
              for  a  significant  fraction  of   $maximal_queue_lifetime   or
              $bounce_queue_lifetime,  or  longer. Use "postsuper -H" only for
              mail that will not expire within a few delivery attempts.

              Note: this action currently affects all recipients of  the  mes-
              sage.

              This feature is available in Postfix 2.0 and later.

       PREPEND headername: headervalue
              Prepend  the specified message header to the message.  When more
              than one PREPEND action executes,  the  first  prepended  header
              appears before the second etc. prepended header.

              Note:  this  action  must  execute before the message content is
              received;   it   cannot    execute    in    the    context    of
              smtpd_end_of_data_restrictions.

              This feature is available in Postfix 2.1 and later.

       REDIRECT user@domain
              After  the  message is queued, send the message to the specified
              address instead of the intended recipient(s).  When multiple RE-
              DIRECT actions fire, only the last one takes effect.

              Note:  this  action  overrides  the FILTER action, and currently
              overrides all recipients of the message.

              This feature is available in Postfix 2.1 and later.

       INFO optional text...
              Log an informational record with  the  optional  text,  together
              with  client  information  and  if available, with helo, sender,
              recipient and protocol information.

              This feature is available in Postfix 3.0 and later.

       WARN optional text...
              Log a warning with  the  optional  text,  together  with  client
              information  and  if available, with helo, sender, recipient and
              protocol information.

              This feature is available in Postfix 2.1 and later.


BR

Rafael
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
Another attempt:

Jan  4 16:39:21 lab postfix/pipe[2026654]: 82B8813DF90D:
to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07,
delays=0.04/0/0/0.03, dsn=2.0.0, status=sent (delivered via
post_queue_content_filter service (action=FILTER localhost:10026))

NOTE:
action=FILTER localhost:10026

The content_filter setting has lower precedence than a FILTER
action that is specified in an access(5), header_checks(5) or
body_checks(5) table.

As described in ACCESS (5):

FILTER transport:destination
              After the message is queued, send the entire message through the
              specified external content filter. The transport name  specifies
              the  first  field  of  a  mail delivery agent definition in mas-
              ter.cf; the syntax of the next-hop destination is  described  in
              the  manual  page  of  the  corresponding  delivery agent.  More
              information about external content filters  is  in  the  Postfix
              FILTER_README file.

              Note  1: do not use $number regular expression substitutions for
              transport or destination unless you know  that  the  information
              has a trusted origin.

              Note  2:  this  action overrides the main.cf content_filter set-
              ting, and affects all recipients of the  message.  In  the  case
              that  multiple  FILTER  actions  fire, only the last one is exe-
              cuted.

              Note 3: the purpose of the FILTER command is to override message
              routing.   To  override  the  recipient's  transport but not the
              next-hop destination, specify an empty filter destination (Post-
              fix  2.7  and  later),  or  specify a transport:destination that
              delivers through a different Postfix instance (Postfix  2.6  and
              earlier). Other options are using the recipient-dependent trans-
              port_maps  or  the  sender-dependent   sender_dependent_default-
              _transport_maps features.

              This feature is available in Postfix 2.0 and later.

What am I missing here?

Thanks!

BR,

Rafael

Em sex, 4 de jan de 2019 às 16:57, Rafael Azevedo <[hidden email]> escreveu:

>
> Digging on FILTER_README, I've noticed that:
>
> &gt; The content_filter setting has lower precedence than a FILTER
> action that is specified in an access(5), header_checks(5) or
> body_checks(5) table.
>
> Even using OK, PREPEND, the message could not go back into queue.
>
> JIT:
>
> ACCEPT ACTIONS
>        OK     Accept the address etc. that matches the pattern.
>
>        all-numerical
>               An  all-numerical result is treated as OK. This format is gener-
>               ated  by  address-based  relay  authorization  schemes  such  as
>               pop-before-smtp.
>
>        For other accept actions, see "OTHER ACTIONS" below.
>
> REJECT ACTIONS
>        Postfix  version 2.3 and later support enhanced status codes as defined
>        in RFC 3463.  When no code is specified at the beginning  of  the  text
>        below, Postfix inserts a default enhanced status code of "5.7.1" in the
>        case of reject actions, and "4.7.1" in the case of defer  actions.  See
>        "ENHANCED STATUS CODES" below.
>
>        4NN text
>
>        5NN text
>               Reject  the  address  etc. that matches the pattern, and respond
>               with the numerical three-digit code and  text.  4NN  means  "try
>               again later", while 5NN means "do not try again".
>
>               The  following  responses  have  special meaning for the Postfix
>               SMTP server:
>
>               421 text (Postfix 2.3 and later)
>
>               521 text (Postfix 2.6 and later)
>                      After responding with the numerical three-digit code  and
>                      text,  disconnect immediately from the SMTP client.  This
>                      frees up SMTP server resources so that they can  be  made
>                      available to another SMTP client.
>
>                      Note: The "521" response should be used only with botnets
>                      and other malware where interoperability is  of  no  con-
>                      cern.   The  "send  521  and  disconnect" behavior is NOT
>                      defined in the SMTP standard.
>
>        REJECT optional text...
>               Reject the address etc. that matches  the  pattern.  Reply  with
>               "$access_map_reject_code  optional  text..."  when  the optional
>               text is specified, otherwise reply with a generic error response
>               message.
>
>        DEFER optional text...
>               Reject  the  address  etc.  that matches the pattern. Reply with
>               "$access_map_defer_code optional text..." when the optional text
>               is specified, otherwise reply with a generic error response mes-
>               sage.
>
>               This feature is available in Postfix 2.6 and later.
>
>        DEFER_IF_REJECT optional text...
>               Defer the request if some later restriction would  result  in  a
>               REJECT action. Reply with "$access_map_defer_code 4.7.1 optional
>               text..." when the optional text is  specified,  otherwise  reply
>               with a generic error response message.
>
>               Prior to Postfix 2.6, the SMTP reply code is 450.
>
>               This feature is available in Postfix 2.1 and later.
>
>        DEFER_IF_PERMIT optional text...
>               Defer the request if some later restriction would result in a an
>               explicit   or    implicit    PERMIT    action.     Reply    with
>               "$access_map_defer_code   4.7.1    optional  text..."  when  the
>               optional text is specified, otherwise reply with a generic error
>               response message.
>
>               Prior to Postfix 2.6, the SMTP reply code is 450.
>
>               This feature is available in Postfix 2.1 and later.
>
>        For other reject actions, see "OTHER ACTIONS" below.
>
> OTHER ACTIONS
>        restriction...
>               Apply    the   named   UCE   restriction(s)   (permit,   reject,
>               reject_unauth_destination, and so on).
>
>        BCC user@domain
>               Send one copy of the message to the specified recipient.
>
>               If multiple BCC actions are specified within the same SMTP  MAIL
>               transaction, with Postfix 3.0 only the last action will be used.
>
>               This feature is available in Postfix 3.0 and later.
>
>        DISCARD optional text...
>               Claim successful delivery and silently discard the message.  Log
>               the optional text if specified, otherwise log a generic message.
>
>               Note: this action currently affects all recipients of  the  mes-
>               sage.   To  discard  only  one  recipient without discarding the
>               entire message, use the transport(5) table to direct mail to the
>               discard(8) service.
>
>               This feature is available in Postfix 2.0 and later.
>
>        DUNNO  Pretend that the lookup key was not found. This prevents Postfix
>               from trying substrings of the lookup key (such  as  a  subdomain
>               name, or a network address subnetwork).
>
>               This feature is available in Postfix 2.0 and later.
>
>        FILTER transport:destination
>               After the message is queued, send the entire message through the
>               specified external content filter. The transport name  specifies
>               the  first  field  of  a  mail delivery agent definition in mas-
>               ter.cf; the syntax of the next-hop destination is  described  in
>               the  manual  page  of  the  corresponding  delivery agent.  More
>               information about external content filters  is  in  the  Postfix
>               FILTER_README file.
>
>               Note  1: do not use $number regular expression substitutions for
>               transport or destination unless you know  that  the  information
>               has a trusted origin.
>
>               Note  2:  this  action overrides the main.cf content_filter set-
>               ting, and affects all recipients of the  message.  In  the  case
>               that  multiple  FILTER  actions  fire, only the last one is exe-
>               cuted.
>
>               Note 3: the purpose of the FILTER command is to override message
>               routing.   To  override  the  recipient's  transport but not the
>               next-hop destination, specify an empty filter destination (Post-
>               fix  2.7  and  later),  or  specify a transport:destination that
>               delivers through a different Postfix instance (Postfix  2.6  and
>               earlier). Other options are using the recipient-dependent trans-
>               port_maps  or  the  sender-dependent   sender_dependent_default-
>               _transport_maps features.
>
>               This feature is available in Postfix 2.0 and later.
>
>        HOLD optional text...
>               Place  the  message  on  the hold queue, where it will sit until
>               someone either deletes it or releases it for delivery.  Log  the
>               optional text if specified, otherwise log a generic message.
>
>               Mail  that is placed on hold can be examined with the postcat(1)
>               command, and can be destroyed or released with the  postsuper(1)
>               command.
>
>               Note:  use  "postsuper -r" to release mail that was kept on hold
>               for  a  significant  fraction  of   $maximal_queue_lifetime   or
>               $bounce_queue_lifetime,  or  longer. Use "postsuper -H" only for
>               mail that will not expire within a few delivery attempts.
>
>               Note: this action currently affects all recipients of  the  mes-
>               sage.
>
>               This feature is available in Postfix 2.0 and later.
>
>        PREPEND headername: headervalue
>               Prepend  the specified message header to the message.  When more
>               than one PREPEND action executes,  the  first  prepended  header
>               appears before the second etc. prepended header.
>
>               Note:  this  action  must  execute before the message content is
>               received;   it   cannot    execute    in    the    context    of
>               smtpd_end_of_data_restrictions.
>
>               This feature is available in Postfix 2.1 and later.
>
>        REDIRECT user@domain
>               After  the  message is queued, send the message to the specified
>               address instead of the intended recipient(s).  When multiple RE-
>               DIRECT actions fire, only the last one takes effect.
>
>               Note:  this  action  overrides  the FILTER action, and currently
>               overrides all recipients of the message.
>
>               This feature is available in Postfix 2.1 and later.
>
>        INFO optional text...
>               Log an informational record with  the  optional  text,  together
>               with  client  information  and  if available, with helo, sender,
>               recipient and protocol information.
>
>               This feature is available in Postfix 3.0 and later.
>
>        WARN optional text...
>               Log a warning with  the  optional  text,  together  with  client
>               information  and  if available, with helo, sender, recipient and
>               protocol information.
>
>               This feature is available in Postfix 2.1 and later.
>
>
> BR
>
> Rafael
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Wietse Venema
In reply to this post by Rafael Azevedo-4
Rafael Azevedo:
> Hi Wietse,
>
> Thanks for your help.
>
> > You forgot to send it back into Postfix.
>
> Would you please tell me how to send it back to POSTFIX ?

FILTER_README has examples for doing that with /usr/sbin/sendmail
and with SMTP.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Wietse Venema
In reply to this post by Rafael Azevedo-4
Rafael Azevedo:
> Another attempt:
>
> Jan  4 16:39:21 lab postfix/pipe[2026654]: 82B8813DF90D:
> to=<[hidden email]>, relay=post_queue_content_filter, delay=0.07,
> delays=0.04/0/0/0.03, dsn=2.0.0, status=sent (delivered via
> post_queue_content_filter service (action=FILTER localhost:10026))

THAT IS POLICY DELEGATION PROTOCOL NOT CONTENT FILTER.
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Matus UHLAR - fantomas
In reply to this post by Rafael Azevedo-4
>> You forgot to send it back into Postfix.

On 04.01.19 16:47, Rafael Azevedo wrote:
>Would you please tell me how to send it back to POSTFIX ?

call sendmail and pass te message to it, or sent it to postfix via
SMTP/LMTP, apparently on different port where content_filter is turned off,
so postfix doesn't send it to your content filter again.

it's explained in http://www.postfix.org/FILTER_README.html#principles
--
Matus UHLAR - fantomas, [hidden email] ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Emacs is a complicated operating system without good text editor.
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Wietse Venema
> FILTER_README has examples for doing that with /usr/sbin/sendmail
> and with SMTP.


Has anybody ever made that example work?

There's no way.

post_queue_content_filter    unix    -       n       n       -       -
      pipe
        flags=Rq user=myuser null_sender=
        argv=/home/postfix/app/tools/postfix-filter.sh -f ${sender} --
${recipient}


/home/postfix/app/tools/postfix-filter.sh:
-----
#!/bin/sh
# Simple shell-based filter. It is meant to be invoked as follows:
#       /path/to/script -f sender recipients...

# Localize these. The -G option does nothing before Postfix 2.3.
INSPECT_DIR=/var/spool/filter
SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.

# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15

# Start processing.
cd $INSPECT_DIR || {
    echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }

cat >in.$$ || {
    echo Cannot save mail to file; exit $EX_TEMPFAIL; }

# Specify your content filter here.
# filter <in.$$ || {
#   echo Message content rejected; exit $EX_UNAVAILABLE; }

$SENDMAIL "$@" <in.$$

exit $?
-----

master.cf:
smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=post_queue_content_filter:dummy


mail.log:

Jan  4 17:41:54 lab postfix/pipe[2027085]: EE5D013E179F:
to=<[hidden email]>, relay=post_queue_content_filter, delay=1.1,
delays=0.04/0/0/1, dsn=4.3.0, status=deferred (temporary failure.
Command output: postdrop: error: untrusted configuration directory
name: /etc/postfix/ postdrop: fatal: specify
"alternate_config_directories = /etc/postfix/" in /etc/postfix/main.cf
sendmail: warning: command "/usr/sbin/postdrop -r" exited with status
1 sendmail: fatal: [hidden email](5001): unable to execute
/usr/sbin/postdrop -r: Success )



Thanks!

BR,
Rafael
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Matus UHLAR - fantomas
Hi Matus,

Thanks a lot for the help.

I tried setting the FILTER to localhost:otherport-with-no-filter but
had same behavior.

action=FILTER localhost:10026

no success.

Em sex, 4 de jan de 2019 às 18:36, Matus UHLAR - fantomas
<[hidden email]> escreveu:

>
> >> You forgot to send it back into Postfix.
>
> On 04.01.19 16:47, Rafael Azevedo wrote:
> >Would you please tell me how to send it back to POSTFIX ?
>
> call sendmail and pass te message to it, or sent it to postfix via
> SMTP/LMTP, apparently on different port where content_filter is turned off,
> so postfix doesn't send it to your content filter again.
>
> it's explained in http://www.postfix.org/FILTER_README.html#principles
> --
> Matus UHLAR - fantomas, [hidden email] ; http://www.fantomas.sk/
> Warning: I wish NOT to receive e-mail advertising to this address.
> Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
> Emacs is a complicated operating system without good text editor.
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Viktor Dukhovni
In reply to this post by Rafael Azevedo-4
> On Jan 4, 2019, at 3:37 PM, Rafael Azevedo <[hidden email]> wrote:
>
> Jan  4 17:41:54 lab postfix/pipe[2027085]: EE5D013E179F:
> to=<[hidden email]>, relay=post_queue_content_filter, delay=1.1,
> delays=0.04/0/0/1, dsn=4.3.0, status=deferred (temporary failure.
> Command output: postdrop: error: untrusted configuration directory
> name: /etc/postfix/ postdrop: fatal: specify
> "alternate_config_directories = /etc/postfix/" in /etc/postfix/main.cf
> sendmail: warning: command "/usr/sbin/postdrop -r" exited with status
> 1 sendmail: fatal: [hidden email](5001): unable to execute
> /usr/sbin/postdrop -r: Success )

DO NOT set "config_directory = /etc/postfix/" in main.cf.  In fact do
do not set it at all.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Matus UHLAR - fantomas
In reply to this post by Rafael Azevedo-4
On 04.01.19 18:41, Rafael Azevedo wrote:
>Thanks a lot for the help.
>
>I tried setting the FILTER to localhost:otherport-with-no-filter but
>had same behavior.
>
>action=FILTER localhost:10026

where did you set it? it's your own filter, it's not postfix, I have no idea
what you need to set ...

>Em sex, 4 de jan de 2019 às 18:36, Matus UHLAR - fantomas
><[hidden email]> escreveu:
>>
>> >> You forgot to send it back into Postfix.
>>
>> On 04.01.19 16:47, Rafael Azevedo wrote:
>> >Would you please tell me how to send it back to POSTFIX ?
>>
>> call sendmail and pass te message to it, or sent it to postfix via
>> SMTP/LMTP, apparently on different port where content_filter is turned off,
>> so postfix doesn't send it to your content filter again.
>>
>> it's explained in http://www.postfix.org/FILTER_README.html#principles
--
Matus UHLAR - fantomas, [hidden email] ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Fucking windows! Bring Bill Gates! (Southpark the movie)
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Viktor Dukhovni
In fact I didn't.
There's no config_directory set in my main.cf file.

Em sex, 4 de jan de 2019 às 18:46, Viktor Dukhovni
<[hidden email]> escreveu:

>
> > On Jan 4, 2019, at 3:37 PM, Rafael Azevedo <[hidden email]> wrote:
> >
> > Jan  4 17:41:54 lab postfix/pipe[2027085]: EE5D013E179F:
> > to=<[hidden email]>, relay=post_queue_content_filter, delay=1.1,
> > delays=0.04/0/0/1, dsn=4.3.0, status=deferred (temporary failure.
> > Command output: postdrop: error: untrusted configuration directory
> > name: /etc/postfix/ postdrop: fatal: specify
> > "alternate_config_directories = /etc/postfix/" in /etc/postfix/main.cf
> > sendmail: warning: command "/usr/sbin/postdrop -r" exited with status
> > 1 sendmail: fatal: [hidden email](5001): unable to execute
> > /usr/sbin/postdrop -r: Success )
>
> DO NOT set "config_directory = /etc/postfix/" in main.cf.  In fact do
> do not set it at all.
>
> --
>         Viktor.
>
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Viktor Dukhovni


> On Jan 4, 2019, at 4:59 PM, Rafael Azevedo <[hidden email]> wrote:
>
>>> Jan  4 17:41:54 lab postfix/pipe[2027085]: EE5D013E179F:
>>> to=<[hidden email]>, relay=post_queue_content_filter, delay=1.1,
>>> delays=0.04/0/0/1, dsn=4.3.0, status=deferred (temporary failure.
>>> Command output: postdrop: error: untrusted configuration directory
>>> name: /etc/postfix/ postdrop: fatal: specify
>>> "alternate_config_directories = /etc/postfix/" in /etc/postfix/main.cf
>>> sendmail: warning: command "/usr/sbin/postdrop -r" exited with status
>>> 1 sendmail: fatal: [hidden email](5001): unable to execute
>>> /usr/sbin/postdrop -r: Success )
>>
>> DO NOT set "config_directory = /etc/postfix/" in main.cf.  In fact do
>> do not set it at all.
>
> In fact I didn't.
> There's no config_directory set in my main.cf file.

The logs don't lie.  Either main.cf has "config_directory = /etc/postfix/"
with a trailing "/", or Postfix was started via "postfix -c /etc/postfix/ start"
or you have enabled multiple instances, and the multi-instance configuration
lists "/etc/postfix/", ... or similar.

By the time "postdrop" is running in your script the "MAIL_CONFIG" environment
variable is set to "/etc/postfix/" rather than just "/etc/postfix".

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Wietse Venema
> THAT IS POLICY DELEGATION PROTOCOL NOT CONTENT FILTER.

What are the differences?
Reply | Threaded
Open this post in threaded view
|

Re: Content filter - reijnect message back into queue

Rafael Azevedo-4
In reply to this post by Viktor Dukhovni
They don't. But there might be some variable with undesired default value.

# cd /etc/postfix/
lab postfix # grep 'config_directory' main.cf master.cf
lab postfix #


Em sex, 4 de jan de 2019 às 20:11, Viktor Dukhovni
<[hidden email]> escreveu:

>
>
>
> > On Jan 4, 2019, at 4:59 PM, Rafael Azevedo <[hidden email]> wrote:
> >
> >>> Jan  4 17:41:54 lab postfix/pipe[2027085]: EE5D013E179F:
> >>> to=<[hidden email]>, relay=post_queue_content_filter, delay=1.1,
> >>> delays=0.04/0/0/1, dsn=4.3.0, status=deferred (temporary failure.
> >>> Command output: postdrop: error: untrusted configuration directory
> >>> name: /etc/postfix/ postdrop: fatal: specify
> >>> "alternate_config_directories = /etc/postfix/" in /etc/postfix/main.cf
> >>> sendmail: warning: command "/usr/sbin/postdrop -r" exited with status
> >>> 1 sendmail: fatal: [hidden email](5001): unable to execute
> >>> /usr/sbin/postdrop -r: Success )
> >>
> >> DO NOT set "config_directory = /etc/postfix/" in main.cf.  In fact do
> >> do not set it at all.
> >
> > In fact I didn't.
> > There's no config_directory set in my main.cf file.
>
> The logs don't lie.  Either main.cf has "config_directory = /etc/postfix/"
> with a trailing "/", or Postfix was started via "postfix -c /etc/postfix/ start"
> or you have enabled multiple instances, and the multi-instance configuration
> lists "/etc/postfix/", ... or similar.
>
> By the time "postdrop" is running in your script the "MAIL_CONFIG" environment
> variable is set to "/etc/postfix/" rather than just "/etc/postfix".
>
> --
>         Viktor.
>
12