Subject: POP reader on UNIX

From: [email-masked] (Brian L Tobin)
Date: 5 Apr 1995 17:06:53 GMT

I have posted this question before, and no one answered.  I dunno if that's just
a stupid question, or there is no product.

What I am looking for is this:
	- A E-Mail reader that has the ability to log onto our school's POP server, and
retreive my mail.

You see, I usually use Eudura for Macintosh over PPP to get my mail.  But, when
I'm in the labs, it's a pain in the butt to get my mail (I have to D/L Eudura,
configure it...etc...)

In any case, if there is such a program available available for UNIX, could
someone please E-Mail with the name?

Thanks alot.

[email-masked]

---

From: [email-masked] (kevin MacRae)
Date: 6 Apr 1995 19:11:44 GMT

In article <[email-masked]>, [email-masked] (Brian L Tobin) writes:
|> I have posted this question before, and no one answered.  I dunno if that's just
|> a stupid question, or there is no product.
|> 
|> What I am looking for is this:
|> 	- A E-Mail reader that has the ability to log onto our school's POP server, and
|> retreive my mail.
|> 
|> You see, I usually use Eudura for Macintosh over PPP to get my mail.  But, when
|> I'm in the labs, it's a pain in the butt to get my mail (I have to D/L Eudura,
|> configure it...etc...)
|> 
|> In any case, if there is such a program available available for UNIX, could
|> someone please E-Mail with the name?
|> 
|> Thanks alot.
|> 
|> [email-masked]

I hate poting other peoples scripts without giving credit, but I do not
know where this came from. (comp.unix.unixware newgroup).

This is a perl script than gets mail from a pop server.

-------- Cut Here  ---------
#!/opt/bin/perl

#
#	get_popmail -- connects to the remote popmail server.  It then transfers 
#	all mail from the popmail server to the local rmail, deleting them in the 
#	process, if successful.
#
#	get_popmail <remote_system> <local_user> <remote_user> <remote_pw>
#
#	(For example: get_popmail popmail.mcs.com jack jack mypasswd)

($remote_system, $local_user, $remote_user, $remote_pw) = @ARGV;

if ($#ARGV != 3) {
    die "usage: get_popmail <remote_system> <local_user> <remote_user> <remote_pw>\n";
}

$debug = 0;	# Set to !=0 to see full text sent and received.
$AF_INET = 2;
$SOCK_STREAM = 2;

sub open_socket {
    local($Socket, $Port, $OtherHost) = @_;
    local($hostname, $name, $aliases, $type, $len);
    local($this, $thisadder, $that, $thatadder);
    local($sockaddr) = 'S n a4 x8';
    
    chop($hostname = 'hostname');
    
    ($name,$aliases,$Port) = getservbyname($Port,'tcp')
        unless $Port =~ /^\d+$/;;

    ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
    ($name,$aliases,$type,$len,$thataddr) = gethostbyname($OtherHost);
    
    $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
    $that = pack($sockaddr, $AF_INET, $Port, $thataddr);
    
    # Give the socket an address.
    bind($Socket, $this)  || die $!;
    
    # Call up the server.
    connect($Socket,$that) || die $!;
    
    # Set socket to be command buffered.
    select($Socket); $| = 1; select (STDOUT);
}

sub send {
    local ($Socket, $Who, $Var);
    $Socket = shift;
    $Who = shift;

    print $Who, " <- " if $debug;
    while ($Var = shift) {
	print $Socket $Var;
	print $Var if $debug;
    }
}

sub expect {
    local($Socket, $Who, $Expect) = @_;
    local($line, $first_field);

    $line=<$Socket>;
    print $Who, " -> ", $line if $debug;
    ($first_field) = split(/[ \t\n]/,$line);
    if ($Expect ne $first_field) {
	print "ERROR from ", $Who, ", expected ", $Expect, ", got ", $first_field, "\n";
    }
}

sub login_remote {
    &expect (RemoteSMTP_Socket, "REM", "+OK");

    &send (RemoteSMTP_Socket, "REM", "USER ", $remote_user, "\n");
    &expect (RemoteSMTP_Socket, "REM", "+OK");

    &send (RemoteSMTP_Socket, "REM", "PASS ", $remote_pw, "\n");
    &expect (RemoteSMTP_Socket, "REM", "+OK");
}

sub logout_remote {
    &send (RemoteSMTP_Socket, "REM", "QUIT\n");
    &expect (RemoteSMTP_Socket, "REM", "+OK");
}

sub message_count {
    &send (RemoteSMTP_Socket, "REM", "STAT\n");
    $line=<RemoteSMTP_Socket>;
    print "REM-> ", $line if $debug;
    ($first_field, $message_count) = split(/[ \t\n]/,$line);
    if ($first_field ne "+OK") {
	print "ERROR from REM, expected +OK, got ", $first_field, "\n";
    }
    print "Message count - ", $message_count, "\n" if $debug;
    $message_count;
}

# Get $proto.
($name, $aliases, $proto) = getprotobyname('tcp');

# Make and open the remote socket filehandle.
socket(RemoteSMTP_Socket, $AF_INET, $SOCK_STREAM, $proto) || die $!;
&open_socket(RemoteSMTP_Socket, 110, $remote_system);

&login_remote;

$count = message_count;
print "Getting ", $count, " message(s)\n" if $debug;

for ($i = 1; $i<=$count; $i++) {
    print "Copying message ", $i, "\n" if $debug;
    open(MAILOUT, "|rmail ".$local_user);
    &send (RemoteSMTP_Socket, "REM", "RETR ", $i, "\n");    
    &expect (RemoteSMTP_Socket, "REM", "+OK");

    $line=<RemoteSMTP_Socket>;		# Throw one line away.

    $line=<RemoteSMTP_Socket>;		# Throw one line away.
    ($first_field) = split(/[ \t\n\r]/,$line);
    while ($first_field ne ".") {
	$line =~ s/\r//;
	print "REM -> ", $line if $debug;
	print MAILOUT $line;
	$line=<RemoteSMTP_Socket>;		# Throw one line away.
    	($first_field) = split(/[ \t\n\r]/,$line);
    }
    close MAILOUT;
    die "rmail failed" if $?;	# rmail gave bad status code

    &send (RemoteSMTP_Socket, "REM", "DELE ", $i, "\n");    
    &expect (RemoteSMTP_Socket, "REM", "+OK");
}

&logout_remote;
----- Cut Here -----

I hope this helps. I have been using it for 2 months. Get perl script.

*******************************************************************************
* Kevin MacRae                                    Phone    (902) 566-3198     *
* Owner/Operator                                  FAX      (902) 566-3423     *
* K & R Management                                Internet [email-masked] *
*******************************************************************************