------------------------------------------------------------------------------ This patch to the FreeBSD mail program enables saving of deleted messages to a file. This is intended to prevent accidental loss of important messages when, for example, culling spam. Apply with patch < srw-bsd-mail.patch from the directory containing the "mail" source directory, and rebuild. Only the quit.c file is affected. To use, add a line to your .mailrc file: set savedelete=/path/to/file The /path/to/file is the path to a file where deleted messages are appended, and it will be created as needed. This grows without bound, so you should delete it periodically. Steve Whiteley 1/13/03 Whiteley Research Inc. ----------------------------------------------------------------------------- diff -c mail.old/quit.c mail/quit.c *** mail.old/quit.c Sat Aug 18 20:44:22 2001 --- mail/quit.c Mon Jan 13 13:21:19 2003 *************** *** 31,36 **** --- 31,39 ---- * SUCH DAMAGE. */ + /* Modified by S. R. Whiteley, stevew@srware.com, 1/13/03 */ + /* If "set savedelete=path" given, deleted messages will be saved in path */ + #ifndef lint #if 0 static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93"; *************** *** 78,83 **** --- 81,90 ---- int c, fd; struct stat minfo; char *mbox, tempname[PATHSIZE]; + /* SRW */ + FILE *dbuf; + char *dsave_name; + /**/ /* * If we are read only, we can't do anything, *************** *** 185,197 **** return; } if (c == 0) { if (p != 0) { writeback(rbuf); (void)Fclose(fbuf); return; } ! goto cream; ! } /* * Create another temporary file and copy user's mbox file --- 192,221 ---- return; } if (c == 0) { + /* SRW */ + dsave_name = value("savedelete"); + if (dsave_name && *dsave_name) { + dbuf = Fopen(dsave_name, "a"); + if (dbuf) { + for (mp = &message[0]; mp < &message[msgCount]; mp++) { + if (mp->m_flag & MDELETED) { + if (sendmessage(mp, dbuf, saveignore, NULL) < 0) { + warnx("%s", dsave_name); + break; + } + } + } + Fclose(dbuf); + } + } + /**/ if (p != 0) { writeback(rbuf); (void)Fclose(fbuf); return; } ! goto cream; ! } /* * Create another temporary file and copy user's mbox file *************** *** 248,255 **** } (void)fchmod(fileno(obuf), 0600); } ! for (mp = &message[0]; mp < &message[msgCount]; mp++) ! if (mp->m_flag & MBOX) if (sendmessage(mp, obuf, saveignore, NULL) < 0) { warnx("%s", mbox); (void)Fclose(ibuf); --- 272,286 ---- } (void)fchmod(fileno(obuf), 0600); } ! /* SRW */ ! dbuf = 0; ! dsave_name = value("savedelete"); ! if (dsave_name && *dsave_name) ! dbuf = Fopen(dsave_name, "a"); ! /**/ ! ! for (mp = &message[0]; mp < &message[msgCount]; mp++) { ! if (mp->m_flag & MBOX) { if (sendmessage(mp, obuf, saveignore, NULL) < 0) { warnx("%s", mbox); (void)Fclose(ibuf); *************** *** 257,262 **** --- 288,309 ---- (void)Fclose(fbuf); return; } + } + /* SRW */ + else if (dbuf && (mp->m_flag & MDELETED)) { + if (sendmessage(mp, dbuf, saveignore, NULL) < 0) { + warnx("%s", dsave_name); + Fclose(dbuf); + dbuf = 0; + + } + } + /**/ + } + /* SRW */ + if (dbuf) + Fclose(dbuf); + /**/ /* * Copy the user's old mbox contents back