From 0a1dc88e11c9c6b1734eaa35849e3476dc425c6d Mon Sep 17 00:00:00 2001 From: tokul Date: Tue, 13 Apr 2004 18:25:54 +0000 Subject: [PATCH] removed $_ variables. added some checks for POST forms. xhtml and string fixes proposed by Fredrik. phpdoc blocks. localized folder names git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7121 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/filters/filters.php | 77 +++++++++++++++++--- plugins/filters/options.php | 124 ++++++++++++++++++-------------- plugins/filters/setup.php | 66 ++++++++++++----- plugins/filters/spamoptions.php | 66 +++++++++-------- 4 files changed, 226 insertions(+), 107 deletions(-) diff --git a/plugins/filters/filters.php b/plugins/filters/filters.php index 251fb5ae..5b9ebdc9 100644 --- a/plugins/filters/filters.php +++ b/plugins/filters/filters.php @@ -1,7 +1,6 @@ $value) { @@ -404,6 +431,10 @@ function filters_spam_check_site($a, $b, $c, $d, &$filters) { return 0; } +/** + * FIXME: Undocumented function + * @access private + */ function load_filters() { global $data_dir, $username; @@ -417,6 +448,10 @@ function load_filters() { return $filters; } +/** + * FIXME: Undocumented function + * @access private + */ function load_spam_filters() { global $data_dir, $username, $SpamFilters_ShowCommercial; @@ -694,6 +729,10 @@ function load_spam_filters() { return $filters; } +/** + * FIXME: Undocumented function + * @access private + */ function remove_filter ($id) { global $data_dir, $username; @@ -706,6 +745,10 @@ function remove_filter ($id) { removePref($data_dir, $username, 'filter' . $id); } +/** + * FIXME: Undocumented function + * @access private + */ function filter_swap($id1, $id2) { global $data_dir, $username; @@ -718,8 +761,10 @@ function filter_swap($id1, $id2) { } } -/* This update the filter rules when - renaming or deleting folders */ +/** + * This update the filter rules when renaming or deleting folders + * @param array $args + */ function update_for_folder ($args) { $old_folder = $args[0]; $new_folder = $args[2]; @@ -746,9 +791,11 @@ function update_for_folder ($args) { } } } -/* + +/** * Function extracted from sqimap_get_small_header_list. * The unused FETCH arguments and HEADERS are disabled. + * @access private */ function filter_get_headers ($imap_stream, $query) { /* Get the small headers for each message in $msg_list */ @@ -866,4 +913,16 @@ function filter_get_headers ($imap_stream, $query) { return $msgs; } +/** + * Display formated error message + * @param string $string text message + * @return string html formated text message + * @access private + */ +function do_error($string) { + global $color; + echo "

"; + echo $string; + echo "

\n"; +} ?> diff --git a/plugins/filters/options.php b/plugins/filters/options.php index 33aecc75..c5d076e3 100644 --- a/plugins/filters/options.php +++ b/plugins/filters/options.php @@ -1,7 +1,6 @@ '); - $action = 'edit'; - } - setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder); - $filters[$theid]['where'] = $filter_where; - $filters[$theid]['what'] = $filter_what; - $filters[$theid]['folder'] = $filter_folder; +if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) { + + if(! isset($theid) ) $theid = 0; + + $complete_post=true; + + // FIXME: write human readable error messages + sqgetGlobalVar('filter_what', $filter_what, SQ_POST); + if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) { + do_error("Post error"); + $complete_post=false; + } + + sqgetGlobalVar('filter_where', $filter_where, SQ_POST); + if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) { + do_error("Post error"); + $complete_post=false; + } + + sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST); + if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) { + do_error("Post error"); + $complete_post=false; + } + + if ($complete_post) { + $filter_what = str_replace(',', ' ', $filter_what); + $filter_what = str_replace("\\\\", "\\", $filter_what); + $filter_what = str_replace("\\\"", '"', $filter_what); + $filter_what = str_replace('"', '"', $filter_what); + + if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) { + do_error(_("WARNING! Header filters should be of the format \"Header: value\"")); + $action = 'edit'; + } + setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder); + $filters[$theid]['where'] = $filter_where; + $filters[$theid]['what'] = $filter_what; + $filters[$theid]['folder'] = $filter_folder; + } } elseif (isset($action) && $action == 'delete') { remove_filter($theid); } elseif (isset($action) && $action == 'move_up') { filter_swap($theid, $theid - 1); } elseif (isset($action) && $action == 'move_down') { filter_swap($theid, $theid + 1); - } elseif (isset($_POST['user_submit'])) { - setPref($data_dir, $username, 'filters_user_scan', $_POST['filters_user_scan_set']); - echo '
'._("Saved Scan type")."
\n"; + } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) { + sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST); + setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set); + echo '
'._("Saved Scan type")."
\n"; } $filters = load_filters(); @@ -103,7 +116,7 @@ sqgetGlobalVar('action', $action, SQ_GET); ) , 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . - '
'. + '
'. '
'. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . html_tag( 'tr' ) . @@ -122,14 +135,14 @@ sqgetGlobalVar('action', $action, SQ_GET); echo '>' . _("Only unread messages") . '' . ''. ''. - html_tag( 'td', '', 'left' ) . + html_tag( 'td', '', 'left' ) . ''. '
'. '
'. html_tag( 'div', '[' . _("New") . '] - [' . _("Done") . ']' , - 'center' ) . '
'; + 'center' ) . '
'; if (isset($action) && ($action == 'add' || $action == 'edit')) { @@ -140,32 +153,32 @@ sqgetGlobalVar('action', $action, SQ_GET); $theid = count($filters); } echo html_tag( 'div', '', 'center' ) . - '
'. + ''. html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . html_tag( 'tr' ) . html_tag( 'td', _("Match:"), 'left' ) . html_tag( 'td', '', 'left' ) . - ''; $L = isset($filters[$theid]['where']); $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':''); - echo "'; + echo "'; $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':''); - echo "'; + echo "'; $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':''); - echo "'; + echo "'; $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':''); - echo "'; + echo "'; $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':''); - echo "'; + echo "'; $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':''); - echo "'; + echo "'; echo ''. ''. @@ -173,18 +186,18 @@ sqgetGlobalVar('action', $action, SQ_GET); html_tag( 'tr' ) . html_tag( 'td', _("Contains:"), 'right' ) . html_tag( 'td', '', 'left' ) . - ''. + echo '" />'. ''. ''. html_tag( 'tr' ) . html_tag( 'td', _("Move to:"), 'left' ) . html_tag( 'td', '', 'left' ) . ''. - ''; $selected = 0; if ( isset($filters[$theid]['folder']) ) $selected = array(strtolower($filters[$theid]['folder'])); @@ -194,8 +207,8 @@ sqgetGlobalVar('action', $action, SQ_GET); ''. ''. ''. - ''. - "". + '\n". + '\n". ''. ''; @@ -210,29 +223,32 @@ sqgetGlobalVar('action', $action, SQ_GET); echo html_tag( 'tr', '', '', $clr ) . html_tag( 'td', '' . - "[" . _("Edit") . ']'. + "[" . _("Edit") . ']'. '' , 'left' ) . html_tag( 'td', '' . - "[" . _("Delete") . ']'. + "[" . _("Delete") . ']'. '' , 'left' ) . html_tag( 'td', '', 'center' ) . '['; if (isset($filters[$i + 1])) { - echo "" . _("Down") . ''; + echo "" . _("Down") . ''; if ($i > 0) { echo ' | '; } } if ($i > 0) { - echo "" . _("Up") . ''; + echo "" . _("Up") . ''; } echo ']'. html_tag( 'td', '-', 'left' ) . html_tag( 'td', '', 'left' ); - printf( _("If %s contains %s then move to %s"), $filters[$i]['where'], $filters[$i]['what'], $fdr ); + printf( _("If %s contains %s then move to %s"), + ''.$filters[$i]['where'].'', + ''.$filters[$i]['what'].'', + ''.imap_utf7_decode_local($fdr).''); echo ''; } diff --git a/plugins/filters/setup.php b/plugins/filters/setup.php index 734386ec..6aa0b057 100644 --- a/plugins/filters/setup.php +++ b/plugins/filters/setup.php @@ -29,22 +29,30 @@ /** SquirrelMail required files. */ require_once(SM_PATH . 'plugins/filters/filters.php'); -/* +/** + * Imap connection control + * * Set this to true if you have problems -- check the README file * Note: This doesn't work all of the time (No idea why) * Seems to be related to UW + * @global bool $UseSeparateImapConnection */ global $UseSeparateImapConnection; $UseSeparateImapConnection = false; -/* +/** + * User level spam filters control + * * Set this to false if you do not want the user to be able to enable * spam filters + * @global bool $AllowSpamFilters */ global $AllowSpamFilters; $AllowSpamFilters = true; -/* +/** + * SpamFilters YourHop Setting + * * Set this to a string containing something unique to the line in the * header you want me to find IPs to scan the databases with. For example, * All the email coming IN from the internet to my site has a line in @@ -57,61 +65,77 @@ $AllowSpamFilters = true; * case-sensitive string will do. You can set it to something found on * every line in the header (like ' ') if you want to scan all IPs in * the header (lots of false alarms here tho). + * @global string $SpamFilters_YourHop */ global $SpamFilters_YourHop; $SpamFilters_YourHop = ' '; -/* +/** + * Commercial Spam Filters Control + * * Some of the SPAM filters are COMMERCIAL and require a fee. If your users * select them and you're not allowed to use them, it will make SPAM filtering * very slow. If you don't want them to even be offered to the users, you * should set SpamFilters_ShowCommercial to false. + * @global bool $SpamFilters_ShowCommercial */ global $SpamFilters_ShowCommercial; $SpamFilters_ShowCommercial = false; -/* +/** + * SpamFiltring Cache + * * A cache of IPs we've already checked or are known bad boys or good boys * ie. $SpamFilters_DNScache["210.54.220.18"] = true; * would tell filters to not even bother doing the DNS queries for that * IP and any email coming from it are SPAM - false would mean that any * email coming from it would NOT be SPAM + * @global array $SpamFilters_DNScache */ global $SpamFilters_DNScache; -/* +/** + * Path to bulkquery program + * * Absolute path to the bulkquery program. Leave blank if you don't have * bulkquery compiled, installed, and lwresd running. See the README file * in the bulkquery directory for more information on using bulkquery. + * @global string $SpamFilters_BulkQuery */ global $SpamFilters_BulkQuery; $SpamFilters_BulkQuery = ''; -/* +/** + * Shared filtering cache control + * * Do you want to use a shared file for the DNS cache or a session variable? * Using a shared file means that every user can benefit from any queries * made by other users. The shared file is named "dnscache" and is in the * data directory. + * @global bool $SpamFilters_SharedCache */ global $SpamFilters_SharedCache; $SpamFilters_SharedCache = true; -/* +/** + * DNS query TTL + * * How long should DNS query results be cached for by default (in seconds)? + * @global integer $SpamFilters_CacheTTL */ global $SpamFilters_CacheTTL; $SpamFilters_CacheTTL = 7200; +/** + * Init plugin + * @access private + */ function squirrelmail_plugin_init_filters() { global $squirrelmail_plugin_hooks; - if (isset($_GET['mailbox'])) { - $mailbox = $_GET['mailbox']; - } - elseif (isset($_POST['mailbox'])) { - $mailbox = $_POST['mailbox']; - } - else { + if (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM)) { + sqgetGlobalVar('mailbox',$mailbox,SQ_FORM); + } else { $mailbox = 'INBOX'; } @@ -125,13 +149,23 @@ function squirrelmail_plugin_init_filters() { $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters'; } +/** + * Report spam folter as special mailbox + * @param string $mb variable used by hook + * @return string spam folder name + * @access private + */ function filters_special_mailbox( $mb ) { - GLOBAL $data_dir, $username; + global $data_dir, $username; return( $mb == getPref($data_dir, $username, 'filters_spam_folder', 'na' ) ); } +/** + * Register option blocks + * @access private + */ function filters_optpage_register_block() { global $optpage_blocks; global $AllowSpamFilters; diff --git a/plugins/filters/spamoptions.php b/plugins/filters/spamoptions.php index da7209b4..5b3a09f3 100644 --- a/plugins/filters/spamoptions.php +++ b/plugins/filters/spamoptions.php @@ -52,15 +52,29 @@ sqgetGlobalVar('action', $action, SQ_GET); displayPageHeader($color, 'None'); -if (isset($_POST['spam_submit'])) { +if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) { $spam_filters = load_spam_filters(); - setPref($data_dir, $username, 'filters_spam_folder', $_POST['filters_spam_folder_set']); - setPref($data_dir, $username, 'filters_spam_scan', $_POST['filters_spam_scan_set']); + + // setting spam folder + sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST); + if (isset($filters_spam_folder_set)) { + setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set); + } else { + echo _("You must select spam folder."); + } + + // setting scan type + sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST); + if (isset($filters_spam_scan_set)) { + setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set); + } else { + echo _("You must select scan type."); + } + foreach ($spam_filters as $Key => $Value) { $input = $spam_filters[$Key]['prefname'] . '_set'; - if ( isset( $_POST[$input] ) ) { - setPref( $data_dir, $username, $spam_filters[$Key]['prefname'], - $_POST[$input]); + if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) { + setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key); } else { removePref($data_dir, $username, $spam_filters[$Key]['prefname']); } @@ -78,12 +92,12 @@ echo html_tag( 'table', 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' ); if ($SpamFilters_YourHop == ' ') { - echo '
' . + echo '
' . html_tag( 'div', '' . - _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") . + sprintf(_("WARNING! Tell your admin to set the %s variable"),'SpamFilters_YourHop') . '' , 'center' ) . - '
'; + '
'; } @@ -101,7 +115,7 @@ if (isset($action) && $action == 'spam') { } } - echo '
'. + echo ''. '
'. html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) . html_tag( 'tr' ) . @@ -128,12 +142,12 @@ if (isset($action) && $action == 'spam') { ''. @@ -142,7 +156,7 @@ if (isset($action) && $action == 'spam') { html_tag( 'tr', html_tag( 'td', ' ' ) . html_tag( 'td', - _("The more messages you scan, the longer it takes. I would suggest that you scan only new messages. If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages. That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.") , + _("The more messages you scan, the longer it takes. I would suggest that you scan only new messages. If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages. That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.") , 'left' ) ); @@ -152,13 +166,13 @@ if (isset($action) && $action == 'spam') { echo html_tag( 'tr' ) . html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" . html_tag( 'td' ) . - ' - '; + echo ' /> - '; if ($spam_filters[$Key]['link']) { echo '', 'center', '', 'colspan="2"' ) + html_tag( 'td', '', 'center', '', 'colspan="2"' ) ) . "\n" . ''. '
'. ''; - echo ''; -} - -if (! isset($_GET['action']) || $_GET['action'] != 'spam') { - +} else { + // action is not set or action is not spam echo html_tag( 'p', '', 'center' ) . '[
' . _("Edit") . ']' . - ' - [' . _("Done") . ']

'; - printf( _("Spam is sent to %s"), ($filters_spam_folder?$filters_spam_folder:_("[not set yet]") ) ); + ' - [' . _("Done") . ']

'; + printf( _("Spam is sent to %s"), ($filters_spam_folder?''.imap_utf7_decode_local($filters_spam_folder).'':'['._("not set yet").']' ) ); echo '
'; printf( _("Spam scan is limited to %s"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) ); echo '

'. - ""; + '
\n"; $spam_filters = load_spam_filters(); @@ -224,7 +235,6 @@ if (! isset($_GET['action']) || $_GET['action'] != 'spam') { echo "\n"; } echo '
'; - echo ''; } - -?> \ No newline at end of file +?> + -- 2.25.1