Commit Graph

174 Commits

Author SHA1 Message Date
Nikolaus Schulz a102b5baf9 Rename archivemail.py to archivemail
On Unix, most scripts don't come with a file extension, it's not needed, and
we distribute the script as "archivemail" anyway.  And most importantly, I
like it better without the extension. :)

With a little trick we can still load the script as a module from the test
suite.
2010-07-29 21:35:58 +02:00
Nikolaus Schulz a04226580b Bump version to 0.8.0 2010-07-29 21:02:07 +02:00
Nikolaus Schulz 0eddfe7357 Updated copyright year 2010-07-29 20:39:46 +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 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 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
Nikolaus Schulz ba8928d279 Cleanup restoring of the mbox timestamps
* Remove code duplication: restore the mbox timestamps once and for all when
  we're done
* Don't bother restoring the file mode when finishing, since this is handled in
  RetainMbox.finalise() (and need be)
* Therefore, rename Mbox.reset_stat() to reset_timestamps()
2009-11-06 21:09:39 +01:00
Nikolaus Schulz 223e2f9802 Cosmetics: in verbose mode, report current mailbox early
This is now before we do the sanity checking, so in verbose mode, we don't error
out before having said that we now turn attention to the current mailbox.
2009-11-06 21:09:39 +01:00
Nikolaus Schulz aee4df2fcf Refuse to process mailboxes owned by someone else
This should also protect people relying on the old setuid feature.
If the mailbox is local, by checking the ownership we necessarily check for
existance.
2009-11-06 21:09:39 +01:00
Nikolaus Schulz 2e0f3cd3aa Sanity check existing archives early
This used to happen when creating the temporary archive, we now do it before we
start processing the mailbox.
2009-11-06 21:09:39 +01:00
Nikolaus Schulz 79bcf86860 Remove simple-minded security checks
Remove the checks if the mailbox is a symlink, and if the output directory is
world-writable.  Better no security than half-baked security.
2009-11-06 21:09:39 +01:00
Nikolaus Schulz a3276f8c68 Move archive naming code into new function make_archive_name() 2009-11-06 21:09:38 +01:00
Nikolaus Schulz cd07a2663e Remove the setuid functionality
It was not a good idea, and trying to do it right would be too much effort.
2009-11-06 21:09:38 +01:00
Nikolaus Schulz bd85cffe37 Simplify imap_get_namespace() and imap_guess_mailboxnames()
I don't think anybody wants to archive folders in shared or public IMAP
namespaces, so we don't bother checking all possible namespaces.  The code was
ugly anyway.
2009-11-06 21:09:38 +01:00
Nikolaus Schulz 9574c4f41c Removed obsolete references to subversion
archivemail development has moved to git.  This patch updates the project
webpage, removes the subversion $Id$ keyword that was stored in
archivemail.__svn_id__, and updates the Makefile.
2009-11-06 17:20:16 +01:00
Nikolaus Schulz c6cb0b4612 IMAP: imap_guess_mailboxnames: check for NIL delimiter.
Only replace the slash with the server's hierarchy delimiter if the latter
actually exists (is not NIL).
2008-04-09 00:22:07 +00:00
Nikolaus Schulz 622c0105ea IMAP: only check for \Deleted in PERMANENTFLAGS if mailbox isn't read-only.
This spewed an error when --dry-running.
2008-04-08 23:06:10 +00:00
Nikolaus Schulz 775952ec98 IMAP: added sanity check for \Deleted in PERMANENTFLAGS. 2008-04-08 19:31:11 +00:00
Nikolaus Schulz 681fd0c527 Minor, local variable renaming. 2008-04-08 19:10:41 +00:00
Nikolaus Schulz e5b6397dd5 Moved IMAP SELECT code into a separate function. 2008-04-08 19:06:42 +00:00
Nikolaus Schulz 78b4923832 IMAP: be NAMESPACE-aware; improved probing for guessed mailbox names.
* Automatically add NAMESPACE prefix to the mailbox path if necessary, 
  * Explicitely check for guessed mailbox names with LIST instead of just trying
    to SELECT them. 
  * Updated documentation about NAMESPACE handling.
2008-04-08 15:38:51 +00:00
Nikolaus Schulz bfff00e395 Code structuring: made a separate group of IMAP functions.
No code changes, just moved functions around.
2008-04-07 20:16:29 +00:00
Nikolaus Schulz 07219ff14b IMAP: servers should never advertise LOGINDISABLED with SSL; removed the check
for it, which was just used to spit a special error message anyway.
2008-03-21 01:05:15 +00:00
Nikolaus Schulz 26ab4611ec Archiving an IMAP folder with --all didn't archive *any* messages.
The message sequence numbers must be strings, but were generated as integers;
fixed.
2008-03-19 18:30:43 +00:00
Nikolaus Schulz efe02ea32a Updated year in another copyright note, which I overlooked before. 2008-03-16 17:57:18 +00:00
Nikolaus Schulz a9215463c4 Removed an assertion which choked upon --days=0. 2008-03-15 20:34:52 +00: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