#8422: em client not allowed to change calendar
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 3 Jun 2013 11:06:01 +0000 (13:06 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 5 Jun 2013 13:26:21 +0000 (15:26 +0200)
- added em client class for vcalendar handling
- this patch was submitted by Thomas Pawassarat <tomp@topanet.de>

https://forge.tine20.org/mantisbt/view.php?id=8422

Change-Id: I5a573495780de75b4f0f9eb8546a8cf4f1c50808
Reviewed-on: https://gerrit.tine20.org/tine20/2077
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Convert/Event/VCalendar/AllTests.php
tests/tine20/Calendar/Convert/Event/VCalendar/EMClientTest.php [new file with mode: 0644]
tests/tine20/Calendar/Import/files/emclient.ics [new file with mode: 0644]
tine20/Calendar/Convert/Event/VCalendar/Abstract.php
tine20/Calendar/Convert/Event/VCalendar/EMClient.php [new file with mode: 0644]
tine20/Calendar/Convert/Event/VCalendar/Factory.php

index 182b37d..0d580b7 100644 (file)
@@ -4,7 +4,7 @@
  * 
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Lars Kneschke <l.kneschke@metaways.de>
  */
 
  */
 require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
 
-if (! defined('PHPUnit_MAIN_METHOD')) {
-    define('PHPUnit_MAIN_METHOD', 'Calendar_Convert_Event_VCalendar_AllTests::main');
-}
-
 class Calendar_Convert_Event_VCalendar_AllTests
 {
     public static function main ()
@@ -31,11 +27,8 @@ class Calendar_Convert_Event_VCalendar_AllTests
         $suite->addTestSuite('Calendar_Convert_Event_VCalendar_GenericTest');
         $suite->addTestSuite('Calendar_Convert_Event_VCalendar_MacOSXTest');
         $suite->addTestSuite('Calendar_Convert_Event_VCalendar_ThunderbirdTest');
+        $suite->addTestSuite('Calendar_Convert_Event_VCalendar_EMClientTest');
         
         return $suite;
     }
 }
-
-if (PHPUnit_MAIN_METHOD == 'Calendar_Convert_Event_VCalendar_AllTests::main') {
-    Calendar_Convert_Event_VCalendar_AllTests::main();
-}
diff --git a/tests/tine20/Calendar/Convert/Event/VCalendar/EMClientTest.php b/tests/tine20/Calendar/Convert/Event/VCalendar/EMClientTest.php
new file mode 100644 (file)
index 0000000..095de36
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ * 
+ * @package     Calendar
+ * @license     http://www.gnu.org/licenses/agpl.html
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Thomas Pawassarat <tomp@topanet.de>
+ */
+
+/**
+ * Test helper
+ */
+require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+/**
+ * Test class for Calendar_Convert_Event_VCalendar_EMClient
+ */
+class Calendar_Convert_Event_VCalendar_EMClientTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var array test objects
+     */
+    protected $objects = array();
+    
+    /**
+     * Runs the test methods of this class.
+     *
+     * @access public
+     * @static
+     */
+    public static function main()
+    {
+        $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Calendar WebDAV EM Client Event Tests');
+        PHPUnit_TextUI_TestRunner::run($suite);
+    }
+
+    /**
+     * Sets up the fixture.
+     * This method is called before a test is executed.
+     *
+     * @access protected
+     */
+    protected function setUp()
+    {
+    }
+
+    /**
+     * Tears down the fixture
+     * This method is called after a test is executed.
+     *
+     * @access protected
+     */
+    protected function tearDown()
+    {
+    }
+    
+    /**
+     * test converting vcard from EM Client to Calendar_Model_Event 
+     */
+    public function testConvertToTine20Model()
+    {
+        $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/emclient.ics', 'r');
+        
+        $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
+        
+        $event = $converter->toTine20Model($vcalendarStream);
+    }
+}
diff --git a/tests/tine20/Calendar/Import/files/emclient.ics b/tests/tine20/Calendar/Import/files/emclient.ics
new file mode 100644 (file)
index 0000000..5dc03bd
--- /dev/null
@@ -0,0 +1,33 @@
+BEGIN:VCALENDAR\r
+PRODID:-//eM Client/5.0.18025.0\r
+VERSION:2.0\r
+BEGIN:VTIMEZONE\r
+TZID:Europe/Berlin\r
+BEGIN:STANDARD\r
+DTSTART:19700329T020000\r
+TZOFFSETFROM:+0200\r
+TZOFFSETTO:+0100\r
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10;WKST=SU\r
+TZNAME:Mitteleuropäische Sommerzeit\r
+END:STANDARD\r
+BEGIN:DAYLIGHT\r
+DTSTART:19701025T030000\r
+TZOFFSETFROM:+0100\r
+TZOFFSETTO:+0200\r
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3;WKST=SU\r
+TZNAME:Mitteleuropäische Zeit\r
+END:DAYLIGHT\r
+END:VTIMEZONE\r
+BEGIN:VEVENT\r
+UID:ccc6ac71-fd50-4308-b64e-388067b3a497\r
+DTSTART;TZID="Europe/Berlin":20130527T080000\r
+DTEND;TZID="Europe/Berlin":20130527T083000\r
+TRANSP:OPAQUE\r
+X-MICROSOFT-CDO-BUSYSTATUS:BUSY\r
+LAST-MODIFIED:20130526T091155Z\r
+DTSTAMP:20130526T091151Z\r
+CREATED:20130526T091151Z\r
+SUMMARY:eM Patch Upload\r
+CLASS:PUBLIC\r
+END:VEVENT\r
+END:VCALENDAR\r
index b649bef..e133a08 100644 (file)
@@ -841,7 +841,7 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
                     break;
                     
                 case 'VALARM':
