options.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
  61. "<tr><td bgcolor=\"$color[0]\">".
  62. '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
  63. '</td></tr></table>'.
  64. '<br><form method=post action="options.php">'.
  65. '<center>'.
  66. '<table cellpadding=2 cellspacing=0 border=0>'.
  67. '<tr>'.
  68. '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
  69. '<td><select name="filters_user_scan_set">'.
  70. '<option value=""';
  71. if ($filters_user_scan == '') {
  72. echo ' SELECTED';
  73. }
  74. echo '>' . _("All messages") . '</option>'.
  75. '<option value="new"';
  76. if ($filters_user_scan == 'new') {
  77. echo ' SELECTED';
  78. }
  79. echo '>' . _("Only unread messages") . '</option>' .
  80. '</select>'.
  81. '</td>'.
  82. '<td><input type=submit name="user_submit" value="' . _("Save") . '"></td></tr>'.
  83. '</table>'.
  84. '</center>'.
  85. '</form>'.
  86. '<center>[<a href="options.php?action=add">' . _("New") .
  87. '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
  88. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  89. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  90. $boxes = sqimap_mailbox_list($imapConnection);
  91. sqimap_logout($imapConnection);
  92. if ( !isset($theid) ) {
  93. $theid = count($filters);
  94. }
  95. echo '<center>'.
  96. '<form action="options.php" method=post>'.
  97. '<table cellpadding=2 cellspacing=0 border=0>'.
  98. '<tr>'.
  99. '<td>' . _("Match:") . '</td>'.
  100. '<td>'.
  101. '<select name=filter_where>';
  102. $L = isset($filters[$theid]['where']);
  103. $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
  104. echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
  105. $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
  106. echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
  107. $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
  108. echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
  109. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
  110. echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
  111. $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
  112. echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
  113. $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
  114. echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
  115. echo '</select>'.
  116. '</td>'.
  117. '</tr>'.
  118. '<tr>'.
  119. '<td align=right>'.
  120. _("Contains:").
  121. '</td>'.
  122. '<td>'.
  123. '<input type=text size=32 name=filter_what value="';
  124. if (isset($filters[$theid]['what'])) {
  125. echo $filters[$theid]["what"];
  126. }
  127. echo '">'.
  128. '</td>'.
  129. '</tr>'.
  130. '<tr>'.
  131. '<td>'.
  132. _("Move to:").
  133. '</td>'.
  134. '<td>'.
  135. '<tt>'.
  136. '<select name=filter_folder>';
  137. for ($i = 0; $i < count($boxes); $i++) {
  138. if (! in_array('noselect', $boxes[$i]['flags'])) {
  139. $box = $boxes[$i]['unformatted'];
  140. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
  141. if (isset($filters[$theid]['folder']) &&
  142. $filters[$theid]['folder'] == $box)
  143. echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
  144. else
  145. echo "<OPTION VALUE=\"$box\">$box2</option>";
  146. }
  147. }
  148. echo '</tt>'.
  149. '</select>'.
  150. '</td>'.
  151. '</tr>'.
  152. '</table>'.
  153. '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
  154. "<input type=hidden name=theid value=$theid>".
  155. '</form>'.
  156. '</center>';
  157. }
  158. echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
  159. for ($i=0; $i < count($filters); $i++) {
  160. $clr = (($i % 2)?$color[0]:$color[9]);
  161. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  162. echo "<tr bgcolor=\"$clr\"><td><small>".
  163. "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
  164. '</small></td><td><small>'.
  165. "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
  166. '</small></td><td align=center><small>[';
  167. if (isset($filters[$i + 1])) {
  168. echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
  169. if ($i > 0) {
  170. echo '&nbsp;|&nbsp;';
  171. }
  172. }
  173. if ($i > 0) {
  174. echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
  175. }
  176. echo ']</small></td><td>-</td><td>';
  177. printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
  178. echo '</td></tr>';
  179. }
  180. echo '</table>'.
  181. '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
  182. '<tr><td>&nbsp</td></tr>'.
  183. '</table>';
  184. ?>