From 256a26a64911ceebe6ed004600f96e3d03e62f62 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 17 Feb 2012 11:43:41 +0100 Subject: [PATCH] dry-run mode: Protect us from actually deleting a message in dry-run mode Document which functions honor dry-run mode and which don't. Signed-off-by: Sebastian Spaeth --- offlineimap/folder/Base.py | 23 ++++++++++++++++++++++- offlineimap/ui/UIBase.py | 5 +++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 01a6ab5..77cc8ad 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -279,15 +279,27 @@ class BaseFolder(object): raise NotImplementedException def deletemessage(self, uid): + """ + Note that this function does not check against dryrun settings, + so you need to ensure that it is never called in a + dryrun mode.""" raise NotImplementedException def deletemessages(self, uidlist): + """ + Note that this function does not check against dryrun settings, + so you need to ensure that it is never called in a + dryrun mode.""" for uid in uidlist: self.deletemessage(uid) def copymessageto(self, uid, dstfolder, statusfolder, register = 1): """Copies a message from self to dst if needed, updating the status + Note that this function does not check against dryrun settings, + so you need to ensure that it is never called in a + dryrun mode. + :param uid: uid of the message to be copied. :param dstfolder: A BaseFolder-derived instance :param statusfolder: A LocalStatusFolder instance @@ -363,6 +375,8 @@ class BaseFolder(object): 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder + + This function checks and protects us from action in ryrun mode. """ threads = [] @@ -400,12 +414,17 @@ class BaseFolder(object): Get all UIDS in statusfolder but not self. These are messages that were deleted in 'self'. Delete those from dstfolder and - statusfolder.""" + statusfolder. + + This function checks and protects us from action in ryrun mode. + """ deletelist = filter(lambda uid: uid>=0 \ and not self.uidexists(uid), statusfolder.getmessageuidlist()) if len(deletelist): self.ui.deletingmessages(deletelist, [dstfolder]) + if self.repository.account.dryrun: + return #don't delete messages in dry-run mode # delete in statusfolder first to play safe. In case of abort, we # won't lose message, we will just retransmit some unneccessary. for folder in [statusfolder, dstfolder]: @@ -418,6 +437,8 @@ class BaseFolder(object): msg has a valid UID and exists on dstfolder (has not e.g. been deleted there), sync the flag change to both dstfolder and statusfolder. + + This function checks and protects us from action in ryrun mode. """ # For each flag, we store a list of uids to which it should be # added. Then, we can call addmessagesflags() to apply them in diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py index 32511a4..4bf4423 100644 --- a/offlineimap/ui/UIBase.py +++ b/offlineimap/ui/UIBase.py @@ -345,8 +345,9 @@ class UIBase(object): def deletingmessages(self, uidlist, destlist): ds = self.folderlist(destlist) - self.logger.info("Deleting %d messages (%s) in %s" % ( - len(uidlist), + prefix = "[DRYRUN] " if self.dryrun else "" + self.info("{}Deleting {} messages ({}) in {}".format( + prefix, len(uidlist), offlineimap.imaputil.uid_sequence(uidlist), ds)) def addingflags(self, uidlist, flags, dest):