From 969cb03f9a3aa9496da68cff53fedce79acc1071 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 01 May 2013 06:26:23 -0400
Subject: [PATCH] Add option to display email address together with a name in mail preview (#1488732)

---
 CHANGELOG                             |    1 +
 program/steps/mail/func.inc           |   27 ++++++++++++++++++---------
 program/steps/settings/func.inc       |   11 +++++++++++
 program/localization/en_US/labels.inc |    1 +
 config/main.inc.php.dist              |    3 +++
 program/steps/settings/save_prefs.inc |    1 +
 program/localization/en_GB/labels.inc |    1 +
 7 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 41b8493..d3bbf5b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Add option to display email address together with a name in mail preview (#1488732)
 - Fix Reply-To header handling in Reply-All action (#1489037)
 - Fix so Sender: address is added to Cc: field on reply to all (#1489011)
 - Fix so addressbook_search_mode works also for group search (#1489079)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 5a652a5..05afed9 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -890,4 +890,7 @@
 // Georgia, Helvetica, Impact, Tahoma, Terminal, Times New Roman, Trebuchet MS, Verdana
 $rcmail_config['default_font'] = '';
 
+// Enables display of email address with name instead of a name (and address in title)
+$rcmail_config['message_show_email'] = false;
+
 // end of config file
diff --git a/program/localization/en_GB/labels.inc b/program/localization/en_GB/labels.inc
index 8d5509b..581a717 100644
--- a/program/localization/en_GB/labels.inc
+++ b/program/localization/en_GB/labels.inc
@@ -397,6 +397,7 @@
 $labels['signature'] = 'Signature';
 $labels['dstactive']  = 'Summer time';
 $labels['showinextwin'] = 'Open message in a new window';
+$labels['showemail'] = 'Show email address with display name';
 $labels['composeextwin'] = 'Compose in a new window';
 $labels['htmleditor'] = 'Compose HTML messages';
 $labels['htmlonreply'] = 'on reply to HTML message only';
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 3e1bde0..ab57007 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -402,6 +402,7 @@
 $labels['htmlonreply'] = 'on reply to HTML message';
 $labels['htmlonreplyandforward'] = 'on forward or reply to HTML message';
 $labels['htmlsignature'] = 'HTML signature';
+$labels['showemail'] = 'Show email address with display name';
 $labels['previewpane'] = 'Show preview pane';
 $labels['skin'] = 'Interface skin';
 $labels['logoutclear'] = 'Clear Trash on logout';
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 60db3f3..f00813e 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1440,7 +1440,8 @@
   $c = count($a_parts);
   $j = 0;
   $out = '';
-  $allvalues = array();
+  $allvalues  = array();
+  $show_email = $RCMAIL->config->get('message_show_email');
 
   if ($addicon && !isset($_SESSION['writeable_abook'])) {
     $_SESSION['writeable_abook'] = $RCMAIL->get_address_sources(true) ? true : false;
@@ -1453,7 +1454,7 @@
     $string = $part['string'];
 
     // phishing email prevention (#1488981), e.g. "valid@email.addr <phishing@email.addr>"
-    if ($name && $name != $mailto && strpos($name, '@')) {
+    if (!$show_email && $name && $name != $mailto && strpos($name, '@')) {
       $name = '';
     }
 
@@ -1471,13 +1472,21 @@
     }
     else if (check_email($part['mailto'], false)) {
       if ($linked) {
-        $address = html::a(array(
-            'href' => 'mailto:'.$mailto,
-            'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($mailto)),
-            'title' => $mailto,
-            'class' => "rcmContactAddress",
-          ),
-        Q($name ? $name : $mailto));
+        $attrs = array(
+           'href' => 'mailto:' . $mailto,
+           'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($mailto)),
+           'class' => "rcmContactAddress",
+        );
+
+        if ($show_email && $name && $mailto) {
+          $content = Q($name ? sprintf('%s <%s>', $name, $mailto) : $mailto);
+        }
+        else {
+          $content = Q($name ? $name : $mailto);
+          $attrs['title'] = $mailto;
+        }
+
+        $address = html::a($attrs, $content);
       }
       else {
         $address = html::span(array('title' => $mailto, 'class' => "rcmContactAddress"),
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index 319c58d..860f36c 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -418,6 +418,17 @@
       );
     }
 
+    // show checkbox to show email instead of name
+    if (!isset($no_override['message_show_email'])) {
+      $field_id = 'rcmfd_message_show_email';
+      $input_msgshowemail = new html_checkbox(array('name' => '_message_show_email', 'id' => $field_id, 'value' => 1));
+
+      $blocks['main']['options']['message_show_email'] = array(
+        'title' => html::label($field_id, Q(rcube_label('showemail'))),
+        'content' => $input_msgshowemail->show($config['message_show_email']?1:0),
+      );
+    }
+
     // show checkbox for HTML/plaintext messages
     if (!isset($no_override['prefer_html'])) {
       $field_id = 'rcmfd_htmlmsg';
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index dfb2b13..3bb82aa 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -60,6 +60,7 @@
   case 'mailview':
     $a_user_prefs = array(
       'message_extwin'  => intval($_POST['_message_extwin']),
+      'message_show_email' => isset($_POST['_message_show_email']) ? TRUE : FALSE,
       'prefer_html'     => isset($_POST['_prefer_html']) ? TRUE : FALSE,
       'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
       'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,

--
Gitblit v1.9.1