44d73afc5a58f12c0c27197ee73d6d1ab8d48948
4 * printer_friendly_bottom.php
6 * with javascript on, it is the bottom frame of printer_friendly_main.php
7 * else, it is alone in a new window
9 * - this is the page that does all the work, really.
11 * @copyright © 1999-2005 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * @package squirrelmail
18 * Path for SquirrelMail required files.
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 require_once(SM_PATH
. 'functions/imap.php');
27 /* get some of these globals */
28 sqgetGlobalVar('username', $username, SQ_SESSION
);
29 sqgetGlobalVar('key', $key, SQ_COOKIE
);
30 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
32 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
33 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
35 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET
) ) {
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
42 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
43 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
45 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
48 $message = &$message->getEntity($passed_ent_id);
51 /* --start display setup-- */
53 $rfc822_header = $message->rfc822_header
;
54 /* From and Date are usually fine as they are... */
55 $from = $rfc822_header->getAddr_s('from');
56 $date = getLongDateString($rfc822_header->date
);
57 $subject = trim($rfc822_header->subject
);
59 /* we can clean these up if the list is too long... */
60 $cc = $rfc822_header->getAddr_s('cc');
61 $to = $rfc822_header->getAddr_s('to');
63 if ($show_html_default == 1) {
64 $ent_ar = $message->findDisplayEntity(array());
66 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
69 if ($ent_ar[0] != '') {
70 for ($i = 0; $i < count($ent_ar); $i++
) {
71 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
72 $body .= '<hr style="height: 1px;" />';
74 $hookResults = do_hook('message_body', $body);
75 $body = $hookResults[1];
77 $body = _("Message not printable");
80 /* now we clean up the display a bit... */
82 $num_leading_spaces = 9; // nine leading spaces for indentation
84 // sometimes I see ',,' instead of ',' separating addresses *shrug*
85 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
86 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
88 // clean up everything else...
89 $subject = pf_clean_string($subject, $num_leading_spaces);
90 $from = pf_clean_string($from, $num_leading_spaces);
91 $date = pf_clean_string($date, $num_leading_spaces);
95 $to = decodeHeader($to);
96 $cc = decodeHeader($cc);
97 $from = decodeHeader($from);
98 $subject = decodeHeader($subject);
100 $attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
102 // --end display setup--
105 /* --start browser output-- */
106 displayHtmlHeader( $subject, '', FALSE );
108 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
109 /* headers (we use table because translations are not all the same width) */
110 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
112 html_tag( 'td', '<b>'._("From").':</b> ', 'left' ,'','valign="top"') .
113 html_tag( 'td', $from, 'left' )
116 html_tag( 'td', '<b>'._("Subject").':</b> ', 'left','','valign="top"' ) .
117 html_tag( 'td', $subject, 'left' )
120 html_tag( 'td', '<b>'._("Date").':</b> ', 'left' ) .
121 html_tag( 'td', htmlspecialchars($date), 'left' )
124 html_tag( 'td', '<b>'._("To").':</b> ', 'left','','valign="top"' ) .
125 html_tag( 'td', $to, 'left' )
127 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
129 html_tag( 'td', '<b>'._("Cc").':</b> ', 'left','','valign="top"' ) .
130 html_tag( 'td', $cc, 'left' )
135 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
138 if (! empty($attachments)) {
141 html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' )
143 // list of attachments
145 html_tag( 'td',$attachments, 'left', '', 'colspan="2"' )
147 // add separator line
149 html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' )
153 echo '</table>' . "\n" .
156 /* --end browser output-- */
159 /* --start pf-specific functions-- */
162 * Function should clean layout of printed messages when user
163 * enables "Printer Friendly Clean Display" option.
164 * For example: $string = pf_clean_string($string, 9);
166 * @param string unclean_string
167 * @param integer num_leading_spaces
171 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
172 global $data_dir, $username;
173 $unclean_string = str_replace(' ',' ',$unclean_string);
174 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
175 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
177 $leading_spaces = '';
178 while ( strlen($leading_spaces) < $num_leading_spaces )
179 $leading_spaces .= ' ';
182 while ( strlen($unclean_string) > $wrap_at )
184 $this_line = substr($unclean_string, 0, $wrap_at);
185 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
187 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
188 $clean_string .= $leading_spaces;
189 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
193 $i = strrpos( $this_line, ' ');
194 $clean_string .= substr( $this_line, 0, $i);
195 $clean_string .= "\n" . $leading_spaces;
196 $unclean_string = substr($unclean_string, 1+
$i);
199 $clean_string .= $unclean_string;
201 return $clean_string;
202 } /* end pf_clean_string() function */
205 * Displays attachment information
207 * Stripped version of formatAttachments() function from functions/mime.php.
208 * @param object $message SquirrelMail message object
209 * @param array $exclude_id message parts that are not attachments.
210 * @param string $mailbox mailbox name
211 * @param integer $id message id
212 * @return string html formated attachment information.
214 function pf_show_attachments($message, $exclude_id, $mailbox, $id) {
215 global $where, $what, $startMessage, $color, $passed_ent_id;
217 $att_ar = $message->getAttachments($exclude_id);
219 if (!count($att_ar)) return '';
223 $urlMailbox = urlencode($mailbox);
225 foreach ($att_ar as $att) {
226 $ent = $att->entity_id
;
227 $header = $att->header
;
228 $type0 = strtolower($header->type0
);
229 $type1 = strtolower($header->type1
);
232 if ($type0 =='message' && $type1 == 'rfc822') {
233 $rfc822_header = $att->rfc822_header
;
234 $filename = $rfc822_header->subject
;
235 if (trim( $filename ) == '') {
236 $filename = 'untitled-[' . $ent . ']' ;
238 $from_o = $rfc822_header->from
;
239 if (is_object($from_o)) {
240 $from_name = decodeHeader($from_o->getAddress(false));
242 $from_name = _("Unknown sender");
244 $description = '<tr>'.
245 html_tag( 'td',_("From:"), 'right') .
246 html_tag( 'td',$from_name, 'left') .
249 $filename = $att->getFilename();
250 if ($header->description
) {
251 $description = '<tr>'.
252 html_tag( 'td',_("Info:"), 'right') .
253 html_tag( 'td',decodeHeader($header->description
), 'left') .
260 $display_filename = $filename;
262 // TODO: maybe make it nicer?
263 $attachments .= '<table cellpadding="0" cellspacing="0" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
265 html_tag( 'td',_("Size:"), 'right') .
266 html_tag( 'td',show_readable_size($header->size
), 'left') .
268 html_tag( 'td',_("Type:"), 'right') .
269 html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left') .
271 if (! empty($description)) {
272 $attachments .= $description;
274 $attachments .= "</table>\n";
280 /* --end pf-specific functions */