def status(imap_account): """Return an interator of directory status. Each directory status provide the following keys:: u'count' # Number of mail in directory u'directory # Name of directory u'recent # Number of recent mail u'unseen # Number of unseen mail .. versionadded:: 0.1 Example: >>> import imap_cli >>> from imap_cli import config >>> conf = config.new_context_from_file(section='imap') >>> imap_account = imap_cli.connect(**conf) >>> for directory_status in imap_cli.status(imap_account): >>> print directory_status """ for directory_info in list_dir(imap_account): status, data = imap_account.status(directory_info['directory'], '(MESSAGES RECENT UNSEEN)') if status != const.STATUS_OK: log.warning('Wrong status : {}'.format(repr(data))) continue status_match = STATUS_RE.match(data[0]) if status_match is None: log.warning('Ignoring directory : {}'.format(repr(data))) continue group_dict = status_match.groupdict() yield { 'directory': string.decode(group_dict['directory']), 'unseen': group_dict['mail_unseen'], 'count': group_dict['mail_count'], 'recent': group_dict['mail_recent'], }
def test_encode(self): assert string.decode(self.encoded_string) == self.decoded_string