spamoptions.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * Message and Spam Filter Plugin - Spam Options
  4. *
  5. * This plugin filters your inbox into different folders based upon given
  6. * criteria. It is most useful for people who are subscibed to mailing lists
  7. * to help organize their messages. The argument stands that filtering is
  8. * not the place of the client, which is why this has been made a plugin for
  9. * SquirrelMail. You may be better off using products such as Sieve or
  10. * Procmail to do your filtering so it happens even when SquirrelMail isn't
  11. * running.
  12. *
  13. * If you need help with this, or see improvements that can be made, please
  14. * email me directly at the address above. I definately welcome suggestions
  15. * and comments. This plugin, as is the case with all SquirrelMail plugins,
  16. * is not directly supported by the developers. Please come to me off the
  17. * mailing list if you have trouble with it.
  18. *
  19. * Also view plugins/README.plugins for more information.
  20. *
  21. * @version $Id$
  22. * @copyright (c) 1999-2004 The SquirrelMail Project Team
  23. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  24. * @package plugins
  25. * @subpackage filters
  26. */
  27. /**
  28. * Path for SquirrelMail required files.
  29. * @ignore
  30. */
  31. define('SM_PATH','../../');
  32. /* SquirrelMail required files. */
  33. require_once(SM_PATH . 'include/validate.php');
  34. require_once(SM_PATH . 'functions/page_header.php');
  35. require_once(SM_PATH . 'functions/imap.php');
  36. require_once(SM_PATH . 'include/load_prefs.php');
  37. require_once(SM_PATH . 'functions/html.php');
  38. require_once(SM_PATH . 'plugins/filters/filters.php');
  39. global $AllowSpamFilters;
  40. /* get globals */
  41. sqgetGlobalVar('username', $username, SQ_SESSION);
  42. sqgetGlobalVar('key', $key, SQ_COOKIE);
  43. sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
  44. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
  45. sqgetGlobalVar('action', $action, SQ_GET);
  46. /* end globals */
  47. displayPageHeader($color, 'None');
  48. if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
  49. $spam_filters = load_spam_filters();
  50. // setting spam folder
  51. sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
  52. if (isset($filters_spam_folder_set)) {
  53. setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
  54. } else {
  55. echo _("You must select a spam folder.");
  56. }
  57. // setting scan type
  58. sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
  59. if (isset($filters_spam_scan_set)) {
  60. setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
  61. } else {
  62. echo _("You must select a scan type.");
  63. }
  64. foreach ($spam_filters as $Key => $Value) {
  65. $input = $spam_filters[$Key]['prefname'] . '_set';
  66. if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
  67. setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
  68. } else {
  69. removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
  70. }
  71. }
  72. }
  73. $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
  74. $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
  75. $filters = load_filters();
  76. echo html_tag( 'table',
  77. html_tag( 'tr',
  78. html_tag( 'th', _("Spam Filtering"), 'center' )
  79. ) ,
  80. 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
  81. if ($SpamFilters_YourHop == ' ') {
  82. echo '<br />' .
  83. html_tag( 'div', '<b>' .
  84. sprintf(_("WARNING! Tell the adminstrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
  85. '</b>' ,
  86. 'center' ) .
  87. '<br />';
  88. }
  89. if (isset($action) && $action == 'spam') {
  90. $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  91. $boxes = sqimap_mailbox_list($imapConnection);
  92. sqimap_logout($imapConnection);
  93. $numboxes = count($boxes);
  94. for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
  95. if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
  96. (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
  97. (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
  98. $filters_spam_folder = $boxes[$i]['unformatted'];
  99. }
  100. }
  101. echo '<form method="post" action="spamoptions.php">'.
  102. '<center>'.
  103. html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
  104. html_tag( 'tr' ) .
  105. html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
  106. html_tag( 'td', '', 'left' ) .
  107. '<select name="filters_spam_folder_set">';
  108. $selected = 0;
  109. if ( isset($filters_spam_folder) )
  110. $selected = array(strtolower($filters_spam_folder));
  111. echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
  112. echo '</select>'.
  113. '</td>'.
  114. '</tr>'.
  115. html_tag( 'tr',
  116. html_tag( 'td', '&nbsp;' ) .
  117. html_tag( 'td',
  118. _("Moving spam directly to the trash may not be a good idea at first, since messages from friends and mailing lists might accidentally be marked as spam. Whatever folder you set this to, make sure that it gets cleaned out periodically, so that you don't have an excessively large mailbox hanging around.") ,
  119. 'left' )
  120. ) .
  121. html_tag( 'tr' ) .
  122. html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
  123. html_tag( 'td' ) .
  124. '<select name="filters_spam_scan_set">'.
  125. '<option value=""';
  126. if ($filters_spam_scan == '') {
  127. echo ' selected';
  128. }
  129. echo '>' . _("All messages") . '</option>'.
  130. '<option value="new"';
  131. if ($filters_spam_scan == 'new') {
  132. echo ' selected';
  133. }
  134. echo '>' . _("Unread messages only") . '</option>' .
  135. '</select>'.
  136. '</td>'.
  137. '</tr>'.
  138. html_tag( 'tr',
  139. html_tag( 'td', '&nbsp;' ) .
  140. html_tag( 'td',
  141. _("The more messages scanned, the longer it takes. It's recommended to scan unread messages only. If a change to the filters is made, it's recommended to set it to scan all messages, then go view the INBOX, then come back and set it to scan unread messages only. That way, the new spam filters will be applied and even the spam you didn't catch with the old filters will be scanned.") ,
  142. 'left' )
  143. );
  144. $spam_filters = load_spam_filters();
  145. foreach ($spam_filters as $Key => $Value) {
  146. echo html_tag( 'tr' ) .
  147. html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
  148. html_tag( 'td' ) .
  149. '<input type="checkbox" name="' .
  150. $spam_filters[$Key]['prefname'] .
  151. '_set"';
  152. if ($spam_filters[$Key]['enabled']) {
  153. echo ' checked';
  154. }
  155. echo ' /> - ';
  156. if ($spam_filters[$Key]['link']) {
  157. echo '<a href="' .
  158. $spam_filters[$Key]['link'] .
  159. '" target="_blank">';
  160. }
  161. echo $spam_filters[$Key]['name'];
  162. if ($spam_filters[$Key]['link']) {
  163. echo '</a>';
  164. }
  165. echo '</td></tr>' .
  166. html_tag( 'tr',
  167. html_tag( 'td', '&nbsp;' ) .
  168. html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
  169. ) . "\n";
  170. }
  171. echo html_tag( 'tr',
  172. html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
  173. ) . "\n" .
  174. '</table>'.
  175. '</center>'.
  176. '</form>';
  177. } else {
  178. // action is not set or action is not spam
  179. echo html_tag( 'p', '', 'center' ) .
  180. '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
  181. ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
  182. printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
  183. echo '<br />';
  184. printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All Messages") ) . '</b>' );
  185. echo '</p>'.
  186. '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
  187. $spam_filters = load_spam_filters();
  188. foreach ($spam_filters as $Key => $Value) {
  189. echo html_tag( 'tr' ) .
  190. html_tag( 'th', '', 'center' );
  191. if ($spam_filters[$Key]['enabled']) {
  192. echo _("ON");
  193. } else {
  194. echo _("OFF");
  195. }
  196. echo '</th>' .
  197. html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
  198. html_tag( 'td', '', 'left' );
  199. if ($spam_filters[$Key]['link']) {
  200. echo '<a href="' .
  201. $spam_filters[$Key]['link'] .
  202. '" target="_blank">';
  203. }
  204. echo $spam_filters[$Key]['name'];
  205. if ($spam_filters[$Key]['link']) {
  206. echo '</a>';
  207. }
  208. echo "</td></tr>\n";
  209. }
  210. echo '</table>';
  211. }
  212. ?>
  213. </body></html>