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.
11 * @copyright 1999-2010 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @subpackage listcommands
19 * Get current list of subscribed non-RFC-compliant mailing lists for logged-in user
21 * @return array The list of mailing list addresses, keyed by integer index
23 function get_non_rfc_lists() {
24 global $username, $data_dir;
25 $lists = getPref($data_dir, $username, 'non_rfc_lists', array());
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;
41 * Show mailing list management option section on options page
43 function plugin_listcommands_optpage_register_block_do()
45 global $optpage_blocks, $listcommands_allow_non_rfc_list_management;
47 // only allow management of non-RFC lists if admin deems necessary
49 @include_once
(SM_PATH
. 'plugins/listcommands/config.php');
50 if (!$listcommands_allow_non_rfc_list_management)
53 $optpage_blocks[] = array(
54 'name' => _("Mailing Lists"),
55 'url' => '../plugins/listcommands/options.php',
56 '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."),
63 * internal function that builds mailing list links
65 function plugin_listcommands_menu_do() {
66 global $passed_id, $passed_ent_id, $mailbox, $message,
67 $startMessage, $oTemplate, $listcommands_allow_non_rfc_list_management;
69 @include_once
(SM_PATH
. 'plugins/listcommands/config.php');
72 * Array of commands we can deal with from the header. The Reply option
73 * is added later because we generate it using the Post information.
75 $fieldsdescr = listcommands_fieldsdescr();
78 foreach ($message->rfc822_header
->mlist
as $cmd => $actions) {
80 /* I don't know this action... skip it */
81 if ( !array_key_exists($cmd, $fieldsdescr) ) {
85 /* proto = {mailto,href} */
86 $aActions = array_keys($actions);
87 $proto = array_shift($aActions);
88 $act = array_shift($actions);
90 if ($proto == 'mailto') {
92 if (($cmd == 'post') ||
($cmd == 'owner')) {
93 $url = 'src/compose.php?'.
94 (isset($startMessage)?
'startMessage='.$startMessage.'&':'');
96 $url = "plugins/listcommands/mailout.php?action=$cmd&";
98 $url .= 'send_to=' . str_replace('?','&', $act);
100 $links[$cmd] = makeComposeLink($url, $fieldsdescr[$cmd]);
102 if ($cmd == 'post') {
103 if (!isset($mailbox))
105 $url .= '&passed_id='.$passed_id.
106 '&mailbox='.urlencode($mailbox).
107 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
108 $url .= '&smaction=reply';
110 $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']);
112 } else if ($proto == 'href') {
113 $links[$cmd] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank');
118 // allow non-rfc reply link if admin allows and message is from
119 // non-rfc list the user has configured
121 if ($listcommands_allow_non_rfc_list_management) {
123 $non_rfc_lists = get_non_rfc_lists();
125 $recipients = formatRecipientString($message->rfc822_header
->to
, "to") . ' '
126 . formatRecipientString($message->rfc822_header
->cc
, "cc") . ' '
127 . formatRecipientString($message->rfc822_header
->bcc
, "bcc");
129 if (!in_array('post', array_keys($links))) {
131 foreach ($non_rfc_lists as $non_rfc_list) {
132 if (preg_match('/(^|,|<|\s)' . preg_quote($non_rfc_list) . '($|,|>|\s)/', $recipients)) {
133 $url = 'src/compose.php?'
134 . (isset($startMessage)?
'startMessage='.$startMessage.'&':'')
135 . 'send_to=' . str_replace('?','&', $non_rfc_list);
137 $links['post'] = makeComposeLink($url, $fieldsdescr['post']);
145 if (!in_array('reply', array_keys($links))) {
147 foreach ($non_rfc_lists as $non_rfc_list) {
148 if (preg_match('/(^|,|\s)' . preg_quote($non_rfc_list) . '($|,|\s)/', $recipients)) {
149 if (!isset($mailbox))
151 $url = 'src/compose.php?'
152 . (isset($startMessage)?
'startMessage='.$startMessage.'&':'')
153 . 'send_to=' . str_replace('?','&', $non_rfc_list)
154 . '&passed_id='.$passed_id
155 . '&mailbox='.urlencode($mailbox)
156 . (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'')
157 . '&smaction=reply';
159 $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']);
170 if (count($links) > 0) {
171 $oTemplate->assign('links', $links);
172 $output = $oTemplate->fetch('plugins/listcommands/read_body_header.tpl');
173 return array('read_body_header' => $output);
179 * Returns an array with the actions as translated strings.
180 * @return array action as key, translated string as value
182 function listcommands_fieldsdescr() {
183 return array('post' => _("Post to List"),
184 'reply' => _("Reply to List"),
185 'subscribe' => _("Subscribe"),
186 'unsubscribe' => _("Unsubscribe"),
187 'archive' => _("List Archives"),
188 'owner' => _("Contact Listowner"),
189 'help' => _("Help"));