📄 deliver.c
字号:
/*--------------------------------------------------------------------*/
importpath( msname, ixfile, path);
mkfilename( msfile, E_spooldir, msname);
stream = FOPEN(msfile, "w", BINARY_MODE);
if ( stream == NULL )
{
printerr(msfile);
printmsg(0, "DeliverRemote: cannot open X file %s", msfile);
return 0;
} /* if */
fprintf(stream, "R %s@%s\nU %s %s\nF %s\nI %s\nC rmail %s\n",
ruser, rnode, uuser , E_nodename,
rdfile, rdfile, everyone);
fclose(stream);
if (SavePath != NULL)
return 1;
/*--------------------------------------------------------------------*/
/* Create the data file with the mail to send to the remote system */
/*--------------------------------------------------------------------*/
importpath(msname, idfile, path);
mkfilename( msfile, E_spooldir, msname);
stream = FOPEN(msfile, "w", BINARY_MODE);
if (stream == NULL )
{
printerr(msfile);
printmsg(0,
"DeliverRemote: Cannot open spool file \"%s\" for output",
msfile);
return 0;
}
if (!CopyData( TRUE, input , stream ))
{
remove( msfile );
return 0;
}
/*--------------------------------------------------------------------*/
/* create local C (call) file */
/*--------------------------------------------------------------------*/
importpath( msname, tmfile, path);
mkfilename( msfile, E_spooldir, msname);
stream = FOPEN(msfile, "w",TEXT_MODE);
if (stream == NULL)
{
printerr( msname );
printmsg(0, "DeliverRemote: cannot open C file %s", msfile);
return 0;
}
fprintf(stream, send_cmd, idfile, rdfile, uuser, idfile);
fprintf(stream, send_cmd, ixfile, rxfile, uuser, ixfile);
fclose(stream);
if (bflag[F_MULTI]) /* Deliver to multiple users at once? */
SavePath = strdup(path); /* Yes --> Save routing info */
return 1;
} /* DeliverRemote */
/*--------------------------------------------------------------------*/
/* C o p y D a t a */
/* */
/* Copy data into its final resting spot */
/*--------------------------------------------------------------------*/
static int CopyData( const boolean remotedelivery,
const char *input,
FILE *dataout)
{
FILE *datain = FOPEN(input, "r",TEXT_MODE);
char buf[BUFSIZ];
int column = 0;
boolean success = TRUE;
int (*put_string) (char *, FILE *) = (int (*)(char *, FILE *)) fputs;
/* Assume no Kanji translation needed */
/*--------------------------------------------------------------------*/
/* Verify the input opened */
/*--------------------------------------------------------------------*/
if (datain == NULL)
{
printerr(input);
printmsg(0,"Unable to open input file \"%s\"", input);
fclose(dataout);
return 0;
} /* datain */
/*--------------------------------------------------------------------*/
/* When we do the From line, we also determine if we must */
/* translate the data. Note that the default is initialized to */
/* fputs() above. */
/* */
/* If Kanji is not enabled, don't translate it */
/* */
/* If local mail queued for local delivery, the data is already */
/* in Shift JIS, so don't translate it. */
/* */
/* If remote mail is queued for remote delivery, the data is */
/* already in JIS 7bit, so don't translate it. */
/* */
/* If delivering remote mail locally, translate to Shift JIS */
/* */
/* If delivering local mail remotely, translate to JIS 7 bit */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Generate a FROM line */
/*--------------------------------------------------------------------*/
switch( (int) remoteMail * 2 + (int) remotedelivery )
{
case 3: /* Remote sender, remote delivery */
strcpy( buf, fromuser );
strtok( buf, "!"); /* Get first host in list */
if ( equal(HostAlias( buf ), fromnode ))
/* Host already in list? */
{ /* Yes --> Don't do it twice */
fprintf(dataout, "From %s %s remote from %s\n",
fromuser, now, E_nodename);
break;
}
else { /* No --> Insert it */
fprintf(dataout, "From %s!%s %s remote from %s\n",
fromnode, fromuser, now, E_nodename);
break;
}
/*--------------------------------------------------------------------*/
/* Note: For the Kanji translation we re-check the */
/* remoteDelivery flag since we do the fall through from above. */
/*--------------------------------------------------------------------*/
case 2: /* Remote sender, local delivery */
if ( bflag[ F_KANJI ] )
/* Kanji from remote node? */
put_string = (int (*)(char *, FILE *)) fputs_shiftjis;
/* Yes --> Translate it */
fprintf(dataout, "From %s %s remote from %s\n",
fromuser, now, fromnode);
break;
case 1: /* Local sender, remote delivery */
if ( bflag[F_KANJI]) /* Translation enabled? */
put_string = (int (*)(char *, FILE *)) fputs_jis7bit;
/* Translate into 7 bit Kanji */
column = strlen(E_domain) - 5;
if ((column > 0) && equali(&E_domain[column],".UUCP"))
/* UUCP domain? */
fprintf(dataout, "From %s %s remote from %s\n",
fromuser, now, E_nodename);
/* Yes --> Use simple address */
else
fprintf(dataout, "From %s!%s %s remote from %s\n",
E_domain, fromuser, now, E_nodename);
/* No --> Use domain address */
break;
case 0: /* Local sender, local delivery */
fprintf(dataout, "From %s %s\n", fromuser, now);
break;
} /* switch */
/*--------------------------------------------------------------------*/
/* Loop to copy the data */
/*--------------------------------------------------------------------*/
while (fgets(buf, BUFSIZ, datain) != NULL)
{
if ((*put_string)(buf, dataout) == EOF) /* I/O error? */
{
printerr("output");
printmsg(0,"I/O error on \"%s\"", "output");
fclose(dataout);
return 0;
} /* if */
} /* while */
/*--------------------------------------------------------------------*/
/* Close up shop and return */
/*--------------------------------------------------------------------*/
if (ferror(datain)) /* Clean end of file on input? */
{
printerr(input);
clearerr(datain);
success = FALSE;
}
fclose(datain);
fclose(dataout);
return success;
} /* CopyData */
/*--------------------------------------------------------------------*/
/* b o u n c e */
/* */
/* Report failed mail to a user. Based on code contributed */
/* by Kevin Meyer <kmeyer@sauron.alt.za> */
/* */
/* This code has a major hole in that the address it replies */
/* to is weak, really having been previously only been used */
/* for internal messages. Perhaps the full address from the */
/* UUCP From line should be used. */
/*--------------------------------------------------------------------*/
size_t Bounce( const char *input,
const char *text,
const char *data,
const char *address ,
const boolean validate )
{
FILE *newfile, *otherfile;
char tname[FILENAME_MAX]; /* name of temporary file used */
char buf[BUFSIZ];
char sender[MAXADDR];
boolean bounce = bflag[F_BOUNCE];
sprintf(sender, "%s%s%s",
ruser,
remoteMail ? "@" : "",
remoteMail ? rnode : "" );
printmsg(0,"Bounce: Mail from %s for %s failed, %s: %s",
sender,
address,
text,
(data == NULL) ? "(no data)" : data );
/*--------------------------------------------------------------------*/
/* Never bounce mail to a select list of user ids */
/*--------------------------------------------------------------------*/
if ( equali( ruser, "postmaster") ||
equali( ruser, "uucp") ||
equali( ruser, "root") ||
equali( ruser, "mmdf") ||
equali( ruser, "mailer-daemon"))
bounce = FALSE;
if ( ! bounce )
return Deliver( input, E_postmaster, FALSE, validate );
mktempname( tname , "TMP"); // Generate a temp file name
if ((otherfile = FOPEN(input,"r", TEXT_MODE ))==NULL)
{
printerr( input );
panic();
};
if ((newfile = FOPEN(tname, "w", TEXT_MODE ))==NULL)
{
printerr( tname );
panic();
};
fprintf(newfile,
"Dear %s,\n"
"Your message for address <%s> could not be delivered at system\n"
"%s (uucp node %s) for the following reason:\n\t\t%s.\n",
ruser,
address, E_domain, E_nodename, text );
if ( data != NULL )
fprintf(newfile,
"The problem address or file in question was: %s\n",
data );
fprintf(newfile,
"\nA copy of the failed mail follows.\n\n"
"Electronically Yours,\n"
"%s %s UUCP mailer daemon\n",
compilep, compilev );
fputs("\n------ Failed Message Follows -----\n", newfile);
while ( fgets(buf, sizeof buf, otherfile) != NULL)
fputs(buf, newfile);
fclose(newfile);
fclose(otherfile);
/*--------------------------------------------------------------------*/
/* Recursively invoke RMAIL to deliver our message */
/*--------------------------------------------------------------------*/
putenv("LOGNAME=uucp");
sprintf( buf, "-w -F %s -s \"Failed mail for %.20s\" %s -c postmaster",
tname,
address,
sender );
if ( execute( myProgramName, buf, NULL, NULL, TRUE, FALSE ))
DeliverLocal( input, E_postmaster, FALSE, validate);
return (1);
} /* Bounce */
/*--------------------------------------------------------------------*/
/* s t a t s */
/* */
/* Report size of file in message, if desired */
/*--------------------------------------------------------------------*/
static char *stats( const char *fname )
{
if (bflag[ F_COLLECTSTATS ] )
{
long size;
time_t ltime = stater(fname, &size);
if ( ltime == -1 )
{
printerr( fname );
return "(unknown size)";
}
else {
static char buf[25]; /* "(nnnnnnn bytes) " */
/* ....+....+....+.. */
sprintf(buf, "(%ld bytes) ",size );
return buf;
} /* else */
} /* if */
else
return ""; /* Pretend we were never here */
} /* stats */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -