head	1.2;
access;
symbols
	4-5-4:1.2
	4-5-3:1.2
	4-5-2:1.2
	4-5-1:1.1;
locks; strict;
comment	@# @;


1.2
date	98.07.06.13.52.27;	author esr;	state Exp;
branches;
next	1.1;

1.1
date	98.07.01.01.47.52;	author esr;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Strip <> out of addresses.
@
text
@#!/usr/bin/perl
#
# orbgate -- fetchmail server gateway for the ORBCOMM satelite system.
#
#    The goal is to provide ORBCOMM mobile users the capability to retrieve
#    e-mail from POP3 servers on the Internet.  The ORBCOMM mobile user
#    will require a laptop connected via the serial port to an ORBCOMM
#    Subscriber Communicator (SC).
#
#    The POP3 protocol itself cannot be used over the ORBCOMM System
#    because the lightspeed lag inherent in satellite communications
#    makes packet-latency times longer than TCP/IP can handle.  Everything
#    has to be tunnelled through special protocols.
#
#    So, in essence, this is a POP3 proxy program.  A server on the Internet,
#    running the POP3 proxy, receives the pertinent POP3 information, goes
#    out and retrieves the POP3 e-mail, then forwards the e-mail to the
#    ORBCOMM mobile user who requested his POP3 e-mail.
#
#    ORBCOMM is currently an e-mail enabled system.  So what the ORBCOMM
#    mobile user essentially creates is e-mail with the pertinent POP3
#    information in the body of the message.
#
#    The e-mail will be arriving at an account on the POP3 proxy server,
#    i.e., pop3-proxy@@fetch.orbcomm.net.   There will be a ~./forward file
#    in the directory, with the following:
#
#    "|/usr/local/bin/orbgate"
#
#    The body of the message must have:
#    * the user name to poll with in the first line
#    * the remote host to poll in the second
#    * the user's password on that host on the third
#    * fetchmail switches on an optional fourth
#
#    The retrieved POP3 e-mail will be forwarded (submitted to sendmail) to
#    the originator of the message from the ORBCOMM mobile customer,
#    This is the "From" field of the RFC-822 header.
#
#    This script emits error messages to stderr when it fails.
#    Any command-line options are passed through to the fetchmail
#    command, overriding any options passed in on the parameters line.
#    Consequently, you can test this script woth `orbgate -V', 
#    `orbgate -v -k -a', etc.
#
# $Id: orbgate,v 1.1 1998/07/01 01:47:52 esr Exp esr $
#

$errors = $mobileaddr = $params = $password = '';

$cmdopts = join(' ', @@ARGV) ."\n";

while (<STDIN>)
{
    if (/^From /) {		# Skip initial Unix From_ line
#	print "Skipping initial: $_";
	next;
    } elsif (/^[Ff]rom: /) {	# From line in form "From: <user>@@orbcomm.net"
	if ($_ =~ /([^\s\<\>]*)\@@([^\s\<\>]*)/) {
	    $mobileuser = $1;
	    $mobilehost = $2;
	} else {
	    chop;
	    $errors = $errors . "Bad From line: $_; "
	}
    } elsif (/^ *$/) {	# Blank line; message headers end here
#	print "Stopped: $_";
	last;
    } else {
#	print "Skipping: $_";
	next;
    }
}

$user = <STDIN>; chop $user;
$server = <STDIN>; chop $server;
$password = <STDIN>; chop $password;
$params = <STDIN>; chop $params;

$errors = $errors . "Missing From line.; " unless $mobileuser && $mobilehost;
$errors = $errors . "Missing user line.; " unless $user;
$errors = $errors . "Missing password line.; " unless $password;
$errors = $errors . "Missing server line.; " unless $server;

if ($errors) {
    $errors = time() . ": $errors\n";
    print STDERR $errors;
    exit 1	
}

$profile = <<EOF;
poll $server with protocol POP3;
    user "$mobileuser" here is "$user" there with password "$password"
    smtphost "$mobilehost"
EOF
$tmp = "/usr/tmp/orbgate$$.tmp";
open(FETCHMAILRC, ">$tmp");
print FETCHMAILRC $profile;
close(FETCHMAILRC);
chmod($tmp, 0600);

system("fetchmail -f $tmp $params $cmdopts\n");
unlink($tmp);

# The following sets edit modes for GNU EMACS
# Local Variables:
# mode:perl
# End:
@


1.1
log
@Initial revision
@
text
@d46 1
a46 1
# $Id$
d59 1
a59 1
	if ($_ =~ /([^\s]*)\@@([^\s]*)/) {
@
