commit | author | age
|
b825f8
|
1 |
<?php |
AM |
2 |
|
|
3 |
/** |
|
4 |
* Identity selection based on additional message headers. |
|
5 |
* |
|
6 |
* On reply to a message user identity selection is based on |
|
7 |
* content of standard headers i.e. From, To, Cc and Return-Path. |
|
8 |
* Here you can add header(s) set by your SMTP server (e.g. |
|
9 |
* Delivered-To, Envelope-To, X-Envelope-To, X-RCPT-TO) to make |
|
10 |
* identity selection more accurate. |
|
11 |
* |
|
12 |
* Enable the plugin in config.inc.php and add your desired headers: |
bcedf0
|
13 |
* $config['identity_select_headers'] = array('Delivered-To'); |
b825f8
|
14 |
* |
AM |
15 |
* @version @package_version@ |
|
16 |
* @author Aleksander Machniak <alec@alec.pl> |
|
17 |
* @license GNU GPLv3+ |
|
18 |
*/ |
|
19 |
class identity_select extends rcube_plugin |
|
20 |
{ |
|
21 |
public $task = 'mail'; |
|
22 |
|
|
23 |
|
|
24 |
function init() |
|
25 |
{ |
|
26 |
$this->add_hook('identity_select', array($this, 'select')); |
|
27 |
$this->add_hook('storage_init', array($this, 'storage_init')); |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* Adds additional headers to supported headers list |
|
32 |
*/ |
|
33 |
function storage_init($p) |
|
34 |
{ |
|
35 |
$rcmail = rcmail::get_instance(); |
|
36 |
|
|
37 |
if ($add_headers = (array)$rcmail->config->get('identity_select_headers', array())) { |
|
38 |
$p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper(join(' ', $add_headers))); |
|
39 |
} |
|
40 |
|
|
41 |
return $p; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Identity selection |
|
46 |
*/ |
|
47 |
function select($p) |
|
48 |
{ |
130507
|
49 |
if ($p['selected'] !== null || !is_object($p['message']->headers)) { |
b825f8
|
50 |
return $p; |
AM |
51 |
} |
|
52 |
|
|
53 |
$rcmail = rcmail::get_instance(); |
|
54 |
|
|
55 |
foreach ((array)$rcmail->config->get('identity_select_headers', array()) as $header) { |
|
56 |
if ($header = $p['message']->headers->get($header, false)) { |
|
57 |
foreach ($p['identities'] as $idx => $ident) { |
|
58 |
if (in_array($ident['email_ascii'], (array)$header)) { |
|
59 |
$p['selected'] = $idx; |
|
60 |
break 2; |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
return $p; |
|
67 |
} |
|
68 |
} |