コード例 #1
0
def add_fake_label(db_session,
                   default_account,
                   display_name='My Label',
                   name=None):
    from inbox.models.label import Label
    return Label.find_or_create(db_session, default_account, display_name,
                                name)
コード例 #2
0
ファイル: imap.py プロジェクト: devwaker/sync-engine
    def update_labels(self, new_labels):
        # TODO(emfree): This is all mad complicated. Simplify if possible?

        # Gmail IMAP doesn't use the normal IMAP \\Draft flag. Silly Gmail
        # IMAP.
        self.is_draft = '\\Draft' in new_labels
        self.is_starred = '\\Starred' in new_labels

        category_map = {
            '\\Inbox': 'inbox',
            '\\Important': 'important',
            '\\Sent': 'sent'
        }

        remote_labels = set()
        for label in new_labels:
            if label in ('\\Draft', '\\Starred'):
                continue
            elif label in category_map:
                remote_labels.add((category_map[label], category_map[label]))
            else:
                remote_labels.add((label, None))

        local_labels = {(l.name, l.canonical_name) for l in self.labels}

        remove = local_labels - remote_labels
        add = remote_labels - local_labels

        with object_session(self).no_autoflush:
            for name, canonical_name in remove:
                label = Label.find_or_create(object_session(self),
                                             self.account, name,
                                             canonical_name)
                self.labels.remove(label)

            for name, canonical_name in add:
                label = Label.find_or_create(object_session(self),
                                             self.account, name,
                                             canonical_name)
                self.labels.add(label)
コード例 #3
0
ファイル: imap.py プロジェクト: steffenmllr/sync-engine
    def update_labels(self, new_labels):
        # TODO(emfree): This is all mad complicated. Simplify if possible?

        # Gmail IMAP doesn't use the normal IMAP \\Draft flag. Silly Gmail
        # IMAP.
        self.is_draft = '\\Draft' in new_labels
        self.is_starred = '\\Starred' in new_labels

        category_map = {
            '\\Inbox': 'inbox',
            '\\Important': 'important',
            '\\Sent': 'sent'
        }

        remote_labels = set()
        for label in new_labels:
            if label in ('\\Draft', '\\Starred'):
                continue
            elif label in category_map:
                remote_labels.add((category_map[label], category_map[label]))
            else:
                remote_labels.add((label, None))

        local_labels = {(l.name, l.canonical_name) for l in self.labels}

        remove = local_labels - remote_labels
        add = remote_labels - local_labels

        with object_session(self).no_autoflush:
            for name, canonical_name in remove:
                label = Label.find_or_create(object_session(self),
                                             self.account, name,
                                             canonical_name)
                self.labels.remove(label)

            for name, canonical_name in add:
                label = Label.find_or_create(object_session(self),
                                             self.account, name,
                                             canonical_name)
                self.labels.add(label)
コード例 #4
0
def test_deleted_labels_get_gced(empty_db, default_account, thread, message,
                                 imapuid, folder):
    # Check that only the labels without messages attached to them
    # get deleted.
    default_namespace = default_account.namespace

    # Create a label w/ no messages attached.
    label = Label.find_or_create(empty_db.session, default_account,
                                 "dangling label")
    label.deleted_at = datetime.utcnow()
    label.category.deleted_at = datetime.utcnow()
    label_id = label.id
    empty_db.session.commit()

    # Create a label with attached messages.
    msg_uid = imapuid.msg_uid
    update_metadata(
        default_account.id,
        folder.id,
        folder.canonical_name,
        {msg_uid: GmailFlags((), ("label", ), None)},
        empty_db.session,
    )

    label_ids = []
    for cat in message.categories:
        for l in cat.labels:
            label_ids.append(l.id)

    handler = DeleteHandler(
        account_id=default_account.id,
        namespace_id=default_namespace.id,
        provider_name=default_account.provider,
        uid_accessor=lambda m: m.imapuids,
        message_ttl=0,
    )
    handler.gc_deleted_categories()
    empty_db.session.commit()

    # Check that the first label got gc'ed
    marked_deleted = empty_db.session.query(Label).get(label_id)
    assert marked_deleted is None

    # Check that the other labels didn't.
    for label_id in label_ids:
        assert empty_db.session.query(Label).get(label_id) is not None
