Exemple #1
0
def test_reply(db, config, message, attach):
    from inbox.server.models.tables.base import (SpoolMessage, FolderItem,
                                                 Folder, Account)

    to, subject, body = message
    attachfiles = create_attachment_metadata(attach)

    account = db.session.query(Account).get(ACCOUNT_ID)
    reply(NAMESPACE_ID, account, THREAD_ID, recipients(to, None, None),
          subject, body, attachfiles)

    sent_messages = db.session.query(SpoolMessage).\
        filter_by(thread_id=THREAD_ID).all()
    assert len(sent_messages) == 1, 'sent message missing'

    expected_in_reply_to = TEST_MSG['message-id']
    in_reply_to = sent_messages[0].in_reply_to
    assert in_reply_to == expected_in_reply_to, 'incorrect in_reply_to header'

    separator = '\t'
    expected_references = TEST_MSG['references'] + separator +\
        TEST_MSG['message-id']
    references = sent_messages[0].references

    assert references.split() == expected_references.split(),\
        'incorrect references header'

    sent_thrid = sent_messages[0].thread_id
    sent_folder = db.session.query(Account).get(ACCOUNT_ID).sent_folder.name
    sent_items = db.session.query(FolderItem).join(Folder).filter(
        FolderItem.thread_id == sent_thrid,
        Folder.name == sent_folder).count()
    assert sent_items == 1, 'sent folder entry missing'
Exemple #2
0
def test_reply_syncback(db, config, message):
    from inbox.server.sendmail.base import reply, recipients
    from inbox.server.models.tables.imap import ImapAccount

    account = db.session.query(ImapAccount).get(ACCOUNT_ID)
    to, subject, body = message
    attachments = None
    cc = '*****@*****.**'
    bcc = None

    reply(NAMESPACE_ID, account, THREAD_ID, recipients(to, cc, bcc), subject,
          body, attachments)

    with crispin_client(account.id, account.provider) as c:
        # Ensure the sent email message is present in the test account,
        # in both the Inbox and Sent folders:
        criteria = ['NOT DELETED', 'SUBJECT "{0}"'.format(THREAD_TOPIC)]

        c.select_folder(account.inbox_folder.name, lambda x, y: None)
        inbox_uids = c.conn.search(criteria)
        assert inbox_uids > 1, 'Reply missing from Inbox'

        # TODO[k]: Don't delete original
        #c.delete_messages(inbox_uids)

        c.select_folder(account.sent_folder.name, lambda x, y: None)
        sent_uids = c.conn.search(criteria)
        assert sent_uids, 'Message missing from Sent'
Exemple #3
0
def test_reply_reconcile(db, config, message, sync_client):
    from inbox.server.models.tables.base import Message, SpoolMessage
    from inbox.server.models.tables.imap import ImapAccount
    from inbox.server.sendmail.base import reply, recipients

    to, subject, body = message
    attachment = None
    cc = '*****@*****.**'
    bcc = None

    account = db.session.query(ImapAccount).get(ACCOUNT_ID)

    # Create email message, store a local copy + send it:
    reply(NAMESPACE_ID, account, THREAD_ID, recipients(to, cc, bcc), subject,
          body, attachment)

    # Sync to verify reconciliation:
    synclet = Greenlet(sync_client.start_sync, ACCOUNT_ID)
    synclet.start()

    print '\nSyncing...'
    Greenlet.join(synclet, timeout=60)

    sync_client.stop_sync(ACCOUNT_ID)

    spool_messages = db.session.query(SpoolMessage).\
        filter_by(subject=THREAD_TOPIC).all()
    assert len(spool_messages) == 1, 'spool message missing'

    resolved_message_id = spool_messages[0].resolved_message_id
    assert resolved_message_id, 'spool message not reconciled'

    inbox_uid = spool_messages[0].inbox_uid
    thread_id = spool_messages[0].thread_id
    g_thrid = spool_messages[0].g_thrid

    killall(synclet)

    reconciled_message = db.session.query(Message).get(resolved_message_id)
    assert reconciled_message.inbox_uid == inbox_uid,\
        'spool message, reconciled message have different inbox_uids'

    assert reconciled_message.thread_id == thread_id,\
        'spool message, reconciled message have different thread_ids'

    assert reconciled_message.g_thrid == g_thrid,\
        'spool message, reconciled message have different g_thrids'
def test_reply_reconcile(db, config, message, sync_client):
    from inbox.server.models.tables.base import Message, SpoolMessage
    from inbox.server.models.tables.imap import ImapAccount
    from inbox.server.sendmail.base import reply, recipients

    to, subject, body = message
    attachment = None
    cc = '*****@*****.**'
    bcc = None

    account = db.session.query(ImapAccount).get(ACCOUNT_ID)

    # Create email message, store a local copy + send it:
    reply(NAMESPACE_ID, account, THREAD_ID, recipients(to, cc, bcc),
          subject, body, attachment)

    # Sync to verify reconciliation:
    synclet = Greenlet(sync_client.start_sync, ACCOUNT_ID)
    synclet.start()

    print '\nSyncing...'
    Greenlet.join(synclet, timeout=60)

    sync_client.stop_sync(ACCOUNT_ID)

    spool_messages = db.session.query(SpoolMessage).\
        filter_by(subject=THREAD_TOPIC).all()
    assert len(spool_messages) == 1, 'spool message missing'

    resolved_message_id = spool_messages[0].resolved_message_id
    assert resolved_message_id, 'spool message not reconciled'

    inbox_uid = spool_messages[0].inbox_uid
    thread_id = spool_messages[0].thread_id
    g_thrid = spool_messages[0].g_thrid

    killall(synclet)

    reconciled_message = db.session.query(Message).get(resolved_message_id)
    assert reconciled_message.inbox_uid == inbox_uid,\
        'spool message, reconciled message have different inbox_uids'

    assert reconciled_message.thread_id == thread_id,\
        'spool message, reconciled message have different thread_ids'

    assert reconciled_message.g_thrid == g_thrid,\
        'spool message, reconciled message have different g_thrids'
Exemple #5
0
def test_send(db, config, message, attach):
    from inbox.server.models.tables.base import (SpoolMessage, FolderItem,
                                                 Folder, Account)

    to, subject, body = message
    cc = '*****@*****.**'
    bcc = None
    attachfiles = create_attachment_metadata(attach)

    account = db.session.query(Account).get(ACCOUNT_ID)
    send(account, recipients(to, cc, bcc), subject, body, attachfiles)

    sent_messages = db.session.query(SpoolMessage).\
        filter_by(subject=subject).all()
    assert len(sent_messages) == 1, 'sent message missing'

    sent_thrid = sent_messages[0].thread_id

    sent_folder = db.session.query(Account).get(ACCOUNT_ID).sent_folder.name
    sent_items = db.session.query(FolderItem).join(Folder).filter(
        FolderItem.thread_id == sent_thrid,
        Folder.name == sent_folder).count()
    assert sent_items == 1, 'sent folder entry missing'