<!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>[13709] CalendarServer/trunk</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/13709">13709</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-07-01 09:39:18 -0700 (Tue, 01 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make sure non-standard timezones are not stripped from calendar data in the db or when returned to clients.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsanonymizepy">CalendarServer/trunk/calendarserver/tools/anonymize.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolsdbinspectpy">CalendarServer/trunk/calendarserver/tools/dbinspect.py</a></li>
<li><a href="#CalendarServertrunkrequirementsdevtxt">CalendarServer/trunk/requirements-dev.txt</a></li>
<li><a href="#CalendarServertrunkrequirementsstabletxt">CalendarServer/trunk/requirements-stable.txt</a></li>
<li><a href="#CalendarServertrunktwistedcaldavicalpy">CalendarServer/trunk/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsanonymizepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/anonymize.py (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/anonymize.py        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/calendarserver/tools/anonymize.py        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -342,7 +342,7 @@
</span><span class="cx">             except KeyError:
</span><span class="cx">                 pass
</span><span class="cx"> 
</span><del>-    return pyobj.getText(includeTimezones=True)
</del><ins>+    return pyobj.getText(includeTimezones=Calendar.ALL_TIMEZONES)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolsdbinspectpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dbinspect.py (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dbinspect.py        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/calendarserver/tools/dbinspect.py        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -772,7 +772,7 @@
</span><span class="cx">             event = yield calendar.calendarObjectWithName(name)
</span><span class="cx">             ical_data = yield event.component()
</span><span class="cx">             ical_data = PerUserDataFilter(uid).filter(ical_data)
</span><del>-            ical_data.stripKnownTimezones()
</del><ins>+            ical_data.stripStandardTimezones()
</ins><span class="cx"> 
</span><span class="cx">             table = tables.Table()
</span><span class="cx">             table.addRow((&quot;Calendar:&quot;, calendar.name(),))
</span><span class="lines">@@ -782,7 +782,7 @@
</span><span class="cx">             table.addRow((&quot;Modified&quot;, event.modified()))
</span><span class="cx">             print(&quot;\n&quot;)
</span><span class="cx">             table.printTable()
</span><del>-            print(ical_data.getTextWithTimezones(includeTimezones=False))
</del><ins>+            print(ical_data.getTextWithoutTimezones())
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunkrequirementsdevtxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-dev.txt (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-dev.txt        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/requirements-dev.txt        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -7,4 +7,4 @@
</span><span class="cx"> mockldap
</span><span class="cx"> q
</span><span class="cx"> --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
</span><del>---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13702#egg=CalDAVTester
</del><ins>+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13708#egg=CalDAVTester
</ins></span></pre></div>
<a id="CalendarServertrunkrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-stable.txt (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-stable.txt        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/requirements-stable.txt        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx"> -e .
</span><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13696#egg=twextpy
</span><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13689#egg=pycalendar
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13707#egg=pycalendar
</ins><span class="cx"> 
</span><span class="cx"> # Specify specific versions of our dependencies so that we're all testing the same config.
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/ical.py (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx"> from twistedcaldav.dateops import timeRangesOverlap, normalizeForIndex, differenceDateTime, \
</span><span class="cx">     normalizeForExpand
</span><span class="cx"> from twistedcaldav.instance import InstanceList, InvalidOverriddenInstanceError
</span><del>-from twistedcaldav.timezones import hasTZ, TimezoneException
</del><ins>+from twistedcaldav.timezones import hasTZ
</ins><span class="cx"> 
</span><span class="cx"> from txdav.caldav.datastore.scheduling.utils import normalizeCUAddr
</span><span class="cx"> 
</span><span class="lines">@@ -602,13 +602,31 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getText(self, format=None):
</span><del>-        return self.getTextWithTimezones(False, format)
</del><ins>+        &quot;&quot;&quot;
+        Return text representation and include non-standard timezones.
+        &quot;&quot;&quot;
+        return self._getTextWithTimezones(includeTimezones=Calendar.NONSTD_TIMEZONES, format=format)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getTextWithTimezones(self, includeTimezones, format=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return text representation and include timezones if the option is on.
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+        includeTimezones = Calendar.ALL_TIMEZONES if includeTimezones else Calendar.NONSTD_TIMEZONES
+        return self._getTextWithTimezones(includeTimezones=includeTimezones, format=format)
+
+
+    def getTextWithoutTimezones(self, format=None):
+        &quot;&quot;&quot;
+        Return text representation without including timezones.
+        &quot;&quot;&quot;
+        return self._getTextWithTimezones(includeTimezones=Calendar.NO_TIMEZONES, format=format)
+
+
+    def _getTextWithTimezones(self, includeTimezones, format=None):
+        &quot;&quot;&quot;
+        Return text representation and include timezones if the option is on.
+        &quot;&quot;&quot;
</ins><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Must be a VCALENDAR: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         result = self._pycalendar.getText(includeTimezones=includeTimezones, format=format)
</span><span class="lines">@@ -1781,28 +1799,13 @@
</span><span class="cx">         return self._resource_type
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def stripKnownTimezones(self):
</del><ins>+    def stripStandardTimezones(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Remove timezones that this server knows about
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+        return self._pycalendar.stripStandardTimezones()
</ins><span class="cx"> 
</span><del>-        changed = False
-        for subcomponent in tuple(self.subcomponents()):
-            if subcomponent.name() == &quot;VTIMEZONE&quot;:
-                tzid = subcomponent.propertyValue(&quot;TZID&quot;)
-                try:
-                    hasTZ(tzid)
-                except TimezoneException:
-                    # tzid not available - do not strip
-                    pass
-                else:
-                    # tzid known - strip component out
-                    self.removeComponent(subcomponent)
-                    changed = True
</del><span class="cx"> 
</span><del>-        return changed
-
-
</del><span class="cx">     def validCalendarData(self, doFix=True, doRaise=True, validateRecurrences=False):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @return: tuple of fixed, unfixed issues
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -1894,7 +1894,7 @@
</span><span class="cx"> 
</span><span class="cx">         # Possible timezone stripping
</span><span class="cx">         if config.EnableTimezonesByReference:
</span><del>-            component.stripKnownTimezones()
</del><ins>+            component.stripStandardTimezones()
</ins><span class="cx"> 
</span><span class="cx">         # Do validation on external requests
</span><span class="cx">         if internal_state == ComponentUpdateState.NORMAL:
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py (13708 => 13709)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2014-07-01 16:39:18 UTC (rev 13709)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> from twistedcaldav.dateops import datetimeMktime
</span><span class="cx"> from twistedcaldav.ical import Component, normalize_iCalStr, diff_iCalStrs
</span><span class="cx"> from twistedcaldav.instance import InvalidOverriddenInstanceError
</span><ins>+from twistedcaldav.timezones import TimezoneCache
</ins><span class="cx"> 
</span><span class="cx"> from txdav.base.propertystore.base import PropertyName
</span><span class="cx"> from txdav.caldav.datastore.query.filter import Filter
</span><span class="lines">@@ -2017,7 +2018,103 @@
</span><span class="cx">         yield self.abort()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def test_standardTimezone(self):
+        &quot;&quot;&quot;
+        Make sure a standard timezone is not stored and not returned in the calendar data when timezones
+        by reference is on.
+        &quot;&quot;&quot;
+        data = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:America/New_York
+X-LIC-LOCATION:America/New_York
+BEGIN:STANDARD
+DTSTART:18000101T000000
+RDATE:18000101T000000
+TZNAME:GMT+1
+TZOFFSETFROM:-0100
+TZOFFSETTO:-0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART;TZID=America/New_York:20130806T000000
+DURATION:PT1H
+DTSTAMP:20051222T210507Z
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
</ins><span class="cx"> 
</span><ins>+        self.patch(config, &quot;EnableTimezonesByReference&quot;, True)
+        TimezoneCache.create()
+        self.addCleanup(TimezoneCache.clear)
+
+        yield self.homeUnderTest(name=&quot;user01&quot;, create=True)
+        calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;user01&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, Component.fromString(data))
+        yield self.commit()
+
+        obj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;user01&quot;)
+        txt = yield obj._text()
+        self.assertTrue(&quot;BEGIN:VTIMEZONE&quot; not in txt)
+        cal = yield obj.componentForUser(&quot;user01&quot;)
+        self.assertEqual(len(tuple(cal.subcomponents())), 1)
+        txt = cal.getTextWithTimezones(False)
+        self.assertTrue(&quot;BEGIN:VTIMEZONE&quot; not in txt)
+
+
+    @inlineCallbacks
+    def test_nonStandardTimezone(self):
+        &quot;&quot;&quot;
+        Make sure a non-standard timezone is stored and returned in the calendar data when timezones
+        by reference is on.
+        &quot;&quot;&quot;
+        data = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:GMTPlusOne
+X-LIC-LOCATION:GMTPlusOne
+BEGIN:STANDARD
+DTSTART:18000101T000000
+RDATE:18000101T000000
+TZNAME:GMT+1
+TZOFFSETFROM:-0100
+TZOFFSETTO:-0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART;TZID=GMTPlusOne:20130806T000000
+DURATION:PT1H
+DTSTAMP:20051222T210507Z
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        self.patch(config, &quot;EnableTimezonesByReference&quot;, True)
+        TimezoneCache.create()
+        self.addCleanup(TimezoneCache.clear)
+
+        yield self.homeUnderTest(name=&quot;user01&quot;, create=True)
+        calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=&quot;user01&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, Component.fromString(data))
+        yield self.commit()
+
+        obj = yield self.calendarObjectUnderTest(name=&quot;data1.ics&quot;, calendar_name=&quot;calendar&quot;, home=&quot;user01&quot;)
+        txt = yield obj._text()
+        self.assertTrue(&quot;TZID:GMTPlusOne&quot; in txt)
+        cal = yield obj.componentForUser(&quot;user01&quot;)
+        self.assertEqual(len(tuple(cal.subcomponents())), 2)
+        txt = cal.getTextWithTimezones(False)
+        self.assertTrue(&quot;BEGIN:VTIMEZONE&quot; in txt)
+
+
+
</ins><span class="cx"> class SchedulingTests(CommonCommonTests, unittest.TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     CalendarObject splitting tests
</span></span></pre>
</div>
</div>

</body>
</html>