| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * printer_friendly_bottom.php |
| 5 | * |
| 6 | * with javascript on, it is the bottom frame of printer_friendly_main.php |
| 7 | * else, it is alone in a new window |
| 8 | * |
| 9 | * - this is the page that does all the work, really. |
| 10 | * |
| 11 | * @copyright © 1999-2006 The SquirrelMail Project Team |
| 12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 13 | * @version $Id$ |
| 14 | * @package squirrelmail |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | * Include the SquirrelMail initialization file. |
| 19 | */ |
| 20 | require('../include/init.php'); |
| 21 | |
| 22 | /* SquirrelMail required files. */ |
| 23 | require_once(SM_PATH . 'functions/imap_general.php'); |
| 24 | require_once(SM_PATH . 'functions/imap_messages.php'); |
| 25 | require_once(SM_PATH . 'functions/date.php'); |
| 26 | require_once(SM_PATH . 'functions/mime.php'); |
| 27 | require_once(SM_PATH . 'functions/url_parser.php'); |
| 28 | |
| 29 | /* get some of these globals */ |
| 30 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 31 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 32 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
| 33 | |
| 34 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
| 35 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
| 36 | |
| 37 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
| 38 | $passed_ent_id = ''; |
| 39 | } |
| 40 | sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM); |
| 41 | /* end globals */ |
| 42 | |
| 43 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 44 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
| 45 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
| 46 | $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
| 47 | } else { |
| 48 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 49 | } |
| 50 | if ($passed_ent_id) { |
| 51 | $message = $message->getEntity($passed_ent_id); |
| 52 | } |
| 53 | |
| 54 | /* --start display setup-- */ |
| 55 | |
| 56 | $rfc822_header = $message->rfc822_header; |
| 57 | /* From and Date are usually fine as they are... */ |
| 58 | $from = $rfc822_header->getAddr_s('from'); |
| 59 | $date = getLongDateString($rfc822_header->date); |
| 60 | $subject = trim($rfc822_header->subject); |
| 61 | |
| 62 | /* we can clean these up if the list is too long... */ |
| 63 | $cc = $rfc822_header->getAddr_s('cc'); |
| 64 | $to = $rfc822_header->getAddr_s('to'); |
| 65 | |
| 66 | if ($show_html_default == 1) { |
| 67 | $ent_ar = $message->findDisplayEntity(array()); |
| 68 | } else { |
| 69 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
| 70 | } |
| 71 | $body = ''; |
| 72 | if ($ent_ar[0] != '') { |
| 73 | for ($i = 0; $i < count($ent_ar); $i++) { |
| 74 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE); |
| 75 | $body .= '<hr style="height: 1px;" />'; |
| 76 | } |
| 77 | $hookResults = do_hook('message_body', $body); |
| 78 | $body = $hookResults[1]; |
| 79 | } else { |
| 80 | $body = _("Message not printable"); |
| 81 | } |
| 82 | |
| 83 | /* now we clean up the display a bit... */ |
| 84 | |
| 85 | $num_leading_spaces = 9; // nine leading spaces for indentation |
| 86 | |
| 87 | // sometimes I see ',,' instead of ',' separating addresses *shrug* |
| 88 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
| 89 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
| 90 | |
| 91 | // clean up everything else... |
| 92 | $subject = pf_clean_string($subject, $num_leading_spaces); |
| 93 | $from = pf_clean_string($from, $num_leading_spaces); |
| 94 | $date = pf_clean_string($date, $num_leading_spaces); |
| 95 | |
| 96 | // end cleanup |
| 97 | |
| 98 | $to = decodeHeader($to); |
| 99 | $cc = decodeHeader($cc); |
| 100 | $from = decodeHeader($from); |
| 101 | $subject = decodeHeader($subject); |
| 102 | |
| 103 | $attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id); |
| 104 | |
| 105 | // --end display setup-- |
| 106 | |
| 107 | |
| 108 | /* --start browser output-- */ |
| 109 | displayHtmlHeader( $subject, '', FALSE ); |
| 110 | |
| 111 | echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" . |
| 112 | /* headers (we use table because translations are not all the same width) */ |
| 113 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
| 114 | html_tag( 'tr', |
| 115 | html_tag( 'td', '<b>'._("From").':</b> ', 'left' ,'','valign="top"') . |
| 116 | html_tag( 'td', $from, 'left' ) |
| 117 | ) . "\n" . |
| 118 | html_tag( 'tr', |
| 119 | html_tag( 'td', '<b>'._("Subject").':</b> ', 'left','','valign="top"' ) . |
| 120 | html_tag( 'td', $subject, 'left' ) |
| 121 | ) . "\n" . |
| 122 | html_tag( 'tr', |
| 123 | html_tag( 'td', '<b>'._("Date").':</b> ', 'left' ) . |
| 124 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
| 125 | ) . "\n" . |
| 126 | html_tag( 'tr', |
| 127 | html_tag( 'td', '<b>'._("To").':</b> ', 'left','','valign="top"' ) . |
| 128 | html_tag( 'td', $to, 'left' ) |
| 129 | ) . "\n"; |
| 130 | if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */ |
| 131 | echo html_tag( 'tr', |
| 132 | html_tag( 'td', '<b>'._("Cc").':</b> ', 'left','','valign="top"' ) . |
| 133 | html_tag( 'td', $cc, 'left' ) |
| 134 | ); |
| 135 | } |
| 136 | /* body */ |
| 137 | echo html_tag( 'tr', |
| 138 | html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' ) |
| 139 | ) . "\n" ; |
| 140 | |
| 141 | if (! empty($attachments)) { |
| 142 | // attachments title |
| 143 | echo html_tag( 'tr', |
| 144 | html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' ) |
| 145 | ) . "\n" ; |
| 146 | // list of attachments |
| 147 | echo html_tag( 'tr', |
| 148 | html_tag( 'td',$attachments, 'left', '', 'colspan="2"' ) |
| 149 | ) . "\n" ; |
| 150 | // add separator line |
| 151 | echo html_tag( 'tr', |
| 152 | html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' ) |
| 153 | ) . "\n" ; |
| 154 | } |
| 155 | |
| 156 | echo '</table>' . "\n"; |
| 157 | $oTemplate->display('footer.tpl'); |
| 158 | |
| 159 | /* --end browser output-- */ |
| 160 | |
| 161 | |
| 162 | /* --start pf-specific functions-- */ |
| 163 | |
| 164 | /** |
| 165 | * Function should clean layout of printed messages when user |
| 166 | * enables "Printer Friendly Clean Display" option. |
| 167 | * For example: $string = pf_clean_string($string, 9); |
| 168 | * |
| 169 | * @param string unclean_string |
| 170 | * @param integer num_leading_spaces |
| 171 | * @return string |
| 172 | * @access private |
| 173 | */ |
| 174 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
| 175 | global $data_dir, $username; |
| 176 | $unclean_string = str_replace(' ',' ',$unclean_string); |
| 177 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
| 178 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
| 179 | |
| 180 | $leading_spaces = ''; |
| 181 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
| 182 | $leading_spaces .= ' '; |
| 183 | |
| 184 | $clean_string = ''; |
| 185 | while ( strlen($unclean_string) > $wrap_at ) |
| 186 | { |
| 187 | $this_line = substr($unclean_string, 0, $wrap_at); |
| 188 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
| 189 | { |
| 190 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" )); |
| 191 | $clean_string .= $leading_spaces; |
| 192 | $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" )); |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | $i = strrpos( $this_line, ' '); |
| 197 | $clean_string .= substr( $this_line, 0, $i); |
| 198 | $clean_string .= "\n" . $leading_spaces; |
| 199 | $unclean_string = substr($unclean_string, 1+$i); |
| 200 | } |
| 201 | } |
| 202 | $clean_string .= $unclean_string; |
| 203 | |
| 204 | return $clean_string; |
| 205 | } /* end pf_clean_string() function */ |
| 206 | |
| 207 | /** |
| 208 | * Displays attachment information |
| 209 | * |
| 210 | * Stripped version of formatAttachments() function from functions/mime.php. |
| 211 | * @param object $message SquirrelMail message object |
| 212 | * @param array $exclude_id message parts that are not attachments. |
| 213 | * @param string $mailbox mailbox name |
| 214 | * @param integer $id message id |
| 215 | * @return string html formated attachment information. |
| 216 | */ |
| 217 | function pf_show_attachments($message, $exclude_id, $mailbox, $id) { |
| 218 | global $where, $what, $startMessage, $color, $passed_ent_id; |
| 219 | |
| 220 | $att_ar = $message->getAttachments($exclude_id); |
| 221 | |
| 222 | if (!count($att_ar)) return ''; |
| 223 | |
| 224 | $attachments = ''; |
| 225 | |
| 226 | $urlMailbox = urlencode($mailbox); |
| 227 | |
| 228 | foreach ($att_ar as $att) { |
| 229 | $ent = $att->entity_id; |
| 230 | $header = $att->header; |
| 231 | $type0 = strtolower($header->type0); |
| 232 | $type1 = strtolower($header->type1); |
| 233 | $name = ''; |
| 234 | |
| 235 | if ($type0 =='message' && $type1 == 'rfc822') { |
| 236 | $rfc822_header = $att->rfc822_header; |
| 237 | $filename = $rfc822_header->subject; |
| 238 | if (trim( $filename ) == '') { |
| 239 | $filename = 'untitled-[' . $ent . ']' ; |
| 240 | } |
| 241 | $from_o = $rfc822_header->from; |
| 242 | if (is_object($from_o)) { |
| 243 | $from_name = decodeHeader($from_o->getAddress(true)); |
| 244 | } else { |
| 245 | $from_name = _("Unknown sender"); |
| 246 | } |
| 247 | $description = '<tr>'. |
| 248 | html_tag( 'td',_("From:"), 'right') . |
| 249 | html_tag( 'td',$from_name, 'left') . |
| 250 | '</tr>'; |
| 251 | } else { |
| 252 | $filename = $att->getFilename(); |
| 253 | if ($header->description) { |
| 254 | $description = '<tr>'. |
| 255 | html_tag( 'td',_("Info:"), 'right') . |
| 256 | html_tag( 'td',decodeHeader($header->description), 'left') . |
| 257 | '</tr>'; |
| 258 | } else { |
| 259 | $description = ''; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | $display_filename = $filename; |
| 264 | |
| 265 | // TODO: maybe make it nicer? |
| 266 | $attachments .= '<table cellpadding="1" cellspacing="0" width="100%" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' . |
| 267 | '<tr>'. |
| 268 | html_tag( 'td',_("Size:"), 'right', '', 'width="25%"') . |
| 269 | html_tag( 'td',show_readable_size($header->size), 'left', '', 'width="75%"') . |
| 270 | '</tr><tr>' . "\n" . |
| 271 | html_tag( 'td',_("Type:"), 'right', '', 'width="25%"') . |
| 272 | html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left', '', 'width="75%"') . |
| 273 | '</tr>'; |
| 274 | if (! empty($description)) { |
| 275 | $attachments .= $description; |
| 276 | } |
| 277 | $attachments .= "</table>\n"; |
| 278 | } |
| 279 | return $attachments; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | /* --end pf-specific functions */ |
| 284 | |
| 285 | ?> |