Commit Graph

67 Commits

Author SHA1 Message Date
Andrew M. Kuchling 70a6dbd46e Bug 3228: Explicitly supply the file mode to avoid creating executable files,
and add corresponding tests.
Possible 2.5 backport candidate
2008-08-04 01:43:43 +00:00
Andrew M. Kuchling 15ce880cc8 Bug 1277: make Maildir use the user-provided factory instead of hard-wiring MaildirMessage.
2.5.2 bugfix candidate.
2008-01-19 20:12:04 +00:00
Andrew M. Kuchling 2b09ef0c6d Avoid exception if there's a stray directory inside a Maildir folder.
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.
2007-07-14 21:56:19 +00:00
Tim Peters f733abb783 Whitespace normalization. 2007-01-30 03:03:46 +00:00
Andrew M. Kuchling b94c0c3ea1 Make comment match the code 2007-01-22 20:27:50 +00:00
Andrew M. Kuchling b78bb74c41 Improve pattern used for mbox 'From' lines; add a simple test 2007-01-22 20:26:40 +00:00
Georg Brandl 5a096e1b10 Use new email module names (#1637162, #1637159, #1637157). 2007-01-22 19:40:21 +00:00
Andrew M. Kuchling eca4c31267 [Apply length-checking.diff from bug #1599254]
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.
2006-12-20 19:48:20 +00:00
Andrew M. Kuchling 1646568b5e [Patch #1599256 from David Watson] check that os.fsync is available before using it 2006-12-14 18:57:53 +00:00
Andrew M. Kuchling 8c456f3b57 Remove file-locking in MH.pack() method.
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.
2006-11-17 13:30:25 +00:00
Andrew M. Kuchling 978d8286ae [Patch #1514543] mailbox (Maildir): avoid losing messages on name clash
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.
2006-11-09 21:16:46 +00:00
Andrew M. Kuchling b5686da24f [Patch #1514544 by David Watson] use fsync() to ensure data is really on disk 2006-11-09 13:51:14 +00:00
Andrew M. Kuchling a3e5d3757c [Bug #1569790] mailbox.Maildir.get_folder() loses factory information
Both the Maildir and MH classes had this bug; the patch fixes both classes
and adds a test.

Will backport to 25-maint.
2006-11-09 13:27:07 +00:00
Andrew M. Kuchling 0f87183cf5 [Bug #1575506] The _singlefileMailbox class was using the wrong file object in its flush() method, causing an error 2006-10-27 16:55:34 +00:00
Andrew MacIntyre afa358fabf Get mailbox module working on OS/2 EMX port. 2006-07-23 13:04:00 +00:00
Neal Norwitz 7983c7298d According to the man pages on Gentoo Linux and Tru64, EACCES or EAGAIN
can be returned if fcntl (lockf) fails.  This fixes the test failure
on Tru64 by checking for either error rather than just EAGAIN.
2006-06-28 05:03:22 +00:00
Andrew M. Kuchling 557325930c [Bug #1512163] Use one set of locking methods, lockf();
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.
2006-06-26 13:12:16 +00:00
Andrew M. Kuchling a7ee9eb3d9 [Bug #1512163] Fix typo.
This change will probably break tests on FreeBSD buildbots, but I'll check in
a fix for that next.
2006-06-26 13:08:24 +00:00
Martin v. Löwis 879768dd97 Change WindowsError to carry the Win32 error code in winerror,
and the DOS error code in errno. Revert changes where
WindowsError catch blocks unnecessarily special-case OSError.
2006-05-11 13:28:43 +00:00
Martin v. Löwis 08041d582b Update checks to consider Windows error numbers. 2006-05-04 14:27:52 +00:00
Andrew M. Kuchling 214db63df8 Use open() instead of file() 2006-05-02 21:44:33 +00:00
Tim Peters 6d7cd7d6f4 Whitespace normalization. 2006-04-22 05:52:59 +00:00
Andrew M. Kuchling 1da4a94719 Add Gregory K. Johnson's revised version of mailbox.py (funded by
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.)
2006-04-22 02:32:43 +00:00
Johannes Gijsbers 6abc685a03 Patch #880621: the last message of a Babyl mailbox ends in '\037' instead of
'\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.
2004-08-21 12:30:26 +00:00
Skip Montanaro 3414c1ceee add missing newlines to read/readline.
fixes bug #996359.
2004-07-24 19:54:44 +00:00
Andrew M. Kuchling 1263bd8b6c [Bug #925107] Make .readline() consider self.stop. This makes read() and readline() very similar, so they're refactored into _read. Patch by Johannes Gijsbers.
2.3 bugfix candidate.
2004-07-07 14:09:21 +00:00
Raymond Hettinger b5ba8d749d Lists work better when popping from the right. 2004-02-07 02:16:24 +00:00
Guido van Rossum 4bf1254342 Undocumented feature: MHMailbox sets the msg object's _mh_msgno
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.
2002-09-12 05:08:00 +00:00
Barry Warsaw da5628f286 Fix an inaccuracy in the comment 2002-08-26 16:44:56 +00:00
Raymond Hettinger 46ac8eb3c8 Code modernization. Replace v=s[i]; del s[i] with single lookup v=s.pop(i) 2002-06-30 03:39:14 +00:00
Raymond Hettinger 54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Tim Peters bc0e910826 Convert a pile of obvious "yes/no" functions to return bool. 2002-04-04 22:55:58 +00:00
Neil Schemenauer 03f3ee6d89 Try /var/mail before trying /usr/mail. Most new systems use /var.
This in inside the test so it really doesn't matter much.  Closes
SF patch 497097.
2002-03-24 01:38:38 +00:00
Barry Warsaw ffd05ee90d Added PortableUnixMailbox to the __all__ variable, and in the __main__
section use this class instead of UnixMailbox as per the comments in
the latter's class.

Bug fix candidate for 2.2.1.
2002-03-01 22:39:14 +00:00
Guido van Rossum 93a696f491 SF bug #461073: mailbox __iter__ bug, by Andrew Dalke.
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.
2001-09-13 01:29:13 +00:00
Guido van Rossum ef8f4dee07 Remove redundant imports (PyChecker). 2001-08-13 15:37:02 +00:00
Fred Drake 72987a4b96 Make the Mailbox objects support iteration -- they already had the
appropriate next() method, and this is what people really want to do with
these objects in practice.
2001-05-02 20:20:53 +00:00
Guido van Rossum 2b5ff073ab Get rid of the seek() method on the _Mailbox class. This was a
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.
2001-04-15 13:32:27 +00:00
Barry Warsaw 81ad67cdc6 Two changes:
- 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.
2001-01-31 22:13:15 +00:00
Skip Montanaro 17ab123cf1 a few more modules get __all__ 2001-01-24 06:27:27 +00:00
Fred Drake 8152d32375 Update the code to better reflect recommended style:
Use != instead of <> since <> is documented as "obsolescent".
Use "is" and "is not" when comparing with None or type objects.
2000-12-12 23:20:45 +00:00
Fred Drake de3518e7ca Maildir.__init__(): Make sure self.boxes is set.
This closes SourceForge bug #117490.
2000-10-23 13:37:01 +00:00
Fred Drake cc4adf27f4 Add missing "s" from format string.
This closes SourceForge patch #101714.
2000-09-30 23:59:04 +00:00
Fred Drake d9a8dec135 Maildir.__init__(): Use the correct filter for filenames, so that this
class conforms to the maildir specification.
2000-09-22 18:41:50 +00:00
Fred Drake e108a02723 Detlef Lannert <lannert@uni-duesseldorf.de>:
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).
2000-09-14 14:44:43 +00:00
Sjoerd Mullender d2653a9e07 Use built in function filter instead of doing it laboriously by hand. 2000-08-11 07:48:36 +00:00
Guido van Rossum 0707fea5ee Improve MHMailbox: messages are now sorted in numerical order.
Also don't allow leading zeros in message numbers.
2000-08-10 03:05:26 +00:00
Fred Drake dbbf76bd5a Make tabnanny happy.
mailbox.py: Convert to 4-space indents.
2000-07-09 16:44:26 +00:00
Guido van Rossum 1571a1e34b Since Thomas Wouters kept complaining that he wants access to the the
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.
2000-04-04 03:31:39 +00:00
Fred Drake 13a2c279c5 Untabify to pass the -tt test. 2000-02-10 17:17:14 +00:00