conversion/commonconversion.cpp conversion/timezoneconverter.cpp tests/testfiles tests/timezonetest.cpp tests/timezonetest.h

Christian Mollekopf mollekopf at kolabsys.com
Fri Mar 1 09:52:39 CET 2013


 conversion/commonconversion.cpp                 |    9 +-
 conversion/timezoneconverter.cpp                |    4 +
 tests/testfiles/timezone/windowsTimezone.ics    |   16 ++++
 tests/testfiles/timezone/windowsTimezoneV3.mime |   86 ++++++++++++++++++++++++
 tests/timezonetest.cpp                          |   45 ++++++++++++
 tests/timezonetest.h                            |    1 
 6 files changed, 159 insertions(+), 2 deletions(-)

New commits:
commit 231229b7bb6747eb8e4e419bdbc11bac8523d17e
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Thu Feb 28 21:31:51 2013 +0100

    Normalize timezones also when reading mime messages.

diff --git a/conversion/commonconversion.cpp b/conversion/commonconversion.cpp
index 489a1d6..87b35c2 100644
--- a/conversion/commonconversion.cpp
+++ b/conversion/commonconversion.cpp
@@ -36,7 +36,11 @@ KDateTime::Spec getTimeSpec(bool isUtc, const std::string& timezone)
         return  KDateTime::Spec(KDateTime::ClockTime);
     }
     //Timezone
-    KTimeZone tz = KSystemTimeZones::zone(QString::fromStdString(timezone)); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html
+
+    //Convert non-olson timezones if necessary
+    const QString normalizedTz = TimezoneConverter::normalizeTimezone(QString::fromStdString(timezone));
+    Debug() << "normalized " << normalizedTz;
+    KTimeZone tz = KSystemTimeZones::zone(normalizedTz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html
     if (!tz.isValid()) {
         Error() << "timezone not found" << QString::fromStdString(timezone);
         if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) {
@@ -161,4 +165,5 @@ std::string fromMailto(const QUrl &mailtoUri, std::string &name)
 }
 
     }
-}
\ No newline at end of file
+}
+
diff --git a/conversion/timezoneconverter.cpp b/conversion/timezoneconverter.cpp
index 73e9ab0..acd81d1 100644
--- a/conversion/timezoneconverter.cpp
+++ b/conversion/timezoneconverter.cpp
@@ -21,12 +21,15 @@
 #include <kdebug.h>
 #include <QRegExp>
 #include <QStringList>
+#include "kolabformat/errorhandler.h"
 
 QString TimezoneConverter::normalizeTimezone(const QString& tz)
 {
     KTimeZone timezone = KSystemTimeZones::zone(tz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html
     if (timezone.isValid()) {
         return tz;
+    } else if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) {
+        Error() << "ktimezoned is not available and required for timezone interpretation";
     }
     //We're dealing with an invalid or unknown timezone, try to parse it
     QString guessedTimezone = fromCityName(tz);
@@ -36,6 +39,7 @@ QString TimezoneConverter::normalizeTimezone(const QString& tz)
     if (guessedTimezone.isEmpty()) {
         guessedTimezone = fromGMTOffsetTimezone(tz);
     }
+    Debug() << "Guessed timezone and found: " << guessedTimezone;
     return guessedTimezone;
 }
 
