setup.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 .= '&amp;send_to=' . $purl['path'];
  68. if (isset($purl['query'])) {
  69. $url .= '&amp;' . $purl['query'];
  70. }
  71. if ($compose_new_win == '1') {
  72. $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$url')\">" . $fieldsdescr[$cmd] . '</A>';
  73. }
  74. else {
  75. $output[] = '<A HREF="' . $url . '">' . $fieldsdescr[$cmd] . '</A>';
  76. }
  77. if ($cmd == 'Post') {
  78. $url .= '&amp;passed_id='.$passed_id.
  79. '&amp;mailbox='.urlencode($mailbox).
  80. (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
  81. $url .= '&amp;action=reply';
  82. if ($compose_new_win == '1') {
  83. $output[] = "<A HREF=\"javascript:void(0)\" onClick=\"comp_in_new('$url')\">" . $fieldsdescr['Reply'] . '</A>';
  84. }
  85. else {
  86. $output[] = '<A HREF="' . $url . '">' . $fieldsdescr['Reply'] . '</A>';
  87. }
  88. }
  89. } else if (eregi('^(http|ftp)', $url)) {
  90. $output[] = '<A HREF="' . $url . '" TARGET="_blank">'
  91. . $fieldsdescr[$cmd] . '</A>';
  92. }
  93. }
  94. if (count($output) > 0) {
  95. echo '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
  96. ' border="0" bgcolor="'.$color[0].'">'. "\n";
  97. echo '<tr>';
  98. echo html_tag( 'td', '<b>'._("Mailing List").':&nbsp;&nbsp;</b>', 'right', $color[0], 'valign="top" width="20%"') . "\n";
  99. echo html_tag( 'td',
  100. '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>', 'left', $color[0], 'valign="top" width="80%"');
  101. echo "\n</tr>";
  102. echo '</table>'."\n";
  103. }
  104. }
  105. ?>