From e04e3144407b7a863999d8aeaf6c3a653219359f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 24 Oct 2012 06:24:37 -0400
Subject: [PATCH] Add option to disable saving sent mail in Sent folder - no_save_sent_messages (#1488686)

---
 CHANGELOG                            |    1 +
 program/steps/mail/compose.inc       |    5 +++++
 skins/classic/templates/compose.html |    4 ++--
 config/main.inc.php.dist             |   10 +++++++---
 program/steps/mail/sendmail.inc      |   11 +++++------
 skins/larry/templates/compose.html   |    2 ++
 6 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index d9707f8..ff33fd9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Add option to disable saving sent mail in Sent folder - no_save_sent_messages (#1488686)
 - Fix handling dont_override with message_sort_col and message_sort_order settings (#1488760)
 - Fix HTML part detection in messages with attachments (#1488769)
 - Fix bug where wrong words were highlighted on spell-before-send check
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 371ccaf..018cea6 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -182,6 +182,9 @@
 // ONLY ENABLE IT IF YOU'RE REALLY SURE WHAT YOU'RE DOING!
 $rcmail_config['enable_installer'] = false;
 
+// don't allow these settings to be overriden by the user
+$rcmail_config['dont_override'] = array();
+
 // provide an URL where a user can get support for this Roundcube installation
 // PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
 $rcmail_config['support_url'] = '';
@@ -349,9 +352,6 @@
 // send plaintext messages as format=flowed
 $rcmail_config['send_format_flowed'] = true;
 
-// don't allow these settings to be overriden by the user
-$rcmail_config['dont_override'] = array();
-
 // Set identities access level:
 // 0 - many identities with possibility to edit all params
 // 1 - many identities with possibility to edit all params but not email address
@@ -379,6 +379,10 @@
 // Enable DNS checking for e-mail address validation
 $rcmail_config['email_dns_check'] = false;
 
+// Disables saving sent messages in Sent folder (like gmail) (Default: false)
+// Note: useful when SMTP server stores sent mail in user mailbox
+$rcmail_config['no_save_sent_messages'] = false;
+
 // ----------------------------------
 // PLUGINS
 // ----------------------------------
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 691eca2..7ac9a8d 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -1528,6 +1528,11 @@
 {
   global $RCMAIL;
 
+  // we'll not save the message, so it doesn't matter
+  if ($RCMAIL->config->get('no_save_sent_messages')) {
+    return true;
+  }
+
   if ($RCMAIL->storage->folder_exists($folder, true)) {
     return true;
   }
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 9fe5107..4fac872 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -49,7 +49,7 @@
 
   if(!empty($CONFIG['sendmail_delay'])) {
     $wait_sec = time() - intval($CONFIG['sendmail_delay']) - intval($CONFIG['last_message_time']);
-    if($wait_sec < 0) {
+    if ($wait_sec < 0) {
       $OUTPUT->show_message('senttooquickly', 'error', array('sec' => $wait_sec * -1));
       $OUTPUT->send('iframe');
     }
@@ -676,19 +676,18 @@
     $smtp_error, $mailbody_file, $smtp_opts);
 
   // return to compose page if sending failed
-  if (!$sent)
-    {
+  if (!$sent) {
     // remove temp file
     if ($mailbody_file) {
       unlink($mailbody_file);
-      }
+    }
 
     if ($smtp_error)
       $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']); 
     else
       $OUTPUT->show_message('sendingfailed', 'error'); 
     $OUTPUT->send('iframe');
-    }
+  }
 
   // save message sent time
   if (!empty($CONFIG['sendmail_delay']))
@@ -706,7 +705,7 @@
 // Determine which folder to save message
 if ($savedraft)
   $store_target = $CONFIG['drafts_mbox'];
-else
+else if (!$RCMAIL->config->get('no_save_sent_messages'))
   $store_target = isset($_POST['_store_target']) ? get_input_value('_store_target', RCUBE_INPUT_POST) : $CONFIG['sent_mbox'];
 
 if ($store_target) {
diff --git a/skins/classic/templates/compose.html b/skins/classic/templates/compose.html
index 1e1403e..23998ee 100644
--- a/skins/classic/templates/compose.html
+++ b/skins/classic/templates/compose.html
@@ -143,10 +143,10 @@
     </tr><tr>
         <td><label for="rcmcomposepriority"><roundcube:label name="priority" />:</label></td>
         <td><roundcube:object name="prioritySelector" form="form" id="rcmcomposepriority" /></td>
-    </tr><tr>
+    </tr><roundcube:if condition="!config:no_save_sent_messages" /><tr>
         <td><label><roundcube:label name="savesentmessagein" />:</label></td>
         <td><roundcube:object name="storetarget" maxlength="30" /></td>
-    </tr>
+    </tr><roundcube:endif />
     </table>
 </div>
 
diff --git a/skins/larry/templates/compose.html b/skins/larry/templates/compose.html
index d29c1bd..ef49ece 100644
--- a/skins/larry/templates/compose.html
+++ b/skins/larry/templates/compose.html
@@ -140,9 +140,11 @@
 		<span class="composeoption">
 			<label><roundcube:object name="dsnCheckBox" form="form" id="rcmcomposedsn" /> <roundcube:label name="dsn" /></label>
 		</span>
+                <roundcube:if condition="!config:no_save_sent_messages" />
 		<span class="composeoption">
 			<label><roundcube:label name="savesentmessagein" /> <roundcube:object name="storetarget" maxlength="30" style="max-width:12em" /></label>
 		</span>
+                <roundcube:endif />
 		<roundcube:container name="composeoptions" id="composeoptions" />
 	</div>
 </div>

--
Gitblit v1.9.1