options.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * Message and Spam Filter Plugin
  4. *
  5. * Copyright (c) 1999-2002 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. */
  26. /* Path for SquirrelMail required files. */
  27. define('SM_PATH','../../');
  28. /* SquirrelMail required files. */
  29. require_once(SM_PATH . 'include/validate.php');
  30. require_once(SM_PATH . 'functions/page_header.php');
  31. require_once(SM_PATH . 'functions/imap.php');
  32. require_once(SM_PATH . 'include/load_prefs.php');
  33. require_once(SM_PATH . 'plugins/filters/filters.php');
  34. global $AllowSpamFilters;
  35. displayPageHeader($color, 'None');
  36. if (isset($filter_submit)) {
  37. if (!isset($theid)) $theid = 0;
  38. $filter_what = ereg_replace(",", " ", $filter_what);
  39. $filter_what = str_replace("\\\\", "\\", $filter_what);
  40. $filter_what = str_replace("\\\"", "\"", $filter_what);
  41. $filter_what = str_replace("\"", "&quot;", $filter_what);
  42. if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
  43. print ('WARNING! Header filters should be of the format "Header: value"<BR>');
  44. $action = 'edit';
  45. }
  46. setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
  47. $filters[$theid]["where"] = $filter_where;
  48. $filters[$theid]["what"] = $filter_what;
  49. $filters[$theid]["folder"] = $filter_folder;
  50. } elseif (isset($action) && $action == 'delete') {
  51. remove_filter($theid);
  52. } elseif (isset($action) && $action == 'move_up') {
  53. filter_swap($theid, $theid - 1);
  54. } elseif (isset($action) && $action == 'move_down') {
  55. filter_swap($theid, $theid + 1);
  56. } elseif (isset($user_submit)) {
  57. echo "<br><center><b>"._("Saved Scan type")."</b></center>\n";
  58. setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
  59. }
  60. $filters = load_filters();
  61. $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
  62. echo html_tag( 'table',
  63. html_tag( 'tr',
  64. html_tag( 'td',
  65. '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
  66. 'left', $color[0] )
  67. ) ,
  68. 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
  69. '<br><form method=post action="options.php">'.
  70. '<center>'.
  71. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  72. html_tag( 'tr' ) .
  73. html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
  74. html_tag( 'td', '', 'left' ) .
  75. '<select name="filters_user_scan_set">'.
  76. '<option value=""';
  77. if ($filters_user_scan == '') {
  78. echo ' selected';
  79. }
  80. echo '>' . _("All messages") . '</option>'.
  81. '<option value="new"';
  82. if ($filters_user_scan == 'new') {
  83. echo ' selected';
  84. }
  85. echo '>' . _("Only unread messages") . '</option>' .
  86. '</select>'.
  87. '</td>'.
  88. html_tag( 'td', '<input type=submit name="user_submit" value="' . _("Save") . '">', 'left' ) .
  89. '</table>'.
  90. '</center>'.
  91. '</form>'.
  92. html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
  93. '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]' ,
  94. 'center' ) . '<br>';
  95. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  96. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  97. $boxes = sqimap_mailbox_list($imapConnection);
  98. sqimap_logout($imapConnection);
  99. if ( !isset($theid) ) {
  100. $theid = count($filters);
  101. }
  102. echo html_tag( 'div', '', 'center' ) .
  103. '<form action="options.php" method=post>'.
  104. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
  105. html_tag( 'tr' ) .
  106. html_tag( 'td', _("Match:"), 'left' ) .
  107. html_tag( 'td', '', 'left' ) .
  108. '<select name=filter_where>';
  109. $L = isset($filters[$theid]['where']);
  110. $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
  111. echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
  112. $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
  113. echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
  114. $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
  115. echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
  116. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
  117. echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
  118. $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
  119. echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
  120. $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
  121. echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
  122. echo '</select>'.
  123. '</td>'.
  124. '</tr>'.
  125. html_tag( 'tr' ) .
  126. html_tag( 'td', _("Contains:"), 'right' ) .
  127. html_tag( 'td', '', 'left' ) .
  128. '<input type=text size=32 name=filter_what value="';
  129. if (isset($filters[$theid]['what'])) {
  130. echo $filters[$theid]["what"];
  131. }
  132. echo '">'.
  133. '</td>'.
  134. '</tr>'.
  135. html_tag( 'tr' ) .
  136. html_tag( 'td', _("Move to:"), 'left' ) .
  137. html_tag( 'td', '', 'left' ) .
  138. '<tt>'.
  139. '<select name=filter_folder>';
  140. for ($i = 0; $i < count($boxes); $i++) {
  141. if (! in_array('noselect', $boxes[$i]['flags'])) {
  142. $box = $boxes[$i]['unformatted'];
  143. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
  144. if (isset($filters[$theid]['folder']) &&
  145. $filters[$theid]['folder'] == $box)
  146. echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
  147. else
  148. echo "<OPTION VALUE=\"$box\">$box2</option>";
  149. }
  150. }
  151. echo '</tt>'.
  152. '</select>'.
  153. '</td>'.
  154. '</tr>'.
  155. '</table>'.
  156. '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
  157. "<input type=hidden name=theid value=$theid>".
  158. '</form>'.
  159. '</div>';
  160. }
  161. echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
  162. for ($i=0; $i < count($filters); $i++) {
  163. $clr = (($i % 2)?$color[0]:$color[9]);
  164. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  165. echo html_tag( 'tr', '', '', $clr ) .
  166. html_tag( 'td',
  167. '<small>' .
  168. "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
  169. '</small>' ,
  170. 'left' ) .
  171. html_tag( 'td',
  172. '<small>' .
  173. "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
  174. '</small>' ,
  175. 'left' ) .
  176. html_tag( 'td', '', 'center' ) . '<small>[';
  177. if (isset($filters[$i + 1])) {
  178. echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
  179. if ($i > 0) {
  180. echo '&nbsp;|&nbsp;';
  181. }
  182. }
  183. if ($i > 0) {
  184. echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
  185. }
  186. echo ']</small></td>'.
  187. html_tag( 'td', '-', 'left' ) .
  188. html_tag( 'td', '', 'left' );
  189. printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
  190. echo '</td></tr>';
  191. }
  192. echo '</table>'.
  193. html_tag( 'table',
  194. html_tag( 'tr',
  195. html_tag( 'td', '&nbsp', 'left' )
  196. ) ,
  197. 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
  198. ?>