| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Message and Spam Filter Plugin - Filtering Options |
| 5 | * |
| 6 | * @copyright 1999-2018 The SquirrelMail Project Team |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * @version $Id$ |
| 9 | * @package plugins |
| 10 | * @subpackage filters |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Include the SquirrelMail initialization file. |
| 15 | */ |
| 16 | require('../../include/init.php'); |
| 17 | include_once(SM_PATH . 'functions/imap_general.php'); |
| 18 | include_once(SM_PATH . 'functions/forms.php'); |
| 19 | include_once(SM_PATH . 'plugins/filters/filters.php'); |
| 20 | |
| 21 | displayPageHeader($color); |
| 22 | |
| 23 | /* get globals */ |
| 24 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 25 | |
| 26 | sqgetGlobalVar('theid', $theid); |
| 27 | sqgetGlobalVar('action', $action, SQ_GET); |
| 28 | global $imap_stream_options; // in case not defined in config |
| 29 | |
| 30 | if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) { |
| 31 | |
| 32 | if(! isset($theid) ) $theid = 0; |
| 33 | |
| 34 | $complete_post=true; |
| 35 | |
| 36 | // FIXME: write human readable error messages |
| 37 | sqgetGlobalVar('filter_what', $filter_what, SQ_POST); |
| 38 | if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) { |
| 39 | do_error("Post error"); |
| 40 | $complete_post=false; |
| 41 | } |
| 42 | |
| 43 | sqgetGlobalVar('filter_where', $filter_where, SQ_POST); |
| 44 | if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) { |
| 45 | do_error("Post error"); |
| 46 | $complete_post=false; |
| 47 | } |
| 48 | |
| 49 | sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST); |
| 50 | if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) { |
| 51 | do_error("Post error"); |
| 52 | $complete_post=false; |
| 53 | } |
| 54 | |
| 55 | if ($complete_post) { |
| 56 | $filter_what = str_replace(',', '###COMMA###', $filter_what); |
| 57 | $filter_what = str_replace("\\\\", "\\", $filter_what); |
| 58 | $filter_what = str_replace("\\\"", '"', $filter_what); |
| 59 | $filter_what = str_replace('"', '"', $filter_what); |
| 60 | |
| 61 | if (empty($filter_what)) { |
| 62 | do_error(_("WARNING! You must enter something to search for.")); |
| 63 | $action = 'edit'; |
| 64 | } |
| 65 | |
| 66 | if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) { |
| 67 | do_error(_("WARNING! Header filters should be of the format "Header: value"")); |
| 68 | $action = 'edit'; |
| 69 | } |
| 70 | if ($action != 'edit') { |
| 71 | setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder); |
| 72 | } |
| 73 | $filters[$theid]['where'] = $filter_where; |
| 74 | $filters[$theid]['what'] = $filter_what; |
| 75 | $filters[$theid]['folder'] = $filter_folder; |
| 76 | } |
| 77 | } elseif (isset($action) && $action == 'delete') { |
| 78 | remove_filter($theid); |
| 79 | } elseif (isset($action) && $action == 'move_up') { |
| 80 | filter_swap($theid, $theid - 1); |
| 81 | } elseif (isset($action) && $action == 'move_down') { |
| 82 | filter_swap($theid, $theid + 1); |
| 83 | } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) { |
| 84 | sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST); |
| 85 | setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set); |
| 86 | echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n"; |
| 87 | } |
| 88 | |
| 89 | $filters = load_filters(); |
| 90 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
| 91 | |
| 92 | echo html_tag( 'table', |
| 93 | html_tag( 'tr', |
| 94 | html_tag( 'td', |
| 95 | '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' , |
| 96 | 'left', $color[0] |
| 97 | ) |
| 98 | ), |
| 99 | 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' |
| 100 | ) . |
| 101 | '<br /><form method="post" action="options.php">'. |
| 102 | html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
| 103 | html_tag( 'tr' ) . |
| 104 | html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) . |
| 105 | html_tag( 'td', '', 'left' ) . |
| 106 | '<select name="filters_user_scan_set">'. |
| 107 | '<option value=""'; |
| 108 | if ($filters_user_scan == '') { |
| 109 | echo ' selected="selected"'; |
| 110 | } |
| 111 | echo '>' . _("All messages") . '</option>'. |
| 112 | '<option value="new"'; |
| 113 | if ($filters_user_scan == 'new') { |
| 114 | echo ' selected="selected"'; |
| 115 | } |
| 116 | echo '>' . _("Only unread messages") . '</option>' . |
| 117 | '</select>'. |
| 118 | '</td>'. |
| 119 | html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) . |
| 120 | '</table>'. |
| 121 | '</form>'. |
| 122 | |
| 123 | html_tag( 'div', '[<a href="options.php?action=add">' . _("New") . |
| 124 | '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' , |
| 125 | 'center' ) . '<br />'; |
| 126 | |
| 127 | if (isset($action) && ($action == 'add' || $action == 'edit')) { |
| 128 | |
| 129 | $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options); |
| 130 | $boxes = sqimap_mailbox_list($imapConnection); |
| 131 | |
| 132 | for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++) { |
| 133 | if (strtolower($boxes[$a]['formatted']) == 'inbox') { |
| 134 | unset($boxes[$a]); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | sqimap_logout($imapConnection); |
| 139 | if ( !isset($theid) ) { |
| 140 | $theid = count($filters); |
| 141 | } |
| 142 | echo html_tag( 'div', '', 'center' ) . |
| 143 | '<form action="options.php" method="post">'. |
| 144 | html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
| 145 | html_tag( 'tr' ) . |
| 146 | html_tag( 'td', _("Match:"), 'left' ) . |
| 147 | html_tag( 'td', '', 'left' ) . |
| 148 | '<select name="filter_where">'; |
| 149 | |
| 150 | $L = isset($filters[$theid]['where']); |
| 151 | |
| 152 | $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':''); |
| 153 | echo "<option value=\"From\"$sel>" . _("From") . '</option>'; |
| 154 | |
| 155 | $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':''); |
| 156 | echo "<option value=\"To\"$sel>" . _("To") . '</option>'; |
| 157 | |
| 158 | $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':''); |
| 159 | echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>'; |
| 160 | |
| 161 | $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':''); |
| 162 | echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>'; |
| 163 | |
| 164 | $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':''); |
| 165 | echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>'; |
| 166 | |
| 167 | $sel = (($L && $filters[$theid]['where'] == 'Message Body')?' selected="selected"':''); |
| 168 | echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>'; |
| 169 | |
| 170 | $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?' selected="selected"':''); |
| 171 | echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>'; |
| 172 | |
| 173 | $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':''); |
| 174 | echo "<option value=\"Header\"$sel>" . _("Header") . '</option>'; |
| 175 | |
| 176 | echo '</select>'. |
| 177 | '</td>'. |
| 178 | '</tr>'. |
| 179 | html_tag( 'tr' ) . |
| 180 | html_tag( 'td', _("Contains:"), 'right' ) . |
| 181 | html_tag( 'td', '', 'left' ) . |
| 182 | '<input type="text" size="32" name="filter_what" value="'; |
| 183 | if (isset($filters[$theid]['what'])) { |
| 184 | echo sm_encode_html_special_chars($filters[$theid]['what']); |
| 185 | } |
| 186 | echo '" />'. |
| 187 | '</td>'. |
| 188 | '</tr>'. |
| 189 | html_tag( 'tr' ) . |
| 190 | html_tag( 'td', _("Move to:"), 'left' ) . |
| 191 | html_tag( 'td', '', 'left' ) . |
| 192 | '<tt>'. |
| 193 | '<select name="filter_folder">'; |
| 194 | $selected = 0; |
| 195 | if ( isset($filters[$theid]['folder']) ) |
| 196 | $selected = array(strtolower($filters[$theid]['folder'])); |
| 197 | echo sqimap_mailbox_option_list(0, $selected, 0, $boxes); |
| 198 | echo '</select>'. |
| 199 | '</tt>'. |
| 200 | '</td>'. |
| 201 | '</tr>'. |
| 202 | '</table>'. |
| 203 | '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n". |
| 204 | addHidden('theid', $theid). |
| 205 | '</form>'. |
| 206 | '</div>'; |
| 207 | |
| 208 | } |
| 209 | |
| 210 | if (count($filters)) { |
| 211 | echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' ); |
| 212 | |
| 213 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
| 214 | |
| 215 | $clr = (($i % 2)?$color[0]:$color[9]); |
| 216 | $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"]; |
| 217 | echo html_tag( 'tr', '', '', $clr ) . |
| 218 | html_tag( 'td', |
| 219 | '<small>' . |
| 220 | "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'. |
| 221 | '</small>' , |
| 222 | 'left' ) . |
| 223 | html_tag( 'td', |
| 224 | '<small>' . |
| 225 | "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'. |
| 226 | '</small>' , |
| 227 | 'left' ); |
| 228 | |
| 229 | if ($num > 1) { |
| 230 | echo html_tag( 'td', '', 'center' ) . '<small>['; |
| 231 | if (isset($filters[$i + 1])) { |
| 232 | echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>'; |
| 233 | if ($i > 0) { |
| 234 | echo ' | '; |
| 235 | } |
| 236 | } |
| 237 | if ($i > 0) { |
| 238 | echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>'; |
| 239 | } |
| 240 | echo ']</small></td>'; |
| 241 | } |
| 242 | echo html_tag( 'td', '-', 'left' ) . |
| 243 | html_tag( 'td', '', 'left' ); |
| 244 | printf( _("If %s contains %s then move to %s"), |
| 245 | '<b>'.$filters[$i]['where'].'</b>', |
| 246 | '<b>'.$filters[$i]['what'].'</b>', |
| 247 | '<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($fdr)).'</b>'); |
| 248 | echo '</td></tr>'; |
| 249 | |
| 250 | } |
| 251 | echo '</table>'; |
| 252 | } |
| 253 | echo html_tag( 'table', |
| 254 | html_tag( 'tr', |
| 255 | html_tag( 'td', ' ', 'left' ) |
| 256 | ) , |
| 257 | 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' ); |
| 258 | echo '</body></html>'; |