4 * printer_friendly_bottom.php
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * with javascript on, it is the bottom frame of printer_friendly_main.php
10 * else, it is alone in a new window
12 * - this is the page that does all the work, really.
15 * @package squirrelmail
19 * Path for SquirrelMail required files.
22 define('SM_PATH','../');
24 /* SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 require_once(SM_PATH
. 'functions/imap.php');
28 /* get some of these globals */
29 sqgetGlobalVar('username', $username, SQ_SESSION
);
30 sqgetGlobalVar('key', $key, SQ_COOKIE
);
31 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
33 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
34 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
36 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET
) ) {
41 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
43 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
44 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
46 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
49 $message = &$message->getEntity($passed_ent_id);
52 /* --start display setup-- */
54 $rfc822_header = $message->rfc822_header
;
55 /* From and Date are usually fine as they are... */
56 $from = $rfc822_header->getAddr_s('from');
57 $date = getLongDateString($rfc822_header->date
);
58 $subject = trim($rfc822_header->subject
);
60 /* we can clean these up if the list is too long... */
61 $cc = $rfc822_header->getAddr_s('cc');
62 $to = $rfc822_header->getAddr_s('to');
64 if ($show_html_default == 1) {
65 $ent_ar = $message->findDisplayEntity(array());
67 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
70 if ($ent_ar[0] != '') {
71 for ($i = 0; $i < count($ent_ar); $i++
) {
72 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
73 $body .= '<hr style="height: 1px;" />';
75 $hookResults = do_hook('message_body', $body);
76 $body = $hookResults[1];
78 $body = _("Message not printable");
81 /* now we clean up the display a bit... */
83 $num_leading_spaces = 9; // nine leading spaces for indentation
85 // sometimes I see ',,' instead of ',' separating addresses *shrug*
86 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
87 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
89 // clean up everything else...
90 $subject = pf_clean_string($subject, $num_leading_spaces);
91 $from = pf_clean_string($from, $num_leading_spaces);
92 $date = pf_clean_string($date, $num_leading_spaces);
96 $to = decodeHeader($to);
97 $cc = decodeHeader($cc);
98 $from = decodeHeader($from);
99 $subject = decodeHeader($subject);
101 $attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
103 // --end display setup--
106 /* --start browser output-- */
107 displayHtmlHeader( $subject, '', FALSE );
109 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
110 /* headers (we use table because translations are not all the same width) */
111 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
113 html_tag( 'td', '<b>'._("From").':</b> ', 'left' ,'','valign="top"') .
114 html_tag( 'td', $from, 'left' )
117 html_tag( 'td', '<b>'._("Subject").':</b> ', 'left','','valign="top"' ) .
118 html_tag( 'td', $subject, 'left' )
121 html_tag( 'td', '<b>'._("Date").':</b> ', 'left' ) .
122 html_tag( 'td', htmlspecialchars($date), 'left' )
125 html_tag( 'td', '<b>'._("To").':</b> ', 'left','','valign="top"' ) .
126 html_tag( 'td', $to, 'left' )
128 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
130 html_tag( 'td', '<b>'._("Cc").':</b> ', 'left','','valign="top"' ) .
131 html_tag( 'td', $cc, 'left' )
136 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
139 if (! empty($attachments)) {
142 html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' )
144 // list of attachments
146 html_tag( 'td',$attachments, 'left', '', 'colspan="2"' )
148 // add separator line
150 html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' )
154 echo '</table>' . "\n" .
157 /* --end browser output-- */
160 /* --start pf-specific functions-- */
163 * Function should clean layout of printed messages when user
164 * enables "Printer Friendly Clean Display" option.
165 * For example: $string = pf_clean_string($string, 9);
167 * @param string unclean_string
168 * @param integer num_leading_spaces
172 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
173 global $data_dir, $username;
174 $unclean_string = str_replace(' ',' ',$unclean_string);
175 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
176 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
178 $leading_spaces = '';
179 while ( strlen($leading_spaces) < $num_leading_spaces )
180 $leading_spaces .= ' ';
183 while ( strlen($unclean_string) > $wrap_at )
185 $this_line = substr($unclean_string, 0, $wrap_at);
186 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
188 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
189 $clean_string .= $leading_spaces;
190 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
194 $i = strrpos( $this_line, ' ');
195 $clean_string .= substr( $this_line, 0, $i);
196 $clean_string .= "\n" . $leading_spaces;
197 $unclean_string = substr($unclean_string, 1+
$i);
200 $clean_string .= $unclean_string;
202 return $clean_string;
203 } /* end pf_clean_string() function */
206 * Displays attachment information
208 * Stripped version of formatAttachments() function from functions/mime.php.
209 * @param object $message SquirrelMail message object
210 * @param array $exclude_id message parts that are not attachments.
211 * @param string $mailbox mailbox name
212 * @param integer $id message id
213 * @return string html formated attachment information.
215 function pf_show_attachments($message, $exclude_id, $mailbox, $id) {
216 global $where, $what, $startMessage, $color, $passed_ent_id;
218 $att_ar = $message->getAttachments($exclude_id);
220 if (!count($att_ar)) return '';
224 $urlMailbox = urlencode($mailbox);
226 foreach ($att_ar as $att) {
227 $ent = $att->entity_id
;
228 $header = $att->header
;
229 $type0 = strtolower($header->type0
);
230 $type1 = strtolower($header->type1
);
233 if ($type0 =='message' && $type1 == 'rfc822') {
234 $rfc822_header = $att->rfc822_header
;
235 $filename = $rfc822_header->subject
;
236 if (trim( $filename ) == '') {
237 $filename = 'untitled-[' . $ent . ']' ;
239 $from_o = $rfc822_header->from
;
240 if (is_object($from_o)) {
241 $from_name = decodeHeader($from_o->getAddress(false));
243 $from_name = _("Unknown sender");
245 $description = '<tr>'.
246 html_tag( 'td',_("From:"), 'right') .
247 html_tag( 'td',$from_name, 'left') .
250 $filename = $att->getFilename();
251 if ($header->description
) {
252 $description = '<tr>'.
253 html_tag( 'td',_("Info:"), 'right') .
254 html_tag( 'td',decodeHeader($header->description
), 'left') .
261 $display_filename = $filename;
263 // TODO: maybe make it nicer?
264 $attachments .= '<table border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
266 html_tag( 'td',_("Size:"), 'right') .
267 html_tag( 'td',show_readable_size($header->size
), 'left') .
269 html_tag( 'td',_("Type:"), 'right') .
270 html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left') .
272 if (! empty($description)) {
273 $attachments .= $description;
275 $attachments .= "</table>\n";
281 /* --end pf-specific functions */