home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
back2roots/padua
/
padua.7z
/
padua
/
ftp.vapor.com
/
microdot-1
/
md1_src_02.lzx
/
rmail.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-24
|
21KB
|
670 lines
#include "uuconv.h"
#ifndef UUXQT_MD
extern char linebuffer[];
#endif
/* Returncodes:
3 = can't open tofile
1 = can't open file
21 = keine from-zeile
22 = from-syntax-error
23 = address convert error
*/
extern long lastoffset;
extern char gzipfullpath[];
extern char tempfile[];
extern APTR app;
#ifndef UUXQT_MD
extern APTR tx[6];
#endif
int rmail( char *from, char *to, char *cmd )
{
struct AsyncFile *newsfile;
struct AsyncFile *tofile;
int offs, c, ch, toctr;
char buffer[á256 ];
char *p, *token, *p2;
BOOL flag_myreceivedby = 0;
BOOL isiso = FALSE;
BOOL ismime = FALSE;
BOOL iscompleteaddress = 0;
int gotsubject = FALSE;
char dummy1[512], dummy2[256];
domui();
set_status( GS( MSG_TXT_CONVERTMAIL ) );
newsfile = CLU_OpenAsync( from, ASMODE_READ, ASYNCBUFF );
if( !newsfile )
return( 1 );
CLU_FGetsAsync( newsfile, linebuffer, 2047 );
clnl( linebuffer );
if( strnicmp( linebuffer, "From ", 5 ) )
{
CLU_CloseAsync( newsfile );
return( 21 );
}
// Printf( "rmail: got %s\n", linebuffer );
strcpy( linebuffer, &linebuffer[á5 ]á);
tofile = CLU_OpenAsync( to, ASMODE_WRITE, ASYNCBUFF );
if( !tofile )
{
CLU_CloseAsync( newsfile );
return( 3 );
}
/* in ROT verwandeln... */
p = strchr( linebuffer, ' 'á);
if( !p )
p = strchr( linebuffer, '\t'á);
token = strrchr( linebuffer, ' 'á);
if( !token )
token = strrchr( linebuffer, '\t'á);
if( ( !p ) || ( !token ) || ( token <= p ) )
{
CLU_CloseAsync( tofile );
DeleteFile( to );
CLU_CloseAsync( newsfile );
return( 22 );
}
*p = 0;
*token++ = 0;
#ifndef UUXQT_MD
set(tx[1], MUIA_Text_Contents, linebuffer );
#endif
p = strrchr( linebuffer, '!'á);
if( p )
{
*p++ = 0;
iscompleteaddress = TRUE;
p2 = linebuffer;
}
else
{
p = linebuffer;
p2 = token;
}
// Printf( "rmail: after rotparse token %s, linebuffer %s\n", token, linebuffer );
if (iscompleteaddress)
CLU_FPrintfAsync( tofile, "WAB:%s@%s\n", p, p2 );
else
CLU_FPrintfAsync( tofile, "WAB:%s\n", p );
if (p = strchr( linebuffer, '@' ))
{
p++;
if (*p != 0)
CLU_FPrintfAsync( tofile, "ROT:%s\n", p );
else
CLU_FPrintfAsync( tofile, "ROT:%s\n", linebuffer );
}
else
CLU_FPrintfAsync( tofile, "ROT:%s\n", linebuffer );
#ifndef UUXQT_MD
*dummy1 = 0;
*dummy2 = 0;
toctr = 0;
#endif
while( *cmd )
{
p = buffer;
while( ( *cmd ) && ( !isspace( *cmd ) ) )
{
*p++ = *cmd++;
}
*p = 0;
cmd = stpblk( cmd );
if( !buffer[á0 ] )
continue;
/* Eventuelle Bang-Pfade l÷st der JSortin auf */
#ifndef UUXQT_MD
if(strlen(buffer) < 255)
{
if (*dummy1)
sprintf(dummy2, ",%s", buffer);
else
sprintf(dummy2,"%s", buffer);
toctr++;
}
if (toctr < 4)
strcat(dummy1,dummy2);
if (toctr == 4)
strcat(dummy1,",...");
toctr++;
#endif
CLU_FPrintfAsync( tofile, "EMP:%s\n", buffer );
}
#ifndef UUXQT_MD
if(*dummy1 == 0)
set(tx[3], MUIA_Text_Contents, "<EmpfΣngerangabe zu umfangreich>");
else
set(tx[3], MUIA_Text_Contents, dummy1);
#endif
// Printf( "rmail: after empgen\n" );
while( readheaderline( newsfile, 0 ) )
{
domui();
// Printf( "rmail: readheaderline %s\n", linebuffer );
if( !linebuffer[á0 ]á)
break;
p = strchr( linebuffer, ':'á);
if( !p )
break;
*p++ = 0;
p = stpblk( p );
// Printf( "rmail: line %s <:> %s\n", linebuffer, p );
if( !stricmp( linebuffer, "Organization" ) )
CLU_FPrintfAsync( tofile, "ORG:%s\n", p );
else if( !stricmp( linebuffer, "Subject" ) )
{
CLU_FPrintfAsync( tofile, "BET:%s\n", p );
#ifndef UUXQT_MD
set(tx[4], MUIA_Text_Contents, p);
#endif
gotsubject = TRUE;
}
else if( !stricmp( linebuffer, "From" ) )
{
c = convertadr( p, buffer );
if( c < 0 )
{
CLU_CloseAsync( newsfile );
CLU_CloseAsync( tofile );
return( 23 );
}
CLU_FPrintfAsync( tofile, "ABS:%s\n", buffer );
// CLU_FPrintfAsync( tofile, "ROT:%s\n", buffer );
if( c )
CLU_FPrintfAsync( tofile, "U-From:%s\n", p );
#ifndef UUXQT_MD
set(tx[2], MUIA_Text_Contents, buffer);
#endif
}
else if( !stricmp( linebuffer, "Return-Receipt-To" ) )
{
c = convertadr( p, buffer );
if( c < 0 )
{
CLU_CloseAsync( newsfile );
CLU_CloseAsync( tofile );
return( 23 );
}
CLU_FPrintfAsync( tofile, "EB:%s\n", buffer );
if( c )
CLU_FPrintfAsync( tofile, "U-Return-Receipt-To:%s\n", p );
}
else if( !stricmp( linebuffer, "x-charset" ) )
{
if( !stricmp( p, "ISO-8859-1" ) )
isiso = TRUE;
}
else if( !stricmp( linebuffer, "content-type" ) )
{
if( strstr( p, "ISO" ) || strstr( p, "Iso" ) || strstr( p, "iso" ) )
isiso = TRUE;
}
else if( !strcmp( linebuffer, "mime-version" ) )
ismime = TRUE;
else if( !strcmp( linebuffer, "content-transfer") )
{
if( stricmp( p, "8bit" ) )
isiso = TRUE;
}
else if( !stricmp( linebuffer, "CC" ) )
{
CLU_FPrintfAsync( tofile, "U-CC:%s\n", p );
while( token = strtok( p, "," ) )
{
p = NULL;
c = convertadr( token, buffer );
if( c < 0 )
{
/* Nichtkonvertierbare, m÷glicherweise falsche Adresse */
continue;
}
CLU_FPrintfAsync( tofile, "KOP:%s\n", buffer );
}
}
else if( !stricmp( linebuffer, "Date" ) )
{
token = convertuudate( p );
if( !token )
return( -2 );
CLU_FPrintfAsync( tofile, "EDA:%s\n", token );
CLU_FPrintfAsync( tofile, "U-Date:%s\n", p );
}
else if( !stricmp( linebuffer, "Reply-To" ) )
{
c = convertadr( p, buffer );
if( c < 0 )
{
CLU_CloseAsync( newsfile );
CLU_CloseAsync( tofile );
return( -1 );
}
CLU_FPrintfAsync( tofile, "ANTWORT-AN:%s\n", buffer );
if( c )
CLU_FPrintfAsync( tofile, "U-Reply-To:%s\n", p );
}
// else if (!stricmp( linebuffer, "To" ) )
// {
// c = convertadr( p, buffer );
// if (c < 0)
// {
// CLU_CloseAsync( newsfile );
// CLU_CloseAsync( tofile );
// return( -1 );
// }
//
// CLU_FPrintfAsync( tofile, "OEM:%s\n", buffer );
//// if ( c )
// CLU_FPrintfAsync( tofile, "U-To:%s\n", p );
// }
else if( !stricmp( linebuffer, "In-Reply-To" ) || !stricmp( linebuffer, "References" ) )
{
p = strchr( p, '<' );
if( p )
{
while( token = strtok( p, ">" ) )
{
if( token[ 0 ]á== '<' )
{
CLU_FPrintfAsync( tofile, "BEZ:%s\n", breakmid( token ) );
}
p = NULL;
}
}
}
else if( !stricmp( linebuffer, "Message-ID" ) )
{
CLU_FPrintfAsync( tofile, "MID:%s\n", breakmid( p ) );
}
else if( !stricmp( linebuffer, "Supersedes" ) )
{
CLU_FPrintfAsync( tofile, "ERSETZT:%s\n", breakmid( p ) );
}
else if( !stricmp( linebuffer, "X-Newsreader" ) )
CLU_FPrintfAsync( tofile, "MAILER:%s\n", p );
else if( !stricmp( linebuffer, "X-Mailer" ) )
CLU_FPrintfAsync( tofile, "MAILER:%s\n", p );
else if( !stricmp( linebuffer, "X-Newssoftware" ) )
CLU_FPrintfAsync( tofile, "MAILER:%s\n", p );
else if( !strnicmp( linebuffer, "X-Z-", 4 ) )
CLU_FPrintfAsync( tofile, "%s:%s\n", &linebuffer[ 4 ], p );
else if( !strnicmp( linebuffer, "X-ZC-", 5 ) )
CLU_FPrintfAsync( tofile, "%s:%s\n", &linebuffer[ 5 ], p );
else if( !stricmp( linebuffer, "Received:" ) )
{
if( !flag_myreceivedby )
{
char x[6];
utunpk( time( NULL ), x );
#ifndef UUXQT_MD
CLU_FPrintfAsync( tofile, "by %s (%02ld-%02ld-%02ld %02ld:%02ld:%02ld; Connectline/AmigaOS v" UUVER ")\n",
CLP_GetSystemAddress(),
x[ 2 ], x[á1 ], x[á0 ],
x[á3 ], x[á4 ], x[á5 ]
);
#else
CLU_FPrintfAsync( tofile, "by %s.%s (%02ld-%02ld-%02ld %02ld:%02ld:%02ld; MicroDot/Amiga v" MDVER ")\n",
prefs.pointname, prefs.boxdomain,
x[ 2 ], x[á1 ], x[á0 ],
x[á3 ], x[á4 ], x[á5 ]
);
#endif
flag_myreceivedby = TRUE;
}
CLU_FPrintfAsync( tofile, "U-Received", p );
}
else
{
if( !strnicmp( linebuffer, "X-", 2 ) )
CLU_FPrintfAsync( tofile, "%s:%s\n", linebuffer, p );
else
CLU_FPrintfAsync( tofile, "U-%s:%s\n", linebuffer, p );
}
}
domui();
// Printf( "rmail:after headerparse\n" );
if( (isiso ) || ( !isiso && !ismime ) )
CLU_WriteAsync( tofile, "CHARSET:ISO1\n", 13 );
/* Zeilen zΣhlen */
offs = CLU_FtellAsync( newsfile );
// Printf( "rmail: offs %ld\n", offs );
c = 0;
FOREVER
{
ch = CLU_ReadCharAsync( newsfile );
if( ch < 0 )
break;
if( ch == 10 )
c += 2;
else if( ch == 13 )
continue;
else c++;
}
CLU_SeekAsync( newsfile, offs, ASMODE_START );
if( !gotsubject )
CLU_FPrintfAsync( tofile, "BET:\n" );
#ifndef UUXQT_MD
CLU_FPrintfAsync( tofile, "__SOURCEFMT:RFC1036/822\nLEN:%ld\n\n", c );
#else
CLU_FPrintfAsync( tofile, "LEN:%ld\n\n", c );
#endif
domui();
// Printf( "rmail: zclen %ld\n", c );
/* Artikelinhalt kopieren */
FOREVER
{
ch = CLU_ReadCharAsync( newsfile );
if( ch < 0 )
break;
if( ch == 13 )
continue;
else if( ch == 10 )
{
CLU_WriteCharAsync( tofile, 13 );
CLU_WriteCharAsync( tofile, 10 );
}
else CLU_WriteCharAsync( tofile, ch );
}
// Printf( "rmail: after msgcopy\n" );
CLU_CloseAsync( tofile );
CLU_CloseAsync( newsfile );
DeleteFile( from );
// Printf( "rmail: exiting rmail\n" );
return( 0 );
}
/* Returncodes:
3 = can't open tofile
1 = can't open file
30 = smtp format error
31 = unexpected EOF
*/
int bsmtp( char *fromname )
{
struct AsyncFile *bfile, *tofile;
char toname[á64 ];
char xname[á64 ];
BPTR xfile;
int Done = FALSE;
int rc = 0;
BOOL havefrom, haveto, havehelo;
char from[ 256 ], sys[á256 ];
char fromsys[á128 ], fromuser[á128 ];
char *p;
BPTR oldcd;
int mailcount = 0;
static char to[ 2048 ];
lastoffset = NULL;
domui();
set_status( GS( MSG_TXT_DOBSMTP ) );
addlog( 6, "extracting smtp batch" );
bfile = CLU_OpenAsync( fromname, ASMODE_READ, ASYNCBUFF );
if( !bfile )
return( 1 );
#ifndef UUXQT_MD
oldcd = CurrentDir( Lock( "UUSPOOL:", SHARED_LOCK ) );
#endif
havehelo = FALSE;
while( !Done )
{
havefrom = FALSE;
haveto = FALSE;
to[á0 ]á= 0;
set_fg( lastoffset = CLU_FtellAsync( bfile ) );
while( !Done )
{
if( !CLU_FGetsAsync( bfile, linebuffer, LBLEN ) )
{
Done = 2;
break;
}
clnl( linebuffer );
if( !stricmp( linebuffer, "QUIT" ) )
{
Done = 1;
break;
}
else if( !stricmp( linebuffer, "DATA" ) )
{
Done = 3;
break;
}
else if( !strnicmp( linebuffer, "HELO", 4 ) )
{
strcpy( sys, stpblk( &linebuffer[á4 ]á) );
p = strchr( sys, '.' );
if( p )
*p = 0;
havehelo = TRUE;
}
else if( !strnicmp( linebuffer, "MAIL FROM:", 10 ) )
{
strcpy( from, stpblk( &linebuffer[á10 ]á) + 1 );
havefrom = TRUE;
from[ástrlen( from ) - 1 ]á= 0;
}
else if( !strnicmp( linebuffer, "RCPT TO:", 8 ) )
{
haveto = TRUE;
strcat( to, stpblk( &linebuffer[á8 ]á) + 1 );
strcpy(á&to[ástrlen( to ) - 1 ], " " );
}
}
if( Done == 1 )
{
rc = 0;
break;
}
// OK, Header ist eingelesen
if( Done == 2 )
{
rc = 31;
break;
}
if( !haveto || !havefrom || !havehelo )
{
rc = 30;
break;
}
// Letztes Leerzeichen
to[ástrlen( to ) - 1 ] = 0;
// Nun gut, also Data...
sprintf( xname, "X.%sNLL%ld", sys, CLU_GetSeqNum() );
sprintf( toname, "D.%sloc%ld", sys, CLU_GetSeqNum() );
xfile = Open( xname, MODE_NEWFILE );
mailcount++;
FPrintf( xfile,
"# bsmtp demangler command file (%ld from %s)\n"
"U root %s\n"
"F %s\n"
"C rmail %s\n",
mailcount, fromname,
sys, toname,
to
);
Close( xfile );
tofile = CLU_OpenAsync( toname, ASMODE_WRITE, 8192 );
strcpy( fromuser, from );
p = strchr( fromuser, '@' );
if( p )
{
*p++ = 0;
strcpy( fromsys, p );
}
CLU_FPrintfAsync( tofile, "From %s!%s remote from %s\n", fromsys, fromuser, sys );
for(;;)
{
if( !CLU_FGetsAsync( bfile, linebuffer, LBLEN ) )
break;
if( !strcmp( linebuffer, ".\n" ) )
break;
CLU_WriteAsync( tofile, linebuffer, strlen( linebuffer ) );
}
CLU_CloseAsync( tofile );
if( Done == 3 )
Done = FALSE;
}
CLU_CloseAsync( bfile );
addlog( 7, "bsmtp batch contained %ld mail(s)", mailcount );
#ifndef UUXQT_MD
UnLock( CurrentDir( oldcd ) );
#endif
return( rc );
}
int cbsmtp( char *file )
{
BPTR dosnewsfile, dostmpfile;
int rc;
dosnewsfile = Open( file, MODE_OLDFILE );
if( !dosnewsfile )
return( 1 );
sprintf( tempfile, "uuconv.%lxtmp", CLU_GetSeqNum() );
addlog( 6, "uncompressing %s to %s", file, tempfile );
dostmpfile = Open( tempfile, MODE_NEWFILE );
if( !dostmpfile )
{
Close( dosnewsfile );
return( 3 );
}
#ifndef UUXQT_MD
CLP_PK_AllocSem();
rc = CLU_MUI_RunCommand( app, "UUCP:C/GZip -d",
NP_Input, dosnewsfile,
NP_Output, dostmpfile,
NP_StackSize, 20480,
NP_Priority, -1,
TAG_DONE
);
CLP_PK_FreeSem();
#else
{
char exec[ 256 ];
strcpy( exec, gzipfullpath );
strcat( exec, " -d" );
rc = SystemTags( exec,
SYS_Input, dosnewsfile,
SYS_Output, dostmpfile,
NP_StackSize, 20480,
NP_Priority, -1,
TAG_DONE
);
Close( dosnewsfile );
Close( dostmpfile );
}
#endif
rc = bsmtp( tempfile );
if( !rc )
{
DeleteFile( file );
DeleteFile( tempfile );
}
return( rc );
}