setup.php 3.2 KB

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