We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / plugins / listcommands / setup.php
CommitLineData
73ee43b1 1<?php
519f07d7 2
3/**
4 * setup.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
519f07d7 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
73ee43b1 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 *
519f07d7 14 * $Id$
ea5f4b8e 15 * @package plugins
16 * @subpackage listcommands
73ee43b1 17 */
519f07d7 18
ea5f4b8e 19/**
20 * Initialize the listcommands plugin
21 */
519f07d7 22function squirrelmail_plugin_init_listcommands () {
73ee43b1 23 global $squirrelmail_plugin_hooks;
24
25 $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu';
26}
27
d54c9a9c 28function plugin_listcommands_menu() {
d62c4938 29 global $passed_id, $passed_ent_id, $color, $mailbox, $message;
73ee43b1 30
d54c9a9c 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.
73ee43b1 34 */
83feb57a 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"));
ff5d0719 42 $output = array();
83feb57a 43
44 foreach ($message->rfc822_header->mlist as $cmd => $actions) {
45
46 /* I don't know this action... skip it */
b1784aaf 47 if ( ( function_exists('array_key_exists') && /* PHP >= 4.1 */
48 !array_key_exists($cmd, $fieldsdescr) ) ||
8f41ffa2 49 ( function_exists('key_exists') &&
50 !key_exists($cmd, $fieldsdescr) ) /* PHP == 4.0.6 */
b1784aaf 51 ) {
83feb57a 52 continue;
d54c9a9c 53 }
d54c9a9c 54
83feb57a 55 /* proto = {mailto,href} */
56 $proto = array_shift(array_keys($actions));
57 $act = array_shift($actions);
73ee43b1 58
83feb57a 59 if ($proto == 'mailto') {
050722c4 60
83feb57a 61 if (($cmd == 'post') || ($cmd == 'owner')) {
d62c4938 62 $url = 'src/compose.php?';
050722c4 63 } else {
d62c4938 64 $url = "plugins/listcommands/mailout.php?action=$cmd&amp;";
73ee43b1 65 }
83feb57a 66 $url .= 'send_to=' . strtr($act,'?','&');
050722c4 67
d62c4938 68 $output[] = makeComposeLink($url, $fieldsdescr[$cmd]);
69
83feb57a 70 if ($cmd == 'post') {
df2c5bc9 71 if (!isset($mailbox))
72 $mailbox = 'INBOX';
d6ba3a2d 73 $url .= '&amp;passed_id='.$passed_id.
74 '&amp;mailbox='.urlencode($mailbox).
75 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
84d12179 76 $url .= '&amp;smaction=reply';
d62c4938 77
78 $output[] = makeComposeLink($url, $fieldsdescr['reply']);
9c3e6cd4 79 }
9feb4369 80 } else if ($proto == 'href') {
b1379bdf 81 $output[] = '<a href="' . $act . '" target="_blank">'
82 . $fieldsdescr[$cmd] . '</a>';
73ee43b1 83 }
73ee43b1 84 }
85
73ee43b1 86 if (count($output) > 0) {
b1379bdf 87 echo '<tr>';
88 echo html_tag('td', '<b>' . _("Mailing List") . ':&nbsp;&nbsp;</b>',
89 'right', '', 'valign="middle" width="20%"') . "\n";
90 echo html_tag('td', '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>',
91 'left', $color[0], 'valign="middle" width="80%"') . "\n";
92 echo '</tr>';
73ee43b1 93 }
050722c4 94}
d54c9a9c 95
96?>