VEVENTS: fixes two problems with broken or empty attender strings
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 19 Aug 2014 13:47:37 +0000 (15:47 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Sep 2014 09:26:42 +0000 (11:26 +0200)
* sanitizes emails
* improves check for empty attender name

Change-Id: I38f40e3a9a45058ccf93ec94e364670e847c80b6
Reviewed-on: http://gerrit.tine20.com/customers/1017
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Convert/Event/VCalendar/GenericTest.php
tests/tine20/Calendar/Import/files/attender_empty_name.ics [new file with mode: 0644]
tine20/Calendar/Model/Attender.php

index bceb4e0..fc7ce7b 100644 (file)
@@ -717,4 +717,14 @@ class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_Tes
         
         $this->assertEquals('Flug nach Hamburg', $savedEvent->summary);
     }
+    
+    /**
+     * testEmptyAttenderNameAndBrokenEmail
+     */
+    public function testEmptyAttenderNameAndBrokenEmail()
+    {
+        $savedEvent = $this->_saveIcsEvent('attender_empty_name.ics', Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX);
+        
+        $this->assertEquals('Telko axel', $savedEvent->summary);
+    }
 }
diff --git a/tests/tine20/Calendar/Import/files/attender_empty_name.ics b/tests/tine20/Calendar/Import/files/attender_empty_name.ics
new file mode 100644 (file)
index 0000000..d6e9561
--- /dev/null
@@ -0,0 +1,47 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Apple Inc.//iCal 4.0.4//EN
+BEGIN:VTIMEZONE
+TZID:Europe/Berlin
+BEGIN:STANDARD
+DTSTART:19961027T030000
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+TZNAME:GMT+01:00
+TZOFFSETFROM:+0200
+TZOFFSETTO:+0100
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19810329T020000
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+TZNAME:GMT+02:00
+TZOFFSETFROM:+0100
+TZOFFSETTO:+0200
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:1D35281C-A4A2-4654-A66B-F1CEF13C5BAF
+DTSTART;TZID=Europe/Berlin:20101214T150000
+DTEND;TZID=Europe/Berlin:20101214T160000
+ATTENDEE;CN=;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;
+ RSVP=TRUE:MAILTO:kai@axelhuepfer.de
+ATTENDEE;CN=hansii.fleche@axelhuepferxxas.de<bambi.rentz@axelhuepferxxas.d
+ e>;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:
+ mailto:hansii.fleche@axelhuepferxxas.de%3Cbambi.rentz@axelhuepferxxas.de%3
+ E
+CLASS:PUBLIC
+CREATED:20101210T105440Z
+DESCRIPTION:Zeit: Dienstag\, 14. Dezember 2010 15:00-16:00. (UTC+01:00) Am
+ sterdam\, Berlin\, Bern\, Rom\, Stockholm\, Wien\nOrt: Büro RL\n\n*~*~*~*
+ ~*~*~*~*~*~*\n\n\n
+DTSTAMP:20101210T105347Z
+LOCATION:Büro RL
+ORGANIZER;CN=;SCHEDULE-AGENT=CLIENT;SCHEDULE-STATUS=5.3:MAILTO:rassmatazzz
+ nn@axelhuepper.de
+SEQUENCE:1
+STATUS:CONFIRMED
+SUMMARY:Telko axel
+TRANSP:OPAQUE
+X-APPLE-NEEDS-REPLY:TRUE
+END:VEVENT
+END:VCALENDAR
index d90b8ef..d431149 100644 (file)
@@ -424,7 +424,7 @@ class Calendar_Model_Attender extends Tinebase_Record_Abstract
     */
     public static function resolveEmailToContact($_attenderData, $_implicitAddMissingContacts = TRUE)
     {
-        if (! isset($_attenderData['email'])) {
+        if (! isset($_attenderData['email']) || empty($_attenderData['email'])) {
             throw new Tinebase_Exception_InvalidArgument('email address is needed to resolve contact');
         }
         
@@ -455,7 +455,7 @@ class Calendar_Model_Attender extends Tinebase_Record_Abstract
             $contactData = array(
                 'note'        => $i18nNote,
                 'email'       => $email,
-                'n_family'    => (isset($_attenderData['lastName'])) ? $_attenderData['lastName'] : $email,
+                'n_family'    => (isset($_attenderData['lastName']) && ! empty($_attenderData['lastName'])) ? $_attenderData['lastName'] : $email,
                 'n_given'     => (isset($_attenderData['firstName'])) ? $_attenderData['firstName'] : '',
             );
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " add new contact " . print_r($contactData, true));
@@ -487,9 +487,16 @@ class Calendar_Model_Attender extends Tinebase_Record_Abstract
             }
             
             if (strlen($result) > 64) {
-                if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ 
-                    . ' Email address could not be sanitized: ' . $email . '(length: ' . strlen($email) . ')');
-                throw new Tinebase_Exception_Record_Validation('email string too long');
+                // try to find first valid email
+                if (preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $result, $matches)) {
+                    $result = $matches[0];
+                }
+                
+                if (strlen($result) > 64) {
+                    if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ 
+                        . ' Email address could not be sanitized: ' . $email . '(length: ' . strlen($email) . ')');
+                    throw new Tinebase_Exception_Record_Validation('email string too long');
+                }
             } else {
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ 
                     . ' Email address has been sanitized: ' . $email . ' -> ' . $result);