Commit Graph

72 Commits

Author SHA1 Message Date
Nikolaus Schulz febd030e14 Drop .py extension from the unittest script 2010-07-29 21:02:12 +02:00
Nikolaus Schulz 0eddfe7357 Updated copyright year 2010-07-29 20:39:46 +02:00
Nikolaus Schulz af3bb16a4c Updated TODO, dropping a lot of obsolete items
Notable items that are now resolved or implemented:
    * archives are now locked
    * the mbox classes have been refactored to a cleaner design
    * we moved from flock locking to fcntl
    * the setuid() feature is long gone
    * symlink attacks for tempfiles are not possible (that is really an
      ancient TODO item from the original author)
    * the test suite now has a lot of maildir test cases
2010-07-29 19:49:42 +02:00
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 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 80b3483439 Python language fix: remove parentheses around asserted expressions
assert is not a function.
2010-07-19 01:40:25 +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 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 37f96c1c84 Remove unused method Mbox.is_empty() 2009-11-06 21:09:40 +01:00
Nikolaus Schulz f43cbb106d Added new option --all to archive all messages in a mailbox.
Updated documentation, and added a first simple unittest for this.
Closes: #1764846.
2008-03-15 20:24:46 +00:00
Nikolaus Schulz 2719645f2c Updated copyright notes to include year 2008. 2008-03-15 19:39:28 +00:00
Nikolaus Schulz f6f7903f58 test_archivemail.py: removed nested calls to setUp() and tearDown(). 2008-03-06 20:09:44 +00:00
Nikolaus Schulz bcb01613d0 archivemail.py, setup.py, test_archivemail.py:
bumped version to 0.7.1, and updated copyright.
2007-11-07 00:57:44 +00:00
Nikolaus Schulz a1641450ed Added simple unittest for the --copy option. Mbox only. :-/ 2007-11-02 18:21:21 +00:00
Nikolaus Schulz 256492039a Added unittest for the new IMAP URL parser. 2007-10-23 23:23:44 +00:00
Nikolaus Schulz 700bce69b4 Testsuite: fixed testDeleteOldMail to check the right option. 2006-10-30 18:25:28 +00:00
Nikolaus Schulz a8e76ead22 Testsuite: create temporary directory with prefix. 2006-10-29 04:05:37 +00:00
Nikolaus Schulz 93015a6d84 Dropped test from testsuite if dotlock file is world-readable, this isn't
required.
2006-10-29 03:59:57 +00:00
Nikolaus Schulz 5eb4cf3cf6 Replaced all tempfile.mktemp() calls with mkstemp()/mkdtemp().
Should just serve as a last security fallback, since we operate in a safe
temporary directory and everything should be okay anyway, but that may be less
obvious. :-)
2006-10-27 03:23:16 +00:00
Nikolaus Schulz e491da3a11 test_archivemail.py: fixed unsafe creation of temporary files.
Derive all testcases that create temporary files from the new class
TestCaseInTempdir, which provides standard fixtures to set up a secure temporary
root directory for tempfiles and cleaning up afterwards.  This also simplifies
the code. 

This addresses Debian bug #385253, and reading the BTS log, it seems this issue
was assigned CVE-2006-4245, although I cannot find any further reference to that
CVE.  Note that the bug was initially reported to affect archivemail itself,
too.  This is not correct.  There *are* race conditions with archivemail, but
they were not subject of that report, and are not that critical.

Also bumped python dependency to version 2.3 since we use tempfile.mkstemp() and
other recent stuff.
2006-10-27 02:12:45 +00:00
Nikolaus Schulz 0a666a10a6 test_archivemail.py: added two missing self.setUp() calls in the TestArchiveMbox
testcase.
2006-10-27 01:30:49 +00:00
Nikolaus Schulz 7ae1b7bb3f test_archivemail.py: put standard setUp() fixtures in the testcases; the
matching tearDown() methods were already there. 
We surely can move more (possibly duplicated) stuff into the setUp() methods
later.
2006-10-27 01:00:39 +00:00
Nikolaus Schulz ee45d946ed test_archivemail.py: don't check for os.fork(), simply use it -- we're targeting
posix platforms only.
2006-10-27 00:13:48 +00:00