options.php 9.8 KB

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