<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14157] CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14157">14157</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-11-12 12:56:24 -0800 (Wed, 12 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix for clients that fail when resources/locations do not have an email address.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorycachingdirectorypy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorydirectorypy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorytesttest_cachedirectorypy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorytesttest_directorypy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavicalpy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavstdconfigpy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavtesttest_icalendarpy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorycachingdirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/cachingdirectory.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -300,6 +300,11 @@
</span><span class="cx">     def recordWithCalendarUserAddress(self, address):
</span><span class="cx">         address = normalizeCUAddr(address)
</span><span class="cx">         record = None
</span><ins>+
+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if address.startswith(&quot;mailto:&quot;) and address.endswith(&quot;@do_not_reply&quot;):
+                address = &quot;urn:uuid:{}&quot;.format(address[7:-13])
+
</ins><span class="cx">         if address.startswith(&quot;mailto:&quot;):
</span><span class="cx">             record = self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_CUA, address)
</span><span class="cx">             return record if record and record.enabledForCalendaring else None
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorydirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/directory.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -225,6 +225,11 @@
</span><span class="cx">     def recordWithCalendarUserAddress(self, address):
</span><span class="cx">         address = normalizeCUAddr(address)
</span><span class="cx">         record = None
</span><ins>+
+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if address.startswith(&quot;mailto:&quot;) and address.endswith(&quot;@do_not_reply&quot;):
+                address = &quot;urn:uuid:{}&quot;.format(address[7:-13])
+
</ins><span class="cx">         if address.startswith(&quot;urn:uuid:&quot;):
</span><span class="cx">             guid = address[9:]
</span><span class="cx">             record = self.recordWithGUID(guid)
</span><span class="lines">@@ -1171,6 +1176,10 @@
</span><span class="cx">         if fullName is None:
</span><span class="cx">             fullName = &quot;&quot;
</span><span class="cx"> 
</span><ins>+        if config.Scheduling.Options.FakeResourceLocationEmail:
+            if recordType in (service.recordType_locations, service.recordType_resources) and not emailAddresses:
+                emailAddresses = set((&quot;%s@do_not_reply&quot; % uid,))
+
</ins><span class="cx">         self.service = service
</span><span class="cx">         self.recordType = recordType
</span><span class="cx">         self.guid = guid
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorytesttest_cachedirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_cachedirectory.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -383,3 +383,20 @@
</span><span class="cx">             self.service.generateMemcacheKey(self.service.INDEX_TYPE_SHORTNAME, &quot;foo&quot;, &quot;users&quot;),
</span><span class="cx">             &quot;dir|v2|20CB1593-DE3F-4422-A7D7-BA9C2099B317|users|shortname|foo&quot;,
</span><span class="cx">         )
</span><ins>+
+
+    def test_fakeemail(self):
+
+        self.patch(config.Scheduling.Options, &quot;FakeResourceLocationEmail&quot;, True)
+        self.dummyRecords()
+
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            &quot;mailto:{}@do_not_reply&quot;.format(self.guidForShortName(&quot;resource02&quot;, recordType=DirectoryService.recordType_resources))
+        ) is not None)
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            &quot;mailto:{}@do_not_reply&quot;.format(self.guidForShortName(&quot;location02&quot;, recordType=DirectoryService.recordType_locations))
+        ) is not None)
+        self.assertTrue(self.service.recordWithCalendarUserAddress(
+            &quot;mailto:bogus@do_not_reply&quot;
+        ) is None)
+        self.assertTrue(self.service.queried)
</ins></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavdirectorytesttest_directorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/directory/test/test_directory.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -1164,7 +1164,38 @@
</span><span class="cx">         self.assertTrue(record is None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_recordWithCalendarUserAddress_fake_email(self):
+        &quot;&quot;&quot;
+        Make sure that recordWithCalendarUserAddress handles fake emails for
+        resources and locations.
+        &quot;&quot;&quot;
</ins><span class="cx"> 
</span><ins>+        self.patch(config.Scheduling.Options, &quot;FakeResourceLocationEmail&quot;, True)
+
+        self.service.createRecord(
+            DirectoryService.recordType_resources,
+            guid=&quot;resource01&quot;,
+            shortNames=(&quot;resource 01&quot;, &quot;Resource 01&quot;),
+            fullName=&quot;Resource 01&quot;,
+            enabledForCalendaring=True,
+        )
+        self.service.createRecord(
+            DirectoryService.recordType_locations,
+            guid=&quot;location02&quot;,
+            shortNames=(&quot;location02&quot;, &quot;Location 02&quot;),
+            fullName=&quot;Location 02&quot;,
+            enabledForCalendaring=True,
+        )
+
+        record = self.service.recordWithCalendarUserAddress(&quot;mailto:resource01@do_not_reply&quot;)
+        self.assertTrue(record is not None)
+        record = self.service.recordWithCalendarUserAddress(&quot;mailto:location02@do_not_reply&quot;)
+        self.assertTrue(record is not None)
+        record = self.service.recordWithCalendarUserAddress(&quot;mailto:location01@do_not_reply&quot;)
+        self.assertTrue(record is None)
+
+
+
</ins><span class="cx"> class DirectoryRecordTests(TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Test L{DirectoryRecord} apis.
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/ical.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -3248,6 +3248,10 @@
</span><span class="cx">                 if oldemail:
</span><span class="cx">                     oldemail = &quot;mailto:%s&quot; % (oldemail,)
</span><span class="cx"> 
</span><ins>+                    if config.Scheduling.Options.FakeResourceLocationEmail:
+                        if oldemail.endswith(&quot;@do_not_reply&quot;):
+                            oldemail = None
+
</ins><span class="cx">                 # Get any CN parameter
</span><span class="cx">                 oldCN = prop.parameterValue(&quot;CN&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -3326,6 +3330,10 @@
</span><span class="cx">                         else:
</span><span class="cx">                             email = None
</span><span class="cx"> 
</span><ins>+                    if config.Scheduling.Options.FakeResourceLocationEmail:
+                        if email.endswith(&quot;@do_not_reply&quot;):
+                            email = &quot;&quot;
+
</ins><span class="cx">                     if email:
</span><span class="cx">                         prop.setParameter(&quot;EMAIL&quot;, email)
</span><span class="cx">                     else:
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -733,6 +733,7 @@
</span><span class="cx">             &quot;AllowResourceWithoutOrganizer&quot;       : True, # Allow resources to have events without an Organizer
</span><span class="cx">             &quot;TrackUnscheduledLocationData&quot;        : True, # Track who the last modifier of an unscheduled location event is
</span><span class="cx">             &quot;TrackUnscheduledResourceData&quot;        : True, # Track who the last modifier of an unscheduled resource event is
</span><ins>+            &quot;FakeResourceLocationEmail&quot;           : False, # Add fake email addresses to work around client bug
</ins><span class="cx">             &quot;LimitFreeBusyAttendees&quot;              : 30, # Maximum number of attendees to request freebusy for
</span><span class="cx">             &quot;AttendeeRefreshBatch&quot;                : 5, # Number of attendees to do batched refreshes: 0 - no batching
</span><span class="cx">             &quot;AttendeeRefreshBatchDelaySeconds&quot;    : 5, # Time after an iTIP REPLY for first batched attendee refresh
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavtesttest_icalendarpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py (14156 => 14157)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py        2014-11-12 18:09:15 UTC (rev 14156)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/test/test_icalendar.py        2014-11-12 20:56:24 UTC (rev 14157)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> from pycalendar.duration import PyCalendarDuration
</span><span class="cx"> from twistedcaldav.dateops import normalizeForExpand
</span><span class="cx"> from pycalendar.value import PyCalendarValue
</span><ins>+from twistedcaldav.config import config
</ins><span class="cx"> 
</span><span class="cx"> class iCalendar (twistedcaldav.test.util.TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -8177,6 +8178,70 @@
</span><span class="cx">         self.assertEquals(prop.parameterValue(&quot;CN&quot;), &quot;{Restricted} Buzz&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_normalizeCalendarUserAddressesWithFakeEmail(self):
+        &quot;&quot;&quot;
+        Ensure fake email addresses are not inserted as EMAIL parameters.
+        &quot;&quot;&quot;
+
+        self.patch(config.Scheduling.Options, &quot;FakeResourceLocationEmail&quot;, True)
+
+        data = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE:/principals/users/foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:mailto:fake1@do_not_reply
+ATTENDEE;CN=Fake 2;EMAIL=fake2@do_not_reply;CUTYPE=ROOM:mailto:fake2@do_not_reply
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        result = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE;CN=Foo;EMAIL=foo@example.com:urn:uuid:foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:urn:uuid:fake1
+ATTENDEE;CN=Fake 2;CUTYPE=ROOM:urn:uuid:fake2
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        component = Component.fromString(data)
+
+
+        def lookupFunction(cuaddr, ignored1, ignored2):
+            return {
+                &quot;/principals/users/foo&quot; : (
+                    &quot;Foo&quot;,
+                    &quot;foo&quot;,
+                    (&quot;urn:uuid:foo&quot;, &quot;mailto:foo@example.com&quot;)
+                ),
+                &quot;mailto:fake1@do_not_reply&quot; : (
+                    &quot;Fake 1&quot;,
+                    &quot;fake1&quot;,
+                    (&quot;urn:uuid:fake1&quot;, &quot;mailto:fake1@do_not_reply&quot;)
+                ),
+                &quot;mailto:fake2@do_not_reply&quot; : (
+                    &quot;Fake 2&quot;,
+                    &quot;fake2&quot;,
+                    (&quot;urn:uuid:fake2&quot;, &quot;mailto:fake2@do_not_reply&quot;)
+                ),
+            }[cuaddr]
+
+        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
+
+        self.assertEqual(normalize_iCalStr(component), normalize_iCalStr(result))
+
+
</ins><span class="cx">     def test_serializationCaching(self):
</span><span class="cx"> 
</span><span class="cx">         data = &quot;&quot;&quot;BEGIN:VCALENDAR
</span></span></pre>
</div>
</div>

</body>
</html>