From e8f8fe9ed3cce2c3fba437c1c8754cdaa78a208b Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 19 Feb 2008 18:59:38 -0500
Subject: [PATCH] Allow to send mail with BCC recipients only + remove some unused vars

---
 CHANGELOG                       |    1 +
 program/steps/mail/sendmail.inc |   26 ++++++++++++++++----------
 program/js/app.js               |    5 ++++-
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c7d1b68..c95d306 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@
 2008/02/20 (thomasb)
 ----------
 - Localize folder name in page title (#1484785)
+- Allow to send mail with BCC recipients only
 
 2008/02/12 (estadtherr)
 ----------
diff --git a/program/js/app.js b/program/js/app.js
index eef6d28..9419d77 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -1695,11 +1695,14 @@
     {
     // check input fields
     var input_to = rcube_find_object('_to');
+    var input_cc = rcube_find_object('_cc');
+    var input_bcc = rcube_find_object('_bcc');
     var input_subject = rcube_find_object('_subject');
     var input_message = rcube_find_object('_message');
 
     // check for empty recipient
-    if (input_to && !rcube_check_email(input_to.value.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
+    var recipients = input_to.value ? input_to.value : (input_cc.value ? input_cc.value : input_bcc.value);
+    if (!rcube_check_email(recipients.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
       {
       alert(this.get_label('norecipientwarning'));
       input_to.focus();
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index ede98e2..21b5b43 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -10,7 +10,7 @@
  |                                                                       |
  | PURPOSE:                                                              |
  |   Compose a new mail message with all headers and attachments         |
- |   and send it using IlohaMail's SMTP methods or with PHP mail()       |
+ |   and send it using the PEAR::Net_SMTP class or with PHP mail()       |
  |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
@@ -129,7 +129,7 @@
 /****** check submission and compose message ********/
 
 
-if (!$savedraft && empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message'])
+if (!$savedraft && empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc']) && empty($_POST['_subject']) && $_POST['_message'])
   {
   $OUTPUT->show_message("sendingfailed", 'error');
   $OUTPUT->send('iframe');
@@ -146,13 +146,19 @@
 
 // replace new lines and strip ending ', '
 $mailto = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset));
+$mailcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
+$mailbcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
 
-// decode address strings
-$to_address_arr = $IMAP->decode_address_list($mailto);
+if (empty($mailto) && !empty($mailcc)) {
+  $mailto = $mailcc;
+  $mailcc = null;
+}
+else if (empty($mailto))
+  $mailto = 'undisclosed-recipients:;';
+
+// get sender name and address
 $identity_arr = rcmail_get_identity(get_input_value('_from', RCUBE_INPUT_POST));
-
 $from = $identity_arr['mailto'];
-$first_to = is_array($to_address_arr[0]) ? $to_address_arr[0]['mailto'] : $mailto;
 
 if (empty($identity_arr['string']))
   $identity_arr['string'] = $from;
@@ -163,11 +169,11 @@
                  'To'   => $mailto);
 
 // additional recipients
-if (!empty($_POST['_cc']))
-  $headers['Cc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
+if (!empty($mailcc))
+  $headers['Cc'] = $mailcc;
 
-if (!empty($_POST['_bcc']))
-  $headers['Bcc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
+if (!empty($mailbcc))
+  $headers['Bcc'] = $mailbcc;
   
 if (!empty($identity_arr['bcc']))
   $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc'];

--
Gitblit v1.9.1