-                    foreach($property as $valarm) {
+                    foreach ($property as $valarm) {
                         
                         if ($valarm->ACTION == 'NONE') {
                             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ 
@@ -849,7 +849,9 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
                             continue;
                         }
                         
-                        if (! is_object($valarm->TRIGGER['VALUE'])) {
+                        $trigger = is_object($valarm->TRIGGER['VALUE']) ? $valarm->TRIGGER['VALUE'] : (is_object($valarm->TRIGGER['RELATED']) ? $valarm->TRIGGER['RELATED'] : NULL);
+                        if ($trigger === NULL) {
+                            // added Trigger/Related for eM Client alarms
                             // @see 0006110: handle iMIP messages from outlook
                             // @todo fix 0007446: handle broken alarm in outlook invitation message
                             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ 
@@ -857,10 +859,9 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
                             continue;
                         }
                         
-                        switch (strtoupper($valarm->TRIGGER['VALUE']->value)) {
+                        switch (strtoupper($trigger->value)) {
                             # TRIGGER;VALUE=DATE-TIME:20111031T130000Z
                             case 'DATE-TIME':
-                                //@TODO fixme
                                 $alarmTime = new Tinebase_DateTime($valarm->TRIGGER->value);
                                 $alarmTime->setTimezone('UTC');
                                 
diff --git a/tine20/Calendar/Convert/Event/VCalendar/EMClient.php b/tine20/Calendar/Convert/Event/VCalendar/EMClient.php
new file mode 100644 (file)
index 0000000..02093fd
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Calendar
+ * @subpackage  Convert
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Thomas Pawassarat <tomp@topanet.de>
+ * @copyright   Copyright (c) 2012-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ */
+
+/**
+ * class to convert an emclient vcalendar to event model and back again
+ *
+ * @package     Calendar
+ * @subpackage  Convert
+ */
+class Calendar_Convert_Event_VCalendar_EMClient extends Calendar_Convert_Event_VCalendar_Abstract
+{
+    // eM Client/5.0.17595.0
+    const HEADER_MATCH = '/eM Client\/(?P<version>.*)/';
+    
+    protected $_supportedFields = array(
+        'seq',
+        'dtend',
+        'transp',
+        'class',
+        'description',
+        #'geo',
+        'location',
+        'priority',
+        'summary',
+        'url',
+        'alarms',
+        #'tags',
+        'dtstart',
+        'exdate',
+        'rrule',
+        'recurid',
+        'is_all_day_event',
+        #'rrule_until',
+        'originator_tz'
+    );
+}
index f5b1861..5b8d13e 100644 (file)
@@ -23,6 +23,7 @@ class Calendar_Convert_Event_VCalendar_Factory
     const CLIENT_KDE         = 'kde';
     const CLIENT_MACOSX      = 'macosx';
     const CLIENT_THUNDERBIRD = 'thunderbird';
+    const CLIENT_EMCLIENT     = 'emclient';
     
     /**
      * factory function to return a selected vcalendar backend class
@@ -58,7 +59,12 @@ class Calendar_Convert_Event_VCalendar_Factory
                 return new Calendar_Convert_Event_VCalendar_Thunderbird($_version);
                  
                 break;
-                     
+            case Calendar_Convert_Event_VCalendar_Factory::CLIENT_EMCLIENT:
+                return new Calendar_Convert_Event_VCalendar_EMClient($_version);
+                 
+                break;
         }
     }
     
@@ -89,6 +95,11 @@ class Calendar_Convert_Event_VCalendar_Factory
             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_THUNDERBIRD;
             $version = $matches['version'];
         
+        // EMClient
+        } elseif (preg_match(Calendar_Convert_Event_VCalendar_EMClient::HEADER_MATCH, $_userAgent, $matches)) {
+            $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_EMCLIENT;
+            $version = $matches['version'];
+        
         } else {
             $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC;
             $version = null;