本文整理汇总了Python中pykolab.imap.IMAP类的典型用法代码示例。如果您正苦于以下问题:Python IMAP类的具体用法?Python IMAP怎么用?Python IMAP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IMAP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: teardown_class
def teardown_class(self):
time.sleep(2)
res_attr = conf.get('cyrus-sasl', 'result_attribute')
exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
expected_number_of_folders = len(ac_folders.keys()) + 1
users = []
result = wap_client.users_list()
for user in result['list'].keys():
user_info = wap_client.user_info(user)
users.append(user_info)
result = wap_client.user_delete({'user': user})
imap = IMAP()
imap.connect()
for user in users:
if len(user[res_attr].split('@')) > 1:
localpart = user[res_attr].split('@')[0]
domain = user[res_attr].split('@')[1]
folders = []
folders.extend(imap.lm('user/%s' % (user[res_attr])))
folders.extend(imap.lm('user/%s/*@%s' % (localpart,domain)))
示例2: execute
def execute(*args, **kw):
"""
Delete a message from a mail folder
"""
try:
folder = conf.cli_args.pop(0)
try:
uid = conf.cli_args.pop(0)
except:
log.error(_("Specify a UID"))
sys.exit(1)
except:
log.error(_("Specify a folder"))
sys.exit(1)
imap = IMAP()
imap.connect()
_folder = imap.lm(folder)
if _folder == None or _folder == []:
log.error(_("No such folder"))
sys.exit(1)
imap.set_acl(folder, 'cyrus-admin', 'lrswt')
imap.select(folder)
imap.store(uid, '+FLAGS', '\\Deleted')
示例3: execute
def execute(*args, **kw):
"""
List mailboxes
"""
searches = []
# See if conf.cli_args components make sense.
for arg in conf.cli_args:
if arg == '*':
searches.append(arg)
if arg.startswith('user'):
searches.append(arg)
if arg.startswith('shared'):
searches.append(arg)
if arg.startswith('DELETED'):
searches.append(arg)
if arg.startswith('news'):
searches.append(arg)
if len(searches) == 0:
searches = [ '' ]
imap = IMAP()
imap.connect()
folders = []
for search in searches:
log.debug(_("Appending folder search for %r") % (search), level=8)
folders.extend(imap.lm(search))
for folder in folders:
print folder
示例4: test_001_inbox_created
def test_001_inbox_created(self):
time.sleep(2)
imap = IMAP()
imap.connect()
folders = imap.lm('user/%(local)[email protected]%(domain)s' % (self.user))
self.assertEqual(len(folders), 1)
示例5: test_001_two_johns
def test_001_two_johns(self):
from tests.functional.user_add import user_add
user_add("John", "Doe")
user_add("John", "Doe")
time.sleep(3)
auth = Auth()
auth.connect()
max_tries = 20
while max_tries > 0:
recipient1 = auth.find_recipient('[email protected]')
recipient2 = auth.find_recipient('[email protected]')
if not recipient1 or not recipient2:
time.sleep(1)
max_tries -= 1
else:
break
imap = IMAP()
imap.connect()
folders = imap.lm('user/[email protected]')
self.assertEqual(len(folders), 1, "No INBOX found for first John")
folders = imap.lm('user/[email protected]')
self.assertEqual(len(folders), 1, "No INBOX found for second John")
示例6: execute
def execute(*args, **kw):
"""
List deleted mailboxes
"""
try:
domain = conf.cli_args.pop(0)
except:
domain = utils.ask_question(_("Domain"))
imap = IMAP()
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = []
for primary,secondaries in domains:
if not domain == primary and not domain in secondaries:
continue
folders.extend(imap.lm("user/%%@%s" % (primary)))
for secondary in secondaries:
folders.extend(imap.lm("user/%%@%s" % (secondary)))
print "Deleted folders:"
for folder in folders:
if not conf.raw:
print imap_utf7.decode(folder)
else:
print folder
示例7: connect
def connect(self, uri):
"""
Dummy connect function that checks if the server that we want to
connect to is actually the server we are connected to.
Uses pykolab.imap.IMAP.connect() in the background.
"""
port = None
result = urlparse(uri)
if hasattr(result, 'hostname'):
scheme = result.scheme
hostname = result.hostname
port = result.port
else:
scheme = uri.split(':')[0]
(hostname, port) = uri.split('/')[2].split(':')
if not port:
if scheme == 'imap':
port = 143
else:
port = 993
if hostname == self.server:
return
imap = IMAP()
imap.connect(uri=uri)
if not self.SEP == self.separator:
self.separator = self.SEP
示例8: test_001_inbox_created
def test_001_inbox_created(self):
imap = IMAP()
imap.connect()
folders = imap.lm('user/%(local)[email protected]%(domain)s' % (self.john))
self.assertEqual(len(folders), 1)
folders = imap.lm('user/%(local)[email protected]%(domain)s' % (self.jane))
self.assertEqual(len(folders), 1)
示例9: execute
def execute(*args, **kw):
"""
Synchronize or display changes
"""
imap = IMAP()
if not conf.connect_server == None:
imap.connect(server=conf.connect_server)
else:
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = imap.lm()
imap_domains_not_domains = []
for folder in folders:
if len(folder.split('@')) > 1 and not folder.startswith('DELETED'):
_folder_domain = folder.split('@')[-1]
if not _folder_domain in list(set(domains.keys() + domains.values())):
imap_domains_not_domains.append(folder.split('@')[-1])
imap_domains_not_domains = list(set(imap_domains_not_domains))
log.debug(_("Domains in IMAP not in LDAP: %r") % (imap_domains_not_domains), level=8)
if len(imap_domains_not_domains) > 0:
for domain in imap_domains_not_domains:
folders = []
folders.extend(imap.lm('shared/%%@%s' % (domain)))
folders.extend(imap.lm('user/%%@%s' % (domain)))
for folder in folders:
if conf.delete:
if conf.dry_run:
if not folder.split('/')[0] == 'shared':
log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
else:
continue
else:
if not '/'.join(folder.split('/')[0]) == 'shared':
log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
try:
imap.dm(folder)
except Exception, errmsg:
log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
else:
log.info(_("Not automatically deleting shared folder '%s'") % (folder))
else:
log.warning(_("No recipients for '%s' (use --delete to delete)!") % ('/'.join(folder.split('/')[1:])))
示例10: test_004_user_additional_folders_created
def test_004_user_additional_folders_created(self):
time.sleep(2)
imap = IMAP()
imap.connect()
ac_folders = conf.get_raw('kolab', 'autocreate_folders')
exec("ac_folders = %s" % (ac_folders))
folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
self.assertEqual(len(folders), len(ac_folders.keys()))
示例11: test_002_autocreate_folders_created
def test_002_autocreate_folders_created(self):
time.sleep(2)
imap = IMAP()
imap.connect()
exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
print folders
print ac_folders.keys()
self.assertEqual(len(folders), len(ac_folders.keys()))
示例12: check_message_received
def check_message_received(self, subject, from_addr=None, mailbox=None):
if mailbox is None:
mailbox = self.john['mailbox']
imap = IMAP()
imap.connect()
mailbox = imap.folder_quote(mailbox)
imap.set_acl(mailbox, "cyrus-admin", "lrs")
imap.imap.m.select(mailbox)
found = None
retries = 15
while not found and retries > 0:
retries -= 1
typ, data = imap.imap.m.search(None, '(UNDELETED HEADER FROM "%s")' % (from_addr) if from_addr else 'UNDELETED')
for num in data[0].split():
typ, msg = imap.imap.m.fetch(num, '(RFC822)')
message = message_from_string(msg[0][1])
if message['Subject'] == subject:
found = message
break
time.sleep(1)
imap.disconnect()
return found
示例13: check_resource_calendar_event
def check_resource_calendar_event(self, mailbox, uid=None):
imap = IMAP()
imap.connect()
imap.set_acl(mailbox, "cyrus-admin", "lrs")
imap.imap.m.select(imap.folder_quote(mailbox))
found = None
retries = 10
while not found and retries > 0:
retries -= 1
typ, data = imap.imap.m.search(None, '(UNDELETED HEADER SUBJECT "%s")' % (uid) if uid else '(UNDELETED HEADER X-Kolab-Type "application/x-vnd.kolab.event")')
for num in data[0].split():
typ, data = imap.imap.m.fetch(num, '(RFC822)')
event_message = message_from_string(data[0][1])
# return matching UID or first event found
if uid and event_message['subject'] != uid:
continue
found = event_from_message(event_message)
if found:
break
time.sleep(1)
imap.disconnect()
return found
示例14: execute
def execute(*args, **kw):
"""
Undelete mailbox
"""
target_folder = None
undelete_folder = conf.cli_args.pop(0)
if len(conf.cli_args) > 0:
target_folder = conf.cli_args.pop(0)
imap = IMAP()
imap.connect()
imap.undelete_mailfolder(undelete_folder, target_folder)
示例15: test_001_user_rename
def test_001_user_rename(self):
"""
Rename user "Doe, John" to "Sixpack, Joe" and verify the recipient
policy is applied, and the IMAP INBOX folder for the user is
renamed.
"""
auth = Auth()
auth.connect()
recipient = auth.find_recipient('[email protected]')
user_info = wap_client.user_info(recipient)
if not user_info.has_key('mailhost'):
from tests.functional.synchronize import synchronize_once
synchronize_once()
imap = IMAP()
imap.connect()
folders = imap.lm('user/[email protected]')
self.assertEqual(len(folders), 1)
auth = Auth()
auth.connect()
recipient = auth.find_recipient("%(local)[email protected]%(domain)s" % (self.user))
user_info = wap_client.user_info(recipient)
user_info['sn'] = 'Sixpack'
user_info['givenname'] = 'Joe'
user_info['uid'] = 'sixpack'
user_edit = wap_client.user_edit(recipient, user_info)
time.sleep(2)
print imap.lm()
user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
if not user_info['mail'] == '[email protected]':
from tests.functional.synchronize import synchronize_once
synchronize_once()
user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
self.assertEqual(user_info['mail'], '[email protected]')
print imap.lm()
folders = imap.lm('user/[email protected]')
self.assertEqual(len(folders), 0, "INBOX for john.doe still exists")
folders = imap.lm('user/[email protected]')
self.assertEqual(len(folders), 1, "INBOX for joe.sixpack does not exist")