projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
install with -s
[unix-history]
/
usr
/
src
/
usr.bin
/
mail
/
quit.c
diff --git
a/usr/src/usr.bin/mail/quit.c
b/usr/src/usr.bin/mail/quit.c
index
efa9bb6
..
7b233ee
100644
(file)
--- a/
usr/src/usr.bin/mail/quit.c
+++ b/
usr/src/usr.bin/mail/quit.c
@@
-1,7
+1,10
@@
-#
+#ifndef lint
+static char *sccsid = "@(#)quit.c 2.9 (Berkeley) %G%";
+#endif
#include "rcv.h"
#include <sys/stat.h>
#include "rcv.h"
#include <sys/stat.h>
+#include <sys/file.h>
/*
* Rcv -- receive mail rationally.
/*
* Rcv -- receive mail rationally.
@@
-9,8
+12,6
@@
* Termination processing.
*/
* Termination processing.
*/
-static char *SccsId = "@(#)quit.c 1.3 %G%";
-
/*
* Save all of the undetermined messages at the top of "mbox"
* Save all untouched messages back in the system mailbox.
/*
* Save all of the undetermined messages at the top of "mbox"
* Save all untouched messages back in the system mailbox.
@@
-19,12
+20,13
@@
static char *SccsId = "@(#)quit.c 1.3 %G%";
quit()
{
quit()
{
- int mcount, p, modify, autohold;
- FILE *ibuf, *obuf, *fbuf, *rbuf;
+ int mcount, p, modify, autohold
, anystat, holdbit, nohold
;
+ FILE *ibuf, *obuf, *fbuf, *rbuf
, *readstat, *abuf
;
register struct message *mp;
register int c;
extern char tempQuit[], tempResid[];
struct stat minfo;
register struct message *mp;
register int c;
extern char tempQuit[], tempResid[];
struct stat minfo;
+ char *id;
/*
* If we are read only, we can't do anything,
/*
* If we are read only, we can't do anything,
@@
-46,19
+48,21
@@
quit()
* anything with the mailbox, unless mail locking works.
*/
* anything with the mailbox, unless mail locking works.
*/
- lock(mailname);
+ fbuf = fopen(mailname, "r");
+ if (fbuf == NULL)
+ goto newmail;
+ flock(fileno(fbuf), LOCK_EX);
#ifndef CANLOCK
if (selfsent) {
printf("You have new mail.\n");
#ifndef CANLOCK
if (selfsent) {
printf("You have new mail.\n");
-
unlock(
);
+
fclose(fbuf
);
return;
}
#endif
rbuf = NULL;
return;
}
#endif
rbuf = NULL;
- if (
stat(mailname
, &minfo) >= 0 && minfo.st_size > mailsize) {
+ if (
fstat(fileno(fbuf)
, &minfo) >= 0 && minfo.st_size > mailsize) {
printf("New mail has arrived.\n");
rbuf = fopen(tempResid, "w");
printf("New mail has arrived.\n");
rbuf = fopen(tempResid, "w");
- fbuf = fopen(mailname, "r");
if (rbuf == NULL || fbuf == NULL)
goto newmail;
#ifdef APPEND
if (rbuf == NULL || fbuf == NULL)
goto newmail;
#ifdef APPEND
@@
-74,42
+78,66
@@
quit()
putc(c, rbuf);
}
#endif
putc(c, rbuf);
}
#endif
- fclose(fbuf);
fclose(rbuf);
if ((rbuf = fopen(tempResid, "r")) == NULL)
goto newmail;
remove(tempResid);
}
fclose(rbuf);
if ((rbuf = fopen(tempResid, "r")) == NULL)
goto newmail;
remove(tempResid);
}
+
+ /*
+ * Adjust the message flags in each message.
+ */
+
+ anystat = 0;
+ autohold = value("hold") != NOSTR;
+ holdbit = autohold ? MPRESERVE : MBOX;
+ nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
+ if (value("keepsave") != NOSTR)
+ nohold &= ~MSAVED;
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
- if (mp->m_flag & MDELETED)
- mp->m_flag = MDELETED|MTOUCH;
+ if (mp->m_flag & MNEW) {
+ mp->m_flag &= ~MNEW;
+ mp->m_flag |= MSTATUS;
+ }
+ if (mp->m_flag & MSTATUS)
+ anystat++;
if ((mp->m_flag & MTOUCH) == 0)
if ((mp->m_flag & MTOUCH) == 0)
- mp->m_flag |= MDELETED;
+ mp->m_flag |= MPRESERVE;
+ if ((mp->m_flag & nohold) == 0)
+ mp->m_flag |= holdbit;
}
}
- autohold = value("hold") != NOSTR;
modify = 0;
modify = 0;
+ if (Tflag != NOSTR) {
+ if ((readstat = fopen(Tflag, "w")) == NULL)
+ Tflag = NOSTR;
+ }
for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
- if ((mp->m_flag & (MSAVED|MDELETED)) == 0 && autohold)
- mp->m_flag |= MPRESERVE;
- if ((mp->m_flag & (MSAVED|MDELETED|MPRESERVE)) == 0)
+ if (mp->m_flag & MBOX)
c++;
c++;
- if (
(mp->m_flag & MPRESERVE) || (mp->m_flag & MTOUCH) == 0
)
+ if (
mp->m_flag & MPRESERVE
)
p++;
if (mp->m_flag & MODIFY)
modify++;
p++;
if (mp->m_flag & MODIFY)
modify++;
+ if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
+ id = hfield("article-id", mp);
+ if (id != NOSTR)
+ fprintf(readstat, "%s\n", id);
+ }
}
}
- if (p == msgCount && !modify) {
+ if (Tflag != NOSTR)
+ fclose(readstat);
+ if (p == msgCount && !modify && !anystat) {
if (p == 1)
printf("Held 1 message in %s\n", mailname);
else
printf("Held %2d messages in %s\n", p, mailname);
if (p == 1)
printf("Held 1 message in %s\n", mailname);
else
printf("Held %2d messages in %s\n", p, mailname);
-
unlock(
);
+
fclose(fbuf
);
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
goto cream;
return;
}
goto cream;
@@
-126,51
+154,51
@@
quit()
if (value("append") == NOSTR) {
if ((obuf = fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
if (value("append") == NOSTR) {
if ((obuf = fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
-
unlock(
);
+
fclose(fbuf
);
return;
}
if ((ibuf = fopen(tempQuit, "r")) == NULL) {
perror(tempQuit);
remove(tempQuit);
fclose(obuf);
return;
}
if ((ibuf = fopen(tempQuit, "r")) == NULL) {
perror(tempQuit);
remove(tempQuit);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
remove(tempQuit);
return;
}
remove(tempQuit);
- if ((
f
buf = fopen(mbox, "r")) != NULL) {
- while ((c = getc(
f
buf)) != EOF)
+ if ((
a
buf = fopen(mbox, "r")) != NULL) {
+ while ((c = getc(
a
buf)) != EOF)
putc(c, obuf);
putc(c, obuf);
- fclose(
f
buf);
+ fclose(
a
buf);
}
if (ferror(obuf)) {
perror(tempQuit);
fclose(ibuf);
fclose(obuf);
}
if (ferror(obuf)) {
perror(tempQuit);
fclose(ibuf);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
fclose(obuf);
close(creat(mbox, 0600));
return;
}
fclose(obuf);
close(creat(mbox, 0600));
- if ((obuf = fopen(mbox, "
w
")) == NULL) {
+ if ((obuf = fopen(mbox, "
r+
")) == NULL) {
perror(mbox);
fclose(ibuf);
perror(mbox);
fclose(ibuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
}
if (value("append") != NOSTR)
if ((obuf = fopen(mbox, "a")) == NULL) {
perror(mbox);
return;
}
}
if (value("append") != NOSTR)
if ((obuf = fopen(mbox, "a")) == NULL) {
perror(mbox);
-
unlock(
);
+
fclose(fbuf
);
return;
}
for (mp = &message[0]; mp < &message[msgCount]; mp++)
return;
}
for (mp = &message[0]; mp < &message[msgCount]; mp++)
- if (
(mp->m_flag & (MDELETED|MSAVED|MPRESERVE)) == 0
)
- if (send(mp, obuf) < 0) {
+ if (
mp->m_flag & MBOX
)
+ if (send(mp, obuf
, 0
) < 0) {
perror(mbox);
fclose(ibuf);
fclose(obuf);
perror(mbox);
fclose(ibuf);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-192,10
+220,11
@@
quit()
fclose(ibuf);
fflush(obuf);
}
fclose(ibuf);
fflush(obuf);
}
+ trunc(obuf);
if (ferror(obuf)) {
perror(mbox);
fclose(obuf);
if (ferror(obuf)) {
perror(mbox);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
fclose(obuf);
return;
}
fclose(obuf);
@@
-211,7
+240,7
@@
quit()
if (p != 0) {
writeback(rbuf);
if (p != 0) {
writeback(rbuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-222,24
+251,26
@@
quit()
cream:
if (rbuf != NULL) {
cream:
if (rbuf != NULL) {
-
fbuf = fopen(mailname, "w
");
- if (
f
buf == NULL)
+
abuf = fopen(mailname, "r+
");
+ if (
a
buf == NULL)
goto newmail;
while ((c = getc(rbuf)) != EOF)
goto newmail;
while ((c = getc(rbuf)) != EOF)
- putc(c,
f
buf);
+ putc(c,
a
buf);
fclose(rbuf);
fclose(rbuf);
- fclose(fbuf);
+ trunc(abuf);
+ fclose(abuf);
alter(mailname);
alter(mailname);
-
unlock(
);
+
fclose(fbuf
);
return;
}
demail();
return;
}
demail();
-
unlock(
);
+
fclose(fbuf
);
return;
newmail:
printf("Thou hast new mail.\n");
return;
newmail:
printf("Thou hast new mail.\n");
- unlock();
+ if (fbuf != NULL)
+ fclose(fbuf);
}
/*
}
/*
@@
-248,7
+279,6
@@
newmail:
* saved. On any error, just return -1. Else return 0.
* Incorporate the any new mail that we found.
*/
* saved. On any error, just return -1. Else return 0.
* Incorporate the any new mail that we found.
*/
-
writeback(res)
register FILE *res;
{
writeback(res)
register FILE *res;
{
@@
-257,7
+287,7
@@
writeback(res)
FILE *obuf;
p = 0;
FILE *obuf;
p = 0;
- if ((obuf = fopen(mailname, "
w
")) == NULL) {
+ if ((obuf = fopen(mailname, "
r+
")) == NULL) {
perror(mailname);
return(-1);
}
perror(mailname);
return(-1);
}
@@
-269,7
+299,7
@@
writeback(res)
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
p++;
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
p++;
- if (send(mp, obuf) < 0) {
+ if (send(mp, obuf
, 0
) < 0) {
perror(mailname);
fclose(obuf);
return(-1);
perror(mailname);
fclose(obuf);
return(-1);
@@
-281,6
+311,7
@@
writeback(res)
putc(c, obuf);
#endif
fflush(obuf);
putc(c, obuf);
#endif
fflush(obuf);
+ trunc(obuf);
if (ferror(obuf)) {
perror(mailname);
fclose(obuf);
if (ferror(obuf)) {
perror(mailname);
fclose(obuf);