From eaa39477bd53130e68bfb26d63308cc9b6af9369 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 11 Apr 2008 09:34:19 -0400
Subject: [PATCH] #1483863: empty trash and expunge inbox on logout

---
 index.php                             |    1 +
 program/include/main.inc              |   24 ++++++++++++++++++++++++
 program/steps/settings/func.inc       |   22 ++++++++++++++++++++++
 program/localization/en_US/labels.inc |    2 ++
 config/main.inc.php.dist              |    6 ++++++
 program/steps/settings/save_prefs.inc |    4 +++-
 6 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 962fb4e..0cde478 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -283,6 +283,12 @@
 // default setting if preview pane is enabled
 $rcmail_config['preview_pane'] = FALSE;
 
+// Clear Trash on logout
+$rcmail_config['logout_purge'] = FALSE;
+
+// Compact INBOX on logout
+$rcmail_config['logout_expunge'] = FALSE;
+
 // don't let users set pagesize to more than this value if set
 $rcmail_config['max_pagesize'] = 200;
 
diff --git a/index.php b/index.php
index 0687763..e9c1cee 100644
--- a/index.php
+++ b/index.php
@@ -185,6 +185,7 @@
 else if (($_task=='logout' || $_action=='logout') && isset($_SESSION['user_id']))
 {
   $OUTPUT->show_message('loggedout');
+  rcmail_logout_actions();
   rcmail_kill_session();
 }
 
diff --git a/program/include/main.inc b/program/include/main.inc
index 5b82640..649dd25 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -352,6 +352,30 @@
   $USER->reset();
   }
 
+/**
+ * Do server side actions on logout
+ */
+function rcmail_logout_actions()
+  {
+  global $CONFIG, $IMAP;
+
+  // on logout action we're not connected to imap server  
+  if (($CONFIG['logout_purge'] && !empty($CONFIG['trash_mbox'])) 
+      || $CONFIG['logout_expunge'])
+    {
+      if (!rcmail_authenticate_session())
+        return;
+
+      rcmail_imap_init(true);
+    }
+
+  if ($CONFIG['logout_purge'] && !empty($CONFIG['trash_mbox']))
+    $IMAP->clear_mailbox($CONFIG['trash_mbox']);
+
+  if ($CONFIG['logout_expunge'])
+    $IMAP->expunge('INBOX');
+  }
+
 
 /**
  * Return correct name for a specific database table
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 2e5f1ba..ddd1a5f 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -250,6 +250,8 @@
 $labels['htmleditor'] = 'Compose HTML messages';
 $labels['htmlsignature'] = 'HTML signature';
 $labels['previewpane'] = 'Show preview pane';
+$labels['logoutclear'] = 'Clear Trash on logout';
+$labels['logoutcompact'] = 'Compact Inbox on logout';
 
 $labels['autosavedraft']  = 'Automatically save draft';
 $labels['everynminutes']  = 'every $n minutes';
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index befc1d7..3edced4 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -195,6 +195,28 @@
                     $select_autosave->show($CONFIG['draft_autosave']));
     }
 
+  // Trash purging on logout
+  if (!isset($no_override['logout_purge']))
+    {
+    $field_id = 'rcmfd_logout_purge';
+    $input_purge = new checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
+    $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
+                    $field_id,
+                    Q(rcube_label('logoutclear')),
+                    $input_purge->show($CONFIG['logout_purge']?1:0));
+    }
+
+  // INBOX compacting on logout
+  if (!isset($no_override['logout_expunge']))
+    {
+    $field_id = 'rcmfd_logout_expunge';
+    $input_expunge = new checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
+    $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
+                    $field_id,
+                    Q(rcube_label('logoutcompact')),
+                    $input_expunge->show($CONFIG['logout_expunge']?1:0));
+    }
+
   $out .= "\n</table>$form_end";
 
   return $out;  
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index caa4a49..8dae7bc 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -27,7 +27,9 @@
   'prefer_html'  => isset($_POST['_prefer_html']) ? TRUE : FALSE,
   'htmleditor'   => isset($_POST['_htmleditor']) ? TRUE : FALSE,
   'preview_pane' => isset($_POST['_preview_pane']) ? TRUE : FALSE,
-  'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0
+  'logout_purge' => isset($_POST['_logout_purge']) ? TRUE : FALSE,
+  'logout_expunge' => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
+  'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
   );
 
 // don't override these parameters

--
Gitblit v1.9.1