本文整理汇总了Python中pykolab.imap.IMAP类的典型用法代码示例。如果您正苦于以下问题:Python IMAP类的具体用法?Python IMAP怎么用?Python IMAP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IMAP类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)))
开发者ID:detrout,项目名称:pykolab,代码行数:27,代码来源:test_002_user_add.py
示例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')
开发者ID:tpokorra,项目名称:pykolab,代码行数:31,代码来源:cmd_delete_message.py
示例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
开发者ID:detrout,项目名称:pykolab,代码行数:34,代码来源:cmd_list_mailboxes.py
示例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)
开发者ID:detrout,项目名称:pykolab,代码行数:7,代码来源:test_002_user_add.py
示例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")
开发者ID:tpokorra,项目名称:pykolab,代码行数:29,代码来源:test_003_two_johns.py
示例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
开发者ID:tpokorra,项目名称:pykolab,代码行数:34,代码来源:cmd_list_domain_mailboxes.py
示例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
开发者ID:tpokorra,项目名称:pykolab,代码行数:33,代码来源:cyrus.py
示例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)
开发者ID:tpokorra,项目名称:pykolab,代码行数:9,代码来源:test_001_user_add.py
示例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:])))
开发者ID:tpokorra,项目名称:pykolab,代码行数:56,代码来源:cmd_sync_mailhost_attrs.py
示例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()))
开发者ID:tpokorra,项目名称:pykolab,代码行数:11,代码来源:test_001_user_sync.py
示例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()))
开发者ID:tpokorra,项目名称:pykolab,代码行数:13,代码来源:test_002_user_add.py
示例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
开发者ID:tpokorra,项目名称:pykolab,代码行数:30,代码来源:test_007_invitationpolicy.py
示例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
开发者ID:tpokorra,项目名称:pykolab,代码行数:31,代码来源:test_005_resource_invitation.py
示例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)
开发者ID:tpokorra,项目名称:pykolab,代码行数:14,代码来源:cmd_undelete_mailbox.py
示例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")
开发者ID:tpokorra,项目名称:pykolab,代码行数:49,代码来源:test_002_user_rename.py
示例16: __init__
def __init__(self, *args, **kw):
# load pykolab conf
conf = pykolab.getConf()
if not hasattr(conf, 'defaults'):
conf.finalize_conf(fatal=False)
self.imap = IMAP()
开发者ID:kolab-groupware,项目名称:bonnie,代码行数:7,代码来源:imapdata.py
示例17: execute
def execute(*args, **kw):
"""
List mailboxes
"""
try:
aci_subject = conf.cli_args.pop(0)
except:
aci_subject = None
imap = IMAP()
imap.connect()
folders = imap.lm()
for folder in folders:
acls = imap.list_acls(folder)
if not aci_subject == None:
if aci_subject in acls.keys():
log.debug(_("Deleting ACL %s for subject %s on folder %s") % (
acls[aci_subject],
aci_subject,
folder
), level=8)
imap.set_acl(folder, aci_subject, '')
#else:
#for _aci_subject in acls.keys():
# connect to auth(!)
# find recipient result_attr=aci_subject
# if no entry, expire acl
开发者ID:tpokorra,项目名称:pykolab,代码行数:33,代码来源:cmd_acl_cleanup.py
示例18: test_002_send_forwarded_email
def test_002_send_forwarded_email(self):
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
smtp = smtplib.SMTP('localhost', 10026)
subject = "%s" % (time.time())
body = "This is a test message"
msg = MIMEMultipart()
msg['From'] = '"Doe, Jane" <[email protected]>'
msg['To'] = '"Doe, John" <[email protected]>'
msg['Subject'] = subject
msg['Date'] = formatdate(localtime=True)
msg.attach(MIMEText(body))
send_to = '[email protected]'
send_from = '[email protected]'
smtp.sendmail(send_from, send_to, msg.as_string())
imap = IMAP()
imap.connect()
imap.set_acl("user/[email protected]", "cyrus-admin", "lrs")
imap.imap.m.select("user/[email protected]")
found = False
max_tries = 20
while not found and max_tries > 0:
max_tries -= 1
typ, data = imap.imap.m.search(None, 'ALL')
for num in data[0].split():
typ, msg = imap.imap.m.fetch(num, '(RFC822)')
_msg = message_from_string(msg[0][1])
if _msg['Subject'] == subject:
found = True
time.sleep(1)
if not found:
raise Exception
开发者ID:tpokorra,项目名称:pykolab,代码行数:45,代码来源:test_001_user_add.py
示例19: IMAPDataHandler
class IMAPDataHandler(object):
"""
Collector handler to provide metadata from IMAP
"""
def __init__(self, *args, **kw):
# load pykolab conf
conf = pykolab.getConf()
if not hasattr(conf, 'defaults'):
conf.finalize_conf(fatal=False)
self.imap = IMAP()
def register(self, callback):
interests = {
'GETMETADATA': {
'callback': self.get_imap_folder_metadata
},
'GETACL': {
'callback': self.get_imap_folder_acl
}
}
callback(interests)
def get_imap_folder_metadata(self, notification):
notification = json.loads(notification)
log.debug("GETMETADATA for %r" % (notification), level=9)
# split the uri parameter into useful parts
uri = parse_imap_uri(notification['uri'])
folder_path = imap_folder_path(uri)
# get metadata using pykolab's imap module
metadata = {}
try:
self.imap.connect()
metadata = self.imap.get_metadata(folder_path)[folder_path]
self.imap.disconnect()
except Exception, e:
log.warning("Failed to get metadata for %r: %r", folder_path, e)
notification['metadata'] = metadata
return json.dumps(notification)
开发者ID:kolab-groupware,项目名称:bonnie,代码行数:45,代码来源:imapdata.py
示例20: execute
def execute(*args, **kw):
"""
Transfer mailbox
"""
if len(conf.cli_args) > 1:
mailfolder = conf.cli_args.pop(0)
target_server = conf.cli_args.pop(0)
if len(conf.cli_args) > 0:
target_partition = conf.cli_args.pop(0)
imap = IMAP()
imap.connect()
mbox_parts = imap.parse_mailfolder(mailfolder)
if mbox_parts['domain'] == None:
domain = conf.get('kolab', 'primary_domain')
user_identifier = mbox_parts['path_parts'][1]
else:
domain = mbox_parts['domain']
user_identifier = "%[email protected]%s" % (mbox_parts['path_parts'][1], mbox_parts['domain'])
auth = Auth(domain=domain)
auth.connect()
user = auth.find_recipient(user_identifier)
source_server = imap.user_mailbox_server(mailfolder)
imap.connect(server=source_server)
imap.imap.xfer(mailfolder, target_server)
if not user == None and not len(user) < 1:
auth.set_entry_attributes(domain, user, {'mailhost': target_server})
开发者ID:tpokorra,项目名称:pykolab,代码行数:35,代码来源:cmd_transfer_mailbox.py
注:本文中的pykolab.imap.IMAP类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论