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