Commit Graph

365 Commits

Author SHA1 Message Date
Nikolaus Schulz 368f312e2d test suite: add more maildir test cases
Maildir testing should now be roughly on par with mbox testing.
2010-07-29 19:29:53 +02:00
Nikolaus Schulz 2ce89ef508 test suite: remove unused remove() methods from maildir classes
For cleanup of temporary files, we lean on shutil.rmtree anyway, so don't
bother wasting more code on this.
2010-07-29 15:46:15 +02:00
Nikolaus Schulz 7058290c2e test suite: remove incomplete MH testing code
I just discovered that archivemails MH support is broken with respect to
message flags, and in my opinion it doesn't make much sense to test
known-broken functionality.

In fact there may well be zero archivemail users with MH mailboxes; MH is
basically an obsolete format, and any archivemail user with MH mailboxes would
probably have complained about lost message flags.
2010-07-29 15:46:15 +02:00
Nikolaus Schulz 0dfae37e04 test suite: first shot at implementing maildir test cases 2010-07-29 15:46:10 +02:00
Nikolaus Schulz 78c4c6e3da test suite: remove obsolete $Id$ subversion keyword 2010-07-29 14:41:05 +02:00
Nikolaus Schulz d845ab862e test suite: cleanup of the mbox testing code
This code is complex, too complex actually.  Rename some methods and
variables, rework some code and and add some explaining comments in order to
make it it least a bit easier to understand.
2010-07-29 14:41:00 +02:00
Nikolaus Schulz 584918b265 test suite: remove obsolete test that we preserve mbox file modes
This test case is obsolete since we no longer replace the mbox file with a new
copy but rewrite it.
2010-07-29 13:32:20 +02:00
Nikolaus Schulz 9ff7774aba Fix TempMbox.saveas() to unregister the right file from _stale 2010-07-28 15:28:39 +02:00
Nikolaus Schulz e5ee9b98c1 Python language fix: replace C-style boolean values "1" and "0" with True/False 2010-07-19 01:40:25 +02:00
Nikolaus Schulz 7269c32734 Remove unused variable 2010-07-19 01:40:25 +02:00
Nikolaus Schulz 80b3483439 Python language fix: remove parentheses around asserted expressions
assert is not a function.
2010-07-19 01:40:25 +02:00
Nikolaus Schulz 2d15728c2d Add a note about the race window when resetting an mbox file timestamp 2010-07-19 01:40:25 +02:00
Nikolaus Schulz dcf849afeb TODO: new items: make IMAP test suite with no network I/O; drop .py extension 2010-07-19 01:40:25 +02:00
Nikolaus Schulz 573f2b9358 Warn if the temporary directory is not empty on cleanup 2010-07-19 01:40:25 +02:00
Nikolaus Schulz 4fb833176e When creating a dotlock, register it slightly earlier for cleanup
This closes a very unlikely window where we could create a dotlock file, but
then encounter an error and fail to clean up the dotlock.
2010-07-19 01:40:25 +02:00
Nikolaus Schulz 2b7baaf294 In verbose mode, say that we're about to dotlock an mbox before trying to do so 2010-07-19 01:40:25 +02:00
Nikolaus Schulz 0f2b04ff89 Minor docstring/whitespace fixes 2010-07-19 01:40:25 +02:00
Nikolaus Schulz b9b2174c45 At critical points, flush mbox files and sync them to disk
This should minimize the risk of data loss.  Flushing a locked mbox file
before unlocking it also ensures that there's no window when another
process could lock the mbox after us, but still see the old content.
2010-07-19 01:40:24 +02:00
Nikolaus Schulz 86471d12a4 Further refactoring of the mbox classes, adding archive locking support
The mbox locking methods move into a new class LockableMboxMixin, and the
Mbox and ArchiveMbox classes become subclasses of LockableMboxMixin.
class StaleFiles is updated to handle multiple dotlock files.
2010-07-19 01:40:24 +02:00
Nikolaus Schulz da595427ff Fail as gracefully as possible if writing out the new mailboxes fails
In particular:

* If writing the archived messages to the final archive fails, try to
  restore the archive and abort (by not handling the exception).  This is
  possible since we first save the archive, and only then the modified
  mailbox, so we don't corrupt the original mbox in this case.
* If writing a modified mbox file fails, save the temporary copy.
2010-07-19 01:40:24 +02:00
Nikolaus Schulz 1db28f2b04 Refactoring of the mbox classes
The RetainMbox and ArchiveMbox classes are now gone, mainly because their
finalise() methods were messing with the archived mbox and the archive,
respectively, which was not good OO design.

The core functionality of the finalise() methods of both removed classes
is moved to the objects that are manipulated: the Mbox class representing
the mbox that is being archived gains a new method overwrite_with(), and
there is a new class ArchiveMbox that represents the actual archive, which
has an append() method (yes, unfortunately the new class has the same name
like the removed class).

The RetainMbox instance is replaced with a TempMbox, and the ArchiveMbox
instance either with a TempMbox, or a CompressedTempMbox if archive
compression is enabled.

Finally, a compressed TempMbox is now a implemented as a subclass of
TempMbox, named CompressedMbox.

Cooperation with the StaleFiles class moves into the TempMbox class.
This means slightly less detailed verbose cleanup reporting, oh well.
2010-07-19 01:40:24 +02:00
Nikolaus Schulz 40f9a4c049 Use safe methods to open the archive mbox and an existing mbox file 2010-07-19 01:17:02 +02:00
Nikolaus Schulz f031573071 mbox locking: omit dotlock if we don't have the permissions to create it
Closes: issue #855269.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 11103e2de2 mbox locking: combine locking functions into one and swap lock order
We used to create a dotlock file first and then lock with fcntl; swap that
order, since locking first with fcntl seems to be more common.

