Add ability to show login error from the IMAP server instead of traditional "Unknown...
[squirrelmail.git] / plugins / filters / spamoptions.php
CommitLineData
63277aaa 1<?php
4b4abf93 2
15e6162e 3/**
b2d8bc6c 4 * Message and Spam Filter Plugin - Spam Options
15e6162e 5 *
701e7bee 6 * @copyright 1999-2014 The SquirrelMail Project Team
b2d8bc6c 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4b4abf93 8 * @version $Id$
ea5f4b8e 9 * @package plugins
10 * @subpackage filters
15e6162e 11 */
63277aaa 12
5b4ba967 13/**
202bcbcc 14 * Include the SquirrelMail initialization file.
5b4ba967 15 */
202bcbcc 16require('../../include/init.php');
08185f2a 17
202bcbcc 18include_once(SM_PATH . 'functions/imap_general.php');
19include_once(SM_PATH . 'functions/imap_messages.php');
e5c8ec61 20include_once(SM_PATH . 'plugins/filters/filters.php');
10a26cea 21
3c66c567 22/* get globals */
3c66c567 23sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41100fce 24
3c66c567 25sqgetGlobalVar('action', $action, SQ_GET);
9aaa9ae2 26global $imapSslOptions; // in case not defined in config
3c66c567 27/* end globals */
41100fce 28
876fdb60 29displayPageHeader($color);
10a26cea 30
0a1dc88e 31if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
10a26cea 32 $spam_filters = load_spam_filters();
0a1dc88e 33
91e0dccc 34 // setting spam folder
0a1dc88e 35 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
36 if (isset($filters_spam_folder_set)) {
37 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
38 } else {
91e0dccc 39 echo _("You must select a spam folder.");
0a1dc88e 40 }
41
42 // setting scan type
43 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
44 if (isset($filters_spam_scan_set)) {
91e0dccc 45 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
0a1dc88e 46 } else {
91e0dccc 47 echo _("You must select a scan type.");
0a1dc88e 48 }
49
10a26cea 50 foreach ($spam_filters as $Key => $Value) {
51 $input = $spam_filters[$Key]['prefname'] . '_set';
0a1dc88e 52 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
53 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
51199e7a 54 } else {
55 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 56 }
57 }
58}
59
60$filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
61$filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
62$filters = load_filters();
63
b01b21d0 64echo html_tag( 'table',
65 html_tag( 'tr',
66 html_tag( 'th', _("Spam Filtering"), 'center' )
67 ) ,
68 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
10a26cea 69
70if ($SpamFilters_YourHop == ' ') {
0a1dc88e 71 echo '<br />' .
b01b21d0 72 html_tag( 'div', '<b>' .
6d440be5 73 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
b01b21d0 74 '</b>' ,
75 'center' ) .
0a1dc88e 76 '<br />';
10a26cea 77}
78
79
80if (isset($action) && $action == 'spam') {
9aaa9ae2 81 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imapSslOptions);
10a26cea 82 $boxes = sqimap_mailbox_list($imapConnection);
83 sqimap_logout($imapConnection);
ae48f757 84 $numboxes = count($boxes);
85
86 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 87 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
88 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
89 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
10a26cea 90 $filters_spam_folder = $boxes[$i]['unformatted'];
91 }
5e2e3895 92 }
93
0a1dc88e 94 echo '<form method="post" action="spamoptions.php">'.
f265009a 95 '<div style="text-align: center;">'.
b01b21d0 96 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
97 html_tag( 'tr' ) .
c435f076 98 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
b01b21d0 99 html_tag( 'td', '', 'left' ) .
100 '<select name="filters_spam_folder_set">';
10a26cea 101
ae8a7931 102 $selected = 0;
103 if ( isset($filters_spam_folder) )
104 $selected = array(strtolower($filters_spam_folder));
105 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
10a26cea 106 echo '</select>'.
107 '</td>'.
108 '</tr>'.
b01b21d0 109 html_tag( 'tr',
110 html_tag( 'td', '&nbsp;' ) .
111 html_tag( 'td',
112 _("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.") ,
113 'left' )
114 ) .
115 html_tag( 'tr' ) .
c435f076 116 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
b01b21d0 117 html_tag( 'td' ) .
118 '<select name="filters_spam_scan_set">'.
10a26cea 119 '<option value=""';
120 if ($filters_spam_scan == '') {
743715c6 121 echo ' selected="selected"';
10a26cea 122 }
123 echo '>' . _("All messages") . '</option>'.
124 '<option value="new"';
125 if ($filters_spam_scan == 'new') {
743715c6 126 echo ' selected="selected"';
10a26cea 127 }
74091b64 128 echo '>' . _("Unread messages only") . '</option>' .
10a26cea 129 '</select>'.
130 '</td>'.
131 '</tr>'.
b01b21d0 132 html_tag( 'tr',
133 html_tag( 'td', '&nbsp;' ) .
134 html_tag( 'td',
74091b64 135 _("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.") ,
b01b21d0 136 'left' )
137 );
10a26cea 138
139 $spam_filters = load_spam_filters();
140
141 foreach ($spam_filters as $Key => $Value) {
b01b21d0 142 echo html_tag( 'tr' ) .
c435f076 143 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
b01b21d0 144 html_tag( 'td' ) .
0a1dc88e 145 '<input type="checkbox" name="' .
10a26cea 146 $spam_filters[$Key]['prefname'] .
147 '_set"';
148 if ($spam_filters[$Key]['enabled']) {
9374fbf7 149 echo ' checked="checked"';
10a26cea 150 }
0a1dc88e 151 echo ' /> - ';
10a26cea 152 if ($spam_filters[$Key]['link']) {
153 echo '<a href="' .
154 $spam_filters[$Key]['link'] .
155 '" target="_blank">';
156 }
157 echo $spam_filters[$Key]['name'];
158 if ($spam_filters[$Key]['link']) {
159 echo '</a>';
160 }
b01b21d0 161 echo '</td></tr>' .
162 html_tag( 'tr',
163 html_tag( 'td', '&nbsp;' ) .
164 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
165 ) . "\n";
166
10a26cea 167 }
b01b21d0 168 echo html_tag( 'tr',
0a1dc88e 169 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
b01b21d0 170 ) . "\n" .
10a26cea 171 '</table>'.
f265009a 172 '</div>'.
10a26cea 173 '</form>';
0a1dc88e 174} else {
175 // action is not set or action is not spam
b01b21d0 176 echo html_tag( 'p', '', 'center' ) .
177 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
f265009a 178 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</div><br /><br />';
3047e291 179 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($filters_spam_folder)).'</b>':'[<i>'._("not set yet").'</i>]' ) );
74091b64 180 echo '<br />';
3ee2d2ae 181 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
10a26cea 182 echo '</p>'.
0a1dc88e 183 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
10a26cea 184
185 $spam_filters = load_spam_filters();
186
187 foreach ($spam_filters as $Key => $Value) {
b01b21d0 188 echo html_tag( 'tr' ) .
189 html_tag( 'th', '', 'center' );
10a26cea 190
191 if ($spam_filters[$Key]['enabled']) {
192 echo _("ON");
193 } else {
194 echo _("OFF");
195 }
196
91e0dccc 197 echo '</th>' .
b01b21d0 198 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
199 html_tag( 'td', '', 'left' );
10a26cea 200
201 if ($spam_filters[$Key]['link']) {
202 echo '<a href="' .
203 $spam_filters[$Key]['link'] .
204 '" target="_blank">';
205 }
206
207 echo $spam_filters[$Key]['name'];
208 if ($spam_filters[$Key]['link']) {
209 echo '</a>';
210 }
211 echo "</td></tr>\n";
212 }
213 echo '</table>';
214}
0a1dc88e 215?>
2128bbc6 216</body></html>