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 <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-02-17 11:43:41 +01:00
parent 5ef69e95c0
commit 256a26a649
2 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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):