Esempio n. 1
0
def _get_folder_email_parts(account_key, folder_name, uid_parts):
    '''
    Get email parts (body parts) for a given folder and a given map of
    UID -> part ID. This happens in parallel for different part ID given, as
    IMAP cannot return different parts of different messages in each request.
    '''

    # Make map of part ID -> UIDs
    part_to_uid = defaultdict(list)

    for uid, part in uid_parts:
        part_to_uid[part].append(uid)

    account = get_account(account_key)
    folder = account.get_folder(folder_name)

    def get_email_parts(uids, part):
        email_parts = folder.get_email_parts(uids, part)
        return (part, email_parts)

    items = execute_threaded(get_email_parts,
                             [(uids, part)
                              for part, uids in part_to_uid.items()])

    emails = defaultdict(dict)

    for part, email_parts in items:
        for uid, data in email_parts.items():
            emails[uid][part] = data

    return emails
Esempio n. 2
0
def get_all_folders():
    def get_folders(account):
        folders = []

        try:
            folders = account.get_folders()
        except Exception as e:
            logger.warning(f'Failed to load folders for {account}: {e}')

        return account.name, folders

    account_folder_names = execute_threaded(get_folders,
                                            [(account, )
                                             for account in get_accounts()])

    meta = {}
    folder_names = []

    for account_name, names in account_folder_names:
        folder_names.extend(names)
        meta[account_name] = {
            'count': len(names),
            'folders': names,
        }

    return sorted(list(set(folder_names))), meta
Esempio n. 3
0
def connect_all():
    def make_account(key, settings):
        return key, Account(key, settings)

    with GET_ACCOUNTS_LOCK:
        ACCOUNTS.update(
            execute_threaded(make_account,
                             [(settings['name'], settings)
                              for settings in get_settings()['accounts']
                              if settings['name'] not in ACCOUNTS]))
Esempio n. 4
0
def get_all_folders():
    def get_folders(account):
        return account.name, account.get_folders()

    account_folder_names = execute_threaded(get_folders,
                                            [(account, )
                                             for account in get_accounts()])

    meta = {}
    folder_names = []

    for account_name, names in account_folder_names:
        folder_names.extend(names)
        meta[account_name] = {
            'count': len(names),
        }

    return list(set(folder_names)), meta