[net.sources] non-uucp mail over a uucp connection

doug@umich.UUCP (Douglas Orr) (02/06/86)

Here are a couple of little programs that let you send mail
using a uucp connection, without having to use uucp style 
addresses.  There is a sender (rxmail) that invokes
a catcher (rgmail) on the remote system.  Rgmail, in turn
invokes sendmail to actually deliver the message.

Rgmail has to be installed in one of the directories that uux
can use and an entry for it has to be put into your L.cmds file.


	-Doug
	ihnp4!umich!doug
	doug@umich.csnet

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	rgmail.c
#	rxmail.c
# This archive created: Thu Feb  6 12:00:17 1986
cat << \SHAR_EOF > rgmail.c
#include <stdio.h>
#include <errno.h>

FILE * popen();
char * realloc();

int nargsize;
char * narg;

main( argc, argv )
int	argc;
char	* argv[];
	{

	FILE * pfd;
	char buf[BUFSIZ];
	int ch;

	narg = (char *)malloc(BUFSIZ);
	nargsize = BUFSIZ;

	strcpy( narg, "/usr/lib/sendmail -oi -em" );


	while( (fgets( buf, sizeof(buf), stdin ) != NULL)
	&&     (strcmp( buf, "->end\n" ) != 0 ) )
		{
		if( strncmp( buf, "->to:", 5 ) == 0 )
			add_arg( &buf[6] );
		else
		/*  a little cooperation is required here - this comes first */
		if( strncmp( buf, "->from:", 7 ) == 0 )
			{
			add_arg( "-f" );
			add_arg( &buf[8] );
			}
		else
			{
			fprintf( stderr, "illegal control line\n" );
			exit( EINVAL );
			}
			
		}
	
	
	if( (pfd = popen( narg, "w" )) == NULL )
		{
		fprintf( stderr, "couldn't open sendmail\n" );
		exit( EIO );
		}
	
	while( (ch = getchar()) != EOF )
		putc( ch, pfd );
	
	exit( pclose(pfd) );

	}


/*	not very efficient, but easy ... */
add_arg( str )
char * str;
	{

	if( (strlen(narg) + strlen(str) + 2) > nargsize )
		narg = (char *)realloc( narg, (nargsize += BUFSIZ) );

	if( !narg )
		exit( E2BIG );

	strcat( narg, " " );
	strcat( narg, str );
	if( narg[strlen(narg)-1] == '\n' )
		narg[strlen(narg)-1] = '\0';

	}

SHAR_EOF
cat << \SHAR_EOF > rxmail.c
#include	<stdio.h>
#include	<sysexits.h>

/*
 *	rsmail:  send mail to a remote mail "catcher" which will, in turn
 *   invoke a local mail delivery program.  Send mail using the fabulous
 *   uucp facility.
 */

FILE * popen();

main( argc, argv )
int	argc;
char	* argv[];
	{

	FILE * pfd;
	char	rmbuf[BUFSIZ];
	int ch;

	if( argc < 4 )
		{
		fprintf( stderr, "rsmail: too few arguments\n" );
		exit( 1 );
		}

	argc--;
	argv++;

	/*  yuk */
	sprintf( rmbuf, "uux -r -n - %s!rgmail", *argv );

	if( (pfd = popen( rmbuf, "w" )) == NULL )
		{
		fprintf( stderr, "rsmail: couldn't open uux\n" );
		exit(1);
		}

	while( --argc )
		{
		if( (*++argv)[0] == '-' )
			{
			switch( (*argv)[1] )
				{
				case 'f':
					if( --argc == 0 )
						goto badopt;
					fprintf( pfd, "->from: %s\n", *++argv );
					break;
				default:
				badopt:
					fprintf( stderr, "illegal option\n" );
					pclose(pfd);
					exit(1);
				}
			}
		else
			fprintf( pfd, "->to: %s\n", *argv );
		}
	
	fprintf( pfd, "->end\n" );

	while( (ch = getchar()) != EOF )
		putc( ch, pfd );
	
	/*  if you have trouble writing to /usr/spool, try again later. */
	if( ferror(stdin) || ferror(pfd) )
		exit( EX_TEMPFAIL );

	exit( pclose( pfd ) );

	}

SHAR_EOF
#	End of shell archive
exit 0