*** empty log message ***
[squirrelmail.git] / plugins / listcommands / setup.php
CommitLineData
73ee43b1 1<?php
519f07d7 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.
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$
73ee43b1 15 */
519f07d7 16
17function squirrelmail_plugin_init_listcommands () {
73ee43b1 18 global $squirrelmail_plugin_hooks;
19
20 $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu';
21}
22
23
24function plugin_listcommands_menu () {
25
050722c4 26 global $imapConnection, $passed_id, $color, $mailbox,
27 $subject, $ent_num, $priority_level;
73ee43b1 28
29 /* Array of commands we can deal with from the header. The Reply option is
30 * added later because we generate it using the Post information.
31 */
050722c4 32 $fieldsdescr = array( 'Help' => _("Help"),
73ee43b1 33 'Unsubscribe' => _("Unsubscribe"),
050722c4 34 'Subscribe' => _("Subscribe"),
73ee43b1 35 'Post' => _("Post to the list"),
050722c4 36 'Archive' => _("List Archives"),
73ee43b1 37 'Owner' => _("Contact Listowner") );
38 $fields = array_keys ($fieldsdescr);
050722c4 39 $fieldsdescr['Reply'] = _("Reply to the list");
40
73ee43b1 41 $cmds = array();
42 $output = array();
43
44 $lfields = 'List-' . implode (' List-', $fields);
45
46 $sid = sqimap_session_id();
47 fputs ($imapConnection, "$sid FETCH $passed_id BODY.PEEK[HEADER.FIELDS ($lfields)]\r\n");
48 $read = sqimap_read_data ($imapConnection, $sid, true, $response, $emessage);
49
050722c4 50 for ($i = 1; $i < count($read); $i++) {
51 foreach ($fields as $field) {
52 if ( preg_match("/^List-$field: *<(.+?)>/i", $read[$i], $match) ) {
73ee43b1 53 $cmds[$field] = $match[1];
54 }
55 }
56 }
57
050722c4 58 foreach ($cmds as $cmd => $url) {
59 if ( eregi('mailto:(.+)', $url, $regs) ) {
73ee43b1 60 $purl = parse_url($url);
050722c4 61
62 if ( $cmd == 'Post' || $cmd == 'Owner' ) {
73ee43b1 63 $url = 'compose.php?';
050722c4 64 } else {
73ee43b1 65 $url = '../plugins/listcommands/mailout.php?action=' . $cmd . '&';
66 }
67
68 $url .= 'mailbox=' . urlencode($mailbox) . '&send_to=' . $purl['path'];
050722c4 69
70 if ( isset($purl['query']) ) {
73ee43b1 71 $url .= '&' . $purl['query'];
72 }
73
74 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>';
75
050722c4 76 if ( $cmd == 'Post' ) {
77 $url .= '&reply_subj=' . urlencode($subject) .
78 '&reply_id=' . $passed_id .
79 '&ent_num=' . $ent_num .
80 '&mailprio=' . $priority_level;
73ee43b1 81 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>';
82 }
050722c4 83 } elseif ( eregi('^(http|ftp)', $url) ) {
73ee43b1 84 $output[] = '<A HREF="' . $url . '" TARGET="_blank">' . $fieldsdescr[$cmd] . '</A>';
85 }
73ee43b1 86 }
87
73ee43b1 88 if (count($output) > 0) {
89 echo "<tr><td BGCOLOR=\"$color[0]\" WIDTH=\"100%\" colspan=\"3\">".
90 '<SMALL>' . _("Mailinglist options:") . ' ' . implode ('&nbsp;|&nbsp;', $output) .
91 '</SMALL>'.
92 '</td></tr>';
93 }
050722c4 94}
73ee43b1 95?>