コード例 #5
0
ファイル: imap.py プロジェクト: ivicac/sync-engine
    def update_labels(self, new_labels):
        # TODO(emfree): This is all mad complicated. Simplify if possible?

        # Gmail IMAP doesn't use the normal IMAP \\Draft flag. Silly Gmail
        # IMAP.
        self.is_draft = "\\Draft" in new_labels
        self.is_starred = "\\Starred" in new_labels

        category_map = {
            "\\Inbox": "inbox",
            "\\Important": "important",
            "\\Sent": "sent",
            "\\Trash": "trash",
            "\\Spam": "spam",
            "\\All": "all",
        }

        remote_labels = set()
        for label in new_labels:
            if label in ("\\Draft", "\\Starred"):
                continue
            elif label in category_map:
                remote_labels.add((category_map[label], category_map[label]))
            else:
                remote_labels.add((label, None))

        local_labels = {(lbl.name, lbl.canonical_name): lbl
                        for lbl in self.labels}

        remove = set(local_labels) - remote_labels
        add = remote_labels - set(local_labels)

        with object_session(self).no_autoflush:
            for key in remove:
                self.labels.remove(local_labels[key])

            for name, canonical_name in add:
                label = Label.find_or_create(object_session(self),
                                             self.account, name,
                                             canonical_name)
                self.labels.add(label)
コード例 #6
0
def test_deleted_labels_get_gced(db, default_account, thread, message,
                                 imapuid, folder):
    # Check that only the labels without messages attached to them
    # get deleted.

    default_namespace = default_account.namespace

    # Create a label w/ no messages attached.
    label = Label.find_or_create(db.session, default_account, 'dangling label')
    label.deleted_at = datetime.utcnow()
    label.category.deleted_at = datetime.utcnow()
    label_id = label.id
    db.session.commit()

    # Create a label with attached messages.
    msg_uid = imapuid.msg_uid
    update_metadata(default_account.id, folder.id, folder.canonical_name,
                    {msg_uid: GmailFlags((), ('label',), None)}, db.session)

    label_ids = []
    for cat in message.categories:
        for l in cat.labels:
            label_ids.append(l.id)

    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=0)
    handler.gc_deleted_categories()
    db.session.commit()

    # Check that the first label got gc'ed
    marked_deleted = db.session.query(Label).get(label_id)
    assert marked_deleted is None

    # Check that the other labels didn't.
    for label_id in label_ids:
        assert db.session.query(Label).get(label_id) is not None
コード例 #7
0
def custom_label(db, default_account):
    from inbox.models import Label
    return Label.find_or_create(db.session, default_account, 'Kraftwerk', '')
コード例 #8
0
def label(db, default_account):
    from inbox.models import Label
    return Label.find_or_create(db.session, default_account, 'Inbox', 'inbox')
コード例 #9
0
ファイル: base.py プロジェクト: brandoncc/sync-engine
def label(db, default_account):
    from inbox.models import Label
    return Label.find_or_create(db.session, default_account,
                                'Inbox', 'inbox')
コード例 #10
0
ファイル: base.py プロジェクト: brandoncc/sync-engine
def add_fake_label(db_session, default_account, display_name='My Label',
                    name=None):
    from inbox.models.label import Label
    return Label.find_or_create(db_session, default_account, display_name, name)
コード例 #11
0
ファイル: base.py プロジェクト: busseyl/sync-engine
def custom_label(db, default_account):
    from inbox.models import Label
    return Label.find_or_create(db.session, default_account,
                                'Kraftwerk', '')