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