options.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /**
  3. * Message and Spam Filter Plugin - Filtering Options
  4. *
  5. * @copyright 1999-2025 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage filters
  10. */
  11. /**
  12. * Include the SquirrelMail initialization file.
  13. */
  14. require('../../include/init.php');
  15. include_once(SM_PATH . 'functions/imap_general.php');
  16. include_once(SM_PATH . 'functions/forms.php');
  17. include_once(SM_PATH . 'plugins/filters/filters.php');
  18. displayPageHeader($color);
  19. /* get globals */
  20. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
  21. sqgetGlobalVar('theid', $theid);
  22. sqgetGlobalVar('action', $action, SQ_GET);
  23. global $imap_stream_options; // in case not defined in config
  24. if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) {
  25. if(! isset($theid) ) $theid = 0;
  26. $complete_post=true;
  27. // FIXME: write human readable error messages
  28. sqgetGlobalVar('filter_what', $filter_what, SQ_POST);
  29. if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) {
  30. do_error("Post error");
  31. $complete_post=false;
  32. }
  33. sqgetGlobalVar('filter_where', $filter_where, SQ_POST);
  34. if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) {
  35. do_error("Post error");
  36. $complete_post=false;
  37. }
  38. sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST);
  39. if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) {
  40. do_error("Post error");
  41. $complete_post=false;
  42. }
  43. if ($complete_post) {
  44. $filter_what = str_replace(',', '###COMMA###', $filter_what);
  45. $filter_what = str_replace("\\\\", "\\", $filter_what);
  46. $filter_what = str_replace("\\\"", '"', $filter_what);
  47. $filter_what = str_replace('"', '&quot;', $filter_what);
  48. if (empty($filter_what)) {
  49. do_error(_("WARNING! You must enter something to search for."));
  50. $action = 'edit';
  51. }
  52. if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
  53. do_error(_("WARNING! Header filters should be of the format &quot;Header: value&quot;"));
  54. $action = 'edit';
  55. }
  56. if ($action != 'edit') {
  57. setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
  58. }
  59. $filters[$theid]['where'] = $filter_where;
  60. $filters[$theid]['what'] = $filter_what;
  61. $filters[$theid]['folder'] = $filter_folder;
  62. }
  63. } elseif (isset($action) && $action == 'delete') {
  64. remove_filter($theid);
  65. } elseif (isset($action) && $action == 'move_up') {
  66. filter_swap($theid, $theid - 1);
  67. } elseif (isset($action) && $action == 'move_down') {
  68. filter_swap($theid, $theid + 1);
  69. } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
  70. sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
  71. setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
  72. echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
  73. }
  74. $filters = load_filters();
  75. $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
  76. echo html_tag( 'table',
  77. html_tag( 'tr',
  78. html_tag( 'td',
  79. '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' ,
  80. 'left', $color[0]
  81. )
  82. ),
  83. 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
  84. ) .
  85. '<br /><form method="post" action="options.php">'.
  86. html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  87. html_tag( 'tr' ) .
  88. html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
  89. html_tag( 'td', '', 'left' ) .
  90. '<select name="filters_user_scan_set">'.
  91. '<option value=""';
  92. if ($filters_user_scan == '') {
  93. echo ' selected="selected"';
  94. }
  95. echo '>' . _("All messages") . '</option>'.
  96. '<option value="new"';
  97. if ($filters_user_scan == 'new') {
  98. echo ' selected="selected"';
  99. }
  100. echo '>' . _("Only unread messages") . '</option>' .
  101. '</select>'.
  102. '</td>'.
  103. html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
  104. '</table>'.
  105. '</form>'.
  106. html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
  107. '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
  108. 'center' ) . '<br />';
  109. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  110. $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
  111. $boxes = sqimap_mailbox_list($imapConnection);
  112. for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++) {
  113. if (strtolower($boxes[$a]['formatted']) == 'inbox') {
  114. unset($boxes[$a]);
  115. }
  116. }
  117. sqimap_logout($imapConnection);
  118. if ( !isset($theid) ) {
  119. $theid = count($filters);
  120. }
  121. echo html_tag( 'div', '', 'center' ) .
  122. '<form action="options.php" method="post">'.
  123. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  124. html_tag( 'tr' ) .
  125. html_tag( 'td', _("Match:"), 'left' ) .
  126. html_tag( 'td', '', 'left' ) .
  127. '<select name="filter_where">';
  128. $L = isset($filters[$theid]['where']);
  129. $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':'');
  130. echo "<option value=\"From\"$sel>" . _("From") . '</option>';
  131. $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':'');
  132. echo "<option value=\"To\"$sel>" . _("To") . '</option>';
  133. $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':'');
  134. echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
  135. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':'');
  136. echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
  137. $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':'');
  138. echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
  139. $sel = (($L && $filters[$theid]['where'] == 'Message Body')?' selected="selected"':'');
  140. echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
  141. $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?' selected="selected"':'');
  142. echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
  143. $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':'');
  144. echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
  145. echo '</select>'.
  146. '</td>'.
  147. '</tr>'.
  148. html_tag( 'tr' ) .
  149. html_tag( 'td', _("Contains:"), 'right' ) .
  150. html_tag( 'td', '', 'left' ) .
  151. '<input type="text" size="32" name="filter_what" value="';
  152. if (isset($filters[$theid]['what'])) {
  153. echo sm_encode_html_special_chars($filters[$theid]['what']);
  154. }
  155. echo '" />'.
  156. '</td>'.
  157. '</tr>'.
  158. html_tag( 'tr' ) .
  159. html_tag( 'td', _("Move to:"), 'left' ) .
  160. html_tag( 'td', '', 'left' ) .
  161. '<tt>'.
  162. '<select name="filter_folder">';
  163. $selected = 0;
  164. if ( isset($filters[$theid]['folder']) )
  165. $selected = array(strtolower($filters[$theid]['folder']));
  166. echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
  167. echo '</select>'.
  168. '</tt>'.
  169. '</td>'.
  170. '</tr>'.
  171. '</table>'.
  172. '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
  173. addHidden('theid', $theid).
  174. '</form>'.
  175. '</div>';
  176. }
  177. if (count($filters)) {
  178. echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
  179. for ($i=0, $num = count($filters); $i < $num; $i++) {
  180. $clr = (($i % 2)?$color[0]:$color[9]);
  181. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  182. echo html_tag( 'tr', '', '', $clr ) .
  183. html_tag( 'td',
  184. '<small>' .
  185. "[<a href=\"options.php?theid=$i&amp;action=edit\">" . _("Edit") . '</a>]'.
  186. '</small>' ,
  187. 'left' ) .
  188. html_tag( 'td',
  189. '<small>' .
  190. "[<a href=\"options.php?theid=$i&amp;action=delete\">" . _("Delete") . '</a>]'.
  191. '</small>' ,
  192. 'left' );
  193. if ($num > 1) {
  194. echo html_tag( 'td', '', 'center' ) . '<small>[';
  195. if (isset($filters[$i + 1])) {
  196. echo "<a href=\"options.php?theid=$i&amp;action=move_down\">" . _("Down") . '</a>';
  197. if ($i > 0) {
  198. echo '&nbsp;|&nbsp;';
  199. }
  200. }
  201. if ($i > 0) {
  202. echo "<a href=\"options.php?theid=$i&amp;action=move_up\">" . _("Up") . '</a>';
  203. }
  204. echo ']</small></td>';
  205. }
  206. echo html_tag( 'td', '-', 'left' ) .
  207. html_tag( 'td', '', 'left' );
  208. printf( _("If %s contains %s then move to %s"),
  209. '<b>'.$filters[$i]['where'].'</b>',
  210. '<b>'.$filters[$i]['what'].'</b>',
  211. '<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($fdr)).'</b>');
  212. echo '</td></tr>';
  213. }
  214. echo '</table>';
  215. }
  216. echo html_tag( 'table',
  217. html_tag( 'tr',
  218. html_tag( 'td', '&nbsp;', 'left' )
  219. ) ,
  220. 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
  221. echo '</body></html>';