[Pkg-owncloud-commits] [php-sabredav] 129/275: Overhauled imip plugin.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:56:00 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 77ba1eb4f79953131b99e3ed142b6caab8422d68
Author: Evert Pot <me at evertpot.com>
Date:   Fri Aug 1 01:06:42 2014 -0400

    Overhauled imip plugin.
---
 lib/CalDAV/Schedule/IMip.php       | 111 -------------------------
 lib/CalDAV/Schedule/IMipPlugin.php | 162 +++++++++++++++++++++++++++++++++++++
 lib/CalDAV/Schedule/Plugin.php     |   7 +-
 3 files changed, 166 insertions(+), 114 deletions(-)

diff --git a/lib/CalDAV/Schedule/IMip.php b/lib/CalDAV/Schedule/IMip.php
deleted file mode 100644
index 9a12681..0000000
--- a/lib/CalDAV/Schedule/IMip.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Schedule;
-
-use Sabre\VObject;
-use Sabre\DAV;
-
-/**
- * iMIP handler.
- *
- * This class is responsible for sending out iMIP messages. iMIP is the
- * email-based transport for iTIP. iTIP deals with scheduling operations for
- * iCalendar objects.
- *
- * If you want to customize the email that gets sent out, you can do so by
- * extending this class and overriding the sendMessage method.
- *
- * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://evertpot.com/)
- * @license http://sabre.io/license/ Modified BSD License
- */
-class IMip {
-
-    /**
-     * Email address used in From: header.
-     *
-     * @var string
-     */
-    protected $senderEmail;
-
-    /**
-     * Creates the email handler.
-     *
-     * @param string $senderEmail. The 'senderEmail' is the email that shows up
-     *                             in the 'From:' address. This should
-     *                             generally be some kind of no-reply email
-     *                             address you own.
-     */
-    public function __construct($senderEmail) {
-
-        $this->senderEmail = $senderEmail;
-
-    }
-
-    /**
-     * Sends one or more iTip messages through email.
-     *
-     * @param string $originator Originator Email
-     * @param array $recipients Array of email addresses
-     * @param VObject\Component $vObject
-     * @param string $principal Principal Url of the originator
-     * @return void
-     */
-    public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
-
-        foreach($recipients as $recipient) {
-
-            $to = $recipient;
-            $replyTo = $originator;
-            $subject = 'SabreDAV iTIP message';
-
-            switch(strtoupper($vObject->METHOD)) {
-                case 'REPLY' :
-                    $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
-                    break;
-                case 'REQUEST' :
-                    $subject = 'Invitation for: ' .$vObject->VEVENT->SUMMARY;
-                    break;
-                case 'CANCEL' :
-                    $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
-                    break;
-            }
-
-            $headers = array();
-            $headers[] = 'Reply-To: ' . $replyTo;
-            $headers[] = 'From: ' . $this->senderEmail;
-            $headers[] = 'Content-Type: text/calendar; method=' . (string)$vObject->method . '; charset=utf-8';
-            if (DAV\Server::$exposeVersion) {
-                $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION;
-            }
-
-            $vcalBody = $vObject->serialize();
-
-            $this->mail($to, $subject, $vcalBody, $headers);
-
-        }
-
-    }
-
-    // @codeCoverageIgnoreStart
-    // This is deemed untestable in a reasonable manner
-
-    /**
-     * This function is reponsible for sending the actual email.
-     *
-     * @param string $to Recipient email address
-     * @param string $subject Subject of the email
-     * @param string $body iCalendar body
-     * @param array $headers List of headers
-     * @return void
-     */
-    protected function mail($to, $subject, $body, array $headers) {
-
-
-        mail($to, $subject, $body, implode("\r\n", $headers));
-
-    }
-
-    // @codeCoverageIgnoreEnd
-
-}
diff --git a/lib/CalDAV/Schedule/IMipPlugin.php b/lib/CalDAV/Schedule/IMipPlugin.php
new file mode 100644
index 0000000..9f914a9
--- /dev/null
+++ b/lib/CalDAV/Schedule/IMipPlugin.php
@@ -0,0 +1,162 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+
+use Sabre\DAV;
+use Sabre\VObject;
+use Sabre\VObject\ITip;
+
+
+
+/**
+ * iMIP handler.
+ *
+ * This class is responsible for sending out iMIP messages. iMIP is the
+ * email-based transport for iTIP. iTIP deals with scheduling operations for
+ * iCalendar objects.
+ *
+ * If you want to customize the email that gets sent out, you can do so by
+ * extending this class and overriding the sendMessage method.
+ *
+ * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class IMipPlugin extends DAV\ServerPlugin {
+
+    /**
+     * Email address used in From: header.
+     *
+     * @var string
+     */
+    protected $senderEmail;
+
+    /**
+     * Server class
+     *
+     * @var DAV\Server
+     */
+    protected $server;
+
+    /**
+     * ITipMessage
+     *
+     * @var ITip\Message
+     */
+    protected $itipMessage;
+
+    /**
+     * Creates the email handler.
+     *
+     * @param string $senderEmail. The 'senderEmail' is the email that shows up
+     *                             in the 'From:' address. This should
+     *                             generally be some kind of no-reply email
+     *                             address you own.
+     */
+    public function __construct($senderEmail) {
+
+        $this->senderEmail = $senderEmail;
+
+    }
+
+    /*
+     * This initializes the plugin.
+     *
+     * This function is called by Sabre\DAV\Server, after
+     * addPlugin is called.
+     *
+     * This method should set up the required event subscriptions.
+     *
+     * @param Server $server
+     * @return void
+     */
+    public function initalize(DAV\Server $server) {
+
+        $server->on('schedule', [$this, 'schedule']);
+
+    }
+
+    /**
+     * Returns a plugin name.
+     *
+     * Using this name other plugins will be able to access other plugins
+     * using \Sabre\DAV\Server::getPlugin
+     *
+     * @return string
+     */
+    public function getPluginName() {
+
+        return 'imip';
+
+    }
+
+    /**
+     * Event handler for the 'schedule' event.
+     *
+     * @param ITip\Mmessage $iTipMessage
+     * @return void
+     */
+    public function schedule(ITip\Message $iTipMessage) {
+
+        $summary = $iTipMessage->message->VEVENT->SUMMARY;
+
+        $sender = $iTipMessage->sender;
+        if ($iTipMessage->senderName) {
+            $sender = $iTipMessage->senderName . ' <' . $sender . '>';
+        }
+        $recipient = $iTipMessage->recipient;
+        if ($iTipMessage->recipientName) {
+            $recipient = $iTipMessage->recipientName . ' <' . $recipient . '>';
+        }
+
+        $subject = 'SabreDAV iTIP message';
+        switch(strtoupper($vObject->METHOD)) {
+            case 'REPLY' :
+                $subject = 'Re: ' . $summary;
+                break;
+            case 'REQUEST' :
+                $subject = $summary;
+                break;
+            case 'CANCEL' :
+                $subject = 'Cancelled: ' . $summary;
+                break;
+        }
+
+        $headers = [
+            'Reply-To: ' . $sender,
+            'From: ' . $this->senderEmail,
+            'Content-Type: text/calendar; charset=UTF-8; method=' . $iTipMessage->method,
+        ];
+        if (DAV\Server::$exposeVersion) {
+            $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION;
+        }
+        $this->mail(
+            $iTipMessage->recipient,
+            $subject,
+            $iTipMessage->message->serialize(),
+            $headers
+        );
+
+    }
+
+    // @codeCoverageIgnoreStart
+    // This is deemed untestable in a reasonable manner
+
+    /**
+     * This function is reponsible for sending the actual email.
+     *
+     * @param string $to Recipient email address
+     * @param string $subject Subject of the email
+     * @param string $body iCalendar body
+     * @param array $headers List of headers
+     * @return void
+     */
+    protected function mail($to, $subject, $body, array $headers) {
+
+/bin/bash: :W: command not found
+
+    }
+
+    // @codeCoverageIgnoreEnd
+
+}
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index ba77324..3f11c45 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -16,6 +16,7 @@ use
     Sabre\VObject\Reader,
     Sabre\VObject\Component\VCalendar,
     Sabre\VObject\ITip,
+    Sabre\VObject\ITip\Message,
     Sabre\DAVACL,
     Sabre\CalDAV\ICalendar,
     Sabre\CalDAV\ICalendarObject,
@@ -104,7 +105,7 @@ class Plugin extends ServerPlugin {
         $server->on('beforeCreateFile',    [$this, 'beforeCreateFile']);
         $server->on('beforeWriteContent',  [$this, 'beforeWriteContent']);
         $server->on('beforeUnbind',        [$this, 'beforeUnbind']);
-        $server->on('schedule',            [$this, 'scheduleLocalDelivery']);
+        $server->on('schedule',            [$this, 'schedulelocaldelivery']);
 
         /**
          * This information ensures that the {DAV:}resourcetype property has
@@ -412,10 +413,10 @@ class Plugin extends ServerPlugin {
      * This handler attempts to look at local accounts to deliver the
      * scheduling object.
      *
-     * @param ITipImessage $iTipMessage
+     * @param ITip\Message $iTipMessage
      * @return void
      */
-    public function scheduleLocalDelivery($iTipMessage) {
+    public function scheduleLocalDelivery(ITip\Message $iTipMessage) {
 
         $aclPlugin = $this->server->getPlugin('acl');
 

-- 
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