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