epg [Thu, 30 Mar 2006 02:28:59 +0000 (02:28 +0000)]
Add a sample processor. This talks to spamassassin spamd to find out
if a message is spam. If so, it moves it to maildir/spam, else it
moves it to maildir/new.
{libspamc,utils}.[ch] are icky, icky bits from spamassassin's spamc.
The only substantial change is to make libspamc.c:_message_read_raw
mmap the message instead of reading the entire thing into memory (wtf
were they thinking?!).
epg [Thu, 30 Mar 2006 01:59:47 +0000 (01:59 +0000)]
Support qmail if the QMAIL macro is defined. This entails exiting 111
on failure, not having to worry about dumbass /^From /, and handling
RPLINE and DTLINE.
Say EX_TEMPFAIL instead of MDELIVER_EXITCODE.
s/TMPNAMLEN/LEN_FILENAME/; it's not just used for the tmp file.
Random cleanup:
- drop some redundant comments
- s/statbuf/st/
- s/STDIN_FILENO/0/
- cleanup error messages
- other style nits
Drop <err.h> and implement custom err and errx, which doesn't need to
be passed an exit code.
Implement and use full_sleep to really sleep the specified time.
(get_filename): Don't break when gethostname truncates.
(strip_from): Don't even compile this for QMAIL.
(deliver): Take a new parameter, the subdirectory to deliver to,
instead of "new". #ifdef QMAIL, write RPLINE and DTLINE to tmp file
before copying stdin.
(deliver): Also had a huge problem: it was using the logic i came up
with for minc, to open an empty file for the target and then rename
onto that. That's fine for mh, which already loses mail this way
(once i switch refile to be like minc this will be fine), but since
other Maildir MDAs follow the official algorithm, this could clobber
mail. Switch to the official algorithm.
(run_processor): Use better error message format.
(main): If .mdeliver-processor exists, pass deliver "mdb" as the
subdirectory and then call run_processor, else pass "new".
epg [Wed, 29 Mar 2006 05:09:18 +0000 (05:09 +0000)]
(run_processor): r1901 was a little off; this should only _exit when
the fork succeeded, and we cannot use vfork, as we need to write an
error message if the exec failed.
epg [Sun, 19 Jan 2003 03:11:14 +0000 (03:11 +0000)]
mdeliver/current/mdeliver.c:
(deliver): In rev 1582 i changed this from using rename(2) to
the recommended link(2) + unlink(2). But in minc i was using
open(2) + rename(2) instead, which is just as safe as link +
unlink but with one advantage. So switch to that model.
minc/current/minc:
(store_message): Document the open + rename procedure and
explain why it is used instead of link + unlink.
epg [Thu, 16 Jan 2003 17:59:18 +0000 (17:59 +0000)]
(deliver): Stick closer to the standard maildir delivery algorithm by
using link(2) + unlink(2) instead of rename(2) to get the message file
from tmp to new. rename(2) will clobber an existing file, which we
don't want; link(2) will not.
Strictly speaking this is an impossible scenario for mdeliver, for
which one process delivers no more than one message. It is, however,
not outside the realm of possibility that a filename identical to the
one chosen by mdeliver came into existence for some unrelated reason
(though the odds of this happening must be staggering).
Perhaps more importantly, it has been reported on the qmail list that
OpenBSD 3.2 will reuse the same PID in the same second, which would
mean this was a real problem on that system.
Whatever the case, this addresses any potential problems.
(run_processor): While there's nothing we can do if any of the
err-file-writing steps fail, there's no reason we can't be a little
more careful in doing it. Do so (including using fflush, fsync,
and close).
(run_processor): Now only takes a single argument, the filename of the
new message. The process to run is now hard-coded to be a dot-file in
the user's home directory.
Rename copy_message to copy_file, document it, and make it slightly
more generic. Now i can share it with other programs (for example, my
portable install(1)).
Only include <sysexits.h> if MDELIVER_EXITCODE is not defined, and if
it isn't defined, define it to EX_TEMPFAIL. Change all references to
EX_TEMPFAIL to MDELIVER_EXITCODE.