X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=plugins%2Flistcommands%2Ffunctions.php;h=6c526c2a49ff4e72a6aa03293cb85ca8dea6bd07;hb=d47243ef228a893fda11d5b8d7169a15cb21c333;hp=adb7b49d22400f16f8c6b637df15a28372384386;hpb=f7b996c37914340010adedd03f5c014dd756d3f1;p=squirrelmail.git diff --git a/plugins/listcommands/functions.php b/plugins/listcommands/functions.php index adb7b49d..6c526c2a 100644 --- a/plugins/listcommands/functions.php +++ b/plugins/listcommands/functions.php @@ -8,18 +8,65 @@ * this plugin displays a menu which gives the user a choice of mailinglist * commands such as (un)subscribe, help and list archives. * - * @copyright © 1999-2006 The SquirrelMail Project Team + * @copyright 1999-2015 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package plugins * @subpackage listcommands */ +/** + * Get current list of subscribed non-RFC-compliant mailing lists for logged-in user + * + * @return array The list of mailing list addresses, keyed by integer index + */ +function get_non_rfc_lists() { + global $username, $data_dir; + $lists = getPref($data_dir, $username, 'non_rfc_lists', array()); + $new_lists = array(); + if (!empty($lists)) { + $lists = explode(':', $lists); + foreach ($lists as $list) { + list($index, $list_addr) = explode('_', $list); + if ((!empty($index) || $index === '0') && !empty($list_addr)) + $new_lists[$index] = $list_addr; + } + } + $lists = $new_lists; + sort($lists); + return $lists; +} + +/** + * Show mailing list management option section on options page + */ +function plugin_listcommands_optpage_register_block_do() +{ + global $optpage_blocks, $listcommands_allow_non_rfc_list_management; + + // only allow management of non-RFC lists if admin deems necessary + // + @include_once(SM_PATH . 'plugins/listcommands/config.php'); + if (!$listcommands_allow_non_rfc_list_management) + return; + + $optpage_blocks[] = array( + 'name' => _("Mailing Lists"), + 'url' => '../plugins/listcommands/options.php', + 'desc' => _("Manage the (non-RFC-compliant) mailing lists that you are subscribed to for the purpose of providing one-click list replies when responding to list messages."), + 'js' => false + ); + +} + /** * internal function that builds mailing list links */ function plugin_listcommands_menu_do() { - global $passed_id, $passed_ent_id, $color, $mailbox, $message, $startMessage, $oTemplate; + global $passed_id, $passed_ent_id, $mailbox, $message, + $startMessage, $oTemplate, $listcommands_allow_non_rfc_list_management; + + @include_once(SM_PATH . 'plugins/listcommands/config.php'); /** * Array of commands we can deal with from the header. The Reply option @@ -37,10 +84,11 @@ function plugin_listcommands_menu_do() { /* proto = {mailto,href} */ $aActions = array_keys($actions); + // note that we only use the first cmd/action, ignore the rest $proto = array_shift($aActions); $act = array_shift($actions); - if (1||$proto == 'mailto') { + if ($proto == 'mailto') { if (($cmd == 'post') || ($cmd == 'owner')) { $url = 'src/compose.php?'. @@ -48,9 +96,19 @@ function plugin_listcommands_menu_do() { } else { $url = "plugins/listcommands/mailout.php?action=$cmd&"; } - $url .= 'send_to=' . str_replace('?','&', $act); - $links[] = makeComposeLink($url, $fieldsdescr[$cmd]); + // if things like subject are given, peel them off and give + // them to src/compose.php as is (not encoded) + if (strpos($act, '?') > 0) { + list($act, $parameters) = explode('?', $act, 2); + $parameters = '&' . $parameters; + } else { + $parameters = ''; + } + + $url .= 'send_to=' . urlencode($act) . $parameters; + + $links[$cmd] = makeComposeLink($url, $fieldsdescr[$cmd]); if ($cmd == 'post') { if (!isset($mailbox)) @@ -60,17 +118,66 @@ function plugin_listcommands_menu_do() { (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); $url .= '&smaction=reply'; - $links[] = makeComposeLink($url, $fieldsdescr['reply']); + $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']); } } else if ($proto == 'href') { - $oTemplate->assign('uri', $act); - $oTemplate->assign('target', '_blank'); - $oTemplate->assign('text', $fieldsdescr[$cmd]); - $output = $oTemplate->fetch('hyperlink.tpl'); - $links[] = $output; + $links[$cmd] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank'); } } + + // allow non-rfc reply link if admin allows and message is from + // non-rfc list the user has configured + // + if ($listcommands_allow_non_rfc_list_management) { + + $non_rfc_lists = get_non_rfc_lists(); + + $recipients = formatRecipientString($message->rfc822_header->to, "to") . ' ' + . formatRecipientString($message->rfc822_header->cc, "cc") . ' ' + . formatRecipientString($message->rfc822_header->bcc, "bcc"); + + if (!in_array('post', array_keys($links))) { + + foreach ($non_rfc_lists as $non_rfc_list) { + if (preg_match('/(^|,|<|\s)' . preg_quote($non_rfc_list) . '($|,|>|\s)/', $recipients)) { + $url = 'src/compose.php?' + . (isset($startMessage)?'startMessage='.$startMessage.'&':'') + . 'send_to=' . str_replace('?','&', $non_rfc_list); + + $links['post'] = makeComposeLink($url, $fieldsdescr['post']); + + break; + } + } + + } + + if (!in_array('reply', array_keys($links))) { + + foreach ($non_rfc_lists as $non_rfc_list) { + if (preg_match('/(^|,|\s)' . preg_quote($non_rfc_list) . '($|,|\s)/', $recipients)) { + if (!isset($mailbox)) + $mailbox = 'INBOX'; + $url = 'src/compose.php?' + . (isset($startMessage)?'startMessage='.$startMessage.'&':'') + . 'send_to=' . str_replace('?','&', $non_rfc_list) + . '&passed_id='.$passed_id + . '&mailbox='.urlencode($mailbox) + . (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:'') + . '&smaction=reply'; + + $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']); + + break; + } + } + + } + + } + + if (count($links) > 0) { $oTemplate->assign('links', $links); $output = $oTemplate->fetch('plugins/listcommands/read_body_header.tpl');