Source for file options.php

Documentation is available at options.php

  1. <?php
  2. /**
  3.  * Message and Spam Filter Plugin - Filtering Options
  4.  *
  5.  * This plugin filters your inbox into different folders based upon given
  6.  * criteria. It is most useful for people who are subscibed to mailing lists
  7.  * to help organize their messages.  The argument stands that filtering is
  8.  * not the place of the client, which is why this has been made a plugin for
  9.  * SquirrelMail.  You may be better off using products such as Sieve or
  10.  * Procmail to do your filtering so it happens even when SquirrelMail isn't
  11.  * running.
  12.  *
  13.  * If you need help with this, or see improvements that can be made, please
  14.  * email me directly at the address above.  I definately welcome suggestions
  15.  * and comments.  This plugin, as is the case with all SquirrelMail plugins,
  16.  * is not directly supported by the developers.  Please come to me off the
  17.  * mailing list if you have trouble with it.
  18.  *
  19.  * Also view plugins/README.plugins for more information.
  20.  *
  21.  * @version $Id: options.php 14840 2020-01-07 07:42:38Z pdontthink $
  22.  * @copyright (c) 1999-2020 The SquirrelMail Project Team
  23.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  24.  * @package plugins
  25.  * @subpackage filters
  26.  */
  27.  
  28. /**
  29.  * Path for SquirrelMail required files.
  30.  * @ignore
  31.  */
  32. define('SM_PATH','../../');
  33.  
  34. /* SquirrelMail required files. */
  35. require_once(SM_PATH 'include/validate.php');
  36. require_once(SM_PATH 'functions/page_header.php');
  37. require_once(SM_PATH 'functions/imap.php');
  38. require_once(SM_PATH 'functions/imap_mailbox.php');
  39. require_once(SM_PATH 'include/load_prefs.php');
  40. require_once(SM_PATH 'functions/forms.php');
  41. require_once(SM_PATH 'plugins/filters/filters.php');
  42.  
  43. global $AllowSpamFilters;
  44.  
  45. displayPageHeader($color'None');
  46.  
  47. /* get globals */
  48. sqgetGlobalVar('username'$usernameSQ_SESSION);
  49. sqgetGlobalVar('key'$keySQ_COOKIE);
  50. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  51. sqgetGlobalVar('delimiter'$delimiterSQ_SESSION);
  52.  
  53. sqgetGlobalVar('theid'$theid);
  54. sqgetGlobalVar('action'$actionSQ_GET);
  55. global $imap_stream_options// in case not defined in config
  56.  
  57. if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) {
  58.  
  59.     if(isset($theid) ) $theid 0;
  60.  
  61.     $complete_post=true;
  62.  
  63.     // FIXME: write human readable error messages
  64.     sqgetGlobalVar('filter_what'$filter_whatSQ_POST);
  65.     if (!sqgetGlobalVar('filter_what'$filter_whatSQ_POST)) {
  66.         do_error("Post error");
  67.         $complete_post=false;
  68.     }
  69.  
  70.     sqgetGlobalVar('filter_where'$filter_whereSQ_POST);
  71.     if (!sqgetGlobalVar('filter_where'$filter_whereSQ_POST)) {
  72.         do_error("Post error");
  73.         $complete_post=false;
  74.     }
  75.  
  76.     sqgetGlobalVar('filter_folder'$filter_folderSQ_POST);
  77.     if (!sqgetGlobalVar('filter_folder'$filter_folderSQ_POST)) {
  78.         do_error("Post error");
  79.         $complete_post=false;
  80.     }
  81.  
  82.     if ($complete_post{
  83.         $filter_what str_replace(',''###COMMA###'$filter_what);
  84.         $filter_what str_replace("\\\\""\\"$filter_what);
  85.         $filter_what str_replace("\\\""'"'$filter_what);
  86.         $filter_what str_replace('"''&quot;'$filter_what);
  87.  
  88.         if (empty($filter_what)) {
  89.             do_error(_("WARNING! You must enter something to search for."));
  90.             $action 'edit';
  91.         }
  92.  
  93.         if (($filter_where == 'Header'&& (strchr($filter_what,':'== '')) {
  94.             do_error(_("WARNING! Header filters should be of the format &quot;Header: value&quot;"));
  95.             $action 'edit';
  96.         }
  97.         if ($action != 'edit'{
  98.             setPref($data_dir$username'filter'.$theid$filter_where.','.$filter_what.','.$filter_folder);
  99.         }
  100.         $filters[$theid]['where'$filter_where;
  101.         $filters[$theid]['what'$filter_what;
  102.         $filters[$theid]['folder'$filter_folder;
  103.     }
  104. elseif (isset($action&& $action == 'delete'{
  105.       remove_filter($theid);
  106. elseif (isset($action&& $action == 'move_up'{
  107.       filter_swap($theid$theid 1);
  108. elseif (isset($action&& $action == 'move_down'{
  109.       filter_swap($theid$theid 1);
  110. elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
  111.     sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
  112.     setPref($data_dir$username'filters_user_scan'$filters_user_scan_set);
  113.     echo '<br /><center><b>'._("Saved Scan type")."</b></center>\n";
  114. }
  115.  
  116.    $filters load_filters();
  117.    $filters_user_scan getPref($data_dir$username'filters_user_scan');
  118.  
  119.    echo html_tag'table',
  120.             html_tag'tr',
  121.                 html_tag'td',
  122.                     '<center><b>' _("Options"' - ' _("Message Filtering"'</b></center>' ,
  123.                     'left'$color[0]
  124.                 )
  125.             ),
  126.             'center''''width="95%" border="0" cellpadding="2" cellspacing="0"'
  127.         .
  128.         '<br /><form method="post" action="options.php">'.
  129.         '<center>'.
  130.         html_tag'table''''''''border="0" cellpadding="2" cellspacing="0"' .
  131.             html_tag'tr' .
  132.                 html_tag'th'_("What to Scan:")'right''''nowrap' .
  133.                 html_tag'td''''left' .
  134.             '<select name="filters_user_scan_set">'.
  135.             '<option value=""';
  136.     if ($filters_user_scan == ''{
  137.         echo ' selected';
  138.     }
  139.     echo '>' _("All messages"'</option>'.
  140.             '<option value="new"';
  141.     if ($filters_user_scan == 'new'{
  142.         echo ' selected';
  143.     }
  144.     echo '>' _("Only unread messages"'</option>' .
  145.             '</select>'.
  146.         '</td>'.
  147.         html_tag'td''<input type="submit" name="user_submit" value="' _("Save"'" />''left' .
  148.         '</table>'.
  149.         '</center>'.
  150.         '</form>'.
  151.  
  152.         html_tag'div''[<a href="options.php?action=add">' _("New".
  153.             '</a>] - [<a href="'.SM_PATH.'src/options.php">' _("Done"'</a>]' ,
  154.         'center' '<br />';
  155.  
  156.     if (isset($action&& ($action == 'add' || $action == 'edit')) {
  157.  
  158.         $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  159.         $boxes sqimap_mailbox_list($imapConnection);
  160.  
  161.         for ($a 0$cnt count($boxes)$a $cnt$a++{
  162.             if (strtolower($boxes[$a]['formatted']== 'inbox'{
  163.                 unset($boxes[$a]);
  164.             }
  165.         }
  166.  
  167.         sqimap_logout($imapConnection);
  168.         if !isset($theid) ) {
  169.             $theid count($filters);
  170.         }
  171.         echo html_tag'div''''center' .
  172.              '<form action="options.php" method="post">'.
  173.              html_tag'table''''''''border="0" cellpadding="2" cellspacing="0"' .
  174.              html_tag'tr' .
  175.                 html_tag'td'_("Match:")'left' .
  176.                 html_tag'td''''left' .
  177.                     '<select name="filter_where">';
  178.  
  179.         $L = isset($filters[$theid]['where']);
  180.  
  181.         $sel (($L && $filters[$theid]['where'== 'From')?'selected':'');
  182.         echo "<option value=\"From\" $sel>_("From"'</option>';
  183.  
  184.         $sel (($L && $filters[$theid]['where'== 'To')?'selected':'');
  185.         echo "<option value=\"To\" $sel>_("To"'</option>';
  186.  
  187.         $sel (($L && $filters[$theid]['where'== 'Cc')?'selected':'');
  188.         echo "<option value=\"Cc\" $sel>_("Cc"'</option>';
  189.  
  190.         $sel (($L && $filters[$theid]['where'== 'To or Cc')?'selected':'');
  191.         echo "<option value=\"To or Cc\" $sel>_("To or Cc"'</option>';
  192.  
  193.         $sel (($L && $filters[$theid]['where'== 'Subject')?'selected':'');
  194.         echo "<option value=\"Subject\" $sel>_("Subject"'</option>';
  195.  
  196.         $sel (($L && $filters[$theid]['where'== 'Header')?'selected':'');
  197.         echo "<option value=\"Header\" $sel>_("Header"'</option>';
  198.  
  199.         echo         '</select>'.
  200.                 '</td>'.
  201.             '</tr>'.
  202.             html_tag'tr' .
  203.                 html_tag'td'_("Contains:")'right' .
  204.                 html_tag'td''''left' .
  205.                     '<input type="text" size="32" name="filter_what" value="';
  206.         if (isset($filters[$theid]['what'])) {
  207.             echo sm_encode_html_special_chars($filters[$theid]['what']);
  208.         }
  209.         echo '" />'.
  210.                 '</td>'.
  211.             '</tr>'.
  212.             html_tag'tr' .
  213.                 html_tag'td'_("Move to:")'left' .
  214.                 html_tag'td''''left' .
  215.                     '<tt>'.
  216.                     '<select name="filter_folder">';
  217.         $selected 0;
  218.         if isset($filters[$theid]['folder']) )
  219.           $selected array(strtolower($filters[$theid]['folder']));
  220.         echo sqimap_mailbox_option_list(0$selected0$boxes);
  221.         echo         '</tt>'.
  222.                     '</select>'.
  223.                 '</td>'.
  224.             '</tr>'.
  225.             '</table>'.
  226.             '<input type="submit" name="filter_submit" value="' _("Submit""\" />\n".
  227.             addHidden('theid'$theid).
  228.             '</form>'.
  229.             '</div>';
  230.  
  231.     }
  232.  
  233.     echo html_tag'table''''center''''border="0" cellpadding="3" cellspacing="0"' );
  234.  
  235.     for ($i=0$num count($filters)$i $num$i++{
  236.  
  237.         $clr (($i 2)?$color[0]:$color[9]);
  238.         $fdr ($folder_prefix)?str_replace($folder_prefix""$filters[$i]["folder"]):$filters[$i]["folder"];
  239.         echo html_tag'tr'''''$clr .
  240.                    html_tag'td',
  241.                        '<small>' .
  242.                        "[<a href=\"options.php?theid=$i&amp;action=edit\">_("Edit"'</a>]'.
  243.                        '</small>' ,
  244.                    'left' .
  245.                    html_tag'td',
  246.                        '<small>' .
  247.                        "[<a href=\"options.php?theid=$i&amp;action=delete\">_("Delete"'</a>]'.
  248.                        '</small>' ,
  249.                    'left' );
  250.  
  251.         if ($num 1{
  252.             echo html_tag'td''''center' '<small>[';
  253.             if (isset($filters[$i 1])) {
  254.                 echo "<a href=\"options.php?theid=$i&amp;action=move_down\">_("Down"'</a>';
  255.                 if ($i 0{
  256.                     echo '&nbsp;|&nbsp;';
  257.                 }
  258.             }
  259.             if ($i 0{
  260.                 echo "<a href=\"options.php?theid=$i&amp;action=move_up\">_("Up"'</a>';
  261.             }
  262.             echo ']</small></td>';
  263.         }
  264.         echo html_tag'td''-''left' .
  265.              html_tag'td''''left' );
  266.         printf_("If %s contains %s then move to %s"),
  267.             '<b>'.$filters[$i]['where'].'</b>',
  268.             '<b>'.$filters[$i]['what'].'</b>',
  269.             '<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($fdr)).'</b>');
  270.         echo '</td></tr>';
  271.  
  272.     }
  273.     echo '</table>'.
  274.         html_tag'table',
  275.             html_tag'tr',
  276.                 html_tag'td''&nbsp;''left' )
  277.             ,
  278.         'center''''width="80%" border="0" cellpadding="2" cellspacing="0"' );
  279.     echo '</body></html>';
  280. ?>

Documentation generated on Mon, 13 Jan 2020 04:25:05 +0100 by phpDocumentor 1.4.3