Changeset View
Changeset View
Standalone View
Standalone View
pykolab/itip/__init__.py
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | while not conflict and not done: | ||||
# Scroll forward the kolab event recurrence until we're in the prime | # Scroll forward the kolab event recurrence until we're in the prime | ||||
# spot. We choose to start with the Kolab event because that is likely | # spot. We choose to start with the Kolab event because that is likely | ||||
# the older one. | # the older one. | ||||
if _ee < _is: | if _ee < _is: | ||||
while _ee < _is and _es is not None and kolab_event.is_recurring(): | while _ee < _is and _es is not None and kolab_event.is_recurring(): | ||||
log.debug("Attempt to move forward kolab event recurrence from %s closer to %s" % (_ee, _is), level=8) | log.debug("Attempt to move forward kolab event recurrence from %s closer to %s" % (_ee, _is), level=8) | ||||
__es = to_dt(kolab_event.get_next_occurence(_es)) | __es = to_dt(kolab_event.get_next_occurence(_es)) | ||||
if not __es is None: | if not __es is None: | ||||
Lint: PEP8 E714: test for object identity should be 'is not' | |||||
_es = __es | _es = __es | ||||
_ee = to_dt(kolab_event.get_occurence_end_date(_es)) | _ee = to_dt(kolab_event.get_occurence_end_date(_es)) | ||||
else: | else: | ||||
done = True | done = True | ||||
break | break | ||||
# Scroll forward the itip event recurrence until we're in the | # Scroll forward the itip event recurrence until we're in the | ||||
# prime spot, this time with the iTip event. | # prime spot, this time with the iTip event. | ||||
elif _ie < _es: | elif _ie < _es: | ||||
while _ie < _es and _is is not None and itip_event['xml'].is_recurring(): | while _ie < _es and _is is not None and itip_event['xml'].is_recurring(): | ||||
log.debug("Attempt to move forward itip event recurrence from %s closer to %s" % (_ie, _es), level=8) | log.debug("Attempt to move forward itip event recurrence from %s closer to %s" % (_ie, _es), level=8) | ||||
__is = to_dt(itip_event['xml'].get_next_occurence(_is)) | __is = to_dt(itip_event['xml'].get_next_occurence(_is)) | ||||
if not __is is None: | if not __is is None: | ||||
Lint: PEP8 E714 test for object identity should be 'is not' Lint: PEP8 E714: test for object identity should be 'is not' | |||||
_is = __is | _is = __is | ||||
_ie = to_dt(itip_event['xml'].get_occurence_end_date(_is)) | _ie = to_dt(itip_event['xml'].get_occurence_end_date(_is)) | ||||
else: | else: | ||||
done = True | done = True | ||||
break | break | ||||
# Now that we have some events somewhere in the same neighborhood... | # Now that we have some events somewhere in the same neighborhood... | ||||
conflict = check_date_conflict(_es, _ee, _is, _ie) | conflict = check_date_conflict(_es, _ee, _is, _ie) | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | def send_reply(from_address, itip_events, response_text, subject=None): | ||||
""" | """ | ||||
Send the given iCal events as a valid iTip REPLY to the organizer. | Send the given iCal events as a valid iTip REPLY to the organizer. | ||||
""" | """ | ||||
import smtplib | import smtplib | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
smtp = None | smtp = None | ||||
sl = pykolab.logger.StderrToLogger(log) | |||||
smtplib.stderr = sl | |||||
smtp = smtplib.SMTP(timeout=15) | |||||
if conf.debuglevel > 8: | |||||
smtp.set_debuglevel(1) | |||||
if isinstance(itip_events, dict): | if isinstance(itip_events, dict): | ||||
itip_events = [ itip_events ] | itip_events = [ itip_events ] | ||||
for itip_event in itip_events: | for itip_event in itip_events: | ||||
success = False | |||||
attempt = 1 | |||||
while not success and attempt <= 5: | |||||
try: | |||||
attendee = itip_event['xml'].get_attendee_by_email(from_address) | attendee = itip_event['xml'].get_attendee_by_email(from_address) | ||||
participant_status = itip_event['xml'].get_ical_attendee_participant_status(attendee) | participant_status = itip_event['xml'].get_ical_attendee_participant_status( | ||||
attendee | |||||
) | |||||
log.debug(_("Send iTip reply %s for %s %r") % (participant_status, itip_event['xml'].type, itip_event['xml'].uid), level=8) | log.debug( | ||||
_("Send iTip reply %s for %s %r") % ( | |||||
participant_status, | |||||
itip_event['xml'].type, | |||||
itip_event['xml'].uid | |||||
), | |||||
level=8 | |||||
) | |||||
event_summary = itip_event['xml'].get_summary() | event_summary = itip_event['xml'].get_summary() | ||||
message_text = response_text % { 'summary':event_summary, 'status':participant_status_label(participant_status), 'name':attendee.get_name() } | |||||
message_text = response_text % { | |||||
'name': attendee.get_name(), | |||||
'status': participant_status_label(participant_status), | |||||
'summary': event_summary | |||||
} | |||||
if subject is not None: | if subject is not None: | ||||
subject = subject % { 'summary':event_summary, 'status':participant_status_label(participant_status), 'name':attendee.get_name() } | subject = subject % { | ||||
'name': attendee.get_name(), | |||||
'status': participant_status_label(participant_status), | |||||
'summary': event_summary | |||||
} | |||||
try: | try: | ||||
message = itip_event['xml'].to_message_itip(from_address, | message = itip_event['xml'].to_message_itip(from_address, | ||||
method="REPLY", | method="REPLY", | ||||
participant_status=participant_status, | participant_status=participant_status, | ||||
message_text=message_text, | message_text=message_text, | ||||
subject=subject | subject=subject | ||||
) | ) | ||||
except Exception, e: | |||||
log.error(_("Failed to compose iTip reply message: %r: %s") % (e, traceback.format_exc())) | except Exception, errmsg: | ||||
log.error( | |||||
_("Failed to compose iTip reply message: %r: %s") % ( | |||||
errmsg, | |||||
traceback.format_exc() | |||||
) | |||||
) | |||||
return | return | ||||
smtp = smtplib.SMTP("localhost", 10026) # replies go through wallace again | |||||
if conf.debuglevel > 8: | smtp.connect("localhost", 10026) | ||||
smtp.set_debuglevel(True) | |||||
try: | _response = smtp.sendmail(message['From'], message['To'], message.as_string()) | ||||
smtp.sendmail(message['From'], message['To'], message.as_string()) | |||||
except Exception, e: | if len(_response) == 0: | ||||
log.error(_("SMTP sendmail error: %r") % (e)) | log.debug(_("SMTP sendmail OK"), level=8) | ||||
else: | |||||
log.debug(_("SMTP sendmail returned: %r") % (_reponse), level=8) | |||||
smtp.quit() | |||||
if smtp: | success = True | ||||
break | |||||
except smtplib.SMTPServerDisconnected, errmsg: | |||||
log.error("SMTP Server Disconnected Error, %r" % (errmsg)) | |||||
except smtplib.SMTPConnectError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP Connect Error, %r" % (errmsg)) | |||||
except smtplib.SMTPDataError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP Data Error, %r" % (errmsg)) | |||||
except smtplib.SMTPHeloError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP HELO Error, %r" % (errmsg)) | |||||
except smtplib.SMTPRecipientsRefused, errmsg: | |||||
# REJECT, send NDR | |||||
log.error("SMTP Recipient(s) Refused, %r" % (errmsg)) | |||||
except smtplib.SMTPSenderRefused, errmsg: | |||||
# REJECT, send NDR | |||||
log.error("SMTP Sender Refused, %r" % (errmsg)) | |||||
except Exception, errmsg: | |||||
log.exception(_("smtplib - Unknown error occurred: %r") % (errmsg)) | |||||
try: | |||||
smtp.quit() | smtp.quit() | ||||
except Exception, errmsg: | |||||
log.error("smtplib quit() error - %r" % errmsg) | |||||
time.sleep(10) | |||||
attempt += 1 | |||||
def send_request(to_address, itip_events, request_text, subject=None, direct=False): | def send_request(to_address, itip_events, request_text, subject=None, direct=False): | ||||
""" | """ | ||||
Send an iTip REQUEST message from the given iCal events | Send an iTip REQUEST message from the given iCal events | ||||
""" | """ | ||||
import smtplib | import smtplib | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
smtp = None | smtp = None | ||||
sl = pykolab.logger.StderrToLogger(log) | |||||
smtplib.stderr = sl | |||||
smtp = smtplib.SMTP(timeout=15) | |||||
if conf.debuglevel > 8: | |||||
smtp.set_debuglevel(1) | |||||
if isinstance(itip_events, dict): | if isinstance(itip_events, dict): | ||||
itip_events = [ itip_events ] | itip_events = [ itip_events ] | ||||
for itip_event in itip_events: | for itip_event in itip_events: | ||||
success = False | |||||
attempt = 1 | |||||
while not success and attempt <= 5: | |||||
try: | |||||
event_summary = itip_event['xml'].get_summary() | event_summary = itip_event['xml'].get_summary() | ||||
message_text = request_text % { 'summary':event_summary } | message_text = request_text % { | ||||
'summary': event_summary | |||||
} | |||||
if subject is not None: | if subject is not None: | ||||
subject = subject % { 'summary':event_summary } | subject = subject % { | ||||
'summary': event_summary | |||||
} | |||||
try: | try: | ||||
message = itip_event['xml'].to_message_itip(None, | message = itip_event['xml'].to_message_itip( | ||||
None, | |||||
method="REQUEST", | method="REQUEST", | ||||
message_text=message_text, | message_text=message_text, | ||||
subject=subject | subject=subject | ||||
) | ) | ||||
except Exception, e: | |||||
log.error(_("Failed to compose iTip request message: %r") % (e)) | except Exception, errmsg: | ||||
log.error( | |||||
_("Failed to compose iTip request message: %r: %s") % ( | |||||
errmsg, | |||||
traceback.format_exc() | |||||
) | |||||
) | |||||
return | return | ||||
port = 10027 if direct else 10026 | if direct: | ||||
smtp = smtplib.SMTP("localhost", port) | smtp.connect("localhost", 10027) | ||||
else: | |||||
smtp.connect("localhost", 10026) | |||||
_response = smtp.sendmail(message['From'], to_address, message.as_string()) | |||||
if conf.debuglevel > 8: | if len(_response) == 0: | ||||
smtp.set_debuglevel(True) | log.debug(_("SMTP sendmail OK"), level=8) | ||||
else: | |||||
log.debug(_("SMTP sendmail returned: %r") % (_reponse), level=8) | |||||
try: | smtp.quit() | ||||
smtp.sendmail(message['From'], to_address, message.as_string()) | |||||
except Exception, e: | |||||
log.error(_("SMTP sendmail error: %r") % (e)) | |||||
if smtp: | success = True | ||||
break | |||||
except smtplib.SMTPServerDisconnected, errmsg: | |||||
log.error("SMTP Server Disconnected Error, %r" % (errmsg)) | |||||
except smtplib.SMTPConnectError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP Connect Error, %r" % (errmsg)) | |||||
except smtplib.SMTPDataError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP Data Error, %r" % (errmsg)) | |||||
except smtplib.SMTPHeloError, errmsg: | |||||
# DEFER | |||||
log.error("SMTP HELO Error, %r" % (errmsg)) | |||||
except smtplib.SMTPRecipientsRefused, errmsg: | |||||
# REJECT, send NDR | |||||
log.error("SMTP Recipient(s) Refused, %r" % (errmsg)) | |||||
except smtplib.SMTPSenderRefused, errmsg: | |||||
# REJECT, send NDR | |||||
log.error("SMTP Sender Refused, %r" % (errmsg)) | |||||
except Exception, errmsg: | |||||
log.exception(_("smtplib - Unknown error occurred: %r") % (errmsg)) | |||||
try: | |||||
smtp.quit() | smtp.quit() | ||||
except Exception, errmsg: | |||||
log.error("smtplib quit() error - %r" % errmsg) | |||||
time.sleep(10) | |||||
attempt += 1 |
test for object identity should be 'is not'