This patch also adds general mbox lock/unlock methods, which call the
dotlock and fcntl-lock methods, and moves the retry logic there.

When the dotlock and fcntl methods fail to acquire a lock, they now raise
a custom exception "LockUnavailable", which gets caught in the general
lock() method.  That way, if we succeed to acquire one lock but fail to
acquire the other, we can release our locks at the upper level and retry.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz d706409c59 Switch mbox locking from flock(2) to posix lockf(2)
flock() locks aren't portable; lockf() locks are.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz d726589414 Rename procmail_lock->dotlock_lock
An entirely cosmetic variable rename, but it's just not correct to call
this a "procmail lock".  Also reword some comments accordingly.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz c6e462fef0 test suite: use common base class with helper methods for mbox testing
These helper methods provide success verification after test archiving runs, and
test case setup.  This is a tradeoff: because these methods need to support all
scenarios in one place, they introduce some new complexity - but they replace a
lot of tedious, very similar, but still not entirely identical code all over the
place.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 84f42ead36 test suite: cut down the test of the --all option
Don't do entire test archiving runs, just call
archivemail.should_archive().
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 512130df02 test suite: cut down the test of the --preserve-unread option
Don't do entire test archiving runs, just call
archivemail.should_archive().
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 03bfb88d30 test suite: change misleading test case name
TestArchiveMboxPreserveStatus actually doesn't test that the message
status is preserved, but that the --preserve-unread option works.
Rename it to TestArchiveMboxPreserveUnread.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 41da26b655 test suite: cut down the test of the --size option
Don't do entire test archiving runs, just call
archivemail.should_archive().
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 6d2e23ac80 test suite: cut down the test of --output-dir
Don't do entire test archiving runs, just call
archivemail.make_archive_name() and verify the result.
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 8ec8a00ffa test suite: cut down testing the handling of flagged messages
Don't do entire test archiving runs, just call
archivemail.should_archive().
2010-07-19 01:13:25 +02:00
Nikolaus Schulz 0ca3f6ceee test suite: remove duplicate test case for --date option 2010-07-19 01:13:25 +02:00
Nikolaus Schulz bf99c6b69d test suite: cut down archive suffix generation testing
Don't do entire test archiving runs, just call
archivemail.make_archive_name() and verify the result.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 232b2256c2 test suite: test weird message headers in one run
Before, every test header was tested in a separate archiving run.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 573cbbce91 test suite: cut down the test of date header processing
Don't do entire test archiving runs, just call
archivemail.should_archive().
2010-07-19 01:13:24 +02:00
Nikolaus Schulz e9d2284a07 test suite: let make_message() optionally return a rfc822.Message 2010-07-19 01:13:24 +02:00
Nikolaus Schulz 8476dcd18f Remove lots of redundant test runs from the test suite
The test suite used to run a lot of triple tests, by first calling
archivemail.archive() directly, and then running the entire archivemail
script twice, once with long and once with short options.  But we already
test option processing seperately, and beyond that, archivemail.main()
essentially just calls archive() for each mailbox in turn.  So we just drop
all runs of the entire archivemail script from the test suite, giving it a
huge speed boost (on my old iBook, running the test suite drops from 73 to
5 seconds).
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 8f58deef5c Test suite: test command line option processing 2010-07-19 01:13:24 +02:00
Nikolaus Schulz f80e709f7e test suite: eliminate remaining call of external gzip program
Use gzip.GzipFile instead.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 8c6f4b99c1 test suite: define and use assertEqualContent() to compare files
This eliminates a lot of copy-and-paste code, and switches from
os.system("gzip <...>") to gzip.GzipFile.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 9d9f13a440 test suite: account for lacking precision of os.utime()
os.utime() uses the utimes(2) system call to set file timestamps.  utimes(2)
has a microsecond resolution, but stat(2) may return timestamps with
nanosecond resolution.  So, the check that we have properly reset the mbox
file timestamp must allow a minor deviation.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz 54821151e4 Fix minor race when deleting messages in a maildir/mh box
Nothing serious, but if another client deleted it in the small window after
we checked it, we would have crashed trying to delete a non-existing file.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz a7414319c9 Simplify the final committing of the mailbox and archive
* Make the finalise() methods spot if they have anything to do
* We used to create the temporary mbox files on demand in the message
  processing loop, if we needed to write to them.  Now we create them
  beforehand, but only if they might be needed (e.g. we don't create an
  archive if options.delete_old_mail is set).
* The above combined makes the final committing of the changes simpler (a
  *lot* simpler for mboxes), and we can dump the Mbox.leave_empty() method.
2010-07-19 01:13:24 +02:00
Nikolaus Schulz b37b3d627e Split out new class TempMbox
This separates write-only mbox access to the temporary mboxes from the read-only
access to the original mbox.
2010-07-19 01:01:04 +02:00
Nikolaus Schulz d6a161cd9e Simplify ArchiveMbox.__init__ 2009-11-06 21:09:40 +01:00
Nikolaus Schulz df680c19be Append to the archive, and don't use rename()
This is WIP to prepare locking for the archive.  Since we no longer copy the
whole archive before appending, archiving should also be faster.
2009-11-06 21:09:40 +01:00
Nikolaus Schulz 37f96c1c84 Remove unused method Mbox.is_empty() 2009-11-06 21:09:40 +01:00
Nikolaus Schulz a78af4c0ff Keep mbox files open, so we don't break our locks
When committing a changed mbox, don't use os.rename(), and don't open/close
the mbox file to truncate it to zero length.  Locking was pretty much broken
before -- at least in theory a quite severe bug.
2009-11-06 21:09:39 +01:00