split by year received
This commit is contained in:
parent
8d3ccc573a
commit
79df8cbaa3
1 changed files with 78 additions and 89 deletions
|
@ -64,19 +64,6 @@ class BackupImap:
|
|||
)
|
||||
self._process_mailbox(self.config['mailbox'])
|
||||
|
||||
def _better_imap_search(self, charset='UTF-8', criterion='UNDELETED'):
|
||||
current = time.gmtime()
|
||||
result = {
|
||||
"result": b"NO",
|
||||
"data": b""
|
||||
}
|
||||
for year in range(current.tm_year-10, current.tm_year+1):
|
||||
search_response, search_data = self.imap.search(charset, criterion, f'BEFORE={year}')
|
||||
if search_response == 'OK':
|
||||
result['result'] = 'OK'
|
||||
result[search_data] += result[search_data]
|
||||
return result
|
||||
|
||||
def _process_mailbox(self, mailbox):
|
||||
self._log.debug("Searching for all mailboxes in mailbox '%s'...", mailbox)
|
||||
list_response, list_data = self.imap.list(f"\"{mailbox}\"", '*')
|
||||
|
@ -112,9 +99,11 @@ class BackupImap:
|
|||
os.mkdir(os.path.dirname(mailbox_path))
|
||||
if not os.path.exists(mailbox_path):
|
||||
os.mkdir(mailbox_path)
|
||||
search_result = self._better_imap_search('UTF-8', 'UNDELETED')
|
||||
if search_result['result'] == 'OK':
|
||||
all_msgs_uids = search_result['data'][0].split()
|
||||
current = time.gmtime()
|
||||
for year in range(current.tm_year-10, current.tm_year+1):
|
||||
search_response, search_data = self.imap.search('UTF-8', 'UNDELETED', f'BEFORE={year}')
|
||||
if search_response == 'OK':
|
||||
all_msgs_uids = search_data[0].split()
|
||||
self._log.debug(
|
||||
"Found %s messages",
|
||||
len(all_msgs_uids)
|
||||
|
|
Loading…
Reference in a new issue