Add ability for listcommands plugin to show reply and post links for user-configured...
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 13 Jan 2007 07:34:17 +0000 (07:34 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 13 Jan 2007 07:34:17 +0000 (07:34 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12115 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
plugins/listcommands/README
plugins/listcommands/functions.php
plugins/listcommands/setup.php

index c605b57975f93e38cf6018c7374594376d1d8802..ddfa752998338a723607d089de2a14faa13c9bba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -172,6 +172,9 @@ Version 1.5.2 - CVS
   - Add warning about magic_quotes_* in configtest.
   - Unify accepted versions for imap_server_type and set_defaults (#1629722).
   - Improve attachment temp file creation.
+  - Add ability for listcommands plugin to show post and reply links for 
+    user-configured non-RFC 2369-compliant lists; admin must enable by 
+    configuring plugin.
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------
index c407be72120751e378c23cbb072955e2c1935833..88851d9a1bd18673c6020ba6d25015d61a4d623f 100644 (file)
@@ -22,11 +22,17 @@ The information in these headers is used to generate an extra menuline on
 messages containing one or more of these headers to help users taking advantage
 of the features offered.
 
+For mailing list subscriptions to non-RFC-compliant lists, the administrator
+may allow users to manage a list of mailing list addresses for which they want
+to show a "reply to list" link when replying to messages on such lists.
+
 
 Installation
 ============
 
-Go to the main directory, run configure and add the plugin.
+Go to the main directory, run configure and add the plugin.  In order to enable
+optional features such as user management of subscriptions to non-RFC-compliant
+lists, copy config_sample.php to config.php and edit that file as desired.
 
 
 Acknowledgements
index d617cee0464a3a4a51b7721946da50d096bbd637..c51c615fb3e8f4e634d7baa3804effa70edefa51 100644 (file)
  * @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, $color, $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
@@ -50,7 +98,7 @@ function plugin_listcommands_menu_do() {
             }
             $url .= 'send_to=' . str_replace('?','&amp;', $act);
 
-            $links[] = makeComposeLink($url, $fieldsdescr[$cmd]);
+            $links[$cmd] = makeComposeLink($url, $fieldsdescr[$cmd]);
 
             if ($cmd == 'post') {
                 if (!isset($mailbox))
@@ -60,13 +108,66 @@ function plugin_listcommands_menu_do() {
                     (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
                 $url .= '&amp;smaction=reply';
 
-                $links[] = makeComposeLink($url, $fieldsdescr['reply']);
+                $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']);
             }
         } else if ($proto == 'href') {
-            $links[] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank');
+            $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.'&amp;':'')
+                         . 'send_to=' . str_replace('?','&amp;', $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.'&amp;':'')
+                         . 'send_to=' . str_replace('?','&amp;', $non_rfc_list)
+                         . '&amp;passed_id='.$passed_id
+                         . '&amp;mailbox='.urlencode($mailbox)
+                         . (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'')
+                         . '&amp;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');
index 18dc40ca7c8772af23f0f97ba45124caf5051d83..50b3add1e750eed86be9b17e01f6d2291cc0c3ab 100644 (file)
@@ -22,6 +22,8 @@ function squirrelmail_plugin_init_listcommands () {
     global $squirrelmail_plugin_hooks;
 
     $squirrelmail_plugin_hooks['template_construct_read_headers.tpl']['listcommands'] = 'plugin_listcommands_menu';
+    $squirrelmail_plugin_hooks['optpage_register_block']['listcommands'] = 'plugin_listcommands_optpage_register_block';
+
 }
 
 /**
@@ -31,3 +33,12 @@ function plugin_listcommands_menu() {
     include_once(SM_PATH . 'plugins/listcommands/functions.php');
     return plugin_listcommands_menu_do();
 }
+
+
+/**
+  * Show mailing list management option section on options page
+  */
+function plugin_listcommands_optpage_register_block() {
+    include_once(SM_PATH . 'plugins/listcommands/functions.php');
+    plugin_listcommands_optpage_register_block_do();
+}