setup.php 4.3 KB

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