email: MOVE: check that the destination exists (#7807)

This commit is contained in:
Martin Richtarsky 2024-09-30 07:06:47 +00:00
parent dd9b10bdf8
commit 6aa515c658

View File

@ -567,13 +567,17 @@ class MailAccountHandler(LoggingMixin):
rule: MailRule, rule: MailRule,
supports_gmail_labels: bool, supports_gmail_labels: bool,
): ):
self.log.debug(f"Rule {rule}: Selecting folder {rule.folder}") folders = [rule.folder]
# In case of MOVE, make sure also the destination exists
if rule.action == MailRule.MailAction.MOVE:
folders.insert(0, rule.action_parameter)
try: try:
M.folder.set(rule.folder) for folder in folders:
self.log.debug(f"Rule {rule}: Selecting folder {folder}")
M.folder.set(folder)
except MailboxFolderSelectError as err: except MailboxFolderSelectError as err:
self.log.error( self.log.error(
f"Unable to access folder {rule.folder}, attempting folder listing", f"Unable to access folder {folder}, attempting folder listing",
) )
try: try:
for folder_info in M.folder.list(): for folder_info in M.folder.list():
@ -585,7 +589,7 @@ class MailAccountHandler(LoggingMixin):
) )
raise MailError( raise MailError(
f"Rule {rule}: Folder {rule.folder} " f"Rule {rule}: Folder {folder} "
f"does not exist in account {rule.account}", f"does not exist in account {rule.account}",
) from err ) from err