plugins/kolab_delegation
Aleksander Machniak
machniak at kolabsys.com
Tue Dec 18 12:58:33 CET 2012
plugins/kolab_delegation/kolab_delegation.php | 19 +++++++++
plugins/kolab_delegation/kolab_delegation_engine.php | 40 ++++++++++++++++++-
2 files changed, 57 insertions(+), 2 deletions(-)
New commits:
commit 5780b841ccc1237181e0b0ac435c6083e3adab3e
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Tue Dec 18 12:57:32 2012 +0100
Use delegator's name in delegatee identities derived from delegator
Set 'Sender:' header in mail sent on behalf of delegator
diff --git a/plugins/kolab_delegation/kolab_delegation.php b/plugins/kolab_delegation/kolab_delegation.php
index 1e2b81f..8ec1f8b 100644
--- a/plugins/kolab_delegation/kolab_delegation.php
+++ b/plugins/kolab_delegation/kolab_delegation.php
@@ -46,6 +46,9 @@ class kolab_delegation extends rcube_plugin
// on-check-recent delegation support
$this->add_hook('check_recent', array($this, 'check_recent_hook'));
+ // on-message-send delegation support
+ $this->add_hook('message_before_send', array($this, 'message_before_send'));
+
// delegation support in Calendar plugin
$this->add_hook('message_load', array($this, 'message_load'));
$this->add_hook('calendar_user_emails', array($this, 'calendar_user_emails'));
@@ -139,6 +142,22 @@ class kolab_delegation extends rcube_plugin
}
/**
+ * Mail send action
+ */
+ public function message_before_send($args)
+ {
+ // Checking headers of email being send, we'll add
+ // Sender: header if mail is send on behalf of someone else
+
+ if (!empty($_SESSION['delegators'])) {
+ $engine = $this->engine();
+ $engine->delegator_delivery_filter($args);
+ }
+
+ return $args;
+ }
+
+ /**
* E-mail message loading action
*/
public function message_load($args)
diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php
index 1d3505c..f056fca 100644
--- a/plugins/kolab_delegation/kolab_delegation_engine.php
+++ b/plugins/kolab_delegation/kolab_delegation_engine.php
@@ -470,6 +470,7 @@ class kolab_delegation_engine
}
}
+ $realname = $name;
if ($uid && $name) {
$name .= ' (' . $uid . ')';
}
@@ -486,6 +487,7 @@ class kolab_delegation_engine
return array(
'uid' => $uid,
'name' => $name,
+ 'realname' => $realname,
'imap_uid' => $imap_uid,
'email' => $email,
'ID' => $data['ID'],
@@ -605,9 +607,9 @@ class kolab_delegation_engine
// create identities for delegator emails
foreach ($email_arr as $email) {
+ // @TODO: "Delegatorname" or "Username on behalf of Delegatorname"?
+ $default['name'] = $delegator['realname'];
$default['email'] = $email;
- // @TODO: "Username" or "Delegatorname" or "Username on behalf of Delegatorname"
- //$default['name'] = $delegator['email'];
$this->rc->user->insert_identity($default);
}
@@ -809,6 +811,40 @@ class kolab_delegation_engine
}
/**
+ * Filters/updates message headers according to delegator context
+ *
+ * @param array $args Reference to plugin hook arguments
+ */
+ public function delegator_delivery_filter(&$args)
+ {
+ // no context, but message still can be send on behalf of...
+ if (!empty($_SESSION['delegators'])) {
+ $message = $args['message'];
+ $headers = $message->headers();
+
+ // get email address from From: header
+ $from = rcube_mime::decode_address_list($headers['From']);
+ $from = array_shift($from);
+ $from = $from['mailto'];
+
+ foreach ($_SESSION['delegators'] as $uid => $addresses) {
+ if (in_array($from, $addresses)) {
+ $context = $uid;
+ break;
+ }
+ }
+
+ // add Sender: header with current user default identity
+ if ($context) {
+ $identity = $this->rc->user->get_identity();
+ $sender = format_email_recipient($identity['email'], $identity['name']);
+
+ $message->headers(array('Sender' => $sender), false, true);
+ }
+ }
+ }
+
+ /**
* Compares two ACLs (according to supported rights)
*
* @todo: this is stolen from acl plugin, move to rcube_storage/rcube_imap
More information about the commits
mailing list