[Pkg-owncloud-commits] [php-sabre-vobject] 30/106: Processing replies.

David Prévot taffit at moszumanska.debian.org
Fri Aug 22 15:10:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit abc5bd9dcdf23832a19fe541c457a81b10e5d6fd
Author: Evert Pot <me at evertpot.com>
Date:   Wed Jul 23 16:57:32 2014 -0400

    Processing replies.
---
 lib/Sabre/VObject/Component/VCalendar.php          |  31 ++++++
 lib/Sabre/VObject/ITip/Broker.php                  |   6 +-
 .../VObject/ITip/BrokerProcessMessageTest.php      | 123 ++++++++++++++++++++-
 3 files changed, 154 insertions(+), 6 deletions(-)

diff --git a/lib/Sabre/VObject/Component/VCalendar.php b/lib/Sabre/VObject/Component/VCalendar.php
index 7b7f628..2d99363 100644
--- a/lib/Sabre/VObject/Component/VCalendar.php
+++ b/lib/Sabre/VObject/Component/VCalendar.php
@@ -189,6 +189,37 @@ class VCalendar extends VObject\Document {
     }
 
     /**
+     * Returns the first component that is not a VTIMEZONE, and does not have
+     * RECURRENCE-ID.
+     *
+     * If there is no such component, null will be returned.
+     *
+     * @param string $componentName filter by component name
+     * @return array
+     */
+    public function getBaseComponent($componentName = null) {
+
+        foreach($this->children as $component) {
+
+            if (!$component instanceof VObject\Component)
+                continue;
+
+            if (isset($component->{'RECURRENCE-ID'}))
+                continue;
+
+            if ($componentName && $component->name !== strtoupper($componentName))
+                continue;
+
+            if ($component->name === 'VTIMEZONE')
+                continue;
+
+            return $component;
+
+        }
+
+    }
+
+    /**
      * If this calendar object, has events with recurrence rules, this method
      * can be used to expand the event into multiple sub-events.
      *
diff --git a/lib/Sabre/VObject/ITip/Broker.php b/lib/Sabre/VObject/ITip/Broker.php
index 077a1f3..f052326 100644
--- a/lib/Sabre/VObject/ITip/Broker.php
+++ b/lib/Sabre/VObject/ITip/Broker.php
@@ -273,7 +273,7 @@ class Broker {
             if (isset($instances[$recurId])) {
                 $attendeeFound = false;
                 foreach($vevent->ATTENDEE as $attendee) {
-                    if ($attendee->getValue() === $message->sender) {
+                    if ($attendee->getValue() === $itipMessage->sender) {
                         $attendeeFound = true;
                         $attendee['PARTSTAT'] = $instances[$recurId];
                         break;
@@ -281,8 +281,8 @@ class Broker {
                 }
                 if (!$attendeeFound) {
                     // Adding a new attendee
-                    $attendee = $vevent->add('ATTENDEE', $message->sender, array(
-                        'CN' => $message->senderName,
+                    $attendee = $vevent->add('ATTENDEE', $itipMessage->sender, array(
+                        'CN' => $itipMessage->senderName,
                         'PARTSTAT' => $instances[$recurId]
                     ));
                 }
diff --git a/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php b/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
index aab7e01..2ef6678 100644
--- a/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
+++ b/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
@@ -127,16 +127,133 @@ ICS;
 
     }
 
+    function testUnsupportedComponent() {
+
+        $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VTODO
+SEQUENCE:2
+UID:foobar
+END:VTODO
+END:VCALENDAR
+ICS;
+
+        $old = null;
+        $expected = null;
+
+        $result = $this->process($itip, $old, $expected);
+
+    }
+
+    function testUnsupportedMethod() {
+
+        $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:PUBLISH
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $old = null;
+        $expected = null;
+
+        $result = $this->process($itip, $old, $expected);
+
+    }
+
+    function testReplyNoOriginal() {
+
+        $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $old = null;
+        $expected = null;
+
+        $result = $this->process($itip, $old, $expected);
+
+    }
+
+    function testReplyAccept() {
+
+        $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+SEQUENCE:2
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $old = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $result = $this->process($itip, $old, $expected);
+
+    }
+
     function process($input, $existingObject = null, $expected = false) {
 
         $version = \Sabre\VObject\Version::VERSION;
 
         $vcal = Reader::read($input);
+
+        $mainComponent = $vcal->getBaseComponent();
+
         $message = new Message();
         $message->message = $vcal;
-        $message->method = $vcal->METHOD;
-        $message->component = 'VEVENT';
-        $message->sequence = $vcal->VEVENT[0]->SEQUENCE;
+        $message->method = isset($vcal->METHOD)?$vcal->METHOD->getValue():null;
+        $message->component = $mainComponent->name;
+        $message->sequence = isset($vcal->VEVENT[0])?$vcal->VEVENT[0]->SEQUENCE:null;
+
+        if ($message->method === 'REPLY') {
+
+            $message->sender = $mainComponent->ATTENDEE->getValue();
+            $message->senderName = isset($mainComponent->ATTENDEE['CN'])?$mainComponent->ATTENDEE['CN']:null;
+            $message->recipient = $mainComponent->ORGANIZER->getValue();
+            $message->senderName = isset($mainComponent->ORGANIZER['CN'])?$mainComponent->ORGANIZER['CN']:null;
+
+        }
+
         $broker = new Broker();
 
         if (is_string($existingObject)) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list