226f5fdf9e36946f24b1cab832db26f074f50749
[squirrelmail.git] / plugins / listcommands / setup.php
1 <?php
2
3 /**
4 * setup.php
5 *
6 * Copyright (c) 1999-2002 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,
25 $message, $compose_new_win;
26
27 /**
28 * Array of commands we can deal with from the header. The Reply option
29 * is added later because we generate it using the Post information.
30 */
31 $fieldsdescr = array('post' => _("Post to List"),
32 'reply' => _("Reply to List"),
33 'subscribe' => _("Subscribe"),
34 'unsubscribe' => _("Unsubscribe"),
35 'archive' => _("List Archives"),
36 'owner' => _("Contact Listowner"),
37 'help' => _("Help"));
38
39 foreach ($message->rfc822_header->mlist as $cmd => $actions) {
40
41 /* I don't know this action... skip it */
42 if(!array_key_exists($cmd, $fieldsdescr)) {
43 continue;
44 }
45
46 /* proto = {mailto,href} */
47 $proto = array_shift(array_keys($actions));
48 $act = array_shift($actions);
49
50 if ($proto == 'mailto') {
51
52 if (($cmd == 'post') || ($cmd == 'owner')) {
53 $url = 'compose.php?';
54 } else {
55 $url = "../plugins/listcommands/mailout.php?action=$cmd&amp;";
56 }
57 $url .= 'send_to=' . strtr($act,'?','&');
58
59 if ($compose_new_win == '1') {
60 $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$url')\">" . $fieldsdescr[$cmd] . '</A>';
61 }
62 else {
63 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>';
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;action=reply';
70 if ($compose_new_win == '1') {
71 $output[] = "<A HREF=\"javascript:void(0)\" onClick=\"comp_in_new('$url')\">" . $fieldsdescr['reply'] . '</A>';
72 }
73 else {
74 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['reply'] . '</A>';
75 }
76 }
77 } elseif ($proto == 'href') {
78 $output[] = '<A HREF="' . $act . '" TARGET="_blank">'
79 . $fieldsdescr[$cmd] . '</A>';
80 }
81 }
82
83 if (count($output) > 0) {
84 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
85 ' border="0" bgcolor="'.$color[0].'">'. "\n";
86 echo '<tr>';
87 echo html_tag( 'td', '<b>'._("Mailing List").':&nbsp;&nbsp;</b>', 'right', $color[0], 'valign="top" width="20%"') . "\n";
88 echo html_tag( 'td',
89 '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>', 'left', $color[0], 'valign="top" width="80%"');
90 echo "\n</tr>";
91 echo '</table>'."\n";
92 }
93 }
94
95 ?>