Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

perl program question

Article: 7557 of alt.hackers
Newsgroups: alt.hackers
From: (*greeeeaaaaaaat*)
Subject: perl program question
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
Date: Wed, 29 Mar 1995 03:50:31 GMT
Approved: What?
Lines: 158
Status: RO


I'm using term on my linux box.  I got sendmail compiled, and modified
it to listen for smtp connections on port 4225 or the machine I'm
dialed into.  It's run out of my .forward.  If I'm logged in, it's
supoosed to deliver the mail immediately. Otherwise, it's supposed to
defer it into a file, to be forwarded through a script.  (It basically
does formail -s smtpforward).  Now, the problem is, it always defers
the mail fine.  When I'm logged in, it never actually forwards it,
just defers it (when run from the .forward).  But, when I run the
script that forwards all of the deferred mail, it works fine!  Anyway,
here is the script:

(Oh, and uhost is a script that takes a username as an argument and
returns something like 'byerr@netcom20')


#!/usr/local/bin/perl  --       # -*-Perl-*-

open(FOO,"/u1/byerr/bin/uhost byerr|");
$them=$_[1] if $_[1] =~ /netcom/;
foreach (@message) {
    if(/From /) {
print "Host: $them\n";
print "From: $from\n";

# ($them,$port)=@ARGV;
$port=4225 unless $port;
$them= "localhost" unless $them;


sub dokill {
    kill 9,$child if $child;

$sockaddr='S n a4 x8';

($name,$aliases,$port)=getservbyname($port, 'tcp') unless $port=~

$this=pack($sockaddr, $AF_INET, 0, $thisaddr);
$that=pack($sockaddr, $AF_INET, $port, $thataddr);

# Make the socket filehandle.

if(socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
    print "socket ok\n";
else {
    die $!;

# Give the socket an address.

if (bind(S, $this)) {
    print "bind ok\n";
else {
    die $!;

# Call up the server,
if (connect(S, $that)) {
    print "connect ok\n";
else {
#    die $!;
        print "retry $trycount\n";
        goto main;
    # Defer the message for when sendmail is running again.
    foreach(@message) {
        print DEFER;
    print "mail deferred\n";

# Set socket to be command buffered.

select(S); $|=1; select(STDOUT);

sleep 3;
print S "EHLO smtpforward\n";
sleep 5;
print S "MAIL FROM: $from\n";
sleep 2;
print S "RCPT TO: root\n";
sleep 5;
print S "data\n";
sleep 2;
foreach(@message) {
    print S;
print S ".\n";
sleep 20;
print S "quit\n";
sleep 3;
print "Done.\n";
if(-r "/u1/byerr/incoming/deferred") {
#    print "Sending deferred messages...\n";
#    system("/u1/byerr/dodeferred");

(if you notice, the commented out part at the end doesn't work,
either... *sigh*)

this is my .forward:
"|exec /usr/local/bin/procmail #byerr "

this is part of my .procmailrc:
:0 c

this is dodeferred:

if test -s /u1/byerr/incoming/deferred;
        sleep 180
        mv /u1/byerr/incoming/deferred /u1/byerr/incoming/deferred.sending
        cat /u1/byerr/incoming/deferred.sending|formail -s
        echo No deferred mail.

Thanks for the help!

Ben Byer     I am not a bushing
M--V--poY+t+5!jRG+tv-b+++D++B---e(see a)u+(*)h!f+n----!y

Back to index