printer_friendly_bottom.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * printer_friendly_bottom.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. * with javascript on, it is the bottom frame of printer_friendly_main.php
  9. * else, it is alone in a new window
  10. *
  11. * - this is the page that does all the work, really.
  12. *
  13. * $Id$
  14. */
  15. require_once('../src/validate.php');
  16. require_once('../functions/strings.php');
  17. require_once('../config/config.php');
  18. require_once('../src/load_prefs.php');
  19. require_once('../functions/imap.php');
  20. require_once('../functions/page_header.php');
  21. $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
  22. $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  23. sqimap_mailbox_select($imap_stream, $mailbox);
  24. $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
  25. /* --start display setup-- */
  26. /* From and Date are usually fine as they are... */
  27. $from = decodeHeader($message->header->from);
  28. $date = getLongDateString($message->header->date);
  29. /* we can clean these up if the list is too long... */
  30. $cc = decodeHeader(getLineOfAddrs($message->header->cc));
  31. $to = decodeHeader(getLineOfAddrs($message->header->to));
  32. /* and Body and Subject could easily stream off the page... */
  33. $id = $message->header->id;
  34. $ent_ar = findDisplayEntity ($message, 0);
  35. $ent_num = $ent_ar[0];
  36. $body_message = getEntity($message, $ent_num);
  37. if (($body_message->header->type0 == 'text') ||
  38. ($body_message->header->type0 == 'rfc822')) {
  39. $body = mime_fetch_body ($imap_stream, $id, $ent_num);
  40. $body = decodeBody($body, $body_message->header->encoding);
  41. $hookResults = do_hook('message_body', $body);
  42. $body = $hookResults[1];
  43. if ($body_message->header->type1 == 'html') {
  44. if( $show_html_default <> 1 ) {
  45. $body = strip_tags( $body );
  46. translateText($body, $wrap_at, $body_message->header->charset);
  47. } else {
  48. $body = MagicHTML( $body, $id, $message );
  49. }
  50. } else {
  51. translateText($body, $wrap_at, $body_message->header->charset);
  52. }
  53. } else {
  54. $body = _("Message not printable");
  55. }
  56. $subject = trim(decodeHeader($message->header->subject));
  57. /* now, if they choose to, we clean up the display a bit... */
  58. /*
  59. if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
  60. $num_leading_spaces = 9; // nine leading spaces for indentation
  61. // sometimes I see ',,' instead of ',' seperating addresses *shrug*
  62. $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
  63. $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
  64. // the body should have no leading zeros
  65. $body = pf_clean_string($body, 0);
  66. // clean up everything else...
  67. $subject = pf_clean_string($subject, $num_leading_spaces);
  68. $from = pf_clean_string($from, $num_leading_spaces);
  69. $date = pf_clean_string($date, $num_leading_spaces);
  70. } // end cleanup
  71. */
  72. // --end display setup--
  73. /* --start browser output-- */
  74. displayHtmlHeader( _("Printer Friendly"), '', FALSE );
  75. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
  76. /* headers (we use table because translations are not all the same width) */
  77. '<table>'.
  78. '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></tr>\n".
  79. '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></tr>\n";
  80. if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
  81. echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></tr>\n";
  82. }
  83. echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></tr>\n".
  84. '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></tr>\n".
  85. '</table>'.
  86. "\n";
  87. /* body */
  88. echo "<hr noshade size=1>\n";
  89. echo $body;
  90. /* --end browser output-- */
  91. echo '</body></html>';
  92. /* --start pf-specific functions-- */
  93. /* $string = pf_clean_string($string, 9); */
  94. function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
  95. global $data_dir, $username;
  96. $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
  97. $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
  98. $leading_spaces = '';
  99. while ( strlen($leading_spaces) < $num_leading_spaces )
  100. $leading_spaces .= ' ';
  101. $clean_string = '';
  102. while ( strlen($unclean_string) > $wrap_at )
  103. {
  104. $this_line = substr($unclean_string, 0, $wrap_at);
  105. if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
  106. {
  107. $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
  108. $clean_string .= $leading_spaces;
  109. $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
  110. }
  111. else
  112. {
  113. $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
  114. $clean_string .= "\n" . $leading_spaces;
  115. $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
  116. }
  117. }
  118. $clean_string .= $unclean_string;
  119. return $clean_string;
  120. } /* end pf_clean_string() function */
  121. /* --end pf-specific functions */
  122. ?>