options.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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-2005 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. ),
  102. 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
  103. ) .
  104. '<br /><form method="post" action="options.php">'.
  105. '<center>'.
  106. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  107. html_tag( 'tr' ) .
  108. html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
  109. html_tag( 'td', '', 'left' ) .
  110. '<select name="filters_user_scan_set">'.
  111. '<option value=""';
  112. if ($filters_user_scan == '') {
  113. echo ' selected="selected"';
  114. }
  115. echo '>' . _("All messages") . '</option>'.
  116. '<option value="new"';
  117. if ($filters_user_scan == 'new') {
  118. echo ' selected="selected"';
  119. }
  120. echo '>' . _("Only unread messages") . '</option>' .
  121. '</select>'.
  122. '</td>'.
  123. html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
  124. '</table>'.
  125. '</center>'.
  126. '</form>'.
  127. html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
  128. '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
  129. 'center' ) . '<br />';
  130. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  131. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  132. $boxes = sqimap_mailbox_list($imapConnection);
  133. sqimap_logout($imapConnection);
  134. if ( !isset($theid) ) {
  135. $theid = count($filters);
  136. }
  137. echo html_tag( 'div', '', 'center' ) .
  138. '<form action="options.php" method="post">'.
  139. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  140. html_tag( 'tr' ) .
  141. html_tag( 'td', _("Match:"), 'left' ) .
  142. html_tag( 'td', '', 'left' ) .
  143. '<select name="filter_where">';
  144. $L = isset($filters[$theid]['where']);
  145. $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':'');
  146. echo "<option value=\"From\"$sel>" . _("From") . '</option>';
  147. $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':'');
  148. echo "<option value=\"To\"$sel>" . _("To") . '</option>';
  149. $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':'');
  150. echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
  151. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':'');
  152. echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
  153. $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':'');
  154. echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
  155. $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':'');
  156. echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
  157. echo '</select>'.
  158. '</td>'.
  159. '</tr>'.
  160. html_tag( 'tr' ) .
  161. html_tag( 'td', _("Contains:"), 'right' ) .
  162. html_tag( 'td', '', 'left' ) .
  163. '<input type="text" size="32" name="filter_what" value="';
  164. if (isset($filters[$theid]['what'])) {
  165. echo $filters[$theid]['what'];
  166. }
  167. echo '" />'.
  168. '</td>'.
  169. '</tr>'.
  170. html_tag( 'tr' ) .
  171. html_tag( 'td', _("Move to:"), 'left' ) .
  172. html_tag( 'td', '', 'left' ) .
  173. '<tt>'.
  174. '<select name="filter_folder">';
  175. $selected = 0;
  176. if ( isset($filters[$theid]['folder']) )
  177. $selected = array(strtolower($filters[$theid]['folder']));
  178. echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
  179. echo '</tt>'.
  180. '</select>'.
  181. '</td>'.
  182. '</tr>'.
  183. '</table>'.
  184. '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
  185. addHidden('theid', $theid).
  186. '</form>'.
  187. '</div>';
  188. }
  189. echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
  190. for ($i=0, $num = count($filters); $i < $num; $i++) {
  191. $clr = (($i % 2)?$color[0]:$color[9]);
  192. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  193. echo html_tag( 'tr', '', '', $clr ) .
  194. html_tag( 'td',
  195. '<small>' .
  196. "[<a href=\"options.php?theid=$i&amp;action=edit\">" . _("Edit") . '</a>]'.
  197. '</small>' ,
  198. 'left' ) .
  199. html_tag( 'td',
  200. '<small>' .
  201. "[<a href=\"options.php?theid=$i&amp;action=delete\">" . _("Delete") . '</a>]'.
  202. '</small>' ,
  203. 'left' );
  204. if ($num > 1) {
  205. echo html_tag( 'td', '', 'center' ) . '<small>[';
  206. if (isset($filters[$i + 1])) {
  207. echo "<a href=\"options.php?theid=$i&amp;action=move_down\">" . _("Down") . '</a>';
  208. if ($i > 0) {
  209. echo '&nbsp;|&nbsp;';
  210. }
  211. }
  212. if ($i > 0) {
  213. echo "<a href=\"options.php?theid=$i&amp;action=move_up\">" . _("Up") . '</a>';
  214. }
  215. echo ']</small></td>';
  216. }
  217. echo html_tag( 'td', '-', 'left' ) .
  218. html_tag( 'td', '', 'left' );
  219. printf( _("If %s contains %s then move to %s"),
  220. '<b>'.$filters[$i]['where'].'</b>',
  221. '<b>'.$filters[$i]['what'].'</b>',
  222. '<b>'.imap_utf7_decode_local($fdr).'</b>');
  223. echo '</td></tr>';
  224. }
  225. echo '</table>'.
  226. html_tag( 'table',
  227. html_tag( 'tr',
  228. html_tag( 'td', '&nbsp;', 'left' )
  229. ) ,
  230. 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
  231. echo '</body></html>';
  232. ?>