diff --git a/tests/testfiles/timezone/windowsTimezone.ics b/tests/testfiles/timezone/windowsTimezone.ics
new file mode 100644
index 0000000..ce41373
--- /dev/null
+++ b/tests/testfiles/timezone/windowsTimezone.ics
@@ -0,0 +1,16 @@
+BEGIN:VCALENDAR
+PRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20090901T113644Z
+CREATED:20090901T113644Z
+UID:KOrganizer-1353608432.168
+LAST-MODIFIED:20090901T113644Z
+SUMMARY:Windows Event
+LOCATION:Here
+DTSTART;TZID=Europe/Berlin:20090902T080000
+DTEND;TZID=Europe/Berlin:20090902T090000
+TRANSP:OPAQUE
+END:VEVENT
+
+END:VCALENDAR
diff --git a/tests/testfiles/timezone/windowsTimezoneV3.mime b/tests/testfiles/timezone/windowsTimezoneV3.mime
new file mode 100644
index 0000000..792657b
--- /dev/null
+++ b/tests/testfiles/timezone/windowsTimezoneV3.mime
@@ -0,0 +1,86 @@
+Date: Thu, 28 Feb 2013 18:22:55 +0000
+X-Kolab-Type: application/x-vnd.kolab.event
+X-Kolab-Mime-Version: 3.0
+User-Agent: Libkolab-0.5
+Content-Type: multipart/mixed; boundary="nextPart3504925.NqhbgOChlS"
+Subject: KOrganizer-1353608432.168
+MIME-Version: 1.0
+
+
+--nextPart3504925.NqhbgOChlS
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7Bit
+
+This is a Kolab Groupware object.
+To view this object you will need an email client that can understand the Kolab Groupware format.
+For a list of such email clients please visit
+http://www.kolab.org/get-kolab
+
+--nextPart3504925.NqhbgOChlS
+Content-Type: application/calendar+xml; name="kolab.xml"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment; filename="kolab.xml"
+
+<?xml version=3D"1.0" encoding=3D"UTF-8" standalone=3D"no" ?>
+<icalendar xmlns=3D"urn:ietf:params:xml:ns:icalendar-2.0">
+
+  <vcalendar>
+    <properties>
+      <prodid>
+        <text>Libkolab-0.5 Libkolabxml-0.8</text>
+      </prodid>
+      <version>
+        <text>2.0</text>
+      </version>
+      <x-kolab-version>
+        <text>3.0dev1</text>
+      </x-kolab-version>
+    </properties>
+    <components>
+      <vevent>
+        <properties>
+          <uid>
+            <text>KOrganizer-1353608432.168</text>
+          </uid>
+          <created>
+            <date-time>2009-09-01T11:36:44Z</date-time>
+          </created>
+          <dtstamp>
+            <date-time>2009-09-01T11:36:44Z</date-time>
+          </dtstamp>
+          <sequence>
+            <integer>0</integer>
+          </sequence>
+          <class>
+            <text>PUBLIC</text>
+          </class>
+          <dtstart>
+            <parameters>
+              <tzid>
+                <text>/kolab.org/W. Europe Standard Time</text>
+              </tzid>
+            </parameters>
+            <date-time>2009-09-02T08:00:00</date-time>
+          </dtstart>
+          <dtend>
+            <parameters>
+              <tzid>
+                <text>/kolab.org/W. Europe Standard Time</text>
+              </tzid>
+            </parameters>
+            <date-time>2009-09-02T09:00:00</date-time>
+          </dtend>
+          <summary>
+            <text>Windows Event</text>
+          </summary>
+          <location>
+            <text>Here</text>
+          </location>
+        </properties>
+      </vevent>
+    </components>
+  </vcalendar>
+
+</icalendar>
+
+--nextPart3504925.NqhbgOChlS--
diff --git a/tests/timezonetest.cpp b/tests/timezonetest.cpp
index 9557d75..7a0878e 100644
--- a/tests/timezonetest.cpp
+++ b/tests/timezonetest.cpp
@@ -19,6 +19,7 @@
 #include <conversion/timezoneconverter.h>
 #include <kolabformat/kolabobject.h>
 #include <kolabformat/errorhandler.h>
+#include "testutils.h"
 
 #include <QTest>
 // #include <unicode/uversion.h>
@@ -26,6 +27,7 @@
 // #include <iostream>
 #include <kdebug.h>
 #include <kcalcore/event.h>
+#include <kcalcore/icalformat.h>
 
 // void icuFoo()
 // {
@@ -100,6 +102,49 @@ void TimezoneTest::testKolabObjectWriter()
     QCOMPARE(result->dtStart().timeZone().name(), KTimeZone(QLatin1String("Africa/Lagos")).name());
 }
 
+void TimezoneTest::testKolabObjectReader()
+{
+    const Kolab::Version version = Kolab::KolabV3;
+    const Kolab::ObjectType type = Kolab::EventObject;
+    QString icalFileName = TESTFILEDIR+QString::fromLatin1("timezone/windowsTimezone.ics"); //To compare
+    QString mimeFileName = TESTFILEDIR+QString::fromLatin1("timezone/windowsTimezoneV3.mime"); //For parsing
+
+    //Parse mime message
+    bool ok = false;
+    const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok );
+    QVERIFY(ok);
+    Kolab::KolabObjectReader reader;
+    Kolab::ObjectType t = reader.parseMimeMessage(msg);
+    QCOMPARE(t, type);
+    QCOMPARE(reader.getVersion(), version);
+    QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+
+    KCalCore::Incidence::Ptr convertedIncidence = reader.getIncidence();
+    kDebug() << "read incidence";
+
+    //Parse ICalFile for comparison
+    QFile icalFile( icalFileName );
+    QVERIFY( icalFile.open( QFile::ReadOnly ) );
+    KCalCore::ICalFormat format;
+    KCalCore::Incidence::Ptr realIncidence( format.fromString( QString::fromUtf8( icalFile.readAll() ) ) );
+
+    // fix up the converted incidence for comparisson
+    normalizeIncidence(convertedIncidence);
+    normalizeIncidence(realIncidence);
+
+    // recurrence objects are created on demand, but KCalCore::Incidence::operator==() doesn't take that into account
+    // so make sure both incidences have one
+    realIncidence->recurrence();
+    convertedIncidence->recurrence();
+
+    realIncidence->setLastModified(convertedIncidence->lastModified());
+
+    //The following test is just for debugging and not really relevant
+    if ( *(realIncidence.data()) != *(convertedIncidence.data()) ) {
+        showDiff(format.toString( realIncidence ), format.toString( convertedIncidence ));
+    }
+    QVERIFY( *(realIncidence.data()) ==  *(convertedIncidence.data()) );
+}
 
 QTEST_MAIN( TimezoneTest )
 
diff --git a/tests/timezonetest.h b/tests/timezonetest.h
index cf7a4d5..7d76969 100644
--- a/tests/timezonetest.h
+++ b/tests/timezonetest.h
@@ -27,6 +27,7 @@ private slots:
     void testFromHardcodedList_data();
     void testFromHardcodedList();
     void testKolabObjectWriter();
+    void testKolabObjectReader();
 };
 
 #endif // TIMEZONETEST_H





More information about the commits mailing list