4 * printer_friendly_bottom.php
6 * Copyright (c) 1999-2004 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 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay', false);
42 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
44 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
45 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
47 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
50 $message = &$message->getEntity($passed_ent_id);
53 /* --start display setup-- */
55 $rfc822_header = $message->rfc822_header
;
56 /* From and Date are usually fine as they are... */
57 $from = $rfc822_header->getAddr_s('from');
58 $date = getLongDateString($rfc822_header->date
);
59 $subject = trim($rfc822_header->subject
);
61 /* we can clean these up if the list is too long... */
62 $cc = $rfc822_header->getAddr_s('cc');
63 $to = $rfc822_header->getAddr_s('to');
65 if ($show_html_default == 1) {
66 $ent_ar = $message->findDisplayEntity(array());
68 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
71 if ($ent_ar[0] != '') {
72 for ($i = 0; $i < count($ent_ar); $i++
) {
73 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
74 $body .= '<hr style="height: 1px;" />';
76 $hookResults = do_hook('message_body', $body);
77 $body = $hookResults[1];
79 $body = _("Message not printable");
82 /* now, if they choose to, we clean up the display a bit... */
84 if ($pf_cleandisplay) {
86 $num_leading_spaces = 9; // nine leading spaces for indentation
88 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
89 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
90 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
92 // the body should have no leading zeros
93 // disabled because it destroys html mail
95 // $body = pf_clean_string($body, 0);
97 // clean up everything else...
98 $subject = pf_clean_string($subject, $num_leading_spaces);
99 $from = pf_clean_string($from, $num_leading_spaces);
100 $date = pf_clean_string($date, $num_leading_spaces);
104 $to = decodeHeader($to);
105 $cc = decodeHeader($cc);
106 $from = decodeHeader($from);
107 $subject = decodeHeader($subject);
109 // --end display setup--
112 /* --start browser output-- */
113 displayHtmlHeader( $subject, '', FALSE );
115 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
116 /* headers (we use table because translations are not all the same width) */
117 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
119 html_tag( 'td', _("From").' ', 'left' ,'','valign="top"') .
120 html_tag( 'td', $from, 'left' )
123 html_tag( 'td', _("Subject").' ', 'left','','valign="top"' ) .
124 html_tag( 'td', $subject, 'left' )
127 html_tag( 'td', _("Date").' ', 'left' ) .
128 html_tag( 'td', htmlspecialchars($date), 'left' )
131 html_tag( 'td', _("To").' ', 'left','','valign="top"' ) .
132 html_tag( 'td', $to, 'left' )
134 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
136 html_tag( 'td', _("Cc").' ', 'left','','valign="top"' ) .
137 html_tag( 'td', $cc, 'left' )
142 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
148 /* --end browser output-- */
151 /* --start pf-specific functions-- */
154 * Function should clean layout of printed messages when user
155 * enables "Printer Friendly Clean Display" option.
156 * For example: $string = pf_clean_string($string, 9);
158 * @param string unclean_string
159 * @param integer num_leading_spaces
163 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
164 global $data_dir, $username;
165 $unclean_string = str_replace(' ',' ',$unclean_string);
166 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
167 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
169 $leading_spaces = '';
170 while ( strlen($leading_spaces) < $num_leading_spaces )
171 $leading_spaces .= ' ';
174 while ( strlen($unclean_string) > $wrap_at )
176 $this_line = substr($unclean_string, 0, $wrap_at);
177 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
179 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
180 $clean_string .= $leading_spaces;
181 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
185 $i = strrpos( $this_line, ' ');
186 $clean_string .= substr( $this_line, 0, $i);
187 $clean_string .= "\n" . $leading_spaces;
188 $unclean_string = substr($unclean_string, 1+
$i);
191 $clean_string .= $unclean_string;
193 return $clean_string;
194 } /* end pf_clean_string() function */
196 /* --end pf-specific functions */