Beispiel #1
0
def test_fs_folder_path():
    assert fs_folder_path("INBOX.A.B") == "INBOX/A/B"
    assert fs_folder_path("INBOX.A.B", prefix="INBOX.") == "A/B"
    assert fs_folder_path("INBOX?A?B", prefix="INBOX?", separator="?") == "A/B"
    assert (fs_folder_path("INBOX.a.very.deep.nested.folder") ==
            "INBOX/a/very/deep/nested/folder")
    assert fs_folder_path(imap_folder_path("a/b")) == "a/b"
Beispiel #2
0
def remote_delete_folder(account_id, category_id):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        try:
            if account_provider not in ['gmail', 'eas']:
                # Translate a Unix-style path to the actual folder path.
                display_name = imap_folder_path(
                    display_name,
                    separator=crispin_client.folder_separator,
                    prefix=crispin_client.folder_prefix)

            crispin_client.conn.delete_folder(display_name)
        except IMAP4.error:
            # Folder has already been deleted on remote. Treat delete as
            # no-op.
            pass

    with session_scope(account_id) as db_session:
        category = db_session.query(Category).get(category_id)
        db_session.delete(category)
        db_session.commit()
Beispiel #3
0
def test_fs_folder_path():
    assert fs_folder_path('INBOX.A.B') == 'INBOX/A/B'
    assert fs_folder_path('INBOX.A.B', prefix='INBOX.') == 'A/B'
    assert fs_folder_path('INBOX?A?B', prefix='INBOX?', separator='?') == 'A/B'
    assert fs_folder_path(
        'INBOX.a.very.deep.nested.folder') == 'INBOX/a/very/deep/nested/folder'
    assert fs_folder_path(imap_folder_path('a/b')) == 'a/b'
Beispiel #4
0
def remote_update_folder(crispin_client, account_id, category_id, old_name,
                         new_name):

    with session_scope(account_id) as db_session:
        account = db_session.query(Account).get(account_id)
        account_provider = account.provider

    if account_provider not in ['gmail', 'eas']:
        new_display_name = imap_folder_path(
            new_name, separator=crispin_client.folder_separator,
            prefix=crispin_client.folder_prefix)
    else:
        new_display_name = new_name

    crispin_client.conn.rename_folder(old_name, new_display_name)

    # TODO @karim: Make the main sync loop detect folder renames
    # more accurately, and get rid of this.
    if new_display_name != old_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name

            for folder in category.folders:
                if folder.name == old_name:
                    folder.name = new_display_name
