version 1.14, 2001/01/16 05:36:09 |
version 1.15, 2001/11/20 20:50:00 |
|
|
* Save all untouched messages back in the system mailbox. |
* Save all untouched messages back in the system mailbox. |
* Remove the system mailbox, if none saved there. |
* Remove the system mailbox, if none saved there. |
*/ |
*/ |
void |
int |
quit() |
quit() |
{ |
{ |
int mcount, p, modify, autohold, anystat, holdbit, nohold; |
int mcount, p, modify, autohold, anystat, holdbit, nohold; |
|
|
* so just return quickly. |
* so just return quickly. |
*/ |
*/ |
if (readonly) |
if (readonly) |
return; |
return(0); |
/* |
/* |
* If editing (not reading system mail box), then do the work |
* If editing (not reading system mail box), then do the work |
* in edstop() |
* in edstop() |
*/ |
*/ |
if (edit) { |
if (edit) |
edstop(); |
return(edstop()); |
return; |
|
} |
|
|
|
/* |
/* |
* See if there any messages to save in mbox. If no, we |
* See if there any messages to save in mbox. If no, we |
|
|
if (flock(fileno(fbuf), LOCK_EX) == -1) { |
if (flock(fileno(fbuf), LOCK_EX) == -1) { |
warn("Unable to lock mailbox"); |
warn("Unable to lock mailbox"); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
return; |
return(-1); |
} |
} |
if (!spool_lock()) { |
if (!spool_lock()) { |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
return; /* lockspool printed error for us */ |
return(-1); /* lockspool printed error for us */ |
} |
} |
rbuf = NULL; |
rbuf = NULL; |
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { |
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { |
|
|
p, p == 1 ? "" : "s", mailname); |
p, p == 1 ? "" : "s", mailname); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(0); |
} |
} |
if (c == 0) { |
if (c == 0) { |
if (p != 0) { |
if (p != 0) { |
writeback(rbuf); |
writeback(rbuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(0); |
} |
} |
goto cream; |
goto cream; |
} |
} |
|
|
warn("%s", tempname); |
warn("%s", tempname); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
if ((ibuf = Fopen(tempname, "r")) == NULL) { |
if ((ibuf = Fopen(tempname, "r")) == NULL) { |
warn("%s", tempname); |
warn("%s", tempname); |
|
|
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
(void)rm(tempname); |
(void)rm(tempname); |
if ((abuf = Fopen(mbox, "r")) != NULL) { |
if ((abuf = Fopen(mbox, "r")) != NULL) { |
|
|
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)close(creat(mbox, 0600)); |
(void)close(creat(mbox, 0600)); |
|
|
(void)Fclose(ibuf); |
(void)Fclose(ibuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
} |
} else { |
else { |
|
if ((obuf = Fopen(mbox, "a")) == NULL) { |
if ((obuf = Fopen(mbox, "a")) == NULL) { |
warn("%s", mbox); |
warn("%s", mbox); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
fchmod(fileno(obuf), 0600); |
fchmod(fileno(obuf), 0600); |
} |
} |
|
|
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
|
|
/* |
/* |
|
|
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(-1); |
} |
} |
(void)Fclose(obuf); |
(void)Fclose(obuf); |
if (mcount == 1) |
if (mcount == 1) |
|
|
writeback(rbuf); |
writeback(rbuf); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(0); |
} |
} |
|
|
/* |
/* |
|
|
alter(mailname); |
alter(mailname); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(0); |
} |
} |
demail(); |
demail(); |
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
return; |
return(0);; |
|
|
newmail: |
newmail: |
puts("Thou hast new mail."); |
puts("Thou hast new mail."); |
|
|
(void)Fclose(fbuf); |
(void)Fclose(fbuf); |
spool_unlock(); |
spool_unlock(); |
} |
} |
|
return(0); |
} |
} |
|
|
/* |
/* |
|
|
* Terminate an editing session by attempting to write out the user's |
* Terminate an editing session by attempting to write out the user's |
* file from the temporary. Save any new stuff appended to the file. |
* file from the temporary. Save any new stuff appended to the file. |
*/ |
*/ |
void |
int |
edstop() |
edstop() |
{ |
{ |
int gotcha, c; |
int gotcha, c; |
|
|
char tempname[PATHSIZE]; |
char tempname[PATHSIZE]; |
|
|
if (readonly) |
if (readonly) |
return; |
return(0); |
holdsigs(); |
holdsigs(); |
if (Tflag != NULL) { |
if (Tflag != NULL) { |
if ((readstat = Fopen(Tflag, "w")) == NULL) |
if ((readstat = Fopen(Tflag, "w")) == NULL) |
|
|
(obuf = Fdopen(fd, "w")) == NULL) { |
(obuf = Fdopen(fd, "w")) == NULL) { |
warn("%s", tempname); |
warn("%s", tempname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
if ((ibuf = Fopen(mailname, "r")) == NULL) { |
if ((ibuf = Fopen(mailname, "r")) == NULL) { |
warn("%s", mailname); |
warn("%s", mailname); |
(void)Fclose(obuf); |
(void)Fclose(obuf); |
(void)rm(tempname); |
(void)rm(tempname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
fseek(ibuf, (long)mailsize, 0); |
fseek(ibuf, (long)mailsize, 0); |
while ((c = getc(ibuf)) != EOF) |
while ((c = getc(ibuf)) != EOF) |
|
|
warn("%s", tempname); |
warn("%s", tempname); |
(void)rm(tempname); |
(void)rm(tempname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
(void)rm(tempname); |
(void)rm(tempname); |
} |
} |
|
|
if ((obuf = Fopen(mailname, "r+")) == NULL) { |
if ((obuf = Fopen(mailname, "r+")) == NULL) { |
warn("%s", mailname); |
warn("%s", mailname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
trunc(obuf); |
trunc(obuf); |
c = 0; |
c = 0; |
|
|
if (sendmessage(mp, obuf, NULL, NULL) < 0) { |
if (sendmessage(mp, obuf, NULL, NULL) < 0) { |
warn("%s", mailname); |
warn("%s", mailname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
} |
} |
gotcha = (c == 0 && ibuf == NULL); |
gotcha = (c == 0 && ibuf == NULL); |
|
|
if (ferror(obuf)) { |
if (ferror(obuf)) { |
warn("%s", mailname); |
warn("%s", mailname); |
relsesigs(); |
relsesigs(); |
reset(0); |
return(-1); |
} |
} |
(void)Fclose(obuf); |
(void)Fclose(obuf); |
if (gotcha) { |
if (gotcha) { |
|
|
|
|
done: |
done: |
relsesigs(); |
relsesigs(); |
|
return(0); |
} |
} |