options.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * Message and Spam Filter Plugin
  4. *
  5. * Copyright (c) 1999-2003 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This plugin filters your inbox into different folders based upon given
  9. * criteria. It is most useful for people who are subscibed to mailing lists
  10. * to help organize their messages. The argument stands that filtering is
  11. * not the place of the client, which is why this has been made a plugin for
  12. * SquirrelMail. You may be better off using products such as Sieve or
  13. * Procmail to do your filtering so it happens even when SquirrelMail isn't
  14. * running.
  15. *
  16. * If you need help with this, or see improvements that can be made, please
  17. * email me directly at the address above. I definately welcome suggestions
  18. * and comments. This plugin, as is the case with all SquirrelMail plugins,
  19. * is not directly supported by the developers. Please come to me off the
  20. * mailing list if you have trouble with it.
  21. *
  22. * Also view plugins/README.plugins for more information.
  23. *
  24. * $Id$
  25. * @package plugins
  26. * @subpackage filters
  27. */
  28. /** Path for SquirrelMail required files. */
  29. define('SM_PATH','../../');
  30. /* SquirrelMail required files. */
  31. require_once(SM_PATH . 'include/validate.php');
  32. require_once(SM_PATH . 'functions/page_header.php');
  33. require_once(SM_PATH . 'functions/imap.php');
  34. require_once(SM_PATH . 'functions/imap_mailbox.php');
  35. require_once(SM_PATH . 'include/load_prefs.php');
  36. require_once(SM_PATH . 'plugins/filters/filters.php');
  37. global $AllowSpamFilters;
  38. displayPageHeader($color, 'None');
  39. /* get globals */
  40. sqgetGlobalVar('username', $username, SQ_SESSION);
  41. sqgetGlobalVar('key', $key, SQ_COOKIE);
  42. sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
  43. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
  44. sqgetGlobalVar('theid', $theid);
  45. sqgetGlobalVar('action', $action, SQ_GET);
  46. // FIXME: use sqgetGlobalVar below.
  47. if (isset($_POST['filter_submit'])) {
  48. if(isset($_GET['theid'])) {
  49. $theid = $_GET['theid'];
  50. } elseif (isset($_POST['theid'])) {
  51. $theid = $_POST['theid'];
  52. } else {
  53. $theid = 0;
  54. }
  55. $filter_what = $_POST['filter_what'];
  56. $filter_where = $_POST['filter_where'];
  57. $filter_folder = $_POST['filter_folder'];
  58. $filter_what = str_replace(',', ' ', $filter_what);
  59. $filter_what = str_replace("\\\\", "\\", $filter_what);
  60. $filter_what = str_replace("\\\"", '"', $filter_what);
  61. $filter_what = str_replace('"', '&quot;', $filter_what);
  62. if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
  63. print ('WARNING! Header filters should be of the format "Header: value"<BR>');
  64. $action = 'edit';
  65. }
  66. setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
  67. $filters[$theid]['where'] = $filter_where;
  68. $filters[$theid]['what'] = $filter_what;
  69. $filters[$theid]['folder'] = $filter_folder;
  70. } elseif (isset($action) && $action == 'delete') {
  71. remove_filter($theid);
  72. } elseif (isset($action) && $action == 'move_up') {
  73. filter_swap($theid, $theid - 1);
  74. } elseif (isset($action) && $action == 'move_down') {
  75. filter_swap($theid, $theid + 1);
  76. } elseif (isset($_POST['user_submit'])) {
  77. setPref($data_dir, $username, 'filters_user_scan', $_POST['filters_user_scan_set']);
  78. echo '<br><center><b>'._("Saved Scan type")."</b></center>\n";
  79. }
  80. $filters = load_filters();
  81. $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
  82. echo html_tag( 'table',
  83. html_tag( 'tr',
  84. html_tag( 'td',
  85. '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
  86. 'left', $color[0] )
  87. ) ,
  88. 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
  89. '<br><form method=post action="options.php">'.
  90. '<center>'.
  91. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  92. html_tag( 'tr' ) .
  93. html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
  94. html_tag( 'td', '', 'left' ) .
  95. '<select name="filters_user_scan_set">'.
  96. '<option value=""';
  97. if ($filters_user_scan == '') {
  98. echo ' selected';
  99. }
  100. echo '>' . _("All messages") . '</option>'.
  101. '<option value="new"';
  102. if ($filters_user_scan == 'new') {
  103. echo ' selected';
  104. }
  105. echo '>' . _("Only unread messages") . '</option>' .
  106. '</select>'.
  107. '</td>'.
  108. html_tag( 'td', '<input type=submit name="user_submit" value="' . _("Save") . '">', 'left' ) .
  109. '</table>'.
  110. '</center>'.
  111. '</form>'.
  112. html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
  113. '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
  114. 'center' ) . '<br>';
  115. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  116. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  117. $boxes = sqimap_mailbox_list($imapConnection);
  118. sqimap_logout($imapConnection);
  119. if ( !isset($theid) ) {
  120. $theid = count($filters);
  121. }
  122. echo html_tag( 'div', '', 'center' ) .
  123. '<form action="options.php" method=post>'.
  124. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  125. html_tag( 'tr' ) .
  126. html_tag( 'td', _("Match:"), 'left' ) .
  127. html_tag( 'td', '', 'left' ) .
  128. '<select name=filter_where>';
  129. $L = isset($filters[$theid]['where']);
  130. $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
  131. echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
  132. $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
  133. echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
  134. $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
  135. echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
  136. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
  137. echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
  138. $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
  139. echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
  140. $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
  141. echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
  142. echo '</select>'.
  143. '</td>'.
  144. '</tr>'.
  145. html_tag( 'tr' ) .
  146. html_tag( 'td', _("Contains:"), 'right' ) .
  147. html_tag( 'td', '', 'left' ) .
  148. '<input type=text size=32 name=filter_what value="';
  149. if (isset($filters[$theid]['what'])) {
  150. echo $filters[$theid]["what"];
  151. }
  152. echo '">'.
  153. '</td>'.
  154. '</tr>'.
  155. html_tag( 'tr' ) .
  156. html_tag( 'td', _("Move to:"), 'left' ) .
  157. html_tag( 'td', '', 'left' ) .
  158. '<tt>'.
  159. '<select name=filter_folder>';
  160. $selected = 0;
  161. if ( isset($filters[$theid]['folder']) )
  162. $selected = array(strtolower($filters[$theid]['folder']));
  163. echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
  164. echo '</tt>'.
  165. '</select>'.
  166. '</td>'.
  167. '</tr>'.
  168. '</table>'.
  169. '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
  170. "<input type=hidden name=theid value=$theid>".
  171. '</form>'.
  172. '</div>';
  173. }
  174. echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
  175. for ($i=0, $num = count($filters); $i < $num; $i++) {
  176. $clr = (($i % 2)?$color[0]:$color[9]);
  177. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  178. echo html_tag( 'tr', '', '', $clr ) .
  179. html_tag( 'td',
  180. '<small>' .
  181. "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
  182. '</small>' ,
  183. 'left' ) .
  184. html_tag( 'td',
  185. '<small>' .
  186. "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
  187. '</small>' ,
  188. 'left' ) .
  189. html_tag( 'td', '', 'center' ) . '<small>[';
  190. if (isset($filters[$i + 1])) {
  191. echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
  192. if ($i > 0) {
  193. echo '&nbsp;|&nbsp;';
  194. }
  195. }
  196. if ($i > 0) {
  197. echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
  198. }
  199. echo ']</small></td>'.
  200. html_tag( 'td', '-', 'left' ) .
  201. html_tag( 'td', '', 'left' );
  202. printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
  203. echo '</td></tr>';
  204. }
  205. echo '</table>'.
  206. html_tag( 'table',
  207. html_tag( 'tr',
  208. html_tag( 'td', '&nbsp;', 'left' )
  209. ) ,
  210. 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
  211. echo '</body></html>';
  212. ?>