Beispiel #5
0
def remote_create_folder(account_id, category_id):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        # Some generic IMAP providers have different conventions
        # regarding folder names. For example, Fastmail wants paths
        # to be of the form "INBOX.A". The API abstracts this.
        if account_provider not in ['gmail', 'eas']:
            # Translate the name of the folder to an actual IMAP name
            # (e.g: "Accounting/Taxes" becomes "Accounting.Taxes")
            new_display_name = imap_folder_path(
                display_name,
                separator=crispin_client.folder_separator,
                prefix=crispin_client.folder_prefix)
        else:
            new_display_name = display_name
        crispin_client.conn.create_folder(new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #6
0
def remote_update_folder(crispin_client, account_id, category_id, old_name,
                         new_name):

    with session_scope(account_id) as db_session:
        account = db_session.query(Account).get(account_id)
        account_provider = account.provider

    if account_provider not in ['gmail', 'eas']:
        new_display_name = imap_folder_path(
            new_name, separator=crispin_client.folder_separator,
            prefix=crispin_client.folder_prefix)
    else:
        new_display_name = new_name

    crispin_client.conn.rename_folder(old_name, new_display_name)

    # TODO @karim: Make the main sync loop detect folder renames
    # more accurately, and get rid of this.
    if new_display_name != old_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name

            for folder in category.folders:
                if folder.name == old_name:
                    folder.name = new_display_name
Beispiel #7
0
def remote_update_folder(account, category_id, db_session, old_name):
    category = db_session.query(Category).get(category_id)
    with writable_connection_pool(account.id).get() as crispin_client:
        if account.provider in ['generic', 'fastmail']:
            # Update the name of the folder to 'INBOX.whatever'.
            # We need to do this to keep track of the folder name
            # on the backend. The API abstracts this anyway.
            category.display_name = imap_folder_path(
                category.display_name,
                separator=crispin_client.folder_delimiter)

        crispin_client.conn.rename_folder(old_name, category.display_name)
Beispiel #8
0
def remote_create_folder(account, category_id, db_session):
    category = db_session.query(Category).get(category_id)

    with writable_connection_pool(account.id).get() as crispin_client:
        # Some generic IMAP providers have different conventions
        # regarding folder names. For example, Fastmail wants paths
        # to be of the form "INBOX.A". The API abstracts this.
        if account.provider in ['generic', 'fastmail']:
            # Update the name of the folder to 'INBOX.whatever'.
            # We need to do this to keep track of the folder name
            # on the backend. The API abstracts this anyway.
            category.display_name = imap_folder_path(
                category.display_name,
                separator=crispin_client.folder_delimiter)

        crispin_client.conn.create_folder(category.display_name)
Beispiel #9
0
def remote_update_folder(account_id, category_id, old_name):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        if account_provider not in ['gmail', 'eas']:
            new_display_name = imap_folder_path(
                display_name, separator=crispin_client.folder_separator,
                prefix=crispin_client.folder_prefix)
        else:
            new_display_name = display_name
        crispin_client.conn.rename_folder(old_name, new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #10
0
def remote_update_folder(crispin_client, account_id, category_id, old_name):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    if account_provider not in ['gmail', 'eas']:
        new_display_name = imap_folder_path(
            display_name,
            separator=crispin_client.folder_separator,
            prefix=crispin_client.folder_prefix)
    else:
        new_display_name = display_name
    crispin_client.conn.rename_folder(old_name, new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #11
0
def remote_update_folder(account_id, category_id, old_name):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        if account_provider in ["generic", "fastmail"]:
            # Update the name of the folder to 'INBOX.whatever'.
            # We need to do this to keep track of the folder name
            # on the backend. The API abstracts this anyway.
            new_display_name = imap_folder_path(display_name, separator=crispin_client.folder_delimiter)
        else:
            new_display_name = display_name
        crispin_client.conn.rename_folder(old_name, new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #12
0
def remote_update_folder(account_id, category_id, old_name):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        if account_provider in ['generic', 'fastmail']:
            # Update the name of the folder to 'INBOX.whatever'.
            # We need to do this to keep track of the folder name
            # on the backend. The API abstracts this anyway.
            new_display_name = imap_folder_path(
                display_name, separator=crispin_client.folder_delimiter)
        else:
            new_display_name = display_name
        crispin_client.conn.rename_folder(old_name, new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #13
0
def remote_create_folder(account_id, category_id):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        # Some generic IMAP providers have different conventions
        # regarding folder names. For example, Fastmail wants paths
        # to be of the form "INBOX.A". The API abstracts this.
        if account_provider in ["generic", "fastmail"]:
            # Update the name of the folder to 'INBOX.whatever'.
            # We need to do this to keep track of the folder name
            # on the backend. The API abstracts this anyway.
            new_display_name = imap_folder_path(display_name, separator=crispin_client.folder_delimiter)
        else:
            new_display_name = display_name
        crispin_client.conn.create_folder(new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #14
0
def remote_create_folder(account_id, category_id):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        # Some generic IMAP providers have different conventions
        # regarding folder names. For example, Fastmail wants paths
        # to be of the form "INBOX.A". The API abstracts this.
        if account_provider not in ['gmail', 'eas']:
            # Translate the name of the folder to an actual IMAP name
            # (e.g: "Accounting/Taxes" becomes "Accounting.Taxes")
            new_display_name = imap_folder_path(
                display_name, separator=crispin_client.folder_separator,
                prefix=crispin_client.folder_prefix)
        else:
            new_display_name = display_name
        crispin_client.conn.create_folder(new_display_name)

    if new_display_name != display_name:
        with session_scope(account_id) as db_session:
            category = db_session.query(Category).get(category_id)
            category.display_name = new_display_name
Beispiel #15
0
def remote_delete_folder(account_id, category_id):
    with session_scope(account_id) as db_session:
        account_provider = db_session.query(Account).get(account_id).provider
        category = db_session.query(Category).get(category_id)
        display_name = category.display_name

    with writable_connection_pool(account_id).get() as crispin_client:
        try:
            if account_provider not in ['gmail', 'eas']:
                # Translate a Unix-style path to the actual folder path.
                display_name = imap_folder_path(
                    display_name, separator=crispin_client.folder_separator,
                    prefix=crispin_client.folder_prefix)

            crispin_client.conn.delete_folder(display_name)
        except IMAP4.error:
            # Folder has already been deleted on remote. Treat delete as
            # no-op.
            pass

    with session_scope(account_id) as db_session:
        category = db_session.query(Category).get(category_id)
        db_session.delete(category)
        db_session.commit()
Beispiel #16
0
def test_fs_folder_path():
    assert fs_folder_path('INBOX.A.B') == 'INBOX/A/B'
    assert fs_folder_path('INBOX.A.B', prefix='INBOX.') == 'A/B'
    assert fs_folder_path('INBOX?A?B', prefix='INBOX?', separator='?') == 'A/B'
    assert fs_folder_path('INBOX.a.very.deep.nested.folder') == 'INBOX/a/very/deep/nested/folder'
    assert fs_folder_path(imap_folder_path('a/b')) == 'a/b'
Beispiel #17
0
def test_imap_folder_path():
    assert imap_folder_path('a/b') == 'a.b'
    assert imap_folder_path('a/b', separator='?') == 'a?b'

    assert imap_folder_path('/A/b') == 'A.b'
    assert imap_folder_path('/INBOX/b') == 'INBOX.b'
    assert imap_folder_path('INBOX/b') == 'INBOX.b'

    assert imap_folder_path('a/very/deep/nested/folder') == 'a.very.deep.nested.folder'
    assert imap_folder_path('/a/very/deep/nested/folder') == 'a.very.deep.nested.folder'

    assert imap_folder_path('') is None
    assert imap_folder_path('/') is None

    assert imap_folder_path('A/B', prefix='INBOX.', separator='.') == 'INBOX.A.B'
    assert imap_folder_path('/A/B', prefix='INBOX.', separator='.') == 'INBOX.A.B'
    assert imap_folder_path('/A/B', prefix='INBOX', separator='.') == 'INBOX.A.B'
    assert imap_folder_path('INBOX/A/B', prefix='INBOX', separator='.') == 'INBOX.A.B'
Beispiel #18
0
def test_imap_folder_path():
    assert imap_folder_path('a/b') == 'a.b'
    assert imap_folder_path('a/b', separator='?') == 'a?b'

    assert imap_folder_path('/A/b') == 'A.b'
    assert imap_folder_path('/INBOX/b') == 'INBOX.b'
    assert imap_folder_path('INBOX/b') == 'INBOX.b'

    assert imap_folder_path(
        'a/very/deep/nested/folder') == 'a.very.deep.nested.folder'
    assert imap_folder_path(
        '/a/very/deep/nested/folder') == 'a.very.deep.nested.folder'

    assert imap_folder_path('') is None
    assert imap_folder_path('/') is None

    assert imap_folder_path('A/B', prefix='INBOX.',
                            separator='.') == 'INBOX.A.B'
    assert imap_folder_path('/A/B', prefix='INBOX.',
                            separator='.') == 'INBOX.A.B'
    assert imap_folder_path('/A/B', prefix='INBOX',
                            separator='.') == 'INBOX.A.B'
    assert imap_folder_path('INBOX/A/B', prefix='INBOX',
                            separator='.') == 'INBOX.A.B'
Beispiel #19
0
def test_fs_folder_path():
    assert fs_folder_path('INBOX.A.B') == 'A/B'
    assert fs_folder_path('INBOX.a.very.deep.nested.folder') == 'a/very/deep/nested/folder'
    assert fs_folder_path(imap_folder_path('/a/b')) == 'a/b'
Beispiel #20
0
def test_imap_folder_path():
    assert imap_folder_path("a/b") == "a.b"
    assert imap_folder_path("a/b", separator="?") == "a?b"

    assert imap_folder_path("/A/b") == "A.b"
    assert imap_folder_path("/INBOX/b") == "INBOX.b"
    assert imap_folder_path("INBOX/b") == "INBOX.b"

    assert imap_folder_path(
        "a/very/deep/nested/folder") == "a.very.deep.nested.folder"
    assert imap_folder_path(
        "/a/very/deep/nested/folder") == "a.very.deep.nested.folder"

    assert imap_folder_path("") is None
    assert imap_folder_path("/") is None

    assert imap_folder_path("A/B", prefix="INBOX.",
                            separator=".") == "INBOX.A.B"
    assert imap_folder_path("/A/B", prefix="INBOX.",
                            separator=".") == "INBOX.A.B"
    assert imap_folder_path("/A/B", prefix="INBOX",
                            separator=".") == "INBOX.A.B"
    assert imap_folder_path("INBOX/A/B", prefix="INBOX",
                            separator=".") == "INBOX.A.B"
Beispiel #21
0
def test_imap_folder_path():
    assert imap_folder_path('/a/b') == 'INBOX.a.b'
    assert imap_folder_path('/A/b') == 'INBOX.A.b'
    assert imap_folder_path('/a/very/deep/nested/folder') == 'INBOX.a.very.deep.nested.folder'
    assert imap_folder_path('') == 'INBOX'