コード例 #1
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criteria_by_date(self):
        self.imap_account = imaplib.IMAP4_SSL()

        date = datetime.datetime(1989, 1, 3)
        search_criterion = search.create_search_criterion(date=date)
        assert search_criterion == ['SINCE 03-Jan-1989']

        search_criterion = search.create_search_criterion_by_date(
            date, relative='BEFORE')
        assert search_criterion == 'BEFORE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='ON')
        assert search_criterion == 'ON 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='SINCE')
        assert search_criterion == 'SINCE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='BEFORE', sent=True)
        assert search_criterion == 'SENTBEFORE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='ON', sent=True)
        assert search_criterion == 'SENTON 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='SINCE', sent=True)
        assert search_criterion == 'SENTSINCE 03-Jan-1989'
コード例 #2
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criteria_by_date(self):
        self.imap_account = imaplib.IMAP4_SSL()

        date = datetime.datetime(1989, 1, 3)
        search_criterion = search.create_search_criterion(date=date)
        assert search_criterion == ['SINCE 03-Jan-1989']

        search_criterion = search.create_search_criterion_by_date(
            date, relative='BEFORE')
        assert search_criterion == 'BEFORE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='ON')
        assert search_criterion == 'ON 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='SINCE')
        assert search_criterion == 'SINCE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='BEFORE', sent=True)
        assert search_criterion == 'SENTBEFORE 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='ON', sent=True)
        assert search_criterion == 'SENTON 03-Jan-1989'

        search_criterion = search.create_search_criterion_by_date(
            date, relative='SINCE', sent=True)
        assert search_criterion == 'SENTSINCE 03-Jan-1989'
コード例 #3
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criterion_by_subject(self):
        self.imap_account = imaplib.IMAP4_SSL()

        subject = 'subject searched'
        search_criterion = search.create_search_criterion(subject=subject)
        assert search_criterion == ['SUBJECT "subject searched"']

        search_criterion = search.create_search_criterion_by_subject(subject)
        assert search_criterion == 'SUBJECT "subject searched"'
コード例 #4
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criteria_by_tag(self):
        self.imap_account = imaplib.IMAP4_SSL()

        tags = ['seen']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['SEEN']

        tags = ['testTag']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['KEYWORD "testTag"']

        tags = ['seen', 'testTag']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['(SEEN KEYWORD "testTag")']

        tags = []
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['']
コード例 #5
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criteria_by_tag(self):
        self.imap_account = imaplib.IMAP4_SSL()

        tags = ['seen']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['SEEN']

        tags = ['testTag']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['KEYWORD "testTag"']

        tags = ['seen', 'testTag']
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['(SEEN KEYWORD "testTag")']

        tags = []
        search_criterion = search.create_search_criterion(tags=tags)
        assert search_criterion == ['']
コード例 #6
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criterion_by_subject(self):
        self.imap_account = imaplib.IMAP4_SSL()

        subject = 'subject searched'
        search_criterion = search.create_search_criterion(subject=subject)
        assert search_criterion == ['SUBJECT "subject searched"']

        search_criterion = search.create_search_criterion_by_subject(subject)
        assert search_criterion == 'SUBJECT "subject searched"'
コード例 #7
0
ファイル: imap_shell.py プロジェクト: xiconet/imap-cli
 def do_unseen(self, arg):
     '''List Unseen mail (equivalent to "search -t unseen").'''
     search_criterion = search.create_search_criterion(tags=['unseen'])
     mail_set = search.fetch_uids(self.imap_account,
                                  search_criterion=search_criterion)
     if len(mail_set) == 0:
         log.error('No unseen mail found')
     else:
         for mail_info in search.fetch_mails_info(self.imap_account,
                                                  mail_set=mail_set):
             sys.stdout.write(
                 u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
                     mail_info['uid'], mail_info['from'],
                     mail_info['subject']))
コード例 #8
0
ファイル: imap_api.py プロジェクト: Gentux/imap-cli
def search_controller(req):
    params = req.params
    inputs = {
        "directory": params.get("directory") or const.DEFAULT_DIRECTORY,
        "tags": params.getall("tag") or None,
        "text": params.get("text") or None,
    }

    imap_cli.change_dir(imap_account, inputs["directory"])

    search_criterion = search.create_search_criterion(tags=inputs["tags"], text=inputs["text"])
    mail_set = search.fetch_uids(imap_account, search_criterion=search_criterion or [])
    mails_info = list(search.fetch_mails_info(imap_account, mail_set=mail_set))
    return json.dumps(mails_info, indent=2)
