options.php 10.0 KB

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