[CalendarServer-changes] [15193] CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav /datastore/scheduling/imip
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 15 14:05:45 PDT 2015
Revision: 15193
http://trac.calendarserver.org//changeset/15193
Author: sagen at apple.com
Date: 2015-10-15 14:05:45 -0700 (Thu, 15 Oct 2015)
Log Message:
-----------
Scrub embedded mail headers; add PRODID missing from replies
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/inbound.py
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/outbound.py
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_outbound.py
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/inbound.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/inbound.py 2015-10-15 18:53:04 UTC (rev 15192)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/inbound.py 2015-10-15 21:05:45 UTC (rev 15193)
@@ -175,7 +175,29 @@
yield txn.commit()
+def sanitizeCalendar(calendar):
+ """
+ Clean up specific issues seen in the wild from third party IMIP capable
+ servers.
+ @param calendar: the calendar Component to sanitize
+ @type calendar: L{Component}
+ """
+ # Don't let a missing PRODID prevent the reply from being processed
+ if not calendar.hasProperty("PRODID"):
+ calendar.addProperty(
+ Property(
+ "PRODID", "Unknown"
+ )
+ )
+
+ # For METHOD:REPLY we can remove STATUS properties
+ methodProperty = calendar.getProperty("METHOD")
+ if methodProperty is not None:
+ if methodProperty.value() == "REPLY":
+ calendar.removeAllPropertiesWithName("STATUS")
+
+
class MailReceiver(object):
NO_TOKEN = 0
@@ -357,6 +379,8 @@
calendar = Component.fromString(calBody)
event = calendar.mainComponent()
+ sanitizeCalendar(calendar)
+
calendar.removeAllButOneAttendee(attendee)
organizerProperty = calendar.getOrganizerProperty()
if organizerProperty is None:
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/outbound.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/outbound.py 2015-10-15 18:53:04 UTC (rev 15192)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/outbound.py 2015-10-15 21:05:45 UTC (rev 15193)
@@ -22,6 +22,7 @@
from cStringIO import StringIO
import os
+import re
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@@ -48,6 +49,8 @@
log = Logger()
+EMBEDDED_HEADER_CHECK = re.compile(r'\n[^ \t]+:')
+
""" SCHEMA:
create sequence WORKITEM_SEQ;
@@ -484,6 +487,17 @@
returnValue(False)
+ def _scrubHeader(self, value):
+ """
+ Check for what would be considered "embedded headers" and, if present,
+ remove the newlines.
+ """
+ if EMBEDDED_HEADER_CHECK.search(value) is not None:
+ value = value.replace("\n", " ")
+ return value
+
+
+
def generateEmail(self, inviteState, calendar, orgEmail, orgCN,
attendees, fromAddress, replyToAddress, toAddress,
language='en'):
@@ -550,9 +564,9 @@
msg = MIMEMultipart()
msg["From"] = fromAddress
- msg["Subject"] = details['subject']
- msg["Reply-To"] = replyToAddress
- msg["To"] = toAddress
+ msg["Subject"] = self._scrubHeader(details['subject'])
+ msg["Reply-To"] = self._scrubHeader(replyToAddress)
+ msg["To"] = self._scrubHeader(toAddress)
msg["Date"] = rfc822date()
msgId = SMTPSender.betterMessageID()
msg["Message-ID"] = msgId
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py 2015-10-15 18:53:04 UTC (rev 15192)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py 2015-10-15 21:05:45 UTC (rev 15193)
@@ -27,6 +27,7 @@
from txdav.caldav.datastore.scheduling.imip.inbound import injectMessage
from txdav.caldav.datastore.scheduling.imip.inbound import shouldDeleteAllMail
from txdav.caldav.datastore.scheduling.imip.inbound import IMAP4DownloadProtocol
+from txdav.caldav.datastore.scheduling.imip.inbound import sanitizeCalendar
from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
from txdav.caldav.datastore.test.util import buildCalendarStore
@@ -473,6 +474,35 @@
+ def test_sanitizeCalendar(self):
+ """
+ Verify certain inbound third party mistakes are corrected.
+ """
+
+ data = """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20130208T120000Z
+DTSTART:20180601T120000Z
+DTEND:20180601T130000Z
+ORGANIZER:urn:x-uid:user01
+ATTENDEE:mailto:xyzzy at example.com;PARTSTAT=ACCEPTED
+STATUS:ACCEPTED
+END:VEVENT
+END:VCALENDAR
+"""
+ calendar = Component.fromString(data)
+ self.assertFalse(calendar.hasProperty("PRODID"))
+ self.assertTrue(calendar.masterComponent().hasProperty("STATUS"))
+ sanitizeCalendar(calendar)
+ self.assertTrue(calendar.hasProperty("PRODID"))
+ self.assertFalse(calendar.masterComponent().hasProperty("STATUS"))
+
+
+
+
class StubFactory(object):
def __init__(self, actionTaken, deleteAllMail):
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_outbound.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_outbound.py 2015-10-15 18:53:04 UTC (rev 15192)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/scheduling/imip/test/test_outbound.py 2015-10-15 21:05:45 UTC (rev 15193)
@@ -53,7 +53,7 @@
F-B543-B2F29A7EEB0B
ORGANIZER;CN=Th\xe9 Organizer;EMAIL=organizer at example.com:urn:uuid:C3B38B00-
4166-11DD-B22C-A07C87E02F6A
-SUMMARY:t\xe9sting outbound( )
+SUMMARY:testing outbound( )\\nEmbedded: Header
DESCRIPTION:awesome description with "<" and "&"
END:VEVENT
END:VCALENDAR
@@ -387,6 +387,7 @@
u"Th\xe9 Organizer <organizer at example.com>",
"=?utf-8?q?Th=C3=A9_Organizer_=3Corganizer=40example=2Ecom=3E?=",
"attendee at example.com",
+ "Event invitation: testing outbound( ) Embedded: Header",
),
# Update
@@ -421,6 +422,7 @@
u"Th\xe9 Organizer <organizer at example.com>",
"=?utf-8?q?Th=C3=A9_Organizer_=3Corganizer=40example=2Ecom=3E?=",
"attendee at example.com",
+ "=?utf-8?q?Event_update=3A_t=C3=A9sting_outbound=28_=29_*update*?=",
),
# Reply
@@ -452,12 +454,13 @@
"attendee at example.com",
"attendee at example.com",
"organizer at example.com",
+ "=?utf-8?q?Event_reply=3A_t=C3=A9sting_outbound=28_=29_*reply*?=",
),
)
for (inputCalendar, UID, inputOriginator, inputRecipient, inviteState,
outputOrganizerEmail, outputOrganizerName, outputAttendeeList,
- outputFrom, encodedFrom, outputRecipient) in data:
+ outputFrom, encodedFrom, outputRecipient, outputSubject) in data:
txn = self.store.newTransaction()
yield self.sender.outbound(
@@ -477,6 +480,7 @@
self.assertEquals(self.attendees, outputAttendeeList)
self.assertEquals(self.fromAddress, outputFrom)
self.assertEquals(self.toAddress, outputRecipient)
+ self.assertEquals(msg["Subject"], outputSubject)
if UID: # The organizer is local, and server is sending to remote
# attendee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151015/f317db12/attachment.html>
More information about the calendarserver-changes
mailing list