Пример #1
0
def process(account):
    (user, password) = account.split(':', 1)

    # Start by logging in
    logging.info("")
    logging.info("Archiving mail for %s", user)
    archivemymail.server = imapclient.IMAPClient(archivemymail.config.server, ssl=True)
    archivemymail.server.login(user, password)

    mboxes = deque(archivemymail.server.list_folders())
    while len(mboxes):
        mbox = mboxes.popleft()
        disposition = archivemymail.archivebox(mbox, user)
        if disposition & archivemymail.HAVE_ARCHIVED \
                and not disposition & archivemymail.MBOX_DELETED \
                and archivemymail.config.do_learning:
            archivemymail.learnbox(mbox)
def test_learnbox(monkeypatch, caplog):

    
    archivemymail.server = imapserver()
    archivemymail.config.bayes_dir = "."
    monkeypatch.setattr('archivemymail.progress.Progress', spamProgress)
    monkeypatch.setattr('archivemymail.wrappers.subprocess', myprocess)

    archivemymail.config.dry_run = True
    archivemymail.learnbox('foospam')
    assert "Would learn spam folder: foospam" in caplog.text

    archivemymail.config.dry_run = False
    archivemymail.learnbox('foospam')
    assert "Learning spam folder: foospam" in caplog.text
    
    monkeypatch.setattr(archivemymail.progress, 'Progress', hamProgress)
    archivemymail.config.dry_run = True
    archivemymail.learnbox('foo')
    assert "Would learn ham folder: foo" in caplog.text