1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
2001-12-18 20:52:09 +00:00
|
|
|
static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rcv -- receive mail rationally.
|
|
|
|
*
|
|
|
|
* Termination processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The "quit" command.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
quitcmd(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we are sourcing, then return 1 so execute() can handle it.
|
|
|
|
* Otherwise, return -1 to abort command loop.
|
|
|
|
*/
|
|
|
|
if (sourcing)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
quit(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int mcount, p, modify, autohold, anystat, holdbit, nohold;
|
|
|
|
FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
|
|
|
int c, fd;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct stat minfo;
|
2001-03-25 04:57:05 +00:00
|
|
|
char *mbox, tempname[PATHSIZE];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are read only, we can't do anything,
|
|
|
|
* so just return quickly.
|
|
|
|
*/
|
|
|
|
if (readonly)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* If editing (not reading system mail box), then do the work
|
|
|
|
* in edstop()
|
|
|
|
*/
|
|
|
|
if (edit) {
|
|
|
|
edstop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* a message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fbuf = Fopen(mailname, "r");
|
|
|
|
if (fbuf == NULL)
|
|
|
|
goto newmail;
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)flock(fileno(fbuf), LOCK_EX);
|
1994-05-27 12:33:43 +00:00
|
|
|
rbuf = NULL;
|
|
|
|
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
|
|
|
|
printf("New mail has arrived.\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(tempname, sizeof(tempname),
|
|
|
|
"%s/mail.RqXXXXXXXXXX", tmpdir);
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((fd = mkstemp(tempname)) == -1 ||
|
|
|
|
(rbuf = Fdopen(fd, "w")) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
goto newmail;
|
|
|
|
#ifdef APPEND
|
2001-09-02 14:40:51 +00:00
|
|
|
(void)fseeko(fbuf, mailsize, SEEK_SET);
|
1994-05-27 12:33:43 +00:00
|
|
|
while ((c = getc(fbuf)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, rbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
|
|
|
p = minfo.st_size - mailsize;
|
|
|
|
while (p-- > 0) {
|
|
|
|
c = getc(fbuf);
|
|
|
|
if (c == EOF)
|
|
|
|
goto newmail;
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, rbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(rbuf);
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((rbuf = Fopen(tempname, "r")) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
goto newmail;
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the message flags in each message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
anystat = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
autohold = value("hold") != NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
holdbit = autohold ? MPRESERVE : MBOX;
|
|
|
|
nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("keepsave") != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
nohold &= ~MSAVED;
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
|
|
|
|
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)
|
|
|
|
mp->m_flag |= MPRESERVE;
|
|
|
|
if ((mp->m_flag & nohold) == 0)
|
|
|
|
mp->m_flag |= holdbit;
|
|
|
|
}
|
|
|
|
modify = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((readstat = Fopen(Tflag, "w")) == NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
Tflag = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
|
|
|
|
if (mp->m_flag & MBOX)
|
|
|
|
c++;
|
|
|
|
if (mp->m_flag & MPRESERVE)
|
|
|
|
p++;
|
|
|
|
if (mp->m_flag & MODIFY)
|
|
|
|
modify++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL && (mp->m_flag & (MREAD|MDELETED)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
char *id;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((id = hfield("article-id", mp)) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(readstat, "%s\n", id);
|
|
|
|
}
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL)
|
|
|
|
(void)Fclose(readstat);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (p == msgCount && !modify && !anystat) {
|
|
|
|
printf("Held %d message%s in %s\n",
|
|
|
|
p, p == 1 ? "" : "s", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (c == 0) {
|
|
|
|
if (p != 0) {
|
|
|
|
writeback(rbuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto cream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mbox = expand("&");
|
|
|
|
mcount = c;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("append") == NULL) {
|
|
|
|
(void)snprintf(tempname, sizeof(tempname),
|
|
|
|
"%s/mail.RmXXXXXXXXXX", tmpdir);
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((fd = mkstemp(tempname)) == -1 ||
|
|
|
|
(obuf = Fdopen(fd, "w")) == NULL) {
|
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((ibuf = Fopen(tempname, "r")) == NULL) {
|
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
|
|
|
(void)Fclose(obuf);
|
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((abuf = Fopen(mbox, "r")) != NULL) {
|
|
|
|
while ((c = getc(abuf)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
|
|
|
(void)Fclose(abuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (ferror(obuf)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(ibuf);
|
|
|
|
(void)Fclose(obuf);
|
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
2016-07-15 19:43:24 +00:00
|
|
|
if ((fd = open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600)) >= 0)
|
|
|
|
(void)close(fd);
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((obuf = Fopen(mbox, "r+")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mbox);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(ibuf);
|
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("append") != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((obuf = Fopen(mbox, "a")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mbox);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fchmod(fileno(obuf), 0600);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++)
|
|
|
|
if (mp->m_flag & MBOX)
|
2001-05-27 20:26:22 +00:00
|
|
|
if (sendmessage(mp, obuf, saveignore, NULL) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("%s", mbox);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(ibuf);
|
|
|
|
(void)Fclose(obuf);
|
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the user's old mbox contents back
|
|
|
|
* to the end of the stuff we just saved.
|
|
|
|
* If we are appending, this is unnecessary.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("append") == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
rewind(ibuf);
|
|
|
|
c = getc(ibuf);
|
|
|
|
while (c != EOF) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf))
|
|
|
|
break;
|
|
|
|
c = getc(ibuf);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(ibuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-12-18 20:52:09 +00:00
|
|
|
(void)fflush(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
trunc(obuf);
|
|
|
|
if (ferror(obuf)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mbox);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (mcount == 1)
|
|
|
|
printf("Saved 1 message in mbox\n");
|
|
|
|
else
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (p != 0) {
|
|
|
|
writeback(rbuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-27 20:26:22 +00:00
|
|
|
* Finally, remove his /var/mail file.
|
1994-05-27 12:33:43 +00:00
|
|
|
* If new mail has arrived, copy it back.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cream:
|
|
|
|
if (rbuf != NULL) {
|
|
|
|
abuf = Fopen(mailname, "r+");
|
|
|
|
if (abuf == NULL)
|
|
|
|
goto newmail;
|
|
|
|
while ((c = getc(rbuf)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, abuf);
|
|
|
|
(void)Fclose(rbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
trunc(abuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(abuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
alter(mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
demail();
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
newmail:
|
|
|
|
printf("Thou hast new mail.\n");
|
|
|
|
if (fbuf != NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
writeback(FILE *res)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
|
|
|
int p, c;
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *obuf;
|
|
|
|
|
|
|
|
p = 0;
|
|
|
|
if ((obuf = Fopen(mailname, "r+")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
#ifndef APPEND
|
|
|
|
if (res != NULL)
|
|
|
|
while ((c = getc(res)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++)
|
|
|
|
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
|
|
|
|
p++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (sendmessage(mp, obuf, NULL, NULL) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("%s", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef APPEND
|
|
|
|
if (res != NULL)
|
|
|
|
while ((c = getc(res)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
trunc(obuf);
|
|
|
|
if (ferror(obuf)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (res != NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(res);
|
|
|
|
(void)Fclose(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
alter(mailname);
|
|
|
|
if (p == 1)
|
|
|
|
printf("Held 1 message in %s\n", mailname);
|
|
|
|
else
|
|
|
|
printf("Held %d messages in %s\n", p, mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Terminate an editing session by attempting to write out the user's
|
|
|
|
* file from the temporary. Save any new stuff appended to the file.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
edstop(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int gotcha, c;
|
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *obuf, *ibuf, *readstat;
|
|
|
|
struct stat statb;
|
2001-03-25 04:57:05 +00:00
|
|
|
char tempname[PATHSIZE];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (readonly)
|
|
|
|
return;
|
|
|
|
holdsigs();
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((readstat = Fopen(Tflag, "w")) == NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
Tflag = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
|
|
|
|
if (mp->m_flag & MNEW) {
|
|
|
|
mp->m_flag &= ~MNEW;
|
|
|
|
mp->m_flag |= MSTATUS;
|
|
|
|
}
|
|
|
|
if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
|
|
|
|
gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL && (mp->m_flag & (MREAD|MDELETED)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
char *id;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((id = hfield("article-id", mp)) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(readstat, "%s\n", id);
|
|
|
|
}
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (Tflag != NULL)
|
|
|
|
(void)Fclose(readstat);
|
|
|
|
if (!gotcha || Tflag != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
goto done;
|
|
|
|
ibuf = NULL;
|
|
|
|
if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
|
2001-03-25 04:57:05 +00:00
|
|
|
int fd;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(tempname, sizeof(tempname),
|
|
|
|
"%s/mbox.XXXXXXXXXX", tmpdir);
|
|
|
|
if ((fd = mkstemp(tempname)) == -1 ||
|
|
|
|
(obuf = Fdopen(fd, "w")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
|
|
|
if ((ibuf = Fopen(mailname, "r")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
|
|
|
(void)rm(tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
2001-09-02 14:40:51 +00:00
|
|
|
(void)fseeko(ibuf, mailsize, SEEK_SET);
|
1994-05-27 12:33:43 +00:00
|
|
|
while ((c = getc(ibuf)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
|
|
|
(void)Fclose(ibuf);
|
|
|
|
(void)Fclose(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((ibuf = Fopen(tempname, "r")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
printf("\"%s\" ", mailname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((obuf = Fopen(mailname, "r+")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mailname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
|
|
|
trunc(obuf);
|
|
|
|
c = 0;
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
|
|
|
|
if ((mp->m_flag & MDELETED) != 0)
|
|
|
|
continue;
|
|
|
|
c++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (sendmessage(mp, obuf, NULL, NULL) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("%s", mailname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gotcha = (c == 0 && ibuf == NULL);
|
|
|
|
if (ibuf != NULL) {
|
|
|
|
while ((c = getc(ibuf)) != EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, obuf);
|
|
|
|
(void)Fclose(ibuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", mailname);
|
1994-05-27 12:33:43 +00:00
|
|
|
relsesigs();
|
|
|
|
reset(0);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (gotcha) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(mailname);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("removed\n");
|
|
|
|
} else
|
|
|
|
printf("complete\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
relsesigs();
|
|
|
|
}
|