Permalink
Browse files

Handle missing attachments in IMIP replies by getting email address f…

…or organizer from directory

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk@7782 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information...
1 parent db7ed2a commit 64d32cabb5c36443ff45c5321cbfa8d0f615433e @m0rgen m0rgen committed Jul 13, 2011
Showing with 46 additions and 13 deletions.
  1. +20 −8 twistedcaldav/mail.py
  2. +26 −5 twistedcaldav/test/test_mail.py
View
@@ -71,7 +71,7 @@
from twistedcaldav.util import AuthorizedHTTPGetter
from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
-from calendarserver.tap.util import getRootResource
+from calendarserver.tap.util import getRootResource, directoryFromConfig
__all__ = [
@@ -624,6 +624,7 @@ def __init__(self, dataRoot=None):
dataRoot = config.DataRoot
self.db = MailGatewayTokensDatabase(dataRoot)
self.days = config.Scheduling['iMIP']['InvitationDaysToLive']
+ self.directory = directoryFromConfig(config)
def purge(self):
"""
@@ -714,7 +715,7 @@ def processDSN(self, calBody, msgId, fn):
self.log_warn("Mail gateway processing DSN %s" % (msgId,))
return fn(organizer, attendee, calendar, msgId)
- def processReply(self, msg, fn):
+ def processReply(self, msg, injectFunction, testMode=False):
# extract the token from the To header
name, addr = email.utils.parseaddr(msg['To'])
if addr:
@@ -744,15 +745,25 @@ def processReply(self, msg, fn):
break
else:
# No icalendar attachment
- self.log_error("Mail gateway didn't find an icalendar attachment in message %s" % (msg['Message-ID'],))
+ self.log_warn("Mail gateway didn't find an icalendar attachment in message %s" % (msg['Message-ID'],))
- if not organizer.startswith("mailto:"):
+ toAddr = None
+ fromAddr = attendee[7:]
+
+ if organizer.startswith("mailto:"):
+ toAddr = organizer[7:]
+ elif organizer.startswith("urn:uuid:"):
+ guid = organizer[9:]
+ record = self.directory.recordWithGUID(guid)
+ if record and record.emailAddresses:
+ toAddr = list(record.emailAddresses)[0]
+
+ if toAddr is None:
self.log_error("Don't have an email address for the organizer; ignoring reply.")
return
- # Forward this email to organizer
- toAddr = organizer[7:]
- fromAddr = attendee[7:]
+ if testMode:
+ return (toAddr, fromAddr)
settings = config.Scheduling["iMIP"]["Sending"]
if settings["UseSSL"]:
@@ -775,6 +786,7 @@ def processReply(self, msg, fn):
requireTransportSecurity=settings["UseSSL"],
)
+ self.log_warn("Mail gateway forwarding reply back to organizer")
_reactor.connectTCP(settings["Server"], settings["Port"], factory)
return deferred
@@ -810,7 +822,7 @@ def processReply(self, msg, fn):
# the appropriate ATTENDEE. This will require a new localizable
# email template for the message.
- return fn(organizer, attendee, calendar, msg['Message-ID'])
+ return injectFunction(organizer, attendee, calendar, msg['Message-ID'])
def inbound(self, message, fn=injectMessage):
@@ -24,6 +24,7 @@
import email
from twistedcaldav.mail import MailHandler
from twistedcaldav.mail import MailGatewayTokensDatabase
+from twistedcaldav.directory.directory import DirectoryRecord
import os
import datetime
@@ -195,10 +196,10 @@ def test_processReply(self):
self.assertEquals(result, None)
# Make sure a known token *is* processed
- self.handler.db.createToken("mailto:user01@example.com", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
+ self.handler.db.createToken("urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
organizer, attendee, calendar, msgId = self.handler.processReply(msg,
echo)
- self.assertEquals(organizer, 'mailto:user01@example.com')
+ self.assertEquals(organizer, 'urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66')
self.assertEquals(attendee, 'mailto:xyzzy@example.com')
self.assertEquals(msgId, '<1983F777-BE86-4B98-881E-06D938E60920@example.com>')
@@ -207,20 +208,20 @@ def test_processReplyMissingOrganizer(self):
file(os.path.join(self.dataDir, 'reply_missing_organizer')).read()
)
# stick the token in the database first
- self.handler.db.createToken("mailto:user01@example.com", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
+ self.handler.db.createToken("urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
organizer, attendee, calendar, msgId = self.handler.processReply(msg,
echo)
organizerProp = calendar.mainComponent().getOrganizerProperty()
self.assertTrue(organizerProp is not None)
- self.assertEquals(organizer, "mailto:user01@example.com")
+ self.assertEquals(organizer, "urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66")
def test_processReplyMissingAttendee(self):
msg = email.message_from_string(
file(os.path.join(self.dataDir, 'reply_missing_attendee')).read()
)
# stick the token in the database first
- self.handler.db.createToken("mailto:user01@example.com", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
+ self.handler.db.createToken("urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
organizer, attendee, calendar, msgId = self.handler.processReply(msg,
echo)
@@ -231,6 +232,26 @@ def test_processReplyMissingAttendee(self):
attendeeProp = calendar.mainComponent().getAttendeeProperty([attendee])
self.assertEquals(attendeeProp.parameterValue("SCHEDULE-STATUS"), iTIPRequestStatus.SERVICE_UNAVAILABLE)
+ def test_processReplyMissingAttachment(self):
+
+ # Fake a directory record
+ record = DirectoryRecord(self.handler.directory, "users",
+ "9DC04A70-E6DD-11DF-9492-0800200C9A66", shortNames=("user01",),
+ emailAddresses=("user01@example.com",))
+ record.enabled = True
+ self.handler.directory._tmpRecords["guids"]["9DC04A70-E6DD-11DF-9492-0800200C9A66"] = record
+
+ msg = email.message_from_string(
+ file(os.path.join(self.dataDir, 'reply_missing_attachment')).read()
+ )
+ # stick the token in the database first
+ self.handler.db.createToken("urn:uuid:9DC04A70-E6DD-11DF-9492-0800200C9A66", "mailto:xyzzy@example.com", icaluid="1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C", token="d7cdf68d-8b73-4df1-ad3b-f08002fb285f")
+
+ self.assertEquals(
+ self.handler.processReply(msg, echo, testMode=True),
+ ("user01@example.com", "xyzzy@example.com")
+ )
+
@inlineCallbacks
def test_outbound(self):

0 comments on commit 64d32ca

Please sign in to comment.