static char sccsid
[] = "@(#)quit.c 2.7 (Berkeley) %G%";
* Rcv -- receive mail rationally.
* Termination processing.
* Save all of the undetermined messages at the top of "mbox"
* Save all untouched messages back in the system mailbox.
* Remove the system mailbox, if none saved there.
int mcount
, p
, modify
, autohold
, anystat
, holdbit
, nohold
;
FILE *ibuf
, *obuf
, *fbuf
, *rbuf
, *readstat
;
register struct message
*mp
;
extern char tempQuit
[], tempResid
[];
* If we are read only, we can't do anything,
* so just return quickly.
* See if there any messages to save in mbox. If no, we
* can save copying mbox to /tmp and back.
* Check also to see if any files need to be preserved.
* Delete all untouched messages to keep them out of mbox.
* If all the messages are to be preserved, just exit with
* If the luser has sent mail to himself, refuse to do
* anything with the mailbox, unless mail locking works.
printf("You have new mail.\n");
if (stat(mailname
, &minfo
) >= 0 && minfo
.st_size
> mailsize
) {
printf("New mail has arrived.\n");
rbuf
= fopen(tempResid
, "w");
fbuf
= fopen(mailname
, "r");
if (rbuf
== NULL
|| fbuf
== NULL
)
fseek(fbuf
, mailsize
, 0);
while ((c
= getc(fbuf
)) != EOF
)
p
= minfo
.st_size
- mailsize
;
if ((rbuf
= fopen(tempResid
, "r")) == NULL
)
* Adjust the message flags in each message.
autohold
= value("hold") != NOSTR
;
holdbit
= autohold
? MPRESERVE
: MBOX
;
nohold
= MBOX
|MSAVED
|MDELETED
|MPRESERVE
;
if (value("keepsave") != NOSTR
)
for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++) {
if (mp
->m_flag
& MSTATUS
)
if ((mp
->m_flag
& MTOUCH
) == 0)
if ((mp
->m_flag
& nohold
) == 0)
if ((readstat
= fopen(Tflag
, "w")) == NULL
)
for (c
= 0, p
= 0, mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++) {
if (mp
->m_flag
& MPRESERVE
)
if (Tflag
!= NOSTR
&& (mp
->m_flag
& (MREAD
|MDELETED
)) != 0) {
id
= hfield("article-id", mp
);
fprintf(readstat
, "%s\n", id
);
if (p
== msgCount
&& !modify
&& !anystat
) {
printf("Held 1 message in %s\n", mailname
);
printf("Held %2d messages in %s\n", p
, mailname
);
* Create another temporary file and copy user's mbox file
* darin. If there is no mbox, copy nothing.
* If he has specified "append" don't copy his mailbox,
* just copy saveable entries at the end.
if (value("append") == NOSTR
) {
if ((obuf
= fopen(tempQuit
, "w")) == NULL
) {
if ((ibuf
= fopen(tempQuit
, "r")) == NULL
) {
if ((fbuf
= fopen(mbox
, "r")) != NULL
) {
while ((c
= getc(fbuf
)) != EOF
)
close(creat(mbox
, 0600));
if ((obuf
= fopen(mbox
, "r+")) == NULL
) {
if (value("append") != NOSTR
)
if ((obuf
= fopen(mbox
, "a")) == NULL
) {
for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
if (send(mp
, obuf
, 0) < 0) {
* Copy the user's old mbox contents back
* to the end of the stuff we just saved.
* If we are appending, this is unnecessary.
if (value("append") == NOSTR
) {
printf("Saved 1 message in mbox\n");
printf("Saved %d messages in mbox\n", mcount
);
* Now we are ready to copy back preserved files to
* the system mailbox, if any were requested.
* Finally, remove his /usr/mail file.
* If new mail has arrived, copy it back.
fbuf
= fopen(mailname
, "r+");
while ((c
= getc(rbuf
)) != EOF
)
printf("Thou hast new mail.\n");
* Preserve all the appropriate messages back in the system
* mailbox, and print a nice message indicated how many were
* saved. On any error, just return -1. Else return 0.
* Incorporate the any new mail that we found.
register struct message
*mp
;
if ((obuf
= fopen(mailname
, "r+")) == NULL
) {
while ((c
= getc(res
)) != EOF
)
for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
if ((mp
->m_flag
&MPRESERVE
)||(mp
->m_flag
&MTOUCH
)==0) {
if (send(mp
, obuf
, 0) < 0) {
while ((c
= getc(res
)) != EOF
)
printf("Held 1 message in %s\n", mailname
);
printf("Held %d messages in %s\n", p
, mailname
);