Make listcommands plugin work again w.r.t. smaction
[squirrelmail.git] / plugins / listcommands / setup.php
1 <?php
2
3 /**
4 * setup.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Implementation of RFC 2369 for SquirrelMail.
10 * When viewing a message from a mailinglist complying with this RFC,
11 * this plugin displays a menu which gives the user a choice of mailinglist
12 * commands such as (un)subscribe, help and list archives.
13 *
14 * $Id$
15 */
16
17 function squirrelmail_plugin_init_listcommands () {
18 global $squirrelmail_plugin_hooks;
19
20 $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu';
21 }
22
23 function plugin_listcommands_menu() {
24 global $passed_id, $passed_ent_id, $color, $mailbox, $message;
25
26 /**
27 * Array of commands we can deal with from the header. The Reply option
28 * is added later because we generate it using the Post information.
29 */
30 $fieldsdescr = array('post' => _("Post to List"),
31 'reply' => _("Reply to List"),
32 'subscribe' => _("Subscribe"),
33 'unsubscribe' => _("Unsubscribe"),
34 'archive' => _("List Archives"),
35 'owner' => _("Contact Listowner"),
36 'help' => _("Help"));
37 $output = array();
38
39 foreach ($message->rfc822_header->mlist as $cmd => $actions) {
40
41 /* I don't know this action... skip it */
42 if ( ( function_exists('array_key_exists') && /* PHP >= 4.1 */
43 !array_key_exists($cmd, $fieldsdescr) ) ||
44 ( function_exists('key_exists') &&
45 !key_exists($cmd, $fieldsdescr) ) /* PHP == 4.0.6 */
46 ) {
47 continue;
48 }
49
50 /* proto = {mailto,href} */
51 $proto = array_shift(array_keys($actions));
52 $act = array_shift($actions);
53
54 if ($proto == 'mailto') {
55
56 if (($cmd == 'post') || ($cmd == 'owner')) {
57 $url = 'src/compose.php?';
58 } else {
59 $url = "plugins/listcommands/mailout.php?action=$cmd&amp;";
60 }
61 $url .= 'send_to=' . strtr($act,'?','&');
62
63 $output[] = makeComposeLink($url, $fieldsdescr[$cmd]);
64
65 if ($cmd == 'post') {
66 $url .= '&amp;passed_id='.$passed_id.
67 '&amp;mailbox='.urlencode($mailbox).
68 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
69 $url .= '&amp;smaction=reply';
70
71 $output[] = makeComposeLink($url, $fieldsdescr['reply']);
72 }
73 } else if ($proto == 'href') {
74 $output[] = '<a href="' . $act . '" target="_blank">'
75 . $fieldsdescr[$cmd] . '</a>';
76 }
77 }
78
79 if (count($output) > 0) {
80 echo '<tr>';
81 echo html_tag('td', '<b>' . _("Mailing List") . ':&nbsp;&nbsp;</b>',
82 'right', '', 'valign="middle" width="20%"') . "\n";
83 echo html_tag('td', '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>',
84 'left', $color[0], 'valign="middle" width="80%"') . "\n";
85 echo '</tr>';
86 }
87 }
88
89 ?>