コード例 #9
0
ファイル: imap_shell.py プロジェクト: Gentux/imap-cli
    def do_search(self, arg):
        '''Search mail.'''
        usage = '\n'.join([
            'Usage: search [options]',
            '',
            'Options:',
            '    -a, --address=<address>     Search by address',
            '    -d, --date=<date>           Search by date (YYYY-MM-DD)',
            '    -s, --size=<SIZE>           Search by size (in bytes)',
            '    -S, --subject=<subject>     Search by subject',
            '    -t, --tags=<tags>           Searched tags (Comma separated)',
            '    -T, --full-text=<text>      Searched tags (Comma separated)',
            '    -h, --help                  Show help options.',
        ])
        try:
            args = docopt.docopt(usage, argv=arg)
        except SystemExit:
            return

        if args.get('--tags') is not None:
            args['--tags'] = args['--tags'].split(',')
        if args['--date'] is not None:
            try:
                date = datetime.datetime.strptime(args['--date'], '%Y-%m-%d')
            except ValueError:
                date = None
        else:
            date = None

        search_criterion = search.create_search_criterion(
            address=args['--address'],
            date=date,
            subject=args['--subject'],
            size=args['--size'],
            tags=args['--tags'],
            text=args['--full-text'],
        )
        mail_set = search.fetch_uids(self.imap_account,
                                     search_criterion=search_criterion)
        if len(mail_set) == 0:
            log.error('No mail found')
            return 0
        for mail_info in search.fetch_mails_info(self.imap_account,
                                                 mail_set=mail_set):
            sys.stdout.write(
                u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
                    mail_info['uid'],
                    mail_info['from'],
                    mail_info['subject']))
コード例 #10
0
ファイル: imap_shell.py プロジェクト: Gentux/imap-cli
 def do_unseen(self, arg):
     '''List Unseen mail (equivalent to "search -t unseen").'''
     search_criterion = search.create_search_criterion(tags=['unseen'])
     mail_set = search.fetch_uids(self.imap_account,
                                  search_criterion=search_criterion)
     if len(mail_set) == 0:
         log.error('No unseen mail found')
     else:
         for mail_info in search.fetch_mails_info(self.imap_account,
                                                  mail_set=mail_set):
             sys.stdout.write(
                 u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
                     mail_info['uid'],
                     mail_info['from'],
                     mail_info['subject']))
コード例 #11
0
def search_controller(req):
    params = req.params
    inputs = {
        'directory': params.get('directory') or const.DEFAULT_DIRECTORY,
        'tags': params.getall('tag') or None,
        'text': params.get('text') or None,
    }

    imap_cli.change_dir(imap_account, inputs['directory'])

    search_criterion = search.create_search_criterion(tags=inputs['tags'],
                                                      text=inputs['text'])
    mail_set = search.fetch_uids(imap_account,
                                 search_criterion=search_criterion or [])
    mails_info = list(search.fetch_mails_info(imap_account, mail_set=mail_set))
    return json.dumps(mails_info, indent=2)
コード例 #12
0
ファイル: imap_shell.py プロジェクト: xiconet/imap-cli
    def do_search(self, arg):
        '''Search mail.'''
        usage = '\n'.join([
            'Usage: search [options]',
            '',
            'Options:',
            '    -a, --address=<address>     Search by address',
            '    -d, --date=<date>           Search by date (YYYY-MM-DD)',
            '    -s, --size=<SIZE>           Search by size (in bytes)',
            '    -S, --subject=<subject>     Search by subject',
            '    -t, --tags=<tags>           Searched tags (Comma separated)',
            '    -T, --full-text=<text>      Searched tags (Comma separated)',
            '    -h, --help                  Show help options.',
        ])
        try:
            args = docopt.docopt(usage, argv=arg)
        except SystemExit:
            return

        if args.get('--tags') is not None:
            args['--tags'] = args['--tags'].split(',')
        if args['--date'] is not None:
            try:
                date = datetime.datetime.strptime(args['--date'], '%Y-%m-%d')
            except ValueError:
                date = None
        else:
            date = None

        search_criterion = search.create_search_criterion(
            address=args['--address'],
            date=date,
            subject=args['--subject'],
            size=args['--size'],
            tags=args['--tags'],
            text=args['--full-text'],
        )
        mail_set = search.fetch_uids(self.imap_account,
                                     search_criterion=search_criterion)
        if len(mail_set) == 0:
            log.error('No mail found')
            return 0
        for mail_info in search.fetch_mails_info(self.imap_account,
                                                 mail_set=mail_set):
            sys.stdout.write(
                u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
                    mail_info['uid'], mail_info['from'], mail_info['subject']))
