options.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
  40. $filters[$theid]["where"] = $filter_where;
  41. $filters[$theid]["what"] = $filter_what;
  42. $filters[$theid]["folder"] = $filter_folder;
  43. } elseif (isset($action) && $action == 'delete') {
  44. remove_filter($theid);
  45. } elseif (isset($action) && $action == 'move_up') {
  46. filter_swap($theid, $theid - 1);
  47. } elseif (isset($action) && $action == 'move_down') {
  48. filter_swap($theid, $theid + 1);
  49. }
  50. $filters = load_filters();
  51. echo '<br>' .
  52. '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
  53. "<tr><td bgcolor=\"$color[0]\">".
  54. '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
  55. '</td></tr></table>'.
  56. '<br><center>[<a href="options.php?action=add">' . _("New") .
  57. '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
  58. if (isset($action) && ($action == 'add' || $action == 'edit')) {
  59. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  60. $boxes = sqimap_mailbox_list($imapConnection);
  61. sqimap_logout($imapConnection);
  62. if ( !isset($theid) ) {
  63. $theid = count($filters);
  64. }
  65. echo '<center>'.
  66. '<form action="options.php" method=post>'.
  67. '<table cellpadding=2 cellspacing=0 border=0>'.
  68. '<tr>'.
  69. '<td>' . _("Match:") . '</td>'.
  70. '<td>'.
  71. '<select name=filter_where>';
  72. $L = isset($filters[$theid]['where']);
  73. $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
  74. echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
  75. $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
  76. echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
  77. $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
  78. echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
  79. $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
  80. echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
  81. $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
  82. echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
  83. echo '</select>'.
  84. '</td>'.
  85. '</tr>'.
  86. '<tr>'.
  87. '<td align=right>'.
  88. _("Contains:").
  89. '</td>'.
  90. '<td>'.
  91. '<input type=text size=32 name=filter_what value="';
  92. if (isset($filters[$theid]['what'])) {
  93. echo $filters[$theid]["what"];
  94. }
  95. echo '">'.
  96. '</td>'.
  97. '</tr>'.
  98. '<tr>'.
  99. '<td>'.
  100. _("Move to:").
  101. '</td>'.
  102. '<td>'.
  103. '<tt>'.
  104. '<select name=filter_folder>';
  105. for ($i = 0; $i < count($boxes); $i++) {
  106. if (! in_array('noselect', $boxes[$i]['flags'])) {
  107. $box = $boxes[$i]['unformatted'];
  108. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
  109. if (isset($filters[$theid]['folder']) &&
  110. $filters[$theid]['folder'] == $box)
  111. echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
  112. else
  113. echo "<OPTION VALUE=\"$box\">$box2</option>";
  114. }
  115. }
  116. echo '</tt>'.
  117. '</select>'.
  118. '</td>'.
  119. '</tr>'.
  120. '</table>'.
  121. '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
  122. "<input type=hidden name=theid value=$theid>".
  123. '</form>'.
  124. '</center>';
  125. }
  126. echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
  127. for ($i=0; $i < count($filters); $i++) {
  128. $clr = (($i % 2)?$color[0]:$color[9]);
  129. $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
  130. echo "<tr bgcolor=\"$clr\"><td><small>".
  131. "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
  132. '</small></td><td><small>'.
  133. "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
  134. '</small></td><td align=center><small>[';
  135. if (isset($filters[$i + 1])) {
  136. echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
  137. if ($i > 0) {
  138. echo '&nbsp;|&nbsp;';
  139. }
  140. }
  141. if ($i > 0) {
  142. echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
  143. }
  144. echo ']</small></td><td>-</td><td>';
  145. printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
  146. echo '</td></tr>';
  147. }
  148. echo '</table>'.
  149. '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
  150. '<tr><td>&nbsp</td></tr>'.
  151. '</table>';
  152. ?>