8812a627b9a3b8e812e18cdbf79bc6ac4f441784
[squirrelmail.git] / plugins / listcommands / setup.php
1 <?php
2
3 /**
4 * setup.php
5 *
6 * Copyright (c) 1999-2005 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 * @package plugins
16 * @subpackage listcommands
17 */
18
19 /**
20 * Initialize the listcommands plugin
21 */
22 function squirrelmail_plugin_init_listcommands () {
23 global $squirrelmail_plugin_hooks;
24
25 $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu';
26 }
27
28 function plugin_listcommands_menu() {
29 global $passed_id, $passed_ent_id, $color, $mailbox, $message, $startMessage;
30
31 /**
32 * Array of commands we can deal with from the header. The Reply option
33 * is added later because we generate it using the Post information.
34 */
35 $fieldsdescr = array('post' => _("Post to List"),
36 'reply' => _("Reply to List"),
37 'subscribe' => _("Subscribe"),
38 'unsubscribe' => _("Unsubscribe"),
39 'archive' => _("List Archives"),
40 'owner' => _("Contact Listowner"),
41 'help' => _("Help"));
42 $output = array();
43
44 foreach ($message->rfc822_header->mlist as $cmd => $actions) {
45
46 /* I don't know this action... skip it */
47 if ( !array_key_exists($cmd, $fieldsdescr) ) {
48 continue;
49 }
50
51 /* proto = {mailto,href} */
52 $proto = array_shift(array_keys($actions));
53 $act = array_shift($actions);
54
55 if ($proto == 'mailto') {
56
57 if (($cmd == 'post') || ($cmd == 'owner')) {
58 $url = 'src/compose.php?'.
59 (isset($startMessage)?'startMessage='.$startMessage.'&amp;'?'');
60 } else {
61 $url = "plugins/listcommands/mailout.php?action=$cmd&amp;";
62 }
63 $url .= 'send_to=' . strtr($act,'?','&');
64
65 $output[] = makeComposeLink($url, $fieldsdescr[$cmd]);
66
67 if ($cmd == 'post') {
68 if (!isset($mailbox))
69 $mailbox = 'INBOX';
70 $url .= '&amp;passed_id='.$passed_id.
71 '&amp;mailbox='.urlencode($mailbox).
72 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
73 $url .= '&amp;smaction=reply';
74
75 $output[] = makeComposeLink($url, $fieldsdescr['reply']);
76 }
77 } else if ($proto == 'href') {
78 $output[] = '<a href="' . $act . '" target="_blank">'
79 . $fieldsdescr[$cmd] . '</a>';
80 }
81 }
82
83 if (count($output) > 0) {
84 echo '<tr>';
85 echo html_tag('td', '<b>' . _("Mailing List") . ':&nbsp;&nbsp;</b>',
86 'right', '', 'valign="middle" width="20%"') . "\n";
87 echo html_tag('td', '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>',
88 'left', $color[0], 'valign="middle" width="80%"') . "\n";
89 echo '</tr>';
90 }
91 }
92
93 ?>