Пример #1
0
def test_basic_message_grouping(db, default_namespace):
    first_thread = add_fake_thread(db.session, default_namespace.id)
    first_thread.subject = 'Some kind of test'

    add_fake_message(db.session,
                     default_namespace.id,
                     thread=first_thread,
                     subject='Some kind of test',
                     from_addr=[('Karim Hamidou', '*****@*****.**')],
                     to_addr=[('Eben Freeman', '*****@*****.**')],
                     bcc_addr=[('Some person', '*****@*****.**')])

    msg2 = add_fake_message(db.session,
                            default_namespace.id,
                            thread=None,
                            subject='Re: Some kind of test',
                            from_addr=[('Some random dude', '*****@*****.**')
                                       ],
                            to_addr=[('Karim Hamidou', '*****@*****.**')])

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg2)
    assert matched_thread is None, "the algo shouldn't thread different convos"

    msg3 = add_fake_message(db.session, default_namespace.id, thread=None)
    msg3.subject = 'Re: Some kind of test'
    msg3.from_addr = [('Eben Freeman', '*****@*****.**')]
    msg3.to_addr = [('Karim Hamidou', '*****@*****.**')]

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg3)
    assert matched_thread is first_thread, "Should match on participants"
Пример #2
0
def test_basic_message_grouping(db, default_namespace):
    first_thread = add_fake_thread(db.session, default_namespace.id)
    first_thread.subject = 'Some kind of test'

    add_fake_message(db.session, default_namespace.id,
                     thread=first_thread,
                     subject='Some kind of test',
                     from_addr=[('Karim Hamidou', '*****@*****.**')],
                     to_addr=[('Eben Freeman', '*****@*****.**')],
                     bcc_addr=[('Some person', '*****@*****.**')])

    msg2 = add_fake_message(db.session, default_namespace.id, thread=None,
                            subject='Re: Some kind of test',
                            from_addr=[('Some random dude',
                                        '*****@*****.**')],
                            to_addr=[('Karim Hamidou', '*****@*****.**')])

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg2)
    assert matched_thread is None, "the algo shouldn't thread different convos"

    msg3 = add_fake_message(db.session, default_namespace.id, thread=None)
    msg3.subject = 'Re: Some kind of test'
    msg3.from_addr = [('Eben Freeman', '*****@*****.**')]
    msg3.to_addr =   [('Karim Hamidou', '*****@*****.**')]

    matched_thread = fetch_corresponding_thread(db.session, default_namespace.id, msg3)
    assert matched_thread is first_thread, "Should match on participants"
Пример #3
0
    def add_message_attrs(self, db_session, new_uid, msg):
        """ Post-create-message bits."""
        with db_session.no_autoflush:
            parent_thread = fetch_corresponding_thread(db_session,
                                                       self.namespace_id,
                                                       new_uid.message)
            construct_new_thread = True

            if parent_thread:
                # If there's a parent thread that isn't too long already,
                # add to it. Otherwise create a new thread.
                parent_message_count = self._count_thread_messages(
                    parent_thread.id, db_session)
                if parent_message_count < MAX_THREAD_LENGTH:
                    construct_new_thread = False

            if construct_new_thread:
                new_uid.message.thread = ImapThread.from_imap_message(
                    db_session, new_uid.account.namespace, new_uid.message)
            else:
                parent_thread.messages.append(new_uid.message)

        db_session.flush()
        # Make sure this thread has all the correct labels
        common.add_any_new_thread_labels(new_uid.message.thread, new_uid,
                                         db_session)
        new_uid.update_flags_and_labels(msg.flags)
        return new_uid
