示例#1
0
def empty_folder(email_account, imap_search, before_date):
    """Empties trash folder for provided account"""


    if before_date == None:
        date = datetime.datetime.now().strftime("%d-%b-%Y")
        delete_date = get_date_for_processing(date)
    else:
        delete_date = before_date

    logging.info('Deleting emails sent before %s' % delete_date)

    if 'imap' in email_account.connection.lower():
        logging.info('Deleting using Imap module')
        email_count = imap_mod.get_inbox_count(email_account)

        while (email_count > 0):
            imap_mod.delete_imap(email_account, delete_date, imap_search)
            email_count = imap_mod.get_inbox_count(email_account)
    else:
        logging.info('Deleting using POP module')
        pop_mod.delete_pop(email_account)
示例#2
0
def main():
    """Main.  Where the magic happens."""

    args = process_args()
    arg_list = [args.file, args.count, args.list]
    accounts_csv = 'accounts.csv'

    for arg in arg_list:
        if arg != None:
            accounts_csv = arg

    all_accounts = get_accounts(accounts_csv)


    if args.list != None:
        list_folders(all_accounts)

    if args.before != None:
        imap_search = 'SENTBEFORE "%s"' % str(args.before)
    else:
        imap_search = 'ALL'


    logging.info("Search criteria: %s" % imap_search)


    for account in all_accounts:
        account_info = account.split(',')

        email_account = EmailAccount(account_info[0], # host
                                     account_info[1].strip(), # email
                                     account_info[2].strip(), # password
                                     account_info[3].strip(), # folder
                                     account_info[4], # port
                                     account_info[5], #connection
                                    )

        if args.count != None:
            email_count = imap_mod.get_inbox_count(email_account)
        else:
            new_thread = threading.Thread(target=empty_folder, args=(email_account, imap_search, args.before))
            new_thread.start()