rfc822_header stuff
[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 $imapConnection, $passed_id, $color, $mailbox,
25 $message, $ent_num, $priority_level, $compose_new_win, $uid_support;
26
27 $subject = trim($message->rfc822_header->subject);
28
29 /**
30 * Array of commands we can deal with from the header. The Reply option
31 * is added later because we generate it using the Post information.
32 */
33 $fieldsdescr = array('Post' => _("Post to List"),
34 'Reply' => _("Reply to List"),
35 'Subscribe' => _("Subscribe"),
36 'Unsubscribe' => _("Unsubscribe"),
37 'Archive' => _("List Archives"),
38 'Owner' => _("Contact Listowner"),
39 'Help' => _("Help"));
40 $fields = array_keys($fieldsdescr);
41
42 $sorted_cmds = array();
43 $unsorted_cmds = array();
44 $output = array();
45
46 $lfields = 'List-' . implode (' List-', $fields);
47
48 $sid = sqimap_session_id($uid_support);
49 fputs ($imapConnection, "$sid FETCH $passed_id BODY.PEEK[HEADER.FIELDS ($lfields)]\r\n");
50 $read = sqimap_read_data($imapConnection, $sid, true, $response, $emessage);
51
52 for ($i = 1; $i < count($read); $i++) {
53 foreach ($fields as $field) {
54 if ( preg_match("/^List-$field: *<(.+?)>/i", $read[$i], $match) ) {
55 $unsorted_cmds[$field] = $match[1];
56 }
57 }
58 }
59
60 if (count($unsorted_cmds) == 0) {
61 return;
62 }
63
64 foreach ($fields as $field) {
65 foreach ($unsorted_cmds as $cmd => $url) {
66 if ($field == $cmd) {
67 $cmds[$cmd] = $url;
68 }
69 }
70 }
71
72 foreach ($cmds as $cmd => $url) {
73 if (eregi('mailto:(.+)', $url, $regs)) {
74 $purl = parse_url($url);
75
76 if (($cmd == 'Post') || ($cmd == 'Owner')) {
77 $url = 'compose.php?';
78 } else {
79 $url = "../plugins/listcommands/mailout.php?action=$cmd&amp;";
80
81 }
82 $url .= '&amp;send_to=' . $purl['path'];
83
84 if (isset($purl['query'])) {
85 $url .= '&amp;' . $purl['query'];
86 }
87 if ($compose_new_win == '1') {
88 $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$url')\">" . $fieldsdescr[$cmd] . '</A>';
89 }
90 else {
91 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>';
92 }
93 if ($cmd == 'Post') {
94 $url .= '&amp;passed_id='.$passed_id.
95 '&amp;mailbox='.urlencode($mailbox).
96 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
97 $url .= '&amp;action=reply';
98 if ($compose_new_win == '1') {
99 $output[] = "<A HREF=\"javascript:void(0)\" onClick=\"comp_in_new('$url')\">" . $fieldsdescr['Reply'] . '</A>';
100 }
101 else {
102 $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>';
103 }
104 }
105 } else if (eregi('^(http|ftp)', $url)) {
106 $output[] = '<A HREF="' . $url . '" TARGET="_blank">'
107 . $fieldsdescr[$cmd] . '</A>';
108 }
109 }
110
111 if (count($output) > 0) {
112 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
113 ' border="0" bgcolor="'.$color[0].'">'. "\n";
114 echo '<tr>';
115 echo html_tag( 'td', '<b>'._("Mailing List").':&nbsp;&nbsp;</b>', 'right', $color[0], 'valign="top" width="20%"') . "\n";
116 echo html_tag( 'td',
117 '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>', 'left', $color[0], 'valign="top" width="80%"');
118 echo "\n</tr>";
119 echo '</table>'."\n";
120 }
121 }
122
123 ?>