Пример #4
0
def test_generic_grouping(db, default_account):
    thread = add_fake_thread(db.session, default_account.namespace.id)
    message = add_fake_message(db.session,
                               default_account.namespace.id,
                               thread,
                               subject="Golden Gate Park next Sat")
    folder = Folder(account=default_account,
                    name='Inbox',
                    canonical_name='inbox')
    ImapUid(message=message,
            account_id=default_account.id,
            msg_uid=2222,
            folder=folder)

    thread = add_fake_thread(db.session, default_account.namespace.id)

    new_namespace = Namespace()
    db.session.add(new_namespace)
    db.session.commit()
    message = add_fake_message(db.session,
                               new_namespace.id,
                               thread,
                               subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session,
                                        default_account.namespace.id, message)
    assert thread is None, ("fetch_similar_threads should "
                            "heed namespace boundaries")
Пример #5
0
def test_generic_grouping(db, default_account):
    thread = add_fake_thread(db.session, default_account.namespace.id)
    message = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread,
        subject="Golden Gate Park next Sat",
    )
    folder = Folder(account=default_account,
                    name="Inbox",
                    canonical_name="inbox")
    ImapUid(message=message,
            account_id=default_account.id,
            msg_uid=2222,
            folder=folder)

    thread = add_fake_thread(db.session, default_account.namespace.id)

    account = add_generic_imap_account(db.session)
    message = add_fake_message(db.session,
                               account.namespace.id,
                               thread,
                               subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session,
                                        default_account.namespace.id, message)
    assert thread is None, "fetch_similar_threads should " "heed namespace boundaries"
Пример #6
0
    def add_message_attrs(self, db_session, new_uid, msg):
        """ Post-create-message bits."""
        with db_session.no_autoflush:
            parent_thread = fetch_corresponding_thread(
                db_session, self.namespace_id, new_uid.message)
            construct_new_thread = True

            if parent_thread:
                # If there's a parent thread that isn't too long already,
                # add to it. Otherwise create a new thread.
                parent_message_count = self._count_thread_messages(
                    parent_thread.id, db_session)
                if parent_message_count < MAX_THREAD_LENGTH:
                    construct_new_thread = False

            if construct_new_thread:
                new_uid.message.thread = ImapThread.from_imap_message(
                    db_session, new_uid.account.namespace, new_uid.message)
            else:
                parent_thread.messages.append(new_uid.message)

        db_session.flush()
        # Make sure this thread has all the correct labels
        common.add_any_new_thread_labels(new_uid.message.thread, new_uid,
                                         db_session)
        new_uid.update_flags_and_labels(msg.flags)
        return new_uid
Пример #7
0
    def add_message_to_thread(self, db_session, message_obj, raw_message):
        """
        Associate message_obj to the right Thread object, creating a new
        thread if necessary.

        """
        with db_session.no_autoflush:
            # Disable autoflush so we don't try to flush a message with null
            # thread_id.
            parent_thread = fetch_corresponding_thread(db_session,
                                                       self.namespace_id,
                                                       message_obj)
            construct_new_thread = True

            if parent_thread:
                # If there's a parent thread that isn't too long already,
                # add to it. Otherwise create a new thread.
                parent_message_count = self._count_thread_messages(
                    parent_thread.id, db_session)
                if parent_message_count < MAX_THREAD_LENGTH:
                    construct_new_thread = False

            if construct_new_thread:
                message_obj.thread = ImapThread.from_imap_message(
                    db_session, self.namespace_id, message_obj)
            else:
                parent_thread.messages.append(message_obj)
Пример #8
0
    def add_message_to_thread(self, db_session, message_obj, raw_message):
        """
        Associate message_obj to the right Thread object, creating a new
        thread if necessary.

        """
        with db_session.no_autoflush:
            # Disable autoflush so we don't try to flush a message with null
            # thread_id.
            parent_thread = fetch_corresponding_thread(
                db_session, self.namespace_id, message_obj)
            construct_new_thread = True

            if parent_thread:
                # If there's a parent thread that isn't too long already,
                # add to it. Otherwise create a new thread.
                parent_message_count = self._count_thread_messages(
                    parent_thread.id, db_session)
                if parent_message_count < MAX_THREAD_LENGTH:
                    construct_new_thread = False

            if construct_new_thread:
                message_obj.thread = ImapThread.from_imap_message(
                    db_session, self.namespace_id, message_obj)
            else:
                parent_thread.messages.append(message_obj)
