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 | |
17 | function squirrelmail_plugin_init_listcommands () { |
73ee43b1 |
18 | global $squirrelmail_plugin_hooks; |
19 | |
20 | $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu'; |
21 | } |
22 | |
d54c9a9c |
23 | function plugin_listcommands_menu() { |
050722c4 |
24 | global $imapConnection, $passed_id, $color, $mailbox, |
8beb6b5b |
25 | $message, $ent_num, $priority_level, $compose_new_win; |
26 | |
27 | $subject = trim($message->header->subject); |
73ee43b1 |
28 | |
d54c9a9c |
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. |
73ee43b1 |
32 | */ |
d54c9a9c |
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(); |
73ee43b1 |
44 | $output = array(); |
45 | |
46 | $lfields = 'List-' . implode (' List-', $fields); |
47 | |
48 | $sid = sqimap_session_id(); |
49 | fputs ($imapConnection, "$sid FETCH $passed_id BODY.PEEK[HEADER.FIELDS ($lfields)]\r\n"); |
d54c9a9c |
50 | $read = sqimap_read_data($imapConnection, $sid, true, $response, $emessage); |
73ee43b1 |
51 | |
050722c4 |
52 | for ($i = 1; $i < count($read); $i++) { |
53 | foreach ($fields as $field) { |
54 | if ( preg_match("/^List-$field: *<(.+?)>/i", $read[$i], $match) ) { |
d54c9a9c |
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; |
73ee43b1 |
68 | } |
69 | } |
70 | } |
71 | |
050722c4 |
72 | foreach ($cmds as $cmd => $url) { |
d54c9a9c |
73 | if (eregi('mailto:(.+)', $url, $regs)) { |
73ee43b1 |
74 | $purl = parse_url($url); |
050722c4 |
75 | |
d54c9a9c |
76 | if (($cmd == 'Post') || ($cmd == 'Owner')) { |
73ee43b1 |
77 | $url = 'compose.php?'; |
050722c4 |
78 | } else { |
f6f50b4d |
79 | $url = "../plugins/listcommands/mailout.php?action=$cmd&"; |
73ee43b1 |
80 | } |
81 | |
d54c9a9c |
82 | $url .= 'mailbox=' . urlencode($mailbox) |
f6f50b4d |
83 | . '&send_to=' . $purl['path']; |
050722c4 |
84 | |
d54c9a9c |
85 | if (isset($purl['query'])) { |
f6f50b4d |
86 | $url .= '&' . $purl['query']; |
73ee43b1 |
87 | } |
9c3e6cd4 |
88 | if ($compose_new_win == '1') { |
020e3c1c |
89 | $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$url')\">" . $fieldsdescr[$cmd] . '</A>'; |
9c3e6cd4 |
90 | } |
91 | else { |
92 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>'; |
93 | } |
d54c9a9c |
94 | if ($cmd == 'Post') { |
f6f50b4d |
95 | $url .= '&reply_subj=' . urlencode($subject) |
96 | . '&reply_id=' . $passed_id |
97 | . '&ent_num=' . $ent_num |
98 | . '&mailprio=' . $priority_level; |
91e33f2c |
99 | if ($compose_new_win == '1') { |
020e3c1c |
100 | $output[] = "<A HREF=\"javascript:void(0)\" onClick=\"comp_in_new(false,'$url')\">" . $fieldsdescr['Reply'] . '</A>'; |
91e33f2c |
101 | } |
102 | else { |
103 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>'; |
104 | } |
9c3e6cd4 |
105 | } |
d54c9a9c |
106 | } else if (eregi('^(http|ftp)', $url)) { |
107 | $output[] = '<A HREF="' . $url . '" TARGET="_blank">' |
108 | . $fieldsdescr[$cmd] . '</A>'; |
73ee43b1 |
109 | } |
73ee43b1 |
110 | } |
111 | |
73ee43b1 |
112 | if (count($output) > 0) { |
d54c9a9c |
113 | echo "<tr>"; |
4cf43843 |
114 | echo html_tag( 'tr', |
115 | html_tag( 'td', str_replace(' ', ' ', _("Mailing List:")), 'right', $color[0]) . |
116 | html_tag( 'td', |
117 | '<small>' . implode(' | ', $output) . '</small>' , |
118 | 'left', $color[0], 'width="100%" colspan="2"') |
119 | ); |
73ee43b1 |
120 | } |
050722c4 |
121 | } |
d54c9a9c |
122 | |
123 | ?> |