options.php 8.8 KB

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