Пример #9
0
def test_self_send(db, default_namespace):
    first_thread = add_fake_thread(db.session, default_namespace.id)
    first_thread.subject = "Some kind of test"

    add_fake_message(
        db.session,
        default_namespace.id,
        thread=first_thread,
        subject="Some kind of test",
        from_addr=[("Karim Hamidou", "*****@*****.**")],
        to_addr=[("Karim Hamidou", "*****@*****.**")],
    )

    msg2 = add_fake_message(
        db.session,
        default_namespace.id,
        thread=None,
        subject="Re: Some kind of test",
        from_addr=[("Karim Hamidou", "*****@*****.**")],
        to_addr=[("Karim Hamidou", "*****@*****.**")],
    )

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg2)
    assert matched_thread is first_thread, "Should match on self-send"
def test_generic_grouping(db, generic_account):
    thread = add_fake_thread(db.session, NAMESPACE_ID)
    message = add_fake_message(db.session, NAMESPACE_ID, thread,
                               subject="Golden Gate Park next Sat")
    imapuid = ImapUid(message=message, account_id=ACCOUNT_ID,
                      msg_uid=2222)

    thread = add_fake_thread(db.session, generic_account.namespace.id)
    message = add_fake_message(db.session, NAMESPACE_ID + 1, thread,
                               subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session, generic_account.namespace.id, message)
    assert thread is None, ("fetch_similar_threads should "
                             "heed namespace boundaries")
Пример #11
0
def test_generic_grouping(db, default_account):
    thread = add_fake_thread(db.session, default_account.namespace.id)
    message = add_fake_message(db.session, default_account.namespace.id,
                               thread, subject="Golden Gate Park next Sat")
    folder = Folder(account=default_account, name='Inbox',
                    canonical_name='inbox')
    ImapUid(message=message, account_id=default_account.id,
            msg_uid=2222, folder=folder)

    thread = add_fake_thread(db.session, default_account.namespace.id)

    account = add_generic_imap_account(db.session)
    message = add_fake_message(db.session, account.namespace.id,
                               thread, subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session,
                                        default_account.namespace.id, message)
    assert thread is None, ("fetch_similar_threads should "
                            "heed namespace boundaries")
Пример #12
0
def test_self_send(db, default_namespace):
    first_thread = add_fake_thread(db.session, default_namespace.id)
    first_thread.subject = 'Some kind of test'

    add_fake_message(db.session, default_namespace.id,
                     thread=first_thread,
                     subject='Some kind of test',
                     from_addr=[('Karim Hamidou', '*****@*****.**')],
                     to_addr=[('Karim Hamidou', '*****@*****.**')])

    msg2 = add_fake_message(db.session, default_namespace.id,
                            thread=None,
                            subject='Re: Some kind of test',
                            from_addr=[('Karim Hamidou', '*****@*****.**')],
                            to_addr=[('Karim Hamidou', '*****@*****.**')])

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg2)
    assert matched_thread is first_thread, "Should match on self-send"
def test_generic_grouping(db, default_account):
    thread = add_fake_thread(db.session, default_account.namespace.id)
    message = add_fake_message(db.session, default_account.namespace.id,
                               thread, subject="Golden Gate Park next Sat")
    ImapUid(message=message, account_id=default_account.id,
            msg_uid=2222, folder=default_account.inbox_folder)

    thread = add_fake_thread(db.session, default_account.namespace.id)

    new_namespace = Namespace()
    db.session.add(new_namespace)
    db.session.commit()
    message = add_fake_message(db.session, new_namespace.id,
                               thread, subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session,
                                        default_account.namespace.id, message)
    assert thread is None, ("fetch_similar_threads should "
                            "heed namespace boundaries")