本文整理汇总了Python中pykolab.imap.IMAP.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python IMAP.disconnect方法的具体用法?Python IMAP.disconnect怎么用?Python IMAP.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykolab.imap.IMAP
的用法示例。
在下文中一共展示了IMAP.disconnect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_resource_calendar_event
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
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
示例2: check_message_received
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
def check_message_received(self, subject, from_addr=None, mailbox=None):
if mailbox is None:
mailbox = self.john['mailbox']
imap = IMAP()
imap.connect()
imap.set_acl(mailbox, "cyrus-admin", "lrs")
imap.imap.m.select(mailbox)
found = None
retries = 10
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
示例3: purge_mailbox
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
def purge_mailbox(self, mailbox):
imap = IMAP()
imap.connect()
imap.set_acl(mailbox, "cyrus-admin", "lrwcdest")
imap.imap.m.select(imap.folder_quote(mailbox))
typ, data = imap.imap.m.search(None, 'ALL')
for num in data[0].split():
imap.imap.m.store(num, '+FLAGS', '\\Deleted')
imap.imap.m.expunge()
imap.disconnect()
示例4: IMAPDataHandler
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
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)
示例5: _synchronize
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
def _synchronize(*args, **kw):
log.info(_("Worker process %s handling %s") % (multiprocessing.current_process().name, kw['dn']))
entry = utils.normalize(entry)
if not entry.has_key('mail'):
return
if not 'kolabinetorgperson' in entry['objectclass']:
return
imap = IMAP()
imap.connect()
if not imap.user_mailbox_exists(entry['mail']):
if entry.has_key('mailhost'):
server = entry['mailhost']
else:
server = None
imap.user_mailbox_create(entry['mail'], server=server)
imap.disconnect()
示例6: heartbeat
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
def heartbeat(lastrun):
global imap
# run archival job every hour only
now = int(time.time())
if lastrun == 0 or now - heartbeat._lastrun < 3600:
return
log.debug(_("module_resources.heartbeat(%d)") % (heartbeat._lastrun), level=8)
# get a list of resource records from LDAP
auth = Auth()
auth.connect()
resource_dns = auth.find_resource('*')
# filter by resource_base_dn
resource_base_dn = conf.get('ldap', 'resource_base_dn', None)
if resource_base_dn is not None:
resource_dns = [dn for dn in resource_dns if resource_base_dn in dn]
if len(resource_dns) > 0:
imap = IMAP()
imap.connect()
for resource_dn in resource_dns:
resource_attrs = auth.get_entry_attributes(None, resource_dn, ['kolabtargetfolder'])
if resource_attrs.has_key('kolabtargetfolder'):
try:
expunge_resource_calendar(resource_attrs['kolabtargetfolder'])
except Exception, e:
log.error(_("Expunge resource calendar for %s (%s) failed: %r") % (
resource_dn, resource_attrs['kolabtargetfolder'], e
))
imap.disconnect()
示例7: execute
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
#.........这里部分代码省略.........
original_resource = resources[resources[resource]['memberof']]
_target_resource = resources[original_resource['uniquemember'][random.randint(0,(len(original_resource['uniquemember'])-1))]]
# unset all
for _r in original_resource['uniquemember']:
del resources[_r]
if original_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]:
itip_event['xml'].set_attendee_participant_status(
[a for a in itip_event['xml'].get_attendees() if a.get_email() == original_resource['mail']][0],
"DECLINED"
)
send_response(original_resource['mail'], itip_events)
# TODO: Accept the message to the other attendees
else:
# No conflicts, go accept
for itip_event in itip_events:
if resources[resource]['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]:
itip_event['xml'].set_attendee_participant_status(
[a for a in itip_event['xml'].get_attendees() if a.get_email() == resources[resource]['mail']][0],
"ACCEPTED"
)
log.debug(
_("Adding event to %r") % (
resources[resource]['kolabtargetfolder']
),
level=9
)
imap.imap.m.setacl(resources[resource]['kolabtargetfolder'], "cyrus-admin", "lrswipkxtecda")
imap.imap.m.append(
resources[resource]['kolabtargetfolder'],
None,
None,
itip_event['xml'].to_message().as_string()
)
send_response(resources[resource]['mail'], itip_event)
else:
# This must have been a resource collection originally.
# We have inserted the reference to the original resource
# record in 'memberof'.
if resources[resource].has_key('memberof'):
original_resource = resources[resources[resource]['memberof']]
# Randomly selects a target resource from the resource
# collection.
_target_resource = resources[original_resource['uniquemember'][random.randint(0,(len(original_resource['uniquemember'])-1))]]
# Remove all resources from the collection.
for _r in original_resource['uniquemember']:
del resources[_r]
if original_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]:
#
# Delegate:
#
# - delegator: the original resource collection
# - delegatee: the target resource
#
itip_event['xml'].delegate(
original_resource['mail'],
_target_resource['mail']
)
itip_event['xml'].set_attendee_participant_status(
[a for a in itip_event['xml'].get_attendees() if a.get_email() == _target_resource['mail']][0],
"ACCEPTED"
)
log.debug(
_("Adding event to %r") % (
_target_resource['kolabtargetfolder']
),
level=9
)
# TODO: The Cyrus IMAP (or Dovecot) Administrator login
# name comes from configuration.
imap.imap.m.setacl(_target_resource['kolabtargetfolder'], "cyrus-admin", "lrswipkxtecda")
imap.imap.m.append(
_target_resource['kolabtargetfolder'],
None,
None,
itip_event['xml'].to_message().as_string()
)
send_response(original_resource['mail'], itip_event)
# Disconnect IMAP or we lock the mailbox almost constantly
imap.disconnect()
del imap
os.unlink(filepath)
示例8: setup_class
# 需要导入模块: from pykolab.imap import IMAP [as 别名]
# 或者: from pykolab.imap.IMAP import disconnect [as 别名]
def setup_class(self, *args, **kw):
# set language to default
pykolab.translate.setUserLanguage(conf.get('kolab','default_locale'))
self.itip_reply_subject = _('"%(summary)s" has been %(status)s')
from tests.functional.purge_users import purge_users
purge_users()
self.john = {
'displayname': 'John Doe',
'mail': '[email protected]',
'dn': 'uid=doe,ou=People,dc=example,dc=org',
'preferredlanguage': 'en_US',
'mailbox': 'user/[email protected]',
'kolabcalendarfolder': 'user/john.doe/[email protected]',
'kolabtasksfolder': 'user/john.doe/[email protected]',
'kolabinvitationpolicy': ['ACT_UPDATE_AND_NOTIFY','ACT_MANUAL']
}
self.jane = {
'displayname': 'Jane Manager',
'mail': '[email protected]',
'dn': 'uid=manager,ou=People,dc=example,dc=org',
'preferredlanguage': 'en_US',
'mailbox': 'user/[email protected]',
'kolabcalendarfolder': 'user/jane.manager/[email protected]',
'kolabtasksfolder': 'user/jane.manager/[email protected]',
'kolabconfidentialcalendar': 'user/jane.manager/Calendar/[email protected]',
'kolabinvitationpolicy': ['ACT_ACCEPT_IF_NO_CONFLICT','ACT_REJECT_IF_CONFLICT','TASK_ACCEPT','ACT_UPDATE']
}
self.jack = {
'displayname': 'Jack Tentative',
'mail': '[email protected]',
'dn': 'uid=tentative,ou=People,dc=example,dc=org',
'preferredlanguage': 'en_US',
'mailbox': 'user/[email protected]',
'kolabcalendarfolder': 'user/jack.tentative/[email protected]',
'kolabtasksfolder': 'user/jack.tentative/[email protected]',
'kolabinvitationpolicy': ['ACT_TENTATIVE_IF_NO_CONFLICT','ALL_SAVE_TO_FOLDER','ACT_UPDATE']
}
self.mark = {
'displayname': 'Mark German',
'mail': '[email protected]',
'dn': 'uid=german,ou=People,dc=example,dc=org',
'preferredlanguage': 'de_DE',
'mailbox': 'user/[email protected]',
'kolabcalendarfolder': 'user/mark.german/[email protected]',
'kolabtasksfolder': 'user/mark.german/[email protected]',
'kolabinvitationpolicy': ['ACT_ACCEPT','ACT_UPDATE_AND_NOTIFY']
}
self.external = {
'displayname': 'Bob External',
'mail': '[email protected]'
}
from tests.functional.user_add import user_add
user_add("John", "Doe", kolabinvitationpolicy=self.john['kolabinvitationpolicy'], preferredlanguage=self.john['preferredlanguage'])
user_add("Jane", "Manager", kolabinvitationpolicy=self.jane['kolabinvitationpolicy'], preferredlanguage=self.jane['preferredlanguage'])
user_add("Jack", "Tentative", kolabinvitationpolicy=self.jack['kolabinvitationpolicy'], preferredlanguage=self.jack['preferredlanguage'])
user_add("Mark", "German", kolabinvitationpolicy=self.mark['kolabinvitationpolicy'], preferredlanguage=self.mark['preferredlanguage'])
time.sleep(1)
from tests.functional.synchronize import synchronize_once
synchronize_once()
# create confidential calendar folder for jane
imap = IMAP()
imap.connect(domain='example.org') # sets self.domain
imap.user_mailbox_create_additional_folders(self.jane['mail'], {
'Calendar/Confidential': {
'annotations': {
'/shared/vendor/kolab/folder-type': "event",
'/private/vendor/kolab/folder-type': "event.confidential"
}
}
})
imap.disconnect()