4 * printer_friendly_bottom.php
6 * Copyright (c) 1999-2003 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
18 /** Path for SquirrelMail required files. */
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/strings.php');
24 require_once(SM_PATH
. 'config/config.php');
25 require_once(SM_PATH
. 'include/load_prefs.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/page_header.php');
28 require_once(SM_PATH
. 'functions/html.php');
30 /* get some of these globals */
31 sqgetGlobalVar('username', $username, SQ_SESSION
);
32 sqgetGlobalVar('key', $key, SQ_COOKIE
);
33 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
35 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
38 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET
) ) {
43 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
44 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
45 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
46 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
47 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
49 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
52 $message = &$message->getEntity($passed_ent_id);
55 /* --start display setup-- */
57 $rfc822_header = $message->rfc822_header
;
58 /* From and Date are usually fine as they are... */
59 $from = $rfc822_header->getAddr_s('from');
60 $date = getLongDateString($rfc822_header->date
);
61 $subject = trim($rfc822_header->subject
);
63 /* we can clean these up if the list is too long... */
64 $cc = $rfc822_header->getAddr_s('cc');
65 $to = $rfc822_header->getAddr_s('to');
67 if ($show_html_default == 1) {
68 $ent_ar = $message->findDisplayEntity(array());
70 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
73 if ($ent_ar[0] != '') {
74 for ($i = 0; $i < count($ent_ar); $i++
) {
75 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
76 $body .= '<hr noshade size="1" />';
78 $hookResults = do_hook('message_body', $body);
79 $body = $hookResults[1];
81 $body = _("Message not printable");
84 /* now, if they choose to, we clean up the display a bit... */
86 if ( empty($pf_cleandisplay) ||
$pf_cleandisplay != 'no' ) {
88 $num_leading_spaces = 9; // nine leading spaces for indentation
90 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
91 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
92 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
94 // the body should have no leading zeros
95 // disabled because it destroys html mail
97 // $body = pf_clean_string($body, 0);
99 // clean up everything else...
100 $subject = pf_clean_string($subject, $num_leading_spaces);
101 $from = pf_clean_string($from, $num_leading_spaces);
102 $date = pf_clean_string($date, $num_leading_spaces);
106 $to = decodeHeader($to);
107 $cc = decodeHeader($cc);
108 $from = decodeHeader($from);
109 $subject = decodeHeader($subject);
111 // --end display setup--
114 /* --start browser output-- */
115 displayHtmlHeader( $subject, '', FALSE );
117 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
118 /* headers (we use table because translations are not all the same width) */
119 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
121 html_tag( 'td', _("From").' ', 'left' ,'','valign="top"') .
122 html_tag( 'td', $from, 'left' )
125 html_tag( 'td', _("Subject").' ', 'left','','valign="top"' ) .
126 html_tag( 'td', $subject, 'left' )
129 html_tag( 'td', _("Date").' ', 'left' ) .
130 html_tag( 'td', htmlspecialchars($date), 'left' )
133 html_tag( 'td', _("To").' ', 'left','','valign="top"' ) .
134 html_tag( 'td', $to, 'left' )
136 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
138 html_tag( 'td', _("CC").' ', 'left','','valign="top"' ) .
139 html_tag( 'td', $cc, 'left' )
144 html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
150 /* --end browser output-- */
153 /* --start pf-specific functions-- */
155 /* $string = pf_clean_string($string, 9); */
156 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
157 global $data_dir, $username;
158 $unclean_string = str_replace(' ',' ',$unclean_string);
159 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
160 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
162 $leading_spaces = '';
163 while ( strlen($leading_spaces) < $num_leading_spaces )
164 $leading_spaces .= ' ';
167 while ( strlen($unclean_string) > $wrap_at )
169 $this_line = substr($unclean_string, 0, $wrap_at);
170 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
172 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
173 $clean_string .= $leading_spaces;
174 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
178 $i = strrpos( $this_line, ' ');
179 $clean_string .= substr( $this_line, 0, $i);
180 $clean_string .= "\n" . $leading_spaces;
181 $unclean_string = substr($unclean_string, 1+
$i);
184 $clean_string .= $unclean_string;
186 return $clean_string;
187 } /* end pf_clean_string() function */
189 /* --end pf-specific functions */