From 0592805b0e858160b431035f9c2c4cd76e319e11 Mon Sep 17 00:00:00 2001
From: Ziba Scott <ziba@umich.edu>
Date: Mon, 5 Oct 2009 15:15:46 -0400
Subject: [PATCH] Core patch: Move identity implications in compose/reply to client side

---
 program/js/app.js               |   38 +++++++++++++++++++++++++++++++++++++-
 program/steps/mail/compose.inc  |    6 ++++++
 program/steps/mail/sendmail.inc |    8 +-------
 3 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index d416171..38726cd 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -2304,9 +2304,45 @@ function rcube_webmail()
     var is_html = ($("input[name='_is_html']").val() == '1');
     var sig, p, len;
 
+    var last_bcc = ""; 
+    var last_replyto = ""; 
+
+    if(this.env.identity){ 
+        last_bcc = this.env.identities[this.env.identity]['bcc']; 
+        last_replyto = this.env.identities[this.env.identity]['reply-to']; 
+    } 
+
     if (!this.env.identity)
       this.env.identity = id
-  
+
+    // Populate the bcc 
+    var input_bcc = rcube_find_object('_bcc'); 
+
+    // Don't change it if the user has edited the field 
+    if(input_bcc.value == last_bcc){ 
+        input_bcc.value = this.env.identities[id]['bcc']; 
+    } 
+
+    // Expand the field if used 
+    if(this.env.identities[id]['bcc']){ 
+        rcmail_show_header_form('bcc', rcube_find_object('addbcclink')); 
+    } 
+
+    // Populate the replyto 
+    var input_replyto = rcube_find_object('_replyto'); 
+
+    // Don't change it if the user has edited the field 
+    if(input_replyto.value == last_replyto){ 
+        input_replyto.value = this.env.identities[id]['reply-to']; 
+    } 
+
+    // Expand the field if used 
+    if(this.env.identities[id]['reply-to']){ 
+        rcmail_show_header_form('replyto', rcube_find_object('addreplytolink')); 
+    } 
+
+
+
     if (!is_html)
       {
       // remove the 'old' signature
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index c894da7..ce8d7f4 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -357,8 +357,14 @@ function rcmail_compose_header_from($attrib)
         else if (in_array(mb_strtolower($sql_arr['email']), $a_recipients) && (empty($from_id) || $sql_arr['standard']))
           $from_id = $sql_arr['identity_id'];
       }
+
+      // Collect identities for export to the client scripting env
+      $identities[$identity_id] = $sql_arr;
     }
 
+    // add identities to client 
+    $OUTPUT->set_env('identities', $identities); 
+
     // overwrite identity selection with post parameter
     if (!empty($_POST['_from']))
       $from_id = get_input_value('_from', RCUBE_INPUT_POST);
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index e8ef47a..4c85341 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -218,8 +218,7 @@ $identity_arr = rcmail_get_identity($from);
 if (!$identity_arr && ($from = rcmail_email_input_format($from))) {
   if (preg_match('/(\S+@\S+)/', $from, $m))
     $identity_arr['mailto'] = $m[1];
-} else
-  $from = $identity_arr['mailto'];
+}
 
 if (empty($identity_arr['string']))
   $identity_arr['string'] = $from;
@@ -279,9 +278,6 @@ if (!empty($mailcc))
 if (!empty($mailbcc))
   $headers['Bcc'] = $mailbcc;
   
-if (!empty($identity_arr['bcc']))
-  $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc'];
-
 // add subject
 $headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, TRUE, $message_charset));
 
@@ -290,8 +286,6 @@ if (!empty($identity_arr['organization']))
 
 if (!empty($_POST['_replyto']))
   $headers['Reply-To'] = rcmail_email_input_format(get_input_value('_replyto', RCUBE_INPUT_POST, TRUE, $message_charset));
-else if (!empty($identity_arr['reply-to']))
-  $headers['Reply-To'] = $identity_arr['reply-to'];
 
 if (!empty($_SESSION['compose']['reply_msgid']))
   $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid'];
-- 
1.5.6

