From b825f86108a91957f6467176e418cfc257874658 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 4 Aug 2013 10:41:02 +0200 Subject: Move identity selection based on non-standard headers into (new) identity_select plugin (#1488553) --- CHANGELOG | 1 + plugins/identity_select/identity_select.php | 68 ++++++++++++++++++++++++ plugins/identity_select/package.xml | 53 ++++++++++++++++++ plugins/identity_select/tests/IdentitySelect.php | 22 ++++++++ program/lib/Roundcube/rcube_storage.php | 2 - program/steps/mail/func.inc | 24 ++------- 6 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 plugins/identity_select/identity_select.php create mode 100644 plugins/identity_select/package.xml create mode 100644 plugins/identity_select/tests/IdentitySelect.php diff --git a/CHANGELOG b/CHANGELOG index ead4a7385..6a30ad772 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Move identity selection based on non-standard headers into (new) identity_select plugin (#1488553) - Fix colorspace issue on image conversion using ImageMagick (#1489270) - Fix XSS vulnerability when editing a message "as new" or draft (#1489251) - Fix downloading binary files with (wrong) text/* content-type (#1489267) diff --git a/plugins/identity_select/identity_select.php b/plugins/identity_select/identity_select.php new file mode 100644 index 000000000..203776725 --- /dev/null +++ b/plugins/identity_select/identity_select.php @@ -0,0 +1,68 @@ + + * @license GNU GPLv3+ + */ +class identity_select extends rcube_plugin +{ + public $task = 'mail'; + + + function init() + { + $this->add_hook('identity_select', array($this, 'select')); + $this->add_hook('storage_init', array($this, 'storage_init')); + } + + /** + * Adds additional headers to supported headers list + */ + function storage_init($p) + { + $rcmail = rcmail::get_instance(); + + if ($add_headers = (array)$rcmail->config->get('identity_select_headers', array())) { + $p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper(join(' ', $add_headers))); + } + + return $p; + } + + /** + * Identity selection + */ + function select($p) + { + if ($p['selected'] !== null) { + return $p; + } + + $rcmail = rcmail::get_instance(); + + foreach ((array)$rcmail->config->get('identity_select_headers', array()) as $header) { + if ($header = $p['message']->headers->get($header, false)) { + foreach ($p['identities'] as $idx => $ident) { + if (in_array($ident['email_ascii'], (array)$header)) { + $p['selected'] = $idx; + break 2; + } + } + } + } + + return $p; + } +} diff --git a/plugins/identity_select/package.xml b/plugins/identity_select/package.xml new file mode 100644 index 000000000..425c28830 --- /dev/null +++ b/plugins/identity_select/package.xml @@ -0,0 +1,53 @@ + + + identity_select + pear.roundcube.net + Extended identity selection + + On reply to a message user identity selection is based on + content of standard headers like From, To, Cc and Return-Path. + Here you can add header(s) set by your SMTP server (e.g. + Delivered-To, Envelope-To, X-Envelope-To, X-RCPT-TO) to make + identity selection more accurate. + + + Aleksander Machniak + alec + alec@alec.pl + yes + + 2013-08-04 + + 1.0 + 1.0 + + + stable + stable + + GNU GPLv3+ + - + + + + + + + + + + + + + 5.2.1 + + + 1.7.0 + + + + + diff --git a/plugins/identity_select/tests/IdentitySelect.php b/plugins/identity_select/tests/IdentitySelect.php new file mode 100644 index 000000000..3d7269711 --- /dev/null +++ b/plugins/identity_select/tests/IdentitySelect.php @@ -0,0 +1,22 @@ +api); + + $this->assertInstanceOf('identity_select', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} diff --git a/program/lib/Roundcube/rcube_storage.php b/program/lib/Roundcube/rcube_storage.php index 4b336f210..de8334551 100644 --- a/program/lib/Roundcube/rcube_storage.php +++ b/program/lib/Roundcube/rcube_storage.php @@ -61,8 +61,6 @@ abstract class rcube_storage 'MAIL-FOLLOWUP-TO', 'MAIL-REPLY-TO', 'RETURN-PATH', - 'DELIVERED-TO', - 'ENVELOPE-TO', ); const UNKNOWN = 0; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index cf3a791d8..e14d25ee3 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1798,27 +1798,13 @@ function rcmail_identity_select($MESSAGE, $identities = null, $compose_mode = 'r } } - // Fallback using Delivered-To - if ($from_idx === null && ($delivered_to = $MESSAGE->headers->others['delivered-to'])) { - foreach ($identities as $idx => $ident) { - if (in_array($ident['email_ascii'], (array)$delivered_to)) { - $from_idx = $idx; - break; - } - } - } + // See identity_select plugin for example usage of this hook + $plugin = rcmail::get_instance()->plugins->exec_hook('identity_select', + array('message' => $MESSAGE, 'identities' => $identities, 'selected' => $from_idx)); - // Fallback using Envelope-To - if ($from_idx === null && ($envelope_to = $MESSAGE->headers->others['envelope-to'])) { - foreach ($identities as $idx => $ident) { - if (in_array($ident['email_ascii'], (array)$envelope_to)) { - $from_idx = $idx; - break; - } - } - } + $selected = $plugin['selected']; - return $identities[$from_idx !== null ? $from_idx : $default_identity]; + return $identities[$selected !== null ? $selected : $default_identity]; } // Fixes some content-type names -- cgit v1.2.3