123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- from imap_tools import MailBox, AND
- import re
- whitelist = {
- '@auto-greiner.de': [
- '@opel-greiner.de'
- ],
- '@autohaus-berkemeier.de': [
- '@auto-berkemeier.de'
- ],
- '@mvcmotors.at': [
- '@mvcautomotive.com'
- ]
- }
- def main():
- mb = MailBox('mail.global-cube.com').login('archiv', 'Gc01am64!')
- messages = mb.fetch(criteria=AND(from_="@global-cube.com"), mark_seen=True, bulk=True)
- # print(mb.folder.list())
- # for folder in mb.folder.list():
- # if '|' in folder.name:
- # print(folder)
- # new_name = folder.name.replace('|', '.') # .replace('@', '').replace('.', '_')
- # mb.folder.rename(folder.name, new_name)
- for msg in messages:
- match = re.findall(r'\+(.*)@', msg.from_)
- if not match:
- print(msg.from_, msg.to, msg.subject)
- else:
- domain = '@' + match[0]
- subfolder = 'Archive.' + domain.replace('@', '').replace('.', '_')
- if not mb.folder.exists(subfolder):
- mb.folder.create(subfolder)
- mb.move(msg.uid, subfolder)
- for to in msg.to:
- if domain not in to and '@global-cube.de' not in to and msg.from_ != to:
- if domain in whitelist:
- valid_domain = [entry in to for entry in whitelist[domain]]
- if any(valid_domain):
- break
- print(domain, to, msg.subject)
- # print(msg.text)
- # print([att.filename for att in msg.attachments if att.filename.endswith('.pdf')])
- if __name__ == '__main__':
- main()
|