From: Paul L. <pdo...@us...> - 2011-05-07 07:45:57
|
Update of /cvsroot/serverfilters/server_side_filters In directory vz-cvs-3.sog:/tmp/cvs-serv11916 Modified Files: config_example.php functions.php options.php setup.php Log Message: Add custom action capability Index: setup.php =================================================================== RCS file: /cvsroot/serverfilters/server_side_filters/setup.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** setup.php 10 Jan 2011 21:40:12 -0000 1.2 --- setup.php 7 May 2011 07:45:55 -0000 1.3 *************** *** 79,82 **** --- 79,93 ---- $ignore = _("%sFolder"); $ignore = _("%sEmail"); + $ignore = _("Flag"); + $ignore = _("Flag for follow-up"); + $ignore = _("Important"); + $ignore = _("Mark as important"); + $ignore = _("Work"); + $ignore = _("Private"); + $ignore = _("Mark as private"); + $ignore = _("TODO"); + $ignore = _("ToDo"); + $ignore = _("Later"); + $ignore = _("Follow-up"); } Index: functions.php =================================================================== RCS file: /cvsroot/serverfilters/server_side_filters/functions.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** functions.php 10 Jan 2011 21:40:12 -0000 1.2 --- functions.php 7 May 2011 07:45:55 -0000 1.3 *************** *** 55,59 **** $imapConnection, $key, $unsupported_matching_methods, $unsupported_matching_locations, $unsupported_actions, ! $additional_headers; server_side_filters_init(); $close_imap_connection = FALSE; --- 55,59 ---- $imapConnection, $key, $unsupported_matching_methods, $unsupported_matching_locations, $unsupported_actions, ! $additional_headers, $custom_actions; server_side_filters_init(); $close_imap_connection = FALSE; *************** *** 93,96 **** --- 93,98 ---- 'COPY' => _("Copy"), 'DELETE' => _("Delete")); + foreach ($custom_actions as $action => $action_details) + $ssf_filter_actions[$action] = _($action_details['SHORT_DESCRIPTION']); foreach ($unsupported_actions as $action) unset($ssf_filter_actions[$action]); *************** *** 336,340 **** // make sure plugin is correctly configured // ! global $server_side_filters_configtest, $predefined_filter_rules; $server_side_filters_configtest = TRUE; if (!server_side_filters_init()) --- 338,343 ---- // make sure plugin is correctly configured // ! global $server_side_filters_configtest, $predefined_filter_rules, ! $custom_actions; $server_side_filters_configtest = TRUE; if (!server_side_filters_init()) *************** *** 372,375 **** --- 375,401 ---- + if (!empty($custom_actions)) + { + if (!is_array($custom_actions)) + { + do_err('Server Side Filters plugin\'s $custom_actions is not configured correctly', FALSE); + return TRUE; + } + foreach ($custom_actions as $action => $action_details) + { + if (empty($action_details['SHORT_DESCRIPTION'])) + { + do_err('Server Side Filters plugin\'s $custom_actions is not configured correctly - the "' . $action . '" action is missing its SHORT_DESCRIPTION', FALSE); + return TRUE; + } + if (empty($action_details['FILTER_ACTION'])) + { + do_err('Server Side Filters plugin\'s $custom_actions is not configured correctly - the "' . $action . '" action is missing its FILTER_ACTION', FALSE); + return TRUE; + } + } + } + + return FALSE; *************** *** 437,443 **** * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", or "DELETE", ! * indicating how to handle a ! * filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to --- 463,471 ---- * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", "DELETE" or any ! * custom action that is defined in ! * $custom_actions in the main ! * configuration file, indicating ! * how to handle a filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to *************** *** 673,679 **** * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", or "DELETE", ! * indicating how to handle a ! * filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to --- 701,709 ---- * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", "DELETE" or any ! * custom action that is defined in ! * $custom_actions in the main ! * configuration file, indicating ! * how to handle a filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to *************** *** 846,852 **** * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", or "DELETE", ! * indicating how to handle a ! * filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to --- 876,884 ---- * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", "DELETE" or any ! * custom action that is defined in ! * $custom_actions in the main ! * configuration file, indicating ! * how to handle a filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to *************** *** 1042,1048 **** * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", or "DELETE", ! * indicating how to handle a ! * filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to --- 1074,1082 ---- * folder for moving or copying * filtered message ! * ACTION -- "MOVE", "COPY", "DELETE" or any ! * custom action that is defined in ! * $custom_actions in the main ! * configuration file, indicating ! * how to handle a filtered message * COPY_TO_FOLDER -- "OFF" or "ON", indicating if a * message should be copied to *************** *** 1238,1242 **** global $ssf_header_fields, $ssf_matching_methods, $ssf_filter_actions, ! $ssf_folder_list, $predefined_filter_rules; define_server_side_filter_constants($configtest); $errors = array(); --- 1272,1277 ---- global $ssf_header_fields, $ssf_matching_methods, $ssf_filter_actions, ! $ssf_folder_list, $predefined_filter_rules, $custom_actions; ! server_side_filters_init(); define_server_side_filter_constants($configtest); $errors = array(); *************** *** 1553,1560 **** } ! // if the action isn't to delete, then we must ! // either put it in a folder or send it elsewhere // ! if (isset($rule['ACTION']) && $rule['ACTION'] != 'DELETE' && isset($rule['SEND_TO_ADDRESS']) && $rule['SEND_TO_ADDRESS'] == 'OFF' && isset($rule['COPY_TO_FOLDER']) && $rule['COPY_TO_FOLDER'] == 'OFF') --- 1588,1601 ---- } ! // if the action isn't to delete (and isn't some custom ! // action that forbids additional message movement), then ! // we must either put it in a folder or send it elsewhere // ! $transport_actions = array('MOVE', 'COPY'); ! foreach ($custom_actions as $action => $action_details) ! if (!empty($action_details['SECONDARY_TRANSPORT']) ! && $action_details['SECONDARY_TRANSPORT'] == 'REQUIRED') ! $transport_actions[] = $action; ! if (isset($rule['ACTION']) && in_array($rule['ACTION'], $transport_actions) && isset($rule['SEND_TO_ADDRESS']) && $rule['SEND_TO_ADDRESS'] == 'OFF' && isset($rule['COPY_TO_FOLDER']) && $rule['COPY_TO_FOLDER'] == 'OFF') Index: options.php =================================================================== RCS file: /cvsroot/serverfilters/server_side_filters/options.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** options.php 10 Jan 2011 21:40:12 -0000 1.2 --- options.php 7 May 2011 07:45:55 -0000 1.3 *************** *** 72,76 **** $rule_number, $messages, $errors, $general_errors, $ssf_debug, $min_create_only, $org_title, $min_create_only_close_self, ! $min_create_only_onload, $min_create_only_finished; $errors = array(); --- 72,76 ---- $rule_number, $messages, $errors, $general_errors, $ssf_debug, $min_create_only, $org_title, $min_create_only_close_self, ! $min_create_only_onload, $min_create_only_finished, $custom_actions; $errors = array(); *************** *** 369,386 **** ! // we could produce an error in the case that DELETE was ! // chosen but a folder or email was selected, but instead ! // let's just auto-correct it and let the user know // $tentative_messages = array(); ! if ($filter_action == 'DELETE') { $original_text_domain = sq_change_text_domain('server_side_filters'); if ($copy_to_folder == 'ON' && $send_to_address == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the folder and email options have been disabled"); else if ($copy_to_folder == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the folder option has been disabled"); else if ($send_to_address == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the email option has been disabled"); sq_change_text_domain($original_text_domain); --- 369,396 ---- ! // we could produce an error in the case that DELETE or some other ! // non-transport-related custom action was chosen but a folder or ! // email was selected, but instead let's just auto-correct it and ! // let the user know // $tentative_messages = array(); ! $no_transport_actions = array('DELETE'); ! foreach ($custom_actions as $action => $action_details) ! if (!empty($action_details['SECONDARY_TRANSPORT']) ! && $action_details['SECONDARY_TRANSPORT'] == 'FORBIDDEN') ! $no_transport_actions[] = $action; ! if (in_array($filter_action, $no_transport_actions)) { $original_text_domain = sq_change_text_domain('server_side_filters'); + if ($filter_action == 'DELETE') + $filter_text = _("deletion"); + else + $filter_text = '"' . _($custom_actions[$filter_action]['SHORT_DESCRIPTION']) . '"'; if ($copy_to_folder == 'ON' && $send_to_address == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the folder and email options have been disabled"), $filter_text); else if ($copy_to_folder == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the folder option has been disabled"), $filter_text); else if ($send_to_address == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the email option has been disabled"), $filter_text); sq_change_text_domain($original_text_domain); *************** *** 693,710 **** ! // we could produce an error in the case that DELETE was ! // chosen but a folder or email was selected, but instead ! // let's just auto-correct it and let the user know // $tentative_messages = array(); ! if ($filter_action == 'DELETE') { $original_text_domain = sq_change_text_domain('server_side_filters'); if ($copy_to_folder == 'ON' && $send_to_address == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the folder and email options have been disabled"); else if ($copy_to_folder == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the folder option has been disabled"); else if ($send_to_address == 'ON') ! $tentative_messages[] = _("Note: because filtered messages are to be deleted, the email option has been disabled"); sq_change_text_domain($original_text_domain); --- 703,730 ---- ! // we could produce an error in the case that DELETE or some other ! // non-transport-related custom action was chosen but a folder or ! // email was selected, but instead let's just auto-correct it and ! // let the user know // $tentative_messages = array(); ! $no_transport_actions = array('DELETE'); ! foreach ($custom_actions as $action => $action_details) ! if (!empty($action_details['SECONDARY_TRANSPORT']) ! && $action_details['SECONDARY_TRANSPORT'] == 'FORBIDDEN') ! $no_transport_actions[] = $action; ! if (in_array($filter_action, $no_transport_actions)) { $original_text_domain = sq_change_text_domain('server_side_filters'); + if ($filter_action == 'DELETE') + $filter_text = _("deletion"); + else + $filter_text = '"' . _($custom_actions[$filter_action]['SHORT_DESCRIPTION']) . '"'; if ($copy_to_folder == 'ON' && $send_to_address == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the folder and email options have been disabled"), $filter_text); else if ($copy_to_folder == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the folder option has been disabled"), $filter_text); else if ($send_to_address == 'ON') ! $tentative_messages[] = sprintf(_("Note: because filtered messages will only be subject to %s, the email option has been disabled"), $filter_text); sq_change_text_domain($original_text_domain); Index: config_example.php =================================================================== RCS file: /cvsroot/serverfilters/server_side_filters/config_example.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** config_example.php 15 Jan 2011 20:02:14 -0000 1.5 --- config_example.php 7 May 2011 07:45:55 -0000 1.6 *************** *** 25,29 **** $filtering_kickoff_file, $ssf_debug, $new_folder_select_location, $unsupported_matching_methods, $unsupported_matching_locations, ! $unsupported_actions, $additional_headers; --- 25,29 ---- $filtering_kickoff_file, $ssf_debug, $new_folder_select_location, $unsupported_matching_methods, $unsupported_matching_locations, ! $unsupported_actions, $additional_headers, $custom_actions; *************** *** 350,354 **** // ACTION -- What to do with matching messages - this value // MUST be one of the following: "MOVE", "COPY", ! // or "DELETE" // COPY_TO_FOLDER -- Whether or not to move or copy matching messages // to a folder - this value MUST be either "ON" or --- 350,355 ---- // ACTION -- What to do with matching messages - this value // MUST be one of the following: "MOVE", "COPY", ! // "DELETE" or any custom action that is defined ! // in $custom_actions in the main configuration file // COPY_TO_FOLDER -- Whether or not to move or copy matching messages // to a folder - this value MUST be either "ON" or *************** *** 624,627 **** --- 625,713 ---- + // On the other hand, some filtering systems might support custom + // features not included in this plugin by default. You can add + // your own filter actions using these settings. Note that the + // action will need to be supported by the plugin that builds your + // filter rules (such as Server Side Filters Maildrop, Server Side + // Filters Sieve or Server Side Filters Procmail, the last of which + // does not currently support this feature). + // + // $custom_actions should be a list of custom actions where keys + // are internal action names (never shown to users) and values + // are a nested list of items, which must include the following + // attributes (but can include more attributes if the filter rules + // plugin being used requires such): + // + // SHORT_DESCRIPTION -- A brief textual description of each + // action that will be shown to users + // in the action selection list. + // FILTER_ACTION -- Text that is for use by the filter + // rules plugin when building the action + // filter syntax + // SECONDARY_TRANSPORT -- Indicates how a secondary action of + // either moving the message to a folder + // and/or forwarding via email is handled: + // "FORBIDDEN" = Additional (transport) + // action(s) are forbidden + // "REQUIRED" = Additional (transport) + // action(s) are required + // "OPTIONAL" = Additional (transport) + // action(s) are optional + // If not given, "OPTIONAL" is assumed. + // SECONDARY_TRANSPORT_COPY -- Indicates, when secondary (transport) + // actions are allowed, if those should + // be executed as MOVE or COPY actions. + // This should be set to 1 if they should + // be COPY actions. Otherwise (including + // if this item is left out), such actions + // will be executed as MOVE actions. + // + // Note that if possible, the SHORT_DESCRIPTION text will be translated. + // Currenlty, these values are known to this plugin and will be + // translated (if you have other suggestions, please contact the plugin + // authors): + // + // Flag + // Flag for follow-up + // Important + // Mark as important + // Work + // Private + // Mark as private + // TODO + // ToDo + // Later + // Follow-up + // + // Here is an example of how to offer your users the ability to add + // the "Important" IMAP KEYWORD (compatible with Thunderbird) when + // using the Maildrop filtering backend: + // + // $custom_actions = array( + // 'IMPORTANT' => array( + // 'SHORT_DESCRIPTION' => 'Important', + // 'FILTER_ACTION' => "if (\"\$KEYWORDS\" ne \"\")\n {\n KEYWORDS=\$KEYWORDS','\n }\n KEYWORDS=$KEYWORDS'\$label1'", + // 'SECONDARY_TRANSPORT' => 'OPTIONAL', + // ), + // ); + // + // Here is an example of how to offer your users the ability to flag + // incoming messages when using the Sieve filtering backend: + // + // $custom_actions = array( + // 'FLAG' => array( + // 'SHORT_DESCRIPTION' => 'Flag', + // 'FILTER_ACTION' => 'addflag "\\\\Flagged";', + // 'SECONDARY_TRANSPORT' => 'OPTIONAL', + // ), + // ); + // + // Change "\\\\Flagged" to "$label1" to make the Sieve example + // do the same thing the Maildrop example does. + // + $custom_actions = array(); + + + // When loading user filter files, all rules are safety-checked and // validated. Normally, this is a good safety mechanism to keep in |