| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * functions.php |
| 5 | * |
| 6 | * Implementation of RFC 2369 for SquirrelMail. |
| 7 | * When viewing a message from a mailinglist complying with this RFC, |
| 8 | * this plugin displays a menu which gives the user a choice of mailinglist |
| 9 | * commands such as (un)subscribe, help and list archives. |
| 10 | * |
| 11 | * @copyright © 1999-2007 The SquirrelMail Project Team |
| 12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 13 | * @version $Id$ |
| 14 | * @package plugins |
| 15 | * @subpackage listcommands |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Get current list of subscribed non-RFC-compliant mailing lists for logged-in user |
| 20 | * |
| 21 | * @return array The list of mailing list addresses, keyed by integer index |
| 22 | */ |
| 23 | function get_non_rfc_lists() { |
| 24 | global $username, $data_dir; |
| 25 | $lists = getPref($data_dir, $username, 'non_rfc_lists', array()); |
| 26 | $new_lists = array(); |
| 27 | if (!empty($lists)) { |
| 28 | $lists = explode(':', $lists); |
| 29 | foreach ($lists as $list) { |
| 30 | list($index, $list_addr) = explode('_', $list); |
| 31 | if ((!empty($index) || $index === '0') && !empty($list_addr)) |
| 32 | $new_lists[$index] = $list_addr; |
| 33 | } |
| 34 | } |
| 35 | $lists = $new_lists; |
| 36 | sort($lists); |
| 37 | return $lists; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Show mailing list management option section on options page |
| 42 | */ |
| 43 | function plugin_listcommands_optpage_register_block_do() |
| 44 | { |
| 45 | |
| 46 | global $optpage_blocks, $listcommands_allow_non_rfc_list_management; |
| 47 | |
| 48 | // only allow management of non-RFC lists if admin deems necessary |
| 49 | // |
| 50 | @include_once(SM_PATH . 'plugins/listcommands/config.php'); |
| 51 | if (!$listcommands_allow_non_rfc_list_management) |
| 52 | return; |
| 53 | |
| 54 | $optpage_blocks[] = array( |
| 55 | 'name' => _("Mailing Lists"), |
| 56 | 'url' => '../plugins/listcommands/options.php', |
| 57 | '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."), |
| 58 | 'js' => false |
| 59 | ); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * internal function that builds mailing list links |
| 65 | */ |
| 66 | function plugin_listcommands_menu_do() { |
| 67 | global $passed_id, $passed_ent_id, $color, $mailbox, $message, |
| 68 | $startMessage, $oTemplate, $listcommands_allow_non_rfc_list_management; |
| 69 | |
| 70 | @include_once(SM_PATH . 'plugins/listcommands/config.php'); |
| 71 | |
| 72 | /** |
| 73 | * Array of commands we can deal with from the header. The Reply option |
| 74 | * is added later because we generate it using the Post information. |
| 75 | */ |
| 76 | $fieldsdescr = listcommands_fieldsdescr(); |
| 77 | $links = array(); |
| 78 | |
| 79 | foreach ($message->rfc822_header->mlist as $cmd => $actions) { |
| 80 | |
| 81 | /* I don't know this action... skip it */ |
| 82 | if ( !array_key_exists($cmd, $fieldsdescr) ) { |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | /* proto = {mailto,href} */ |
| 87 | $aActions = array_keys($actions); |
| 88 | $proto = array_shift($aActions); |
| 89 | $act = array_shift($actions); |
| 90 | |
| 91 | if ($proto == 'mailto') { |
| 92 | |
| 93 | if (($cmd == 'post') || ($cmd == 'owner')) { |
| 94 | $url = 'src/compose.php?'. |
| 95 | (isset($startMessage)?'startMessage='.$startMessage.'&':''); |
| 96 | } else { |
| 97 | $url = "plugins/listcommands/mailout.php?action=$cmd&"; |
| 98 | } |
| 99 | $url .= 'send_to=' . str_replace('?','&', $act); |
| 100 | |
| 101 | $links[$cmd] = makeComposeLink($url, $fieldsdescr[$cmd]); |
| 102 | |
| 103 | if ($cmd == 'post') { |
| 104 | if (!isset($mailbox)) |
| 105 | $mailbox = 'INBOX'; |
| 106 | $url .= '&passed_id='.$passed_id. |
| 107 | '&mailbox='.urlencode($mailbox). |
| 108 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
| 109 | $url .= '&smaction=reply'; |
| 110 | |
| 111 | $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']); |
| 112 | } |
| 113 | } else if ($proto == 'href') { |
| 114 | $links[$cmd] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank'); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
| 119 | // allow non-rfc reply link if admin allows and message is from |
| 120 | // non-rfc list the user has configured |
| 121 | // |
| 122 | if ($listcommands_allow_non_rfc_list_management) { |
| 123 | |
| 124 | $non_rfc_lists = get_non_rfc_lists(); |
| 125 | |
| 126 | $recipients = formatRecipientString($message->rfc822_header->to, "to") . ' ' |
| 127 | . formatRecipientString($message->rfc822_header->cc, "cc") . ' ' |
| 128 | . formatRecipientString($message->rfc822_header->bcc, "bcc"); |
| 129 | |
| 130 | if (!in_array('post', array_keys($links))) { |
| 131 | |
| 132 | foreach ($non_rfc_lists as $non_rfc_list) { |
| 133 | if (preg_match('/(^|,|<|\s)' . preg_quote($non_rfc_list) . '($|,|>|\s)/', $recipients)) { |
| 134 | $url = 'src/compose.php?' |
| 135 | . (isset($startMessage)?'startMessage='.$startMessage.'&':'') |
| 136 | . 'send_to=' . str_replace('?','&', $non_rfc_list); |
| 137 | |
| 138 | $links['post'] = makeComposeLink($url, $fieldsdescr['post']); |
| 139 | |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | } |
| 145 | |
| 146 | if (!in_array('reply', array_keys($links))) { |
| 147 | |
| 148 | foreach ($non_rfc_lists as $non_rfc_list) { |
| 149 | if (preg_match('/(^|,|\s)' . preg_quote($non_rfc_list) . '($|,|\s)/', $recipients)) { |
| 150 | if (!isset($mailbox)) |
| 151 | $mailbox = 'INBOX'; |
| 152 | $url = 'src/compose.php?' |
| 153 | . (isset($startMessage)?'startMessage='.$startMessage.'&':'') |
| 154 | . 'send_to=' . str_replace('?','&', $non_rfc_list) |
| 155 | . '&passed_id='.$passed_id |
| 156 | . '&mailbox='.urlencode($mailbox) |
| 157 | . (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:'') |
| 158 | . '&smaction=reply'; |
| 159 | |
| 160 | $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']); |
| 161 | |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | } |
| 167 | |
| 168 | } |
| 169 | |
| 170 | |
| 171 | if (count($links) > 0) { |
| 172 | $oTemplate->assign('links', $links); |
| 173 | $output = $oTemplate->fetch('plugins/listcommands/read_body_header.tpl'); |
| 174 | return array('read_body_header' => $output); |
| 175 | } |
| 176 | |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns an array with the actions as translated strings. |
| 181 | * @return array action as key, translated string as value |
| 182 | */ |
| 183 | function listcommands_fieldsdescr() { |
| 184 | return array('post' => _("Post to List"), |
| 185 | 'reply' => _("Reply to List"), |
| 186 | 'subscribe' => _("Subscribe"), |
| 187 | 'unsubscribe' => _("Unsubscribe"), |
| 188 | 'archive' => _("List Archives"), |
| 189 | 'owner' => _("Contact Listowner"), |
| 190 | 'help' => _("Help")); |
| 191 | } |
| 192 | |