setup.php 3.7 KB

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