warn(mbox);
warn("%s", mbox);
quit(){	int mcount, p, modify, autohold, anystat, holdbit, nohold;	FILE *ibuf = NULL, *obuf, *fbuf, *rbuf, *readstat = NULL, *abuf;	struct message *mp;	int c, fd;	struct stat minfo;	char *mbox, tempname[PATHSIZE];	/*	 * 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;	if (flock(fileno(fbuf), LOCK_EX) == -1) {		warn("Unable to lock mailbox");		(void)Fclose(fbuf);		return;	}	if (!spool_lock()) {		(void)Fclose(fbuf);		return;			/* lockspool printed error for us */	}	rbuf = NULL;	if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {		puts("New mail has arrived.");		(void)snprintf(tempname, sizeof(tempname),		    "%s/mail.RqXXXXXXXXXX", tmpdir);		if ((fd = mkstemp(tempname)) == -1 ||		    (rbuf = Fdopen(fd, "w")) == NULL)			goto newmail;#ifdef APPEND		fseek(fbuf, (long)mailsize, 0);		while ((c = getc(fbuf)) != EOF)			(void)putc(c, rbuf);#else		p = minfo.st_size - mailsize;		while (p-- > 0) {			c = getc(fbuf);			if (c == EOF)				goto newmail;			(void)putc(c, rbuf);		}#endif		(void)Fclose(rbuf);		if ((rbuf = Fopen(tempname, "r")) == NULL)			goto newmail;		(void)rm(tempname);	}	/*	 * Adjust the message flags in each message.	 */	anystat = 0;	autohold = value("hold") != NULL;	holdbit = autohold ? MPRESERVE : MBOX;	nohold = MBOX|MSAVED|MDELETED|MPRESERVE;	if (value("keepsave") != NULL)		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;	if (Tflag != NULL) {		if ((readstat = Fopen(Tflag, "w")) == NULL)			Tflag = NULL;	}	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++;		if (Tflag != NULL && (mp->m_flag & (MREAD|MDELETED)) != 0) {			char *id;			if ((id = hfield("article-id", mp)) != NULL)				fprintf(readstat, "%s\n", id);		}	}	if (Tflag != NULL)		(void)Fclose(readstat);	if (p == msgCount && !modify && !anystat) {		printf("Held %d message%s in %s\n",			p, p == 1 ? "" : "s", mailname);		(void)Fclose(fbuf);		spool_unlock();		return;	}	if (c == 0) {		if (p != 0) {			writeback(rbuf);			(void)Fclose(fbuf);			spool_unlock();			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;	if (value("append") == NULL) {		(void)snprintf(tempname, sizeof(tempname),		    "%s/mail.RmXXXXXXXXXX", tmpdir);		if ((fd = mkstemp(tempname)) == -1 ||		    (obuf = Fdopen(fd, "w")) == NULL) {			warn(tempname);			(void)Fclose(fbuf);			spool_unlock();			return;		}		if ((ibuf = Fopen(tempname, "r")) == NULL) {			warn(tempname);			(void)rm(tempname);			(void)Fclose(obuf);			(void)Fclose(fbuf);			spool_unlock();			return;		}		(void)rm(tempname);		if ((abuf = Fopen(mbox, "r")) != NULL) {			while ((c = getc(abuf)) != EOF)				(void)putc(c, obuf);			(void)Fclose(abuf);		}		if (ferror(obuf)) {			warn(tempname);			(void)Fclose(ibuf);			(void)Fclose(obuf);			(void)Fclose(fbuf);			spool_unlock();			return;		}		(void)Fclose(obuf);		(void)close(creat(mbox, 0600));		if ((obuf = Fopen(mbox, "r+")) == NULL) {			warn(mbox);			(void)Fclose(ibuf);			(void)Fclose(fbuf);			spool_unlock();			return;		}	}	else {		if ((obuf = Fopen(mbox, "a")) == NULL) {			warn(mbox);			(void)Fclose(fbuf);			spool_unlock();			return;		}		fchmod(fileno(obuf), 0600);	}	for (mp = &message[0]; mp < &message[msgCount]; mp++)		if (mp->m_flag & MBOX)			if (sendmessage(mp, obuf, saveignore, NULL) < 0) {				warn(mbox);				(void)Fclose(ibuf);				(void)Fclose(obuf);				(void)Fclose(fbuf);				spool_unlock();				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.	 */	if (value("append") == NULL) {		rewind(ibuf);		c = getc(ibuf);		while (c != EOF) {			(void)putc(c, obuf);			if (ferror(obuf))				break;			c = getc(ibuf);		}		(void)Fclose(ibuf);		fflush(obuf);	}	trunc(obuf);	if (ferror(obuf)) {		warn(mbox);		(void)Fclose(obuf);		(void)Fclose(fbuf);		spool_unlock();		return;	}	(void)Fclose(obuf);	if (mcount == 1)		puts("Saved 1 message in mbox");	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);		(void)Fclose(fbuf);		spool_unlock();		return;	}	/*	 * Finally, remove his /var/mail file.	 * 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)			(void)putc(c, abuf);		(void)Fclose(rbuf);		trunc(abuf);		(void)Fclose(abuf);		alter(mailname);		(void)Fclose(fbuf);		spool_unlock();		return;	}	demail();	(void)Fclose(fbuf);	spool_unlock();	return;newmail:	puts("Thou hast new mail.");	if (fbuf != NULL) {		(void)Fclose(fbuf);		spool_unlock();	}}