| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * printer_friendly_bottom.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 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 | /* Path for SquirrelMail required files. */ |
| 18 | define('SM_PATH','../'); |
| 19 | |
| 20 | /* SquirrelMail required files. */ |
| 21 | require_once(SM_PATH . 'include/validate.php'); |
| 22 | require_once(SM_PATH . 'functions/strings.php'); |
| 23 | require_once(SM_PATH . 'config/config.php'); |
| 24 | require_once(SM_PATH . 'include/load_prefs.php'); |
| 25 | require_once(SM_PATH . 'functions/imap.php'); |
| 26 | require_once(SM_PATH . 'functions/page_header.php'); |
| 27 | require_once(SM_PATH . 'functions/html.php'); |
| 28 | |
| 29 | /* get some of these globals */ |
| 30 | $key = $_COOKIE['key']; |
| 31 | $username = $_SESSION['username']; |
| 32 | $onetimepad = $_SESSION['onetimepad']; |
| 33 | |
| 34 | $passed_id = (int) $_GET['passed_id']; |
| 35 | $mailbox = $_GET['mailbox']; |
| 36 | |
| 37 | if (!isset($_GET['passed_ent_id'])) { |
| 38 | $passed_ent_id = ''; |
| 39 | } else { |
| 40 | $passed_ent_id = $_GET['passed_ent_id']; |
| 41 | } |
| 42 | /* end globals */ |
| 43 | |
| 44 | $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay'); |
| 45 | $mailbox = urldecode($mailbox); |
| 46 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 47 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
| 48 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
| 49 | $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
| 50 | } else { |
| 51 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 52 | } |
| 53 | if ($passed_ent_id) { |
| 54 | $message = &$message->getEntity($passed_ent_id); |
| 55 | } |
| 56 | |
| 57 | /* --start display setup-- */ |
| 58 | |
| 59 | $rfc822_header = $message->rfc822_header; |
| 60 | /* From and Date are usually fine as they are... */ |
| 61 | $from = decodeHeader($rfc822_header->getAddr_s('from')); |
| 62 | $date = getLongDateString($rfc822_header->date); |
| 63 | $subject = trim(decodeHeader($rfc822_header->subject)); |
| 64 | |
| 65 | /* we can clean these up if the list is too long... */ |
| 66 | $cc = decodeHeader($rfc822_header->getAddr_s('cc')); |
| 67 | $to = decodeHeader($rfc822_header->getAddr_s('to')); |
| 68 | |
| 69 | if ($show_html_default == 1) { |
| 70 | $ent_ar = $message->findDisplayEntity(array()); |
| 71 | } else { |
| 72 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
| 73 | } |
| 74 | $body = ''; |
| 75 | if ($ent_ar[0] != '') { |
| 76 | for ($i = 0; $i < count($ent_ar); $i++) { |
| 77 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
| 78 | $body .= '<hr noshade size="1" />'; |
| 79 | } |
| 80 | $hookResults = do_hook('message_body', $body); |
| 81 | $body = $hookResults[1]; |
| 82 | } else { |
| 83 | $body = _("Message not printable"); |
| 84 | } |
| 85 | |
| 86 | /* now, if they choose to, we clean up the display a bit... */ |
| 87 | |
| 88 | if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) { |
| 89 | |
| 90 | $num_leading_spaces = 9; // nine leading spaces for indentation |
| 91 | |
| 92 | // sometimes I see ',,' instead of ',' seperating addresses *shrug* |
| 93 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
| 94 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
| 95 | |
| 96 | // the body should have no leading zeros |
| 97 | // disabled because it destroys html mail |
| 98 | |
| 99 | // $body = pf_clean_string($body, 0); |
| 100 | |
| 101 | // clean up everything else... |
| 102 | $subject = pf_clean_string($subject, $num_leading_spaces); |
| 103 | $from = pf_clean_string($from, $num_leading_spaces); |
| 104 | $date = pf_clean_string($date, $num_leading_spaces); |
| 105 | |
| 106 | } // end cleanup |
| 107 | |
| 108 | // --end display setup-- |
| 109 | |
| 110 | |
| 111 | /* --start browser output-- */ |
| 112 | displayHtmlHeader( _("Printer Friendly"), '', FALSE ); |
| 113 | |
| 114 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" . |
| 115 | /* headers (we use table because translations are not all the same width) */ |
| 116 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
| 117 | html_tag( 'tr', |
| 118 | html_tag( 'td', _("From").' ', 'left' ,'','valign="top"') . |
| 119 | html_tag( 'td', htmlspecialchars($from), 'left' ) |
| 120 | ) . "\n" . |
| 121 | html_tag( 'tr', |
| 122 | html_tag( 'td', _("Subject").' ', 'left','','valign="top"' ) . |
| 123 | html_tag( 'td', htmlspecialchars($subject), 'left' ) |
| 124 | ) . "\n" . |
| 125 | html_tag( 'tr', |
| 126 | html_tag( 'td', _("Date").' ', 'left' ) . |
| 127 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
| 128 | ) . "\n" . |
| 129 | html_tag( 'tr', |
| 130 | html_tag( 'td', _("To").' ', 'left','','valign="top"' ) . |
| 131 | html_tag( 'td', htmlspecialchars($to), 'left' ) |
| 132 | ) . "\n"; |
| 133 | if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */ |
| 134 | echo html_tag( 'tr', |
| 135 | html_tag( 'td', _("CC").' ', 'left','','valign="top"' ) . |
| 136 | html_tag( 'td', htmlspecialchars($cc), 'left' ) |
| 137 | ); |
| 138 | } |
| 139 | /* body */ |
| 140 | echo html_tag( 'tr', |
| 141 | html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' ) |
| 142 | ) . "\n" . |
| 143 | |
| 144 | '</table>' . "\n" . |
| 145 | '</body></html>'; |
| 146 | |
| 147 | /* --end browser output-- */ |
| 148 | |
| 149 | |
| 150 | /* --start pf-specific functions-- */ |
| 151 | |
| 152 | /* $string = pf_clean_string($string, 9); */ |
| 153 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
| 154 | global $data_dir, $username; |
| 155 | |
| 156 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
| 157 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
| 158 | |
| 159 | $leading_spaces = ''; |
| 160 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
| 161 | $leading_spaces .= ' '; |
| 162 | |
| 163 | $clean_string = ''; |
| 164 | while ( strlen($unclean_string) > $wrap_at ) |
| 165 | { |
| 166 | $this_line = substr($unclean_string, 0, $wrap_at); |
| 167 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
| 168 | { |
| 169 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" )); |
| 170 | $clean_string .= $leading_spaces; |
| 171 | $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" )); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' )); |
| 176 | $clean_string .= "\n" . $leading_spaces; |
| 177 | $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' ))); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | $clean_string .= $unclean_string; |
| 182 | |
| 183 | return $clean_string; |
| 184 | } /* end pf_clean_string() function */ |
| 185 | |
| 186 | /* --end pf-specific functions */ |
| 187 | |
| 188 | ?> |