Beispiel #1
0
def local_save_draft(db_session, log, account_id, drafts_folder, draftmsg):
    """
    Save the draft email message to the local data store.

    Notes
    -----
    The message is stored as a SpoolMessage.

    """
    msg = RawMessage(uid=draftmsg.uid,
                     internaldate=draftmsg.date,
                     flags=draftmsg.flags,
                     body=draftmsg.msg,
                     g_thrid=None,
                     g_msgid=None,
                     g_labels=set(),
                     created=True)

    new_uids = create_db_objects(account_id, db_session, log, drafts_folder,
                                 [msg], create_gmail_message)

    assert len(new_uids) == 1
    new_uid = new_uids[0]

    new_uid.created_date = draftmsg.date

    # Set SpoolMessage's special draft attributes
    new_uid.message.state = 'draft'
    new_uid.message.parent_draft = draftmsg.original_draft
    new_uid.message.replyto_thread_id = draftmsg.reply_to

    commit_uids(db_session, log, new_uids)

    return new_uid
Beispiel #2
0
def local_save_draft(db_session, log, account_id, drafts_folder, draftmsg):
    """
    Save the draft email message to the local data store.

    Notes
    -----
    The message is stored as a SpoolMessage.

    """
    msg = RawMessage(uid=draftmsg.uid, internaldate=draftmsg.date,
                     flags=draftmsg.flags, body=draftmsg.msg, g_thrid=None,
                     g_msgid=None, g_labels=set(), created=True)

    new_uids = create_db_objects(account_id, db_session, log,
                                 drafts_folder, [msg],
                                 create_gmail_message)

    assert len(new_uids) == 1
    new_uid = new_uids[0]

    new_uid.created_date = draftmsg.date

    # Set SpoolMessage's special draft attributes
    new_uid.message.state = 'draft'
    new_uid.message.parent_draft = draftmsg.original_draft
    new_uid.message.replyto_thread_id = draftmsg.reply_to

    commit_uids(db_session, log, new_uids)

    return new_uid
Beispiel #3
0
def download_and_commit_uids(crispin_client, db_session, log, folder_name, uids, msg_create_fn, syncmanager_lock, c):
    raw_messages = safe_download(crispin_client, log, uids, c)
    with syncmanager_lock:
        new_imapuids = create_db_objects(
            crispin_client.account_id, db_session, log, folder_name, raw_messages, msg_create_fn
        )
        commit_uids(db_session, log, new_imapuids)
    return len(new_imapuids)
Beispiel #4
0
def gmail_download_and_commit_uids(crispin_client, db_session, log,
                                   folder_name, uids, msg_create_fn,
                                   syncmanager_lock, c):
    raw_messages = safe_download(crispin_client, log, uids, c)
    with syncmanager_lock:
        # there is the possibility that another green thread has already
        # downloaded some message(s) from this batch... check within the lock
        raw_messages = deduplicate_message_object_creation(
            crispin_client.account_id, db_session, log, raw_messages)
        log.debug("Have {} unsaved messages objects".format(len(raw_messages)))
        new_imapuids = create_db_objects(crispin_client.account_id, db_session,
                                         log, folder_name, raw_messages,
                                         msg_create_fn)
        commit_uids(db_session, log, new_imapuids)
        log.debug("Committed {} new messages".format(len(new_imapuids)))
    return len(new_imapuids)
Beispiel #5
0
def save_gmail_email(account_id, db_session, log, uid, email):
    # TODO[k]: Check these -
    uid = uuid.uuid4().int & (1 << 16) - 1
    date = datetime.now()
    folder_name = 'sent'

    msg = RawMessage(uid=uid, internaldate=date, flags=set(), body=email,
                     g_thrid=0, g_msgid=0, g_labels=set(), created=True)
    new_uids = create_db_objects(account_id, db_session, log, folder_name,
                                 [msg], create_gmail_message)

    assert len(new_uids) == 1
    new_uids[0].created_date = date

    commit_uids(db_session, log, new_uids)

    return new_uids[0]
Beispiel #6
0
def gmail_download_and_commit_uids(crispin_client, db_session, log,
                                   folder_name, uids, msg_create_fn,
                                   syncmanager_lock):
    log.debug("Downloading uids {}".format(uids))
    raw_messages = safe_download(crispin_client, log, uids)
    with syncmanager_lock:
        log.debug("gmail_download_and_commit_uids acquired syncmanager_lock")
        # there is the possibility that another green thread has already
        # downloaded some message(s) from this batch... check within the lock
        raw_messages = deduplicate_message_object_creation(
            crispin_client.account_id, db_session, log, raw_messages)
        log.debug("Have {} unsaved messages objects".format(len(raw_messages)))
        new_imapuids = create_db_objects(crispin_client.account_id, db_session,
                                         log, folder_name, raw_messages,
                                         msg_create_fn)
        commit_uids(db_session, log, new_imapuids)
        log.debug("Committed {} new messages".format(len(new_imapuids)))
    return len(new_imapuids)