Discussion:
Postfix: Read input stream of a spawned content filter
(too old to reply)
j***@gmail.com
2018-09-28 09:21:24 UTC
Permalink
Similarly to this [question](https://serverfault.com/questions/604924/postfix-after-queue-content-filter-advanced-filter-not-working), I followed the [documentation](http://www.postfix.org/FILTER_README.html) for an advanced content filter and ended up with the same configurations.

main.cf

content_filter = scan:localhost:10025
receive_override_options = no_address_mappings

master.cf

smtp inet n - y - 10 smtpd
-o smtpd_proxy_filter=127.0.0.1:10025


# =============================================================
# service type private unpriv chroot wakeup maxproc command
# (yes) (yes) (yes) (never) (100)
# =============================================================
scan unix - - n - 10 smtp
-o smtp_send_xforward_command=yes
-o disable_mime_output_conversion=yes
-o smtp_generic_maps=
-o smtp_bind_address=127.0.0.1
-o smtp_bind_address6=
-o smtp_address_preference=ipv4
# -o smtp_bind_address=127.0.0.1

#running the content filter
localhost:10025 inet n n n - 10 spawn
user=filter argv=/usr/local/bin/spawn_content_filter.py


# Injecting mail back into postfix
localhost:10026 inet n - n - 10 smtpd
-o content_filter=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
# Postfix 2.10 and later: specify empty smtpd_relay_restrictions.
-o smtpd_relay_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o smtpd_authorized_xforward_hosts=127.0.0.0/8

The content filter which in my case is a python script, reads the input stream like this:

...
while True:
line = sys.stdin.readline()
...

The output I'm getting in /var/log/mail.log shows that the connection is deferred.

Sep 28 09:31:00 host postfix/pickup[25596]: 9175F160116: uid=1001 from=<***@host>
Sep 28 09:31:00 host postfix/cleanup[27002]: 9175F160116: message-id=<***@host>
Sep 28 09:31:00 host postfix/qmgr[25039]: 9175F160116: from=<***@host>, size=315, nrcpt=1 (queue active)
Sep 28 09:31:00 host postfix/spawn[27005]: warning: command /usr/local/bin/filter.py exit status 1
Sep 28 09:31:00 host postfix/smtp[27004]: 9175F160116: lost connection with localhost[127.0.0.1] while receiving the initial server greeting
Sep 28 09:31:00 host postfix/smtp[27004]: connect to localhost[::1]:10025: Connection refused
Sep 28 09:31:00 keid postfix/smtp[27004]: 9175F160116: to=<***@host>, relay=none, delay=0.14, delays=0.01/0/0.13/0, dsn=4.4.1, status=deferred (connect to localhost[::1]:10025: Connection refused)

The error happens in the connection between the port 10025 and the content filter.
Likewise an [inetd](https://en.wikipedia.org/wiki/Inetd) service I expect the stream to pass through the stdin.


Can you identify the possible reason for a connection failure? or which configuration is missing?
j***@gmail.com
2018-09-28 14:40:43 UTC
Permalink
Also posted at https://serverfault.com/questions/931996/postfix-read-input-stream-of-a-spawned-content-filter .
j***@gmail.com
2018-10-11 11:56:07 UTC
Permalink
Post by j***@gmail.com
Similarly to this [question](https://serverfault.com/questions/604924/postfix-after-queue-content-filter-advanced-filter-not-working), I followed the [documentation](http://www.postfix.org/FILTER_README.html) for an advanced content filter and ended up with the same configurations.
main.cf
content_filter = scan:localhost:10025
receive_override_options = no_address_mappings
master.cf
smtp inet n - y - 10 smtpd
-o smtpd_proxy_filter=127.0.0.1:10025
# =============================================================
# service type private unpriv chroot wakeup maxproc command
# (yes) (yes) (yes) (never) (100)
# =============================================================
scan unix - - n - 10 smtp
-o smtp_send_xforward_command=yes
-o disable_mime_output_conversion=yes
-o smtp_generic_maps=
-o smtp_bind_address=127.0.0.1
-o smtp_bind_address6=
-o smtp_address_preference=ipv4
# -o smtp_bind_address=127.0.0.1
#running the content filter
localhost:10025 inet n n n - 10 spawn
user=filter argv=/usr/local/bin/spawn_content_filter.py
# Injecting mail back into postfix
localhost:10026 inet n - n - 10 smtpd
-o content_filter=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
# Postfix 2.10 and later: specify empty smtpd_relay_restrictions.
-o smtpd_relay_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
...
line = sys.stdin.readline()
...
The output I'm getting in /var/log/mail.log shows that the connection is deferred.
Sep 28 09:31:00 host postfix/spawn[27005]: warning: command /usr/local/bin/filter.py exit status 1
Sep 28 09:31:00 host postfix/smtp[27004]: 9175F160116: lost connection with localhost[127.0.0.1] while receiving the initial server greeting
Sep 28 09:31:00 host postfix/smtp[27004]: connect to localhost[::1]:10025: Connection refused
The error happens in the connection between the port 10025 and the content filter.
Likewise an [inetd](https://en.wikipedia.org/wiki/Inetd) service I expect the stream to pass through the stdin.
Can you identify the possible reason for a connection failure? or which configuration is missing?
It seems that the reason for a deferred email error lies on the message reaching a timeout inside the while loop. Also occurs that the standard input reading is triggered once but an empty content is arriving. It's empty in spite of the email containing a message.
Loading...