version 1.14, 2001/11/21 15:26:39 |
version 1.15, 2001/11/28 01:26:35 |
|
|
#include "rcv.h" |
#include "rcv.h" |
#include "extern.h" |
#include "extern.h" |
|
|
|
static volatile sig_atomic_t sendsignal; /* Interrupted by a signal? */ |
|
|
/* |
/* |
* Mail -- a mail program |
* Mail -- a mail program |
* |
* |
|
|
int c = 0; |
int c = 0; |
int length; |
int length; |
int prefixlen = 0; |
int prefixlen = 0; |
|
int rval; |
|
struct sigaction act, saveint; |
|
sigset_t oset; |
|
|
|
sendsignal = 0; |
|
rval = -1; |
|
sigemptyset(&act.sa_mask); |
|
act.sa_flags = SA_RESTART; |
|
act.sa_handler = sendint; |
|
(void)sigaction(SIGINT, &act, &saveint); |
|
(void)sigprocmask(SIG_UNBLOCK, &intset, &oset); |
|
|
/* |
/* |
* Compute the prefix string, without trailing whitespace |
* Compute the prefix string, without trailing whitespace |
*/ |
*/ |
|
|
* fields |
* fields |
*/ |
*/ |
if (dostat) { |
if (dostat) { |
statusput(mp, obuf, prefix); |
if (statusput(mp, obuf, prefix) == -1) |
|
goto out; |
dostat = 0; |
dostat = 0; |
} |
} |
ishead = 0; |
ishead = 0; |
|
|
* there are no headers at all. |
* there are no headers at all. |
*/ |
*/ |
if (dostat) { |
if (dostat) { |
statusput(mp, obuf, prefix); |
if (statusput(mp, obuf, prefix) == -1) |
|
goto out; |
dostat = 0; |
dostat = 0; |
} |
} |
if (doign != ignoreall) |
if (doign != ignoreall) |
|
|
* and print the real Status: field |
* and print the real Status: field |
*/ |
*/ |
if (dostat) { |
if (dostat) { |
statusput(mp, obuf, prefix); |
if (statusput(mp, obuf, prefix) == -1) |
|
goto out; |
dostat = 0; |
dostat = 0; |
} |
} |
ignoring = 1; |
ignoring = 1; |
|
|
} |
} |
(void)fwrite(line, sizeof(*line), length, obuf); |
(void)fwrite(line, sizeof(*line), length, obuf); |
if (ferror(obuf)) |
if (ferror(obuf)) |
return(-1); |
goto out; |
} |
} |
|
if (sendsignal == SIGINT) |
|
goto out; |
} |
} |
/* |
/* |
* Copy out message body |
* Copy out message body |
|
|
if (strncmp(line, "From ", 5) == 0) |
if (strncmp(line, "From ", 5) == 0) |
(void)fwrite(">", 1, 1, obuf); /* '>' before 'From ' */ |
(void)fwrite(">", 1, 1, obuf); /* '>' before 'From ' */ |
(void)fwrite(line, sizeof(*line), c, obuf); |
(void)fwrite(line, sizeof(*line), c, obuf); |
if (ferror(obuf)) |
if (ferror(obuf) || sendsignal == SIGINT) |
return(-1); |
goto out; |
} |
} |
if (doign == ignoreall && c > 0 && line[c - 1] != '\n') |
if (doign == ignoreall && c > 0 && line[c - 1] != '\n') |
/* no final blank line */ |
/* no final blank line */ |
if ((c = getc(ibuf)) != EOF && putc(c, obuf) == EOF) |
if ((c = getc(ibuf)) != EOF && putc(c, obuf) == EOF) |
return(-1); |
goto out; |
return(0); |
rval = 0; |
|
out: |
|
sendsignal = 0; |
|
(void)sigprocmask(SIG_SETMASK, &oset, NULL); |
|
(void)sigaction(SIGINT, &saveint, NULL); |
|
return(rval); |
} |
} |
|
|
/* |
/* |
* Output a reasonable looking status field. |
* Output a reasonable looking status field. |
*/ |
*/ |
void |
int |
statusput(struct message *mp, FILE *obuf, char *prefix) |
statusput(struct message *mp, FILE *obuf, char *prefix) |
{ |
{ |
char statout[3]; |
char statout[3]; |
|
|
if ((mp->m_flag & MNEW) == 0) |
if ((mp->m_flag & MNEW) == 0) |
*cp++ = 'O'; |
*cp++ = 'O'; |
*cp = 0; |
*cp = 0; |
if (statout[0]) |
if (statout[0]) { |
fprintf(obuf, "%sStatus: %s\n", |
fprintf(obuf, "%sStatus: %s\n", |
prefix == NULL ? "" : prefix, statout); |
prefix == NULL ? "" : prefix, statout); |
|
return(ferror(obuf) ? -1 : 0); |
|
} |
|
return(0); |
} |
} |
|
|
/* |
/* |
|
|
(void)Fclose(fo); |
(void)Fclose(fo); |
rewind(fi); |
rewind(fi); |
return(0); |
return(0); |
|
} |
|
|
|
/*ARGSUSED*/ |
|
void |
|
sendint(int s) |
|
{ |
|
|
|
sendsignal = s; |
} |
} |