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, |
9c3e6cd4 |
25 | $subject, $ent_num, $priority_level, $compose_new_win; |
73ee43b1 |
26 | |
d54c9a9c |
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. |
73ee43b1 |
30 | */ |
d54c9a9c |
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 | $fields = array_keys($fieldsdescr); |
39 | |
40 | $sorted_cmds = array(); |
41 | $unsorted_cmds = array(); |
73ee43b1 |
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"); |
d54c9a9c |
48 | $read = sqimap_read_data($imapConnection, $sid, true, $response, $emessage); |
73ee43b1 |
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) ) { |
d54c9a9c |
53 | $unsorted_cmds[$field] = $match[1]; |
54 | } |
55 | } |
56 | } |
57 | |
58 | if (count($unsorted_cmds) == 0) { |
59 | return; |
60 | } |
61 | |
62 | foreach ($fields as $field) { |
63 | foreach ($unsorted_cmds as $cmd => $url) { |
64 | if ($field == $cmd) { |
65 | $cmds[$cmd] = $url; |
73ee43b1 |
66 | } |
67 | } |
68 | } |
69 | |
050722c4 |
70 | foreach ($cmds as $cmd => $url) { |
d54c9a9c |
71 | if (eregi('mailto:(.+)', $url, $regs)) { |
73ee43b1 |
72 | $purl = parse_url($url); |
050722c4 |
73 | |
d54c9a9c |
74 | if (($cmd == 'Post') || ($cmd == 'Owner')) { |
73ee43b1 |
75 | $url = 'compose.php?'; |
050722c4 |
76 | } else { |
d54c9a9c |
77 | $url = "../plugins/listcommands/mailout.php?action=$cmd&"; |
73ee43b1 |
78 | } |
79 | |
d54c9a9c |
80 | $url .= 'mailbox=' . urlencode($mailbox) |
81 | . '&send_to=' . $purl['path']; |
050722c4 |
82 | |
d54c9a9c |
83 | if (isset($purl['query'])) { |
73ee43b1 |
84 | $url .= '&' . $purl['query']; |
85 | } |
9c3e6cd4 |
86 | if ($compose_new_win == '1') { |
87 | $output[] = '<A HREF="' . $url . '" target="compose_window" onClick="comp_in_new()">' . $fieldsdescr[$cmd] . '</A>'; |
88 | } |
89 | else { |
90 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>'; |
91 | } |
d54c9a9c |
92 | if ($cmd == 'Post') { |
93 | $url .= '&reply_subj=' . urlencode($subject) |
94 | . '&reply_id=' . $passed_id |
95 | . '&ent_num=' . $ent_num |
96 | . '&mailprio=' . $priority_level; |
9c3e6cd4 |
97 | if ($compose_new_win == '1') { |
98 | $output[] = '<A HREF="' . $url . '" target="compose_window" onClick="comp_in_new()">' . $fieldsdescr['Reply'] . '</A>'; |
99 | } |
100 | else { |
73ee43b1 |
101 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>'; |
102 | } |
9c3e6cd4 |
103 | } |
d54c9a9c |
104 | } else if (eregi('^(http|ftp)', $url)) { |
105 | $output[] = '<A HREF="' . $url . '" TARGET="_blank">' |
106 | . $fieldsdescr[$cmd] . '</A>'; |
73ee43b1 |
107 | } |
73ee43b1 |
108 | } |
109 | |
73ee43b1 |
110 | if (count($output) > 0) { |
d54c9a9c |
111 | echo "<tr>"; |
4cfbfd69 |
112 | echo "<td ALIGN=RIGHT BGCOLOR=\"$color[0]\">" |
d54c9a9c |
113 | . str_replace(' ', ' ', _("Mailing List:")) |
114 | . '</td>'; |
115 | echo "<td BGCOLOR=\"$color[0]\" WIDTH=\"100%\" colspan=\"2\">" |
116 | . '<SMALL>' . implode(' | ', $output) . '</SMALL>' |
117 | . '</td>'; |
118 | echo '</tr>'; |
73ee43b1 |
119 | } |
050722c4 |
120 | } |
d54c9a9c |
121 | |
122 | ?> |