[Pkg-owncloud-commits] [php-sabredav] 14/275: Sending emails when inviting attendees.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:55:45 UTC 2014


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

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

commit 09683099e6379e294a8cd5d4635a5132cc2e069b
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sun Aug 25 16:04:22 2013 +0100

    Sending emails when inviting attendees.
---
 lib/Sabre/CalDAV/Calendar.php             |   2 +-
 lib/Sabre/CalDAV/Schedule/ITipMessage.php |  68 ++++++++++++++++
 lib/Sabre/CalDAV/Schedule/Plugin.php      | 125 +++++++++++++++++++++++++-----
 3 files changed, 174 insertions(+), 21 deletions(-)

diff --git a/lib/Sabre/CalDAV/Calendar.php b/lib/Sabre/CalDAV/Calendar.php
index 156598c..20c8149 100644
--- a/lib/Sabre/CalDAV/Calendar.php
+++ b/lib/Sabre/CalDAV/Calendar.php
@@ -16,7 +16,7 @@ use
  * @author Evert Pot (http://evertpot.com/)
  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  */
-class Calendar implements ICalendar, DAV\IProperties, DAVACL\IACL, DAV\Sync\ISyncCollection, DAV\IMultiGet {
+class Calendar implements ICalendar, DAV\IProperties, DAV\Sync\ISyncCollection, DAV\IMultiGet {
 
     /**
      * This is an array with calendar information
diff --git a/lib/Sabre/CalDAV/Schedule/ITipMessage.php b/lib/Sabre/CalDAV/Schedule/ITipMessage.php
new file mode 100644
index 0000000..2c9cd97
--- /dev/null
+++ b/lib/Sabre/CalDAV/Schedule/ITipMessage.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+
+class ITipMessage {
+
+    /**
+     * The senders' email address.
+     *
+     * Note that this does not imply that this has to be used in a From: field
+     * if the message is sent by email. It may also be populated in Reply-To:
+     * or not at all.
+     *
+     * @var string
+     */
+    public $sender;
+
+    /**
+     * The name of the sender. This is often populated from a CN parameter from
+     * either the ORGANIZER or ATTENDEE, depending on the message.
+     *
+     * @var string|null
+     */
+    public $senderName;
+
+    /**
+     * The recipient's email address.
+     *
+     * @var string
+     */
+    public $recipient;
+
+    /**
+     * The name of the recipient. This is usually populated with the CN
+     * parameter from the ATTENDEE or ORGANIZER property, if it's available.
+     *
+     * @var string|null
+     */
+    public $recipientName;
+
+    /**
+     * The contents of the METHOD property on the iCalendar body.
+     *
+     * @var string
+     */
+    public $method;
+
+    /**
+     * After the message has been delivered, this should contain a string such
+     * as : 1.1;Sent or 1.2;Delivered.
+     *
+     * In case of a failure, this will hold the error status code.
+     *
+     * See:
+     * http://tools.ietf.org/html/rfc6638#section-7.3
+     *
+     * @var string
+     */
+    public $scheduleStatus;
+
+    /**
+     * The iCalendar / iTip body.
+     *
+     * @var \Sabre\VObject\Component\VCalendar
+     */
+    public $message;
+
+}
diff --git a/lib/Sabre/CalDAV/Schedule/Plugin.php b/lib/Sabre/CalDAV/Schedule/Plugin.php
index 5d5b2f8..4dab4b3 100644
--- a/lib/Sabre/CalDAV/Schedule/Plugin.php
+++ b/lib/Sabre/CalDAV/Schedule/Plugin.php
@@ -337,11 +337,11 @@ class Plugin extends ServerPlugin {
      *
      * @param string $path path to new object.
      * @param string|resource $data Contents of new object.
-     * @param \Sabre\DAV\INode $parent Parent object
+     * @param \Sabre\DAV\INode $parentNode Parent object
      * @param bool $modified Wether or not the item's data was modified/
      * @return bool|null
      */
-    public function beforeCreateFile($path, &$data, $parent, &$modified) {
+    public function beforeCreateFile($path, &$data, $parentNode, &$modified) {
 
         if (!$parentNode instanceof ICalendar) {
             return;
@@ -349,6 +349,9 @@ class Plugin extends ServerPlugin {
 
         // It's a calendar, so the contents are most likely an iCalendar
         // object. It's time to start processing this.
+        //
+        // This step also ensures that $data is re-propagated with a string
+        // version of the object.
         if (is_resource($data)) {
             $data = stream_get_contents($data);
         }
@@ -371,39 +374,121 @@ class Plugin extends ServerPlugin {
             $organizer = (string)$vevent->ORGANIZER;
         }
 
-        if (isset($vevent->ATTENDEES)) foreach($vevent->ATTENDEES as $attendee) {
-            $attendees[] = (string)$attendee;
-        }
-
         // If the object doesn't have organizer or attendee information, we can
         // ignore it.
-        if (!$organizer && !$attendees) {
+        if (!$organizer || !isset($vevent->ATTENDEE)) {
+            return;
+        }
+
+        $addresses = $this->getAddressesForPrincipal(
+            $parentNode->getOwner()
+        );
+
+        // We're only handling creation of new objects by the ORGANIZER.
+        // Support for ATTENDEE will come later.
+        if (!in_array($organizer, $addresses)) {
             return;
         }
 
-        // Finding all the email addresses for the user that owns the
-        // calendar.
-        $calendarOwner = $node->getOwner();
+        // For each attendee we're going to generate a scheduling message.
+        // We do this based on the original object.
+        //
+        // $vObj is the copy for the user that created the object. We will use
+        // that to update some values, such as SCHEDULE-STATUS per attendee.
+        $original = clone $vObj;
+
+        foreach($vevent->ATTENDEE as $attendee) {
+
+            if (!isset($attendee['SCHEDULE-AGENT'])) {
+                $agent = 'SERVER';
+            } else {
+                $agent = strtoupper($attendee['SCHEDULE-AGENT']);
+            }
+
+            // The SCHEDULE-AGENT parameter is 'SERVER' by default, but if it
+            // was set to 'NONE' or 'CLIENT', we are not responsible for
+            // delivering the message.
+            if ($agent!=='SERVER') continue;
+
+            $status = null;
+
+            // Currently only handling mailto: addresses.
+            if (strtolower(substr($attendee->getValue(),0,7))!=='mailto:') {
+                $status = '5.1;This server can currently only handle mailto: addresses';
+            } else {
+
+                $iTipMessage = new ITipMessage();
+
+                // Stripping the mailto:
+                $iTipMessage->recipient = strtolower(substr($attendee->getValue(), 7));
+                if (isset($attendee['CN'])) $iTipMessage->recipientName = (string)$attendee['CN'];
+
+                $iTipMessage->sender = strtolower(substr($organizer, 7));
+                if (isset($vevent->ORGANIZER['CN'])) $iTipMessage->senderName = $vevent->ORGANIZER['CN'];
+
+                $iTipMessage->method = 'REQUEST';
+
+                $iTipBody = clone $original;
+                $iTipBody->METHOD = 'REQUEST';
+
+                $iTipMessage->message = $iTipBody;
+
+                $this->deliver($iTipMessage);
+
+                $attendee['SCHEDULE-STATUS'] = $iTipMessage->scheduleStatus;
+
+            }
+
+        }
+
+        // After all this exciting action we set $data to the updated event
+        // that contains all the new status information (if any).
+        $newData = $vObj->serialize();
+        if ($newData !== $data) {
+            $data = $newData;
+
+            // Setting $modified tells sabredav that the object has changed,
+            // and that no ETag must be sent back.
+            $modified = true;
+        }
+
+    }
 
-        $CAUS = '{' . self::NS_CALDAV . '}calendar-user-address-set';
+    /**
+     * This method is responsible for delivering the ITip message.
+     *
+     * @param ITipMessage $itipMessage
+     * @return void
+     */
+    public function deliver(ITipMessage $iTipMessage) {
+
+        $iTipMessage->scheduleStatus =
+            $this->iMipMessage($iTipMessage->sender, [$iTipMessage->recipient], $iTipMessage->message, '');
+
+    }
+
+    /**
+     * Returns a list of addresses that are associated with a principal.
+     *
+     * @param string $principal
+     * @return array
+     */
+    protected function getAddressesForPrincipal($principal) {
+
+        $CUAS = '{' . self::NS_CALDAV . '}calendar-user-address-set';
 
         $properties = $this->server->getProperties(
-            $calendarOwner,
-            [$CAUS],
+            $principal,
+            [$CUAS]
         );
 
         // If we can't find this information, we'll stop processing
-        if (!isset($properties[$CAUS])) {
+        if (!isset($properties[$CUAS])) {
             return;
         }
 
         $addresses = $properties[$CUAS]->getHrefs();
-
-        // We're only handling creation of new objects by the ORGANIZER.
-        // Support for ATTENDEE will come later.
-        if (!in_array($organizer, $addresses)) {
-            return;
-        }
+        return $addresses;
 
     }
 

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



More information about the Pkg-owncloud-commits mailing list