#!/bin/sh ########################################################## # Aleksander Adamowski # śro lut 26 15:52:05 CET 2003 # Skrypt przekazujacy dane do serwera pocztowego # nasluchujacego na porcie 2500 i dopisujacy # naglowek received od rblsmtpd # # The script adds a "Received" header based on info from # rblsmtpd/tcpserver passed inside env variables # and forwards data to a mail server that listens # on a filtered port 2500 # ########################################################## perl_filter=' use POSIX; if (!defined($ENV{TCPREMOTEHOST})){ $ENV{TCPREMOTEHOST}="unknownhost"; } if (!defined($ENV{TCPREMOTEIP})){ $ENV{TCPREMOTEIP}="127.0.0.1"; } if (!defined($ENV{TCPLOCALHOST})){ $ENV{TCPLOCALHOST}=$ENV{HOSTNAME}; } $| = 1; $data_notyet = 1; $tls_notyet = 1; setlocale(LC_TIME, "C"); $now=POSIX::strftime(" %a, %d %b %Y %H:%M:%S %z", localtime); LINE: while ($tls_notyet && ($_ = <>)) { # If STARTTLS detected, exit the loop and switch to byte-by-byte binary forwarding mode: if (/^starttls/i) { print $_ or die "-p destination: $!\n"; $tls_notyet = 0; } last LINE if !$tls_notyet; if ($data_notyet) { if (s/(^data\r?\n)/$1Received: from $ENV{TCPREMOTEHOST} ([$ENV{TCPREMOTEIP}])\r\n by $ENV{TCPLOCALHOST} (rblsmtpd);$now\r\n/im) { $data_notyet = 0; s/^(.{72})(.)$/$1\r\n $2/gm; } } } continue { print $_ or die "-p destination: $!\n"; } # STARTTLS occured, we have to forward all data byte-by-byte without buffering # (as we cannot predict how long will the data be) if (!$tls_notyet) { my $buf; while (sysread STDIN, $buf, 1) { syswrite STDOUT, $buf; } } ' if [ -n "$RBL_TRUSTED_NET" ]; then # the client is in a trusted net - we connect from 127.0.0.1 so that Netscape Messaging Server # can differentiate and allow relaying for this client: perl -e "$perl_filter" | nc -w 8 localhost 2500 else # the client is in an untrusted net - we connect from 127.0.0.3 so that Netscape Messaging Server # will block any relaying attempts using its antirelay plug-in: perl -e "$perl_filter" | nc -w 8 -s 127.0.0.3 localhost 2500 fi