From f798aa098a52e1fb7d9c8d0e91b072f74e677d6b Mon Sep 17 00:00:00 2001
From: Falko Timme <ft@falkotimme.com>
Date: Wed, 12 Feb 2014 16:10:10 +0100
Subject: [PATCH] - Implemented FS#3310 - add support for multiple email
 addresses in send copy to field (patch).

---
 interface/lib/classes/tform.inc.php                     | 2 +-
 interface/web/mail/form/mail_user.tform.php             | 2 +-
 interface/web/mail/lib/lang/de_mail_user.lng            | 1 +
 interface/web/mail/lib/lang/en_mail_user.lng            | 1 +
 interface/web/mail/templates/mail_user_mailbox_edit.htm | 2 +-
 interface/web/mailuser/form/mail_user_cc.tform.php      | 3 ++-
 interface/web/mailuser/lib/lang/de_mail_user_cc.lng     | 2 ++
 interface/web/mailuser/lib/lang/en_mail_user_cc.lng     | 2 ++
 interface/web/mailuser/mail_user_spamfilter_edit.php    | 3 ++-
 interface/web/mailuser/templates/mail_user_cc_edit.htm  | 2 +-
 server/conf/sieve_filter.master                         | 4 +++-
 server/conf/sieve_filter_1.2.master                     | 4 +++-
 server/plugins-available/maildeliver_plugin.inc.php     | 7 +++++++
 server/plugins-available/maildrop_plugin.inc.php        | 6 +++++-
 14 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index 26040368fe..5fc06279bc 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -1302,7 +1302,7 @@ class tform {
 		$perm = $app->db->quote($perm);
 		$table = $app->db->quote($table);
 		
-		if($_SESSION["s"]["user"]["typ"] == 'admin') {
+		if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
 			return '1';
 		} else {
 			if ($table != ''){
diff --git a/interface/web/mail/form/mail_user.tform.php b/interface/web/mail/form/mail_user.tform.php
index b6f8dfa093..66bc8e3c21 100644
--- a/interface/web/mail/form/mail_user.tform.php
+++ b/interface/web/mail/form/mail_user.tform.php
@@ -160,7 +160,7 @@ $form["tabs"]['mailuser'] = array(
 					'type' => 'TOLOWER')
 			),
 			'validators' => array (  0 => array ( 'type' => 'REGEX',
-					'regex' => '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,1}$/i',
+					'regex' => '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,1}(,\s*\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,}$/i',
 					'errmsg'=> 'cc_error_isemail'),
 			),
 			'default' => '',
diff --git a/interface/web/mail/lib/lang/de_mail_user.lng b/interface/web/mail/lib/lang/de_mail_user.lng
index b5bdc598b4..cd8928ad81 100644
--- a/interface/web/mail/lib/lang/de_mail_user.lng
+++ b/interface/web/mail/lib/lang/de_mail_user.lng
@@ -48,4 +48,5 @@ $wb['repeat_password_txt'] = 'Passwort wiederholen';
 $wb['password_mismatch_txt'] = 'Die Passwörter stimmen nicht überein.';
 $wb['password_match_txt'] = 'Die Passwörter stimmen überein.';
 $wb['email_error_isascii'] = 'Bitte verwenden Sie keine Umlaute im Passwort. Dies kann zu Problemen mit Ihrem E-Mail-Programm führen.';
+$wb['cc_note_txt'] = '(Mehrere E-Mail-Adressen mit Kommas trennen)';
 ?>
\ No newline at end of file
diff --git a/interface/web/mail/lib/lang/en_mail_user.lng b/interface/web/mail/lib/lang/en_mail_user.lng
index 81301db352..7c80c76638 100644
--- a/interface/web/mail/lib/lang/en_mail_user.lng
+++ b/interface/web/mail/lib/lang/en_mail_user.lng
@@ -48,4 +48,5 @@ $wb['repeat_password_txt'] = 'Repeat Password';
 $wb['password_mismatch_txt'] = 'The passwords do not match.';
 $wb['password_match_txt'] = 'The passwords do match.';
 $wb['email_error_isascii'] = 'Please do not use special unicode characters for your password. This could lead to problems with your mail client.';
+$wb['cc_note_txt'] = '(Separate multiple email addresses with commas)';
 ?>
diff --git a/interface/web/mail/templates/mail_user_mailbox_edit.htm b/interface/web/mail/templates/mail_user_mailbox_edit.htm
index 0460bc6983..f946502dbd 100644
--- a/interface/web/mail/templates/mail_user_mailbox_edit.htm
+++ b/interface/web/mail/templates/mail_user_mailbox_edit.htm
@@ -42,7 +42,7 @@
             </div>
             <div class="ctrlHolder">
                 <label for="name">{tmpl_var name='cc_txt'}</label>
-                <input name="cc" id="cc" value="{tmpl_var name='cc'}" size="30" maxlength="255" type="text" class="textInput" /> &nbsp; {tmpl_var name='name_optional_txt'}
+                <input name="cc" id="cc" value="{tmpl_var name='cc'}" size="30" maxlength="255" type="text" class="textInput" /> &nbsp; {tmpl_var name='name_optional_txt'} {tmpl_var name='cc_note_txt'}
             </div>
             <div class="ctrlHolder">
                 <label for="policy">{tmpl_var name='policy_txt'}</label>
diff --git a/interface/web/mailuser/form/mail_user_cc.tform.php b/interface/web/mailuser/form/mail_user_cc.tform.php
index 6458bb730a..5f1d9ef7a9 100644
--- a/interface/web/mailuser/form/mail_user_cc.tform.php
+++ b/interface/web/mailuser/form/mail_user_cc.tform.php
@@ -69,7 +69,8 @@ $form["tabs"]['mailuser'] = array (
 					'type' => 'TOLOWER')
 			),
 			'validators' => array (  0 => array ( 'type' => 'REGEX',
-					'regex' => '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\w+\.[a-z\-]{2,10}){0,1}$/i',
+					//'regex' => '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\w+\.[a-z\-]{2,10}){0,1}$/i',
+					'regex' => '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,1}(,\s*\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,}$/i',
 					'errmsg'=> 'cc_error_isemail'),
 			),
 			'default' => '',
diff --git a/interface/web/mailuser/lib/lang/de_mail_user_cc.lng b/interface/web/mailuser/lib/lang/de_mail_user_cc.lng
index f39785ba8f..cfb1ab3ca5 100644
--- a/interface/web/mailuser/lib/lang/de_mail_user_cc.lng
+++ b/interface/web/mailuser/lib/lang/de_mail_user_cc.lng
@@ -4,4 +4,6 @@ $wb['cc_txt'] = 'Kopie senden an';
 $wb['email_txt'] = 'E-Mail';
 $wb['cc_error_isemail'] = 'E-Mail Adresse ungültig im -Kopie senden an- Feld';
 $wb['email_is_cc_error'] = 'E-Mail Adresse und ';
+$wb['name_optional_txt'] = '(optional)';
+$wb['cc_note_txt'] = '(Mehrere E-Mail-Adressen mit Kommas trennen)';
 ?>
\ No newline at end of file
diff --git a/interface/web/mailuser/lib/lang/en_mail_user_cc.lng b/interface/web/mailuser/lib/lang/en_mail_user_cc.lng
index 0073c71647..3437d50d19 100644
--- a/interface/web/mailuser/lib/lang/en_mail_user_cc.lng
+++ b/interface/web/mailuser/lib/lang/en_mail_user_cc.lng
@@ -4,4 +4,6 @@ $wb["cc_txt"] = 'Send copy to';
 $wb["email_txt"] = 'Email';
 $wb["cc_error_isemail"] = 'Email address invalid in -Send copy to- field';
 $wb["email_is_cc_error"] = 'Email address and send copy to address can not be the same.';
+$wb["name_optional_txt"] = '(Optional)';
+$wb['cc_note_txt'] = '(Separate multiple email addresses with commas)';
 ?>
\ No newline at end of file
diff --git a/interface/web/mailuser/mail_user_spamfilter_edit.php b/interface/web/mailuser/mail_user_spamfilter_edit.php
index dfc397dda3..3ea2aa57d5 100644
--- a/interface/web/mailuser/mail_user_spamfilter_edit.php
+++ b/interface/web/mailuser/mail_user_spamfilter_edit.php
@@ -51,7 +51,8 @@ $app->load('tform_actions');
 class page_action extends tform_actions {
 
 	function onShow() {
-
+		global $app;
+		
 		$this->id = $app->functions->intval($_SESSION['s']['user']['mailuser_id']);
 
 		parent::onShow();
diff --git a/interface/web/mailuser/templates/mail_user_cc_edit.htm b/interface/web/mailuser/templates/mail_user_cc_edit.htm
index ba715c89ae..3b82c46479 100644
--- a/interface/web/mailuser/templates/mail_user_cc_edit.htm
+++ b/interface/web/mailuser/templates/mail_user_cc_edit.htm
@@ -11,7 +11,7 @@
             </div>
             <div class="ctrlHolder">
                 <label for="name">{tmpl_var name='cc_txt'}</label>
-                <input name="cc" id="cc" value="{tmpl_var name='cc'}" size="30" maxlength="255" type="text" class="textInput" /> &nbsp; {tmpl_var name='name_optional_txt'}
+                <input name="cc" id="cc" value="{tmpl_var name='cc'}" size="30" maxlength="255" type="text" class="textInput" /> &nbsp; {tmpl_var name='name_optional_txt'} {tmpl_var name='cc_note_txt'}
             </div>
         </fieldset>
 
diff --git a/server/conf/sieve_filter.master b/server/conf/sieve_filter.master
index 09d7fa9431..e161a9f499 100644
--- a/server/conf/sieve_filter.master
+++ b/server/conf/sieve_filter.master
@@ -2,7 +2,9 @@ require ["fileinto", "regex", "vacation"];
 
 <tmpl_if name="cc">
 # Send a copy of email to
-redirect "<tmpl_var name='cc'>";
+<tmpl_loop name="ccloop">
+redirect "<tmpl_var name='address'>";
+</tmpl_loop>
 </tmpl_if>
 
 <tmpl_if name="move_junk" op="==" value="y">
diff --git a/server/conf/sieve_filter_1.2.master b/server/conf/sieve_filter_1.2.master
index a88dc2d600..08473e69c0 100644
--- a/server/conf/sieve_filter_1.2.master
+++ b/server/conf/sieve_filter_1.2.master
@@ -2,7 +2,9 @@ require ["fileinto", "regex", "date", "relational", "vacation"];
 
 <tmpl_if name="cc">
 # Send a copy of email to
-redirect "<tmpl_var name='cc'>";
+<tmpl_loop name="ccloop">
+redirect "<tmpl_var name='address'>";
+</tmpl_loop>
 </tmpl_if>
 
 <tmpl_if name="move_junk" op="==" value="y">
diff --git a/server/plugins-available/maildeliver_plugin.inc.php b/server/plugins-available/maildeliver_plugin.inc.php
index 16e3e73069..e3799d716e 100644
--- a/server/plugins-available/maildeliver_plugin.inc.php
+++ b/server/plugins-available/maildeliver_plugin.inc.php
@@ -120,7 +120,14 @@ class maildeliver_plugin {
 			$tpl->newTemplate($filter_file_template);
 
 			// cc Field
+			$tmp_mails_arr = explode(',',$data["new"]["cc"]);
+			$tmp_addresses_arr = array();
+			foreach($tmp_mails_arr as $address) {
+				if(trim($address) != '') $tmp_addresses_arr[] = array('address' => trim($address));
+			}
+			
 			$tpl->setVar('cc', $data["new"]["cc"]);
+			$tpl->setLoop('ccloop', $tmp_addresses_arr);
 
 			// Custom filters
 			$tpl->setVar('custom_mailfilter', $data["new"]["custom_mailfilter"]);
diff --git a/server/plugins-available/maildrop_plugin.inc.php b/server/plugins-available/maildrop_plugin.inc.php
index 73bace85fe..37b0306080 100644
--- a/server/plugins-available/maildrop_plugin.inc.php
+++ b/server/plugins-available/maildrop_plugin.inc.php
@@ -192,7 +192,11 @@ class maildrop_plugin {
 				$mailfilter_content = '';
 
 				if($data["new"]["cc"] != '') {
-					$mailfilter_content .= "cc \"!".$data["new"]["cc"]."\"\n";
+					$tmp_mails_arr = explode(',',$data["new"]["cc"]);
+					foreach($tmp_mails_arr as $address) {
+						if(trim($address) != '') $mailfilter_content .= "cc \"!".trim($address)."\"\n";
+					}
+					//$mailfilter_content .= "cc \"!".$data["new"]["cc"]."\"\n";
 					$app->log("Added CC address ".$data["new"]["cc"].' to mailfilter file.', LOGLEVEL_DEBUG);
 				}
 
-- 
GitLab