The Maildir specification doesn't seem to say anything about this
situation, and it can happen if you're keeping a Maildir mailbox in
Subversion (.svn directories) or some similar system. The patch just
ignores directories in the cur/, new/, tmp/ folders.
Add length checking to single-file mailbox formats: before doing a
flush() on a mailbox, seek to the end and verify its length is
unchanged, raising ExternalClashError if the file's length has
changed.
This fix avoids potential data loss if some other process appends to
the mailbox file after the table of contents has been generated;
instead of overwriting the modified file, you'll get the exception.
I also noticed that the self._lookup() call in self.flush() wasn't
necessary (everything that sets self._pending to True also calls
self.lookup()), and replaced it by an assertion.
2.5 backport candidate.
This change looks massive but it's mostly a re-indenting after
removing some try...finally blocks.
Also adds a test case that does a pack() while the mailbox is locked; this
test would have turned up bugs in the original code on some platforms.
In both nmh and GNU Mailutils' implementation of MH-format mailboxes,
no locking is done of individual message files when renaming them.
The original mailbox.py code did do locking, which meant that message
files had to be opened. This code was buggy on certain platforms
(found through reading the code); there were code paths that closed
the file object and then called _unlock_file() on it.
Will backport to 25-maint once I see how the buildbots react to this patch.
Two changes:
Where possible, use link()/remove() to move files into a directory; this
makes it easier to avoid overwriting an existing file.
Use _create_carefully() to create files in tmp/, which uses O_EXCL.
Backport candidate.
remove the flock() calls.
On FreeBSD, the two methods lockf() and flock() end up using the same
mechanism and the second one fails. A Linux man page claims that the
two methods are orthogonal (so locks acquired one way don't interact
with locks acquired the other way) but that clearly must be false.
the 2005 Summer of Code).
The revision adds a number of new mailbox classes that support adding
and removing messages; these classes also support mailbox locking and
default to using email.Message instead of rfc822.Message.
The old mailbox classes are largely left alone for backward compatibility.
The exception is the Maildir class, which was present in the old module
and now inherits from the new classes. The Maildir class's interface
is pretty simple, though, so I think it'll be compatible with existing
code.
(The change to the NEWS file also adds a missing word to a different
news item, which unfortunately required rewrapping the line.)
'\037\014\n' (see http://quimby.gnus.org/notes/BABYL) so look for that as well,
so that applications won't get '\037' as the last line of the last message.
attribute to the (stringized) message number (if this attribute is
settable). This is useful so users of this class can report the
correct message number (e.g. when classifying spam).
Also added a blank line before the first method of each class.
Andrew quite correctly notices that the next() method isn't quite what
we need, since it returns None upon end instead of raising
StopIteration. His fix is easy enough, using iter(self.next, None)
instead.
cut-and-paste copy of the seek() method on the _Subfile class, but it
didn't make one bit of sense: it sets self.pos, which is not used in
this class or its subclasses, and it uses self.start and self.stop,
which aren't defined on this class or its subclasses. This is purely
my own fault -- I added this in rev 1.4 and apparently never tried to
use it. Since it's not documented, and of very questionable use given
that there's no tell(), I'm ripping it out.
This resolves SF bug 416199 by Andrew Dalke: mailbox.py seek problems.
- All constructors grow an optional argument `factory' which is a
callable used when new message instances are created by the next()
methods. Defaults to the rfc822.Message class.
- A new subclass of UnixMailbox is added, called PortableUnixMailbox.
It's identical to UnixMailbox, but uses a more portable test for
From_ delimiter lines. With PortableUnixMailbox, any line that
starts with "From " is considered a delimiter (this should really
check for two newlines before the F, but it doesn't.
mailbox.py (from the CVS tree) doesn't work with qmail Maildirs:
Filenames are completed when the directories are scanned, and
the directory name is prepended again in the next() method.
Another suggestion: Change the print statement in the _test()
driver to show two more date characters (probably the length
has increased due to the recent Y2K hype ;). Now it shows the
complete date, including the seconds -- at least for me. (I've
also made the sender field left justified, in case it is ever
shorter than the field width).
Unix From lines, change the UnixMailbox class so that _search_start()
positions the file *before* the Unix From line instead of after it;
change _search_end() to skip one line before looking for the next From
line. The rfc822.Message class automatically recognizes these Unix
From lines and squirrels them away in the 'unixfrom' instance variable.