From 62e43d2c1a61d26f9a07419f7155a2881cb57332 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sat, 14 Jun 2008 13:35:26 -0400
Subject: [PATCH] Complete implementation of #1484601: add link for saving sender to address book and reload message

---
 program/localization/de_DE/labels.inc |    1 
 skins/default/mail.css                |    5 +-
 program/localization/en_US/labels.inc |    1 
 program/steps/mail/show.inc           |   49 ++++++++++--------------
 program/localization/de_CH/labels.inc |    1 
 program/include/rcube_message.php     |    6 ++-
 program/js/app.js                     |    9 ++++
 7 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/program/include/rcube_message.php b/program/include/rcube_message.php
index d810ef3..6654c3f 100644
--- a/program/include/rcube_message.php
+++ b/program/include/rcube_message.php
@@ -42,6 +42,7 @@
   public $mime_parts = array();
   public $attachments = array();
   public $subject = '';
+  public $sender = null;
   public $is_safe = false;
   
   
@@ -53,9 +54,10 @@
     $this->uid = $uid;
     $this->headers = $this->imap->get_headers($uid);
     $this->subject = rcube_imap::decode_mime_string($this->headers->subject, $this->headers->charset);
+    list(, $this->sender) = each($this->imap->decode_address_list($this->headers->from));
     
-    $this->is_safe = (intval($_GET['_safe']) || $_SESSION['safe_messages'][$uid]) ? true : false;
-    $_SESSION['safe_messages'][$uid] = $this->is_safe;
+    $this->set_safe((intval($_GET['_safe']) || $_SESSION['safe_messages'][$uid]));
+    $this->set_safe(0);
     
     $this->opt = array(
       'safe' => $this->is_safe,
diff --git a/program/js/app.js b/program/js/app.js
index 667b9fb..e04da55 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -185,7 +185,7 @@
           {
           if (this.gui_objects.remoteobjectsmsg)
             this.gui_objects.remoteobjectsmsg.style.display = 'block';
-          this.enable_command('load-images', true);
+          this.enable_command('load-images', 'always-load', true);
           }
 
         if (this.env.action=='compose')
@@ -705,6 +705,13 @@
         this.mark_message(flag, uid);
         break;
         
+      case 'always-load':
+        if (this.env.uid && this.env.sender) {
+          this.add_contact(urlencode(this.env.sender));
+          window.setTimeout(function(){ ref.command('load-images'); }, 300);
+          break;
+        }
+        
       case 'load-images':
         if (this.env.uid)
           this.show_message(this.env.uid, true, this.env.action=='preview');
diff --git a/program/localization/de_CH/labels.inc b/program/localization/de_CH/labels.inc
index 79b0c5d..3851a9f 100644
--- a/program/localization/de_CH/labels.inc
+++ b/program/localization/de_CH/labels.inc
@@ -184,6 +184,7 @@
 
 $labels['nosubject']  = '(kein Betreff)';
 $labels['showimages'] = 'Bilder anzeigen';
+$labels['alwaysshow'] = 'Bilder von $sender immer zeigen';
 
 $labels['htmltoggle'] = 'HTML';
 $labels['plaintoggle'] = 'Klartext';
diff --git a/program/localization/de_DE/labels.inc b/program/localization/de_DE/labels.inc
index 8565993..8a13f12 100644
--- a/program/localization/de_DE/labels.inc
+++ b/program/localization/de_DE/labels.inc
@@ -146,6 +146,7 @@
 $labels['highest'] = 'Höchste';
 $labels['nosubject'] = '(kein Betreff)';
 $labels['showimages'] = 'Bilder anzeigen';
+$labels['alwaysshow'] = 'Bilder von $sender immer zeigen';
 $labels['htmltoggle'] = 'HTML';
 $labels['plaintoggle'] = 'Nur-Text';
 $labels['addcc'] = 'Cc hinzufügen';
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 6eae419..4dfdb63 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -184,6 +184,7 @@
 
 $labels['nosubject']  = '(no subject)';
 $labels['showimages'] = 'Display images';
+$labels['alwaysshow'] = 'Always show images from $sender';
 
 $labels['htmltoggle'] = 'HTML';
 $labels['plaintoggle'] = 'Plain text';
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index ed44edd..8b6ce58 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -47,21 +47,15 @@
 
   // check known senders to display images
   if (!$MESSAGE->is_safe 
-	&& !$_SESSION['safe_messages'][$MESSAGE->uid]
-	&& !isset($_GET['_safe']) 
-	&& $RCMAIL->config->get('addrbook_show_images')
-	&& $MESSAGE->has_html_part())
-    {
-      $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
-      $senders = $IMAP->decode_address_list($MESSAGE->headers->from);
-
-      foreach ($senders as $sender)
-        if ($sender['mailto'] && $CONTACTS->search('email', $sender['mailto'], true, false)->count)
-	  {
-	  $MESSAGE->set_safe();
-	  break;
-	  }
+      && !empty($MESSAGE->sender['mailto'])
+      && $RCMAIL->config->get('addrbook_show_images')
+      && $MESSAGE->has_html_part()) {
+    $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
+    
+    if ($CONTACTS->search('email', $MESSAGE->sender['mailto'], true, false)->count) {
+      $MESSAGE->set_safe(true);
     }
+  }
 
   // allow caching, unless remote images are present
   if ((bool)$MESSAGE->is_safe)
@@ -85,6 +79,7 @@
   // give message uid to the client
   $OUTPUT->set_env('uid', $MESSAGE->uid);
   $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
+  $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
   
   // check for unset disposition notification
   if ($MESSAGE->headers->mdn_to && !$MESSAGE->headers->mdn_sent &&
@@ -174,26 +169,24 @@
 
 
 function rcmail_remote_objects_msg($attrib)
-  {
-  global $CONFIG, $OUTPUT;
+{
+  global $MESSAGE, $RCMAIL;
   
   if (!$attrib['id'])
     $attrib['id'] = 'rcmremoteobjmsg';
-
-  // allow the following attributes to be added to the <div> tag
-  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
-  $out = '<div' . $attrib_str . ">";
   
-  $out .= sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>',
-                  Q(rcube_label('blockedimages')),
-                  JS_OBJECT_NAME,
-                  Q(rcube_label('showimages')));
+  $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
+  $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
   
-  $out .= '</div>';
-  
-  $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']);
-  return $out;
+  // add link to save sender in addressbook and reload message
+  if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('addrbook_show_images')) {
+    $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
+      Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
   }
+  
+  $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
+  return html::div($attrib, $msg);
+}
 
 
 $OUTPUT->add_handlers(array(
diff --git a/skins/default/mail.css b/skins/default/mail.css
index 9f0dc27..2110d96 100644
--- a/skins/default/mail.css
+++ b/skins/default/mail.css
@@ -730,10 +730,9 @@
 #remote-objects-message
 {
   display: none;
-  height: 20px;
+  margin: 8px;
   min-height: 20px;
-  margin: 8px 8px 0px 8px;
-  padding: 10px 10px 6px 46px;  
+  padding: 10px 10px 6px 46px;
 }
 
 #remote-objects-message a

--
Gitblit v1.9.1