Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: archiving mail



> shimpei@example.com (lists.tlug):
> >of things could happen between individual calls. If mail gets delivered
> >between the move and new creation, the mail could get truncated; if it
> 
> Yes, I spotted that bug this morning.
> 
> >gets delivered between creation and flock, it could get overwritten by
> >whatever the script does afterwards.
> 
> You can only lock a filehandle, and you only have a filehandle once
> you've opened a file. Perl doesn't have atomic open-and-flock, as far
> as I'm aware. The way to fix it would be to use:
>  unless (open ORIG, "+>".$file) {
> which won't clobber, and writing will be safe since we only write when
> we've got a lock.

You could conceivably hack up the .procmailrc and wrapper your mail client
so that they compete for a dotlock (which can be done atomically unless
your filesystem is NFS) with your mail archive program before attempting 
delivery. This, of course, assumes that absolutely no one else is going to 
touch your mail spool, which is not guaranteed.

I went in circles around these ideas a few years ago and eventually reached
the conclusion that the file-per-message format is the only sane one for
mailboxes that expect to be written to from multiple sources. A database
would work, too, but a) you can't grep a database and b) good luck 
finding a mail client that works with one. Maildir [1] is pretty much worry-free
in this respect. It also makes the original problem that started this thread
trivial: grep the Date: line in each message file and mv old ones to a new 
folder. You don't even have to conjure up new filenames for them.

Shimpei.

[1] Dan Bernstein's handiwork. Insert obligatory flames here. ->
It's completely independent of qmail, though.


-----------------------------------------------------------------------
Next Technical Meeting: July 8 (Sat)  13:30  Place: LinuxProbe Hall
Next Nomikai meeting: August 18 (Fri) 19:00  Place: TBD
-----------------------------------------------------------------------
more info: http://www.tlug.gr.jp        Sponsor: Global Online Japan


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links