identity_select: Support Received header (#5085)

pull/5507/head
Aleksander Machniak 8 years ago
parent 485c50a5f3
commit 059dc8b635

@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- identity_select: Support Received header (#5085)
- Plugin API: Added get_compose_responses hook (#5457)
- Display error when trying to upload more files than specified in max_file_uploads (#5483)
- Add missing sql upgrade file for 'ip' column resize in session table (#5465)

@ -3,7 +3,7 @@
"type": "roundcube-plugin",
"description": "On reply to a message user identity selection is based on\n\t\tcontent of standard headers like From, To, Cc and Return-Path.\n\t\tHere you can add header(s) set by your SMTP server (e.g.\n\t\tDelivered-To, Envelope-To, X-Envelope-To, X-RCPT-TO) to make\n\t\tidentity selection more accurate.",
"license": "GPLv3+",
"version": "1.0",
"version": "1.1",
"authors": [
{
"name": "Aleksander Machniak",

@ -12,6 +12,10 @@
* Enable the plugin in config.inc.php and add your desired headers:
* $config['identity_select_headers'] = array('Delivered-To');
*
* Note: 'Received' header is also supported, but has bigger impact
* on performance, as it's body is potentially much bigger
* than other headers used by Roundcube
*
* @author Aleksander Machniak <alec@alec.pl>
* @license GNU GPLv3+
*/
@ -52,9 +56,9 @@ class identity_select extends rcube_plugin
$rcmail = rcmail::get_instance();
foreach ((array)$rcmail->config->get('identity_select_headers', array()) as $header) {
if ($header = $p['message']->headers->get($header, false)) {
if ($emails = $this->get_email_from_header($p['message'], $header)) {
foreach ($p['identities'] as $idx => $ident) {
if (in_array($ident['email_ascii'], (array)$header)) {
if (in_array($ident['email_ascii'], $emails)) {
$p['selected'] = $idx;
break 2;
}
@ -64,4 +68,27 @@ class identity_select extends rcube_plugin
return $p;
}
/**
* Extract email address from specified message header
*/
protected function get_email_from_header($message, $header)
{
$value = $message->headers->get($header, false);
if (strtolower($header) == 'received') {
// find first email address in all Received headers
$email = null;
foreach ((array) $value as $entry) {
if (preg_match('/[\s\t]+for[\s\t]+<([^>]+)>/', $entry, $matches)) {
$email = $matches[1];
break;
}
}
$value = $email;
}
return (array) $value;
}
}

Loading…
Cancel
Save