Split out functionality that gathers system specs
[squirrelmail.git] / plugins / filters / spamoptions.php
index 40e8326fda4df48df9abac9f84c90c25ab5626eb..730086cf6bc788496d49cbcb4862a7ec4e4f6aca 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 /**
- * Message and Spam Filter Plugin
- *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
+ * Message and Spam Filter Plugin - Spam Options
  *
  * This plugin filters your inbox into different folders based upon given
  * criteria.  It is most useful for people who are subscibed to mailing lists
  *
  * Also view plugins/README.plugins for more information.
  *
- * $Id$
+ * @version $Id$
+ * @copyright (c) 1999-2004 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @package plugins
+ * @subpackage filters
  */
 
-chdir ('..');
-require_once('../src/validate.php');
-require_once('../functions/page_header.php');
-require_once('../functions/imap.php');
-require_once('../src/load_prefs.php');
-require_once('../functions/html.php');
-
+/**
+ * Path for SquirrelMail required files.
+ * @ignore
+ */
+define('SM_PATH','../../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/page_header.php');
+require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'include/load_prefs.php');
+require_once(SM_PATH . 'functions/html.php');
+require_once(SM_PATH . 'plugins/filters/filters.php');
 global $AllowSpamFilters;
 
+/* get globals */
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
+
+sqgetGlobalVar('action', $action, SQ_GET);
+/* end globals */
+
 displayPageHeader($color, 'None');
 
-if (isset($spam_submit)) {
+if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
     $spam_filters = load_spam_filters();
-    setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
-    setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
+
+    // setting spam folder    
+    sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
+    if (isset($filters_spam_folder_set)) {
+        setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
+    } else {
+       echo _("You must select spam folder.");
+    }
+
+    // setting scan type
+    sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
+    if (isset($filters_spam_scan_set)) {
+       setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
+    } else {
+       echo _("You must select scan type.");
+    }
+
     foreach ($spam_filters as $Key => $Value) {
         $input = $spam_filters[$Key]['prefname'] . '_set';
-        if ( isset( $$input ) ) {
-            setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
-                     $$input);
+        if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
+            setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
         } else {
             removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
         }
@@ -61,12 +91,12 @@ echo html_tag( 'table',
         'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
 
 if ($SpamFilters_YourHop == ' ') {
-    echo '<br>' .
+    echo '<br />' .
         html_tag( 'div', '<b>' .
-            _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
+            sprintf(_("WARNING! Tell your admin to set the %s variable"),'SpamFilters_YourHop') .
             '</b>' ,
         'center' ) .
-        '<br>';
+        '<br />';
 }
 
 
@@ -74,16 +104,17 @@ if (isset($action) && $action == 'spam') {
     $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
     $boxes = sqimap_mailbox_list($imapConnection);
     sqimap_logout($imapConnection);
-    for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
+    $numboxes = count($boxes);
 
-        if ($boxes[$i]['flags'][0] != 'noselect' &&
-            $boxes[$i]['flags'][1] != 'noselect' &&
-            $boxes[$i]['flags'][2] != 'noselect') {
+    for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
+        if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
+            (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
+            (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
             $filters_spam_folder = $boxes[$i]['unformatted'];
         }
     }
 
-    echo '<form method=post action="spamoptions.php">'.
+    echo '<form method="post" action="spamoptions.php">'.
         '<center>'.
         html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
             html_tag( 'tr' ) .
@@ -91,17 +122,10 @@ if (isset($action) && $action == 'spam') {
                 html_tag( 'td', '', 'left' ) .
                     '<select name="filters_spam_folder_set">';
 
-    for ($i = 0; $i < count($boxes); $i++) {
-        if (! in_array('noselect', $boxes[$i]['flags'])) {
-            $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
-            if ($filters_spam_folder == $box) {
-                echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
-            } else {
-                echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
-            }
-        }
-    }
+        $selected = 0;
+        if ( isset($filters_spam_folder) )
+          $selected = array(strtolower($filters_spam_folder));
+        echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
     echo    '</select>'.
         '</td>'.
         '</tr>'.
@@ -117,12 +141,12 @@ if (isset($action) && $action == 'spam') {
             '<select name="filters_spam_scan_set">'.
             '<option value=""';
     if ($filters_spam_scan == '') {
-        echo ' SELECTED';
+        echo ' selected';
     }
     echo '>' . _("All messages") . '</option>'.
             '<option value="new"';
     if ($filters_spam_scan == 'new') {
-        echo ' SELECTED';
+        echo ' selected';
     }
     echo '>' . _("Only unread messages") . '</option>' .
             '</select>'.
@@ -131,7 +155,7 @@ if (isset($action) && $action == 'spam') {
     html_tag( 'tr',
           html_tag( 'td', '&nbsp;' ) .
           html_tag( 'td',
-              _("The more messages you scan, the longer it takes.  I would suggest that you scan only new messages.  If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages.  That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.") ,
+              _("The more messages you scan, the longer it takes. I would suggest that you scan only new messages. If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages. That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.") ,
           'left' )
       );
 
@@ -141,13 +165,13 @@ if (isset($action) && $action == 'spam') {
         echo html_tag( 'tr' ) .
                    html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
                    html_tag( 'td' ) .
-            '<input type=checkbox name="' .
+            '<input type="checkbox" name="' .
             $spam_filters[$Key]['prefname'] .
             '_set"';
         if ($spam_filters[$Key]['enabled']) {
-            echo ' CHECKED';
+            echo ' checked';
         }
-        echo '> - ';
+        echo ' /> - ';
         if ($spam_filters[$Key]['link']) {
             echo '<a href="' .
                  $spam_filters[$Key]['link'] .
@@ -165,24 +189,21 @@ if (isset($action) && $action == 'spam') {
 
     }
     echo html_tag( 'tr',
-        html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
+        html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
     ) . "\n" .
         '</table>'.
         '</center>'.
         '</form>';
-
-}
-
-if (! isset($action) || $action != 'spam') {
-
+} else {
+    // action is not set or action is not spam
     echo html_tag( 'p', '', 'center' ) .
          '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
-         ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
-    printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
+         ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
+    printf( _("Spam is sent to %s"), ($filters_spam_folder?'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
     echo '<br>';
     printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
     echo '</p>'.
-        "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
+        '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
 
     $spam_filters = load_spam_filters();
 
@@ -214,5 +235,5 @@ if (! isset($action) || $action != 'spam') {
     }
     echo '</table>';
 }
-
 ?>
+</body></html>