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) --- plugins/identity_select/identity_select.php | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 plugins/identity_select/identity_select.php (limited to 'plugins/identity_select/identity_select.php') 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; + } +} -- cgit v1.2.3