[CalendarServer-changes] [14607] CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 20 15:43:16 PDT 2015
Revision: 14607
http://trac.calendarserver.org//changeset/14607
Author: sagen at apple.com
Date: 2015-03-20 15:43:16 -0700 (Fri, 20 Mar 2015)
Log Message:
-----------
Peek at incoming IMIPs, and if we don't recognize the token, leave the message unseen so another pod can pick it up. If an unrecognized-token email is older than 72 hours, delete it instead.
Modified Paths:
--------------
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py
Added Paths:
-----------
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_future
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_past
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py 2015-03-20 21:01:07 UTC (rev 14606)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py 2015-03-20 22:43:16 UTC (rev 14607)
@@ -38,6 +38,8 @@
from txdav.common.datastore.sql_tables import schema
import datetime
+import dateutil.parser
+import dateutil.tz
import email.utils
@@ -191,12 +193,13 @@
NO_TOKEN = 0
UNKNOWN_TOKEN = 1
- MALFORMED_TO_ADDRESS = 2
- NO_ORGANIZER_ADDRESS = 3
- REPLY_FORWARDED_TO_ORGANIZER = 4
- INJECTION_SUBMITTED = 5
- INCOMPLETE_DSN = 6
- UNKNOWN_FAILURE = 7
+ UNKNOWN_TOKEN_OLD = 2
+ MALFORMED_TO_ADDRESS = 3
+ NO_ORGANIZER_ADDRESS = 4
+ REPLY_FORWARDED_TO_ORGANIZER = 5
+ INJECTION_SUBMITTED = 6
+ INCOMPLETE_DSN = 7
+ UNKNOWN_FAILURE = 8
def __init__(self, store, directory):
self.store = store
@@ -326,10 +329,26 @@
record = records[0]
except:
# This isn't a token we recognize
- log.error(
+ log.info(
"Mail gateway found a token (%s) but didn't "
"recognize it in message %s"
% (token, msg['Message-ID']))
+ # Any email with an unknown token which was sent over 72 hours ago
+ # is deleted. If we can't parse the date we leave it in the inbox.
+ dateString = msg.get("Date")
+ if dateString is not None:
+ try:
+ dateSent = dateutil.parser.parse(dateString)
+ except Exception, e:
+ log.info(
+ "Could not parse date in IMIP email '{}' ({})".format(
+ dateString, e
+ )
+ )
+ returnValue(self.UNKNOWN_TOKEN)
+ now = datetime.datetime.now(dateutil.tz.tzutc())
+ if dateSent < now - datetime.timedelta(hours=72):
+ returnValue(self.UNKNOWN_TOKEN_OLD)
returnValue(self.UNKNOWN_TOKEN)
for part in msg.walk():
@@ -437,6 +456,7 @@
NO_TOKEN - there was no token in the To address
UNKNOWN_TOKEN - there was an unknown token in the To address
+ UNKNOWN_TOKEN_OLD - there was an unknown token and it's an old email
MALFORMED_TO_ADDRESS - we could not parse the To address at all
NO_ORGANIZER_ADDRESS - no ics attachment and no email to forward to
REPLY_FORWARDED_TO_ORGANIZER - no ics attachment, but reply forwarded
@@ -662,9 +682,8 @@
self.cbGotMessage, messageListToFetch).addErrback(
self.ebLogError)
else:
- self.log.debug("Seeing if anything new has arrived")
- # Go back and see if any more messages have come in
- self.expunge().addCallback(self.cbInboxSelected)
+ # We're done for this polling interval
+ self.expunge()
@inlineCallbacks
@@ -684,13 +703,30 @@
# Delete all mail we see
yield self.cbFlagDeleted(messageList)
else:
- # Delete only mail we've processed; the rest are left flagged Seen
+ # Delete only mail we've processed; the rest are left flagged \Seen
if actionTaken == MailReceiver.INJECTION_SUBMITTED:
yield self.cbFlagDeleted(messageList)
+ elif actionTaken == MailReceiver.UNKNOWN_TOKEN:
+ # It's not a token we recognize (probably meant for another pod)
+ # so remove the \Seen flag
+ yield self.cbFlagUnseen(messageList)
+ elif actionTaken == MailReceiver.UNKNOWN_TOKEN_OLD:
+ # It's not a token we recognize, but it's old, so delete it
+ yield self.cbFlagDeleted(messageList)
else:
self.fetchNextMessage()
+ def cbFlagUnseen(self, messageList):
+ self.removeFlags(
+ messageList, ("\\Seen",), uid=True
+ ).addCallback(self.cbMessageUnseen, messageList)
+
+ def cbMessageUnseen(self, results, messageList):
+ self.log.debug("Removed \\Seen flag from message")
+ self.fetchNextMessage()
+
+
def cbFlagDeleted(self, messageList):
self.addFlags(
messageList, ("\\Deleted",), uid=True
Added: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_future
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_future (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_future 2015-03-20 22:43:16 UTC (rev 14607)
@@ -0,0 +1,92 @@
+Return-path: <xyzzy at example.com>
+Received: from hemlock.example.com ([17.128.115.180])
+ by mail4.example.com (Sun Java(tm) System Messaging Server 6.3-6.03 (built Mar
+ 14 2008; 32bit)) with ESMTP id <0K5I00I8I8G50QC0 at mail4.example.com> for
+ ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com; Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Original-recipient:
+ rfc822;ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com
+Received: from relay14.example.com ([17.128.113.52])
+ by hemlock.example.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28
+ 2007)) with ESMTP id <0K5I004UB8G5UR90 at hemlock.example.com> for
+ ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com
+ (ORCPT ical-living-on+2Bd7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com); Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Received: from relay14.example.com (unknown [127.0.0.1])
+ by relay14.example.com (Symantec Mail Security) with ESMTP id 6A5EF28087 for
+ <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>; Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Received: from [17.83.208.154] (unknown [17.83.208.154])
+ (using TLSv1 with cipher AES128-SHA (128/128 bits))
+ (No client certificate requested) by relay14.example.com (example SCV relay)
+ with ESMTP id CAEE22808B for
+ <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>; Tue,
+ 12 Aug 2008 13:19:16 -0700 (PDT)
+Date: Tue, 12 Aug 2100 13:19:14 -0700
+From: plugh xyzzy <xyzzy at example.com>
+Subject: Event accepted: New Event
+To: User 01 <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>
+Message-id: <1983F777-BE86-4B98-881E-06D938E60920 at example.com>
+MIME-version: 1.0 (example Message framework v928.1)
+X-Mailer: example Mail (2.928.1)
+Content-type: multipart/alternative; boundary=example-Mail-1--253014167
+X-Mail-Calendar-Part: Yes
+X-Brightmail-Tracker: AAAAAA==
+
+
+--example-Mail-1--253014167
+Content-Type: text/plain;
+ charset=US-ASCII;
+ format=flowed;
+ delsp=yes
+Content-Transfer-Encoding: 7bit
+
+plugh xyzzy has accepted your iCal event invitation to the event: New
+Event, scheduled for August 12, 2008 at 10:00 AM (US/Pacific).
+--example-Mail-1--253014167
+Content-Type: multipart/mixed;
+ boundary=example-Mail-2--253014167
+
+
+--example-Mail-2--253014167
+Content-Type: text/html;
+ charset=US-ASCII
+Content-Transfer-Encoding: 7bit
+
+<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">plugh xyzzy has accepted your iCal event invitation to the event: New Event, scheduled for August 12, 2008 at 10:00 AM (US/Pacific).</font></div></div></body></html>
+--example-Mail-2--253014167
+Content-Disposition: attachment;
+ filename=iCal-20080812-131911.ics
+Content-Type: text/calendar;
+ x-unix-mode=0644;
+ name="iCal-20080812-131911.ics"
+Content-Transfer-Encoding: quoted-printable
+
+BEGIN:VCALENDAR=0D=0APRODID:-//example=20Inc.//iCal=203.0//EN=0D=0A=
+CALSCALE:GREGORIAN=0D=0AVERSION:2.0=0D=0AMETHOD:REPLY=0D=0A=
+BEGIN:VTIMEZONE=0D=0ATZID:US/Pacific=0D=0ABEGIN:DAYLIGHT=0D=0A=
+TZOFFSETFROM:-0800=0D=0ATZOFFSETTO:-0700=0D=0ADTSTART:20070311T020000=0D=0A=
+RRULE:FREQ=3DYEARLY;BYMONTH=3D3;BYDAY=3D2SU=0D=0ATZNAME:PDT=0D=0A=
+END:DAYLIGHT=0D=0ABEGIN:STANDARD=0D=0ATZOFFSETFROM:-0700=0D=0A=
+TZOFFSETTO:-0800=0D=0ADTSTART:20071104T020000=0D=0A=
+RRULE:FREQ=3DYEARLY;BYMONTH=3D11;BYDAY=3D1SU=0D=0ATZNAME:PST=0D=0A=
+END:STANDARD=0D=0AEND:VTIMEZONE=0D=0ABEGIN:VEVENT=0D=0ASEQUENCE:7=0D=0A=
+DTSTART;TZID=3DUS/Pacific:20080812T100000=0D=0A=
+UID:1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C=0D=0AORGANIZER;CN=3D"User=20=
+01":mailto:ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08=0D=0A=20=
+002fb285f at example.com=0D=0ADTSTAMP:20080812T201911Z=0D=0ASUMMARY:New=20=
+Event=0D=0A=
+ATTENDEE;CN=3D"xyzzy at example.com";CUTYPE=3DINDIVIDUAL;PARTSTAT=3DACCEPTED;RO=
+LE=3DR=0D=0A=20EQ-PARTICIPANT:mailto:xyzzy at example.com=0D=0A=
+CREATED:20080812T201906Z=0D=0ADTEND;TZID=3DUS/Pacific:20080812T110000=0D=0A=
+END:VEVENT=0D=0AEND:VCALENDAR=0D=0A=
+
+--example-Mail-2--253014167
+Content-Type: text/html;
+ charset=US-ASCII
+Content-Transfer-Encoding: 7bit
+
+<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "></div></div></body></html>
+--example-Mail-2--253014167--
+
+--example-Mail-1--253014167--
Added: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_past
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_past (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/data/good_reply_past 2015-03-20 22:43:16 UTC (rev 14607)
@@ -0,0 +1,92 @@
+Return-path: <xyzzy at example.com>
+Received: from hemlock.example.com ([17.128.115.180])
+ by mail4.example.com (Sun Java(tm) System Messaging Server 6.3-6.03 (built Mar
+ 14 2008; 32bit)) with ESMTP id <0K5I00I8I8G50QC0 at mail4.example.com> for
+ ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com; Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Original-recipient:
+ rfc822;ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com
+Received: from relay14.example.com ([17.128.113.52])
+ by hemlock.example.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28
+ 2007)) with ESMTP id <0K5I004UB8G5UR90 at hemlock.example.com> for
+ ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com
+ (ORCPT ical-living-on+2Bd7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com); Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Received: from relay14.example.com (unknown [127.0.0.1])
+ by relay14.example.com (Symantec Mail Security) with ESMTP id 6A5EF28087 for
+ <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>; Tue,
+ 12 Aug 2008 13:19:17 -0700 (PDT)
+Received: from [17.83.208.154] (unknown [17.83.208.154])
+ (using TLSv1 with cipher AES128-SHA (128/128 bits))
+ (No client certificate requested) by relay14.example.com (example SCV relay)
+ with ESMTP id CAEE22808B for
+ <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>; Tue,
+ 12 Aug 2008 13:19:16 -0700 (PDT)
+Date: Tue, 12 Aug 2008 13:19:14 -0700
+From: plugh xyzzy <xyzzy at example.com>
+Subject: Event accepted: New Event
+To: User 01 <ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08002fb285f at example.com>
+Message-id: <1983F777-BE86-4B98-881E-06D938E60920 at example.com>
+MIME-version: 1.0 (example Message framework v928.1)
+X-Mailer: example Mail (2.928.1)
+Content-type: multipart/alternative; boundary=example-Mail-1--253014167
+X-Mail-Calendar-Part: Yes
+X-Brightmail-Tracker: AAAAAA==
+
+
+--example-Mail-1--253014167
+Content-Type: text/plain;
+ charset=US-ASCII;
+ format=flowed;
+ delsp=yes
+Content-Transfer-Encoding: 7bit
+
+plugh xyzzy has accepted your iCal event invitation to the event: New
+Event, scheduled for August 12, 2008 at 10:00 AM (US/Pacific).
+--example-Mail-1--253014167
+Content-Type: multipart/mixed;
+ boundary=example-Mail-2--253014167
+
+
+--example-Mail-2--253014167
+Content-Type: text/html;
+ charset=US-ASCII
+Content-Transfer-Encoding: 7bit
+
+<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: 12.0px Helvetica">plugh xyzzy has accepted your iCal event invitation to the event: New Event, scheduled for August 12, 2008 at 10:00 AM (US/Pacific).</font></div></div></body></html>
+--example-Mail-2--253014167
+Content-Disposition: attachment;
+ filename=iCal-20080812-131911.ics
+Content-Type: text/calendar;
+ x-unix-mode=0644;
+ name="iCal-20080812-131911.ics"
+Content-Transfer-Encoding: quoted-printable
+
+BEGIN:VCALENDAR=0D=0APRODID:-//example=20Inc.//iCal=203.0//EN=0D=0A=
+CALSCALE:GREGORIAN=0D=0AVERSION:2.0=0D=0AMETHOD:REPLY=0D=0A=
+BEGIN:VTIMEZONE=0D=0ATZID:US/Pacific=0D=0ABEGIN:DAYLIGHT=0D=0A=
+TZOFFSETFROM:-0800=0D=0ATZOFFSETTO:-0700=0D=0ADTSTART:20070311T020000=0D=0A=
+RRULE:FREQ=3DYEARLY;BYMONTH=3D3;BYDAY=3D2SU=0D=0ATZNAME:PDT=0D=0A=
+END:DAYLIGHT=0D=0ABEGIN:STANDARD=0D=0ATZOFFSETFROM:-0700=0D=0A=
+TZOFFSETTO:-0800=0D=0ADTSTART:20071104T020000=0D=0A=
+RRULE:FREQ=3DYEARLY;BYMONTH=3D11;BYDAY=3D1SU=0D=0ATZNAME:PST=0D=0A=
+END:STANDARD=0D=0AEND:VTIMEZONE=0D=0ABEGIN:VEVENT=0D=0ASEQUENCE:7=0D=0A=
+DTSTART;TZID=3DUS/Pacific:20080812T100000=0D=0A=
+UID:1E71F9C8-AEDA-48EB-98D0-76E898F6BB5C=0D=0AORGANIZER;CN=3D"User=20=
+01":mailto:ical-living-on+d7cdf68d-8b73-4df1-ad3b-f08=0D=0A=20=
+002fb285f at example.com=0D=0ADTSTAMP:20080812T201911Z=0D=0ASUMMARY:New=20=
+Event=0D=0A=
+ATTENDEE;CN=3D"xyzzy at example.com";CUTYPE=3DINDIVIDUAL;PARTSTAT=3DACCEPTED;RO=
+LE=3DR=0D=0A=20EQ-PARTICIPANT:mailto:xyzzy at example.com=0D=0A=
+CREATED:20080812T201906Z=0D=0ADTEND;TZID=3DUS/Pacific:20080812T110000=0D=0A=
+END:VEVENT=0D=0AEND:VCALENDAR=0D=0A=
+
+--example-Mail-2--253014167
+Content-Type: text/html;
+ charset=US-ASCII
+Content-Transfer-Encoding: 7bit
+
+<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "></div></div></body></html>
+--example-Mail-2--253014167--
+
+--example-Mail-1--253014167--
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py 2015-03-20 21:01:07 UTC (rev 14606)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_inbound.py 2015-03-20 22:43:16 UTC (rev 14607)
@@ -190,9 +190,13 @@
@inlineCallbacks
def test_processReply(self):
- msg = email.message_from_string(self.dataFile('good_reply'))
+ # Make sure an unknown token in an older email is deleted
+ msg = email.message_from_string(self.dataFile('good_reply_past'))
+ result = (yield self.receiver.processReply(msg))
+ self.assertEquals(result, MailReceiver.UNKNOWN_TOKEN_OLD)
# Make sure an unknown token is not processed
+ msg = email.message_from_string(self.dataFile('good_reply_future'))
result = (yield self.receiver.processReply(msg))
self.assertEquals(result, MailReceiver.UNKNOWN_TOKEN)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150320/27287e5d/attachment-0001.html>
More information about the calendarserver-changes
mailing list