コード例 #13
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criteria_by_size(self):
        self.imap_account = imaplib.IMAP4_SSL()

        size = 3141592
        search_criterion = search.create_search_criterion(size=size)
        assert search_criterion == ['LARGER "3141592"']

        search_criterion = search.create_search_criterion_by_size(
            size, relative='SMALLER')
        assert search_criterion == 'SMALLER "3141592"'

        search_criterion = search.create_search_criterion_by_size(
            size, relative='LARGER')
        assert search_criterion == 'LARGER "3141592"'

        search_criterion = search.create_search_criterion_by_size(
            size, relative='Anything')
        assert search_criterion == 'LARGER "3141592"'
コード例 #14
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criteria_by_size(self):
        self.imap_account = imaplib.IMAP4_SSL()

        size = 3141592
        search_criterion = search.create_search_criterion(size=size)
        assert search_criterion == ['LARGER "3141592"']

        search_criterion = search.create_search_criterion_by_size(
            size, relative='SMALLER')
        assert search_criterion == 'SMALLER "3141592"'

        search_criterion = search.create_search_criterion_by_size(
            size, relative='LARGER')
        assert search_criterion == 'LARGER "3141592"'

        search_criterion = search.create_search_criterion_by_size(
            size, relative='Anything')
        assert search_criterion == 'LARGER "3141592"'
コード例 #15
0
ファイル: vimap.py プロジェクト: Gentux/vimap
def imap_search(adress):
    ensure_connection()
    search_criterion = search.create_search_criterion(address=adress)
    mail_set = search.fetch_uids(
        imap_account, search_criterion=search_criterion)
    if len(mail_set) == 0:
        print 'VIMAP: No mail found'
        return 0

    reset_buffer('vimap-list')
    b = vim.current.buffer
    b[:] = None
    for mail_info in search.fetch_mails_info(imap_account, mail_set=mail_set):
        b.append(display_conf['format_list'].format(
            **mail_info).replace('\n', ' '))

    b[0] = u'Mails from «{}»:'.format(adress)

    for key, action in list_mappings:
        vim.command("nnoremap <silent> <buffer> {} {}".format(key, action))
コード例 #16
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criterion_by_mail_address(self):
        self.imap_account = imaplib.IMAP4_SSL()

        mail_address = '*****@*****.**'
        search_criterion = search.create_search_criterion(address=mail_address)
        assert search_criterion == ['FROM "*****@*****.**"']

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='WRONG')
        assert search_criterion == 'FROM "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='CC')
        assert search_criterion == 'CC "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='BCC')
        assert search_criterion == 'BCC "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='TO')
        assert search_criterion == 'TO "*****@*****.**"'
コード例 #17
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criterion_by_mail_address(self):
        self.imap_account = imaplib.IMAP4_SSL()

        mail_address = '*****@*****.**'
        search_criterion = search.create_search_criterion(address=mail_address)
        assert search_criterion == ['FROM "*****@*****.**"']

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='WRONG')
        assert search_criterion == 'FROM "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='CC')
        assert search_criterion == 'CC "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='BCC')
        assert search_criterion == 'BCC "*****@*****.**"'

        search_criterion = search.create_search_criterion_by_mail_address(
            mail_address, header_name='TO')
        assert search_criterion == 'TO "*****@*****.**"'
コード例 #18
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_create_search_criteria_by_text(self):
        self.imap_account = imaplib.IMAP4_SSL()

        text = 'CONTENT'
        search_criterion = search.create_search_criterion(text=text)
        assert search_criterion == ['BODY "CONTENT"']
コード例 #19
0
ファイル: test_search.py プロジェクト: xiconet/imap-cli
    def test_basic_search(self):
        self.imap_account = imaplib.IMAP4_SSL()

        assert search.create_search_criterion() == ['ALL']
コード例 #20
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_create_search_criteria_by_text(self):
        self.imap_account = imaplib.IMAP4_SSL()

        text = 'CONTENT'
        search_criterion = search.create_search_criterion(text=text)
        assert search_criterion == ['BODY "CONTENT"']
コード例 #21
0
ファイル: test_search.py プロジェクト: Gentux/imap-cli
    def test_basic_search(self):
        self.imap_account = imaplib.IMAP4_SSL()

        assert search.create_search_criterion() == ['ALL']