summaryrefslogtreecommitdiff
path: root/imap-tool
diff options
context:
space:
mode:
Diffstat (limited to 'imap-tool')
-rwxr-xr-ximap-tool28
1 files changed, 17 insertions, 11 deletions
diff --git a/imap-tool b/imap-tool
index 0fbc169..f88f9b7 100755
--- a/imap-tool
+++ b/imap-tool
@@ -136,20 +136,15 @@ class imap_tool():
year_start = self.archive_year
year_stop = self.archive_year + 1
- ret, data = imap.create(mailbox_archive)
- if ret != "OK":
- if not self.error_decode(data).startswith("[ALREADYEXISTS]"):
- print("Error creating mailbox " + mailbox_archive + ": " + self.error_decode(data))
- raise Exception()
- else:
- print("Created mailbox " + mailbox_archive)
-
- ret, date = imap.select(self.mailbox)
+ ret, data = imap.select(self.mailbox)
if ret != "OK":
print("Error selecting mailbox " + self.mailbox + ": " + self.error_decode(data))
raise Exception()
- ret, data = imap.uid("SEARCH", None, "(SINCE \"01-Jan-" + str(year_start) + "\" BEFORE \"01-Jan-" + str(year_stop) + "\")")
+ # Two ways to search:
+ # - SINCE/BEFORE that use native dating (often fs-backed), a bit faster
+ # - SENTSINCE/SENTBEFORE that use message dating, a bit slower
+ ret, data = imap.uid("SEARCH", None, "(SENTSINCE \"01-Jan-" + str(year_start) + "\" SENTBEFORE \"01-Jan-" + str(year_stop) + "\")")
if ret != "OK":
print("Error searching mailbox " + self.mailbox + ": " + self.error_decode(data))
raise Exception()
@@ -157,7 +152,18 @@ class imap_tool():
uids_search = data[0].decode("ascii").split()
uids_search_count = len(uids_search)
- print("Retrieved " + str(uids_search_count) + " messages from mailbox " + self.mailbox + " for year " + str(self.archive_year))
+ print("Found " + str(uids_search_count) + " messages from mailbox " + self.mailbox + " for year " + str(self.archive_year))
+
+ if uids_search_count == 0:
+ raise Exception()
+
+ ret, data = imap.create(mailbox_archive)
+ if ret != "OK":
+ if not self.error_decode(data).startswith("[ALREADYEXISTS]"):
+ print("Error creating mailbox " + mailbox_archive + ": " + self.error_decode(data))
+ raise Exception()
+ else:
+ print("Created mailbox " + mailbox_archive)
index = 0
uids = []