| 1 | <?php |
| 2 | /* |
| 3 | * Listcommands plugin v1.3 |
| 4 | * |
| 5 | * Implementation of RFC 2369 for SquirrelMail. |
| 6 | * When viewing a message from a mailinglist complying with this RFC, |
| 7 | * this plugin displays a menu which gives the user a choice of mailinglist |
| 8 | * commands such as (un)subscribe, help and list archives. |
| 9 | * |
| 10 | * last modified: 2002/01/21 by Thijs Kinkhorst |
| 11 | * please send bug reports to <thijs@kinkhorst.com> |
| 12 | * |
| 13 | */ |
| 14 | function squirrelmail_plugin_init_listcommands () |
| 15 | { |
| 16 | global $squirrelmail_plugin_hooks; |
| 17 | |
| 18 | $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu'; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | function plugin_listcommands_menu () { |
| 23 | |
| 24 | global $imapConnection, $passed_id, $color, $mailbox, |
| 25 | $subject, $ent_num, $priority_level; |
| 26 | |
| 27 | /* Array of commands we can deal with from the header. The Reply option is |
| 28 | * added later because we generate it using the Post information. |
| 29 | */ |
| 30 | $fieldsdescr = array( 'Help' => _("Help"), |
| 31 | 'Unsubscribe' => _("Unsubscribe"), |
| 32 | 'Subscribe' => _("Subscribe"), |
| 33 | 'Post' => _("Post to the list"), |
| 34 | 'Archive' => _("List Archives"), |
| 35 | 'Owner' => _("Contact Listowner") ); |
| 36 | $fields = array_keys ($fieldsdescr); |
| 37 | $fieldsdescr['Reply'] = _("Reply to the list"); |
| 38 | |
| 39 | $cmds = array(); |
| 40 | $output = array(); |
| 41 | |
| 42 | $lfields = 'List-' . implode (' List-', $fields); |
| 43 | |
| 44 | $sid = sqimap_session_id(); |
| 45 | fputs ($imapConnection, "$sid FETCH $passed_id BODY.PEEK[HEADER.FIELDS ($lfields)]\r\n"); |
| 46 | $read = sqimap_read_data ($imapConnection, $sid, true, $response, $emessage); |
| 47 | |
| 48 | for ($i = 1; $i < count($read); $i++) { |
| 49 | foreach ($fields as $field) { |
| 50 | if ( preg_match("/^List-$field: *<(.+?)>/i", $read[$i], $match) ) { |
| 51 | $cmds[$field] = $match[1]; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | foreach ($cmds as $cmd => $url) { |
| 57 | if ( eregi('mailto:(.+)', $url, $regs) ) { |
| 58 | $purl = parse_url($url); |
| 59 | |
| 60 | if ( $cmd == 'Post' || $cmd == 'Owner' ) { |
| 61 | $url = 'compose.php?'; |
| 62 | } else { |
| 63 | $url = '../plugins/listcommands/mailout.php?action=' . $cmd . '&'; |
| 64 | } |
| 65 | |
| 66 | $url .= 'mailbox=' . urlencode($mailbox) . '&send_to=' . $purl['path']; |
| 67 | |
| 68 | if ( isset($purl['query']) ) { |
| 69 | $url .= '&' . $purl['query']; |
| 70 | } |
| 71 | |
| 72 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>'; |
| 73 | |
| 74 | if ( $cmd == 'Post' ) { |
| 75 | $url .= '&reply_subj=' . urlencode($subject) . |
| 76 | '&reply_id=' . $passed_id . |
| 77 | '&ent_num=' . $ent_num . |
| 78 | '&mailprio=' . $priority_level; |
| 79 | $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>'; |
| 80 | } |
| 81 | } elseif ( eregi('^(http|ftp)', $url) ) { |
| 82 | $output[] = '<A HREF="' . $url . '" TARGET="_blank">' . $fieldsdescr[$cmd] . '</A>'; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (count($output) > 0) { |
| 87 | echo "<tr><td BGCOLOR=\"$color[0]\" WIDTH=\"100%\" colspan=\"3\">". |
| 88 | '<SMALL>' . _("Mailinglist options:") . ' ' . implode (' | ', $output) . |
| 89 | '</SMALL>'. |
| 90 | '</td></tr>'; |
| 91 | } |
| 92 | } |
| 93 | ?> |