information about administrative restrictions in bug_report plugin
[squirrelmail.git] / src / printer_friendly_bottom.php
... / ...
CommitLineData
1<?php
2
3/**
4 * printer_friendly_bottom.php
5 *
6 * with javascript on, it is the bottom frame of printer_friendly_main.php
7 * else, it is alone in a new window
8 *
9 * - this is the page that does all the work, really.
10 *
11 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @version $Id$
14 * @package squirrelmail
15 */
16
17/**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
21define('SM_PATH','../');
22
23/* SquirrelMail required files. */
24require_once(SM_PATH . 'include/validate.php');
25require_once(SM_PATH . 'functions/imap.php');
26
27/* get some of these globals */
28sqgetGlobalVar('username', $username, SQ_SESSION);
29sqgetGlobalVar('key', $key, SQ_COOKIE);
30sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
31
32sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
33sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
34
35if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
36 $passed_ent_id = '';
37}
38/* end globals */
39
40$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
42if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
43 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
44} else {
45 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
46}
47if ($passed_ent_id) {
48 $message = &$message->getEntity($passed_ent_id);
49}
50
51/* --start display setup-- */
52
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);
58
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');
62
63if ($show_html_default == 1) {
64 $ent_ar = $message->findDisplayEntity(array());
65} else {
66 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
67}
68$body = '';
69if ($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;" />';
73 }
74 $hookResults = do_hook('message_body', $body);
75 $body = $hookResults[1];
76} else {
77 $body = _("Message not printable");
78}
79
80/* now we clean up the display a bit... */
81
82$num_leading_spaces = 9; // nine leading spaces for indentation
83
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);
87
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);
92
93// end cleanup
94
95$to = decodeHeader($to);
96$cc = decodeHeader($cc);
97$from = decodeHeader($from);
98$subject = decodeHeader($subject);
99
100$attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
101
102// --end display setup--
103
104
105/* --start browser output-- */
106displayHtmlHeader( $subject, '', FALSE );
107
108echo '<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%"' ) .
111 html_tag( 'tr',
112 html_tag( 'td', '<b>'._("From").':</b>&nbsp;', 'left' ,'','valign="top"') .
113 html_tag( 'td', $from, 'left' )
114 ) . "\n" .
115 html_tag( 'tr',
116 html_tag( 'td', '<b>'._("Subject").':</b>&nbsp;', 'left','','valign="top"' ) .
117 html_tag( 'td', $subject, 'left' )
118 ) . "\n" .
119 html_tag( 'tr',
120 html_tag( 'td', '<b>'._("Date").':</b>&nbsp;', 'left' ) .
121 html_tag( 'td', htmlspecialchars($date), 'left' )
122 ) . "\n" .
123 html_tag( 'tr',
124 html_tag( 'td', '<b>'._("To").':</b>&nbsp;', 'left','','valign="top"' ) .
125 html_tag( 'td', $to, 'left' )
126 ) . "\n";
127 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
128 echo html_tag( 'tr',
129 html_tag( 'td', '<b>'._("Cc").':</b>&nbsp;', 'left','','valign="top"' ) .
130 html_tag( 'td', $cc, 'left' )
131 );
132 }
133 /* body */
134 echo html_tag( 'tr',
135 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
136 ) . "\n" ;
137
138 if (! empty($attachments)) {
139 // attachments title
140 echo html_tag( 'tr',
141 html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' )
142 ) . "\n" ;
143 // list of attachments
144 echo html_tag( 'tr',
145 html_tag( 'td',$attachments, 'left', '', 'colspan="2"' )
146 ) . "\n" ;
147 // add separator line
148 echo html_tag( 'tr',
149 html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' )
150 ) . "\n" ;
151 }
152
153 echo '</table>' . "\n" .
154 '</body></html>';
155
156/* --end browser output-- */
157
158
159/* --start pf-specific functions-- */
160
161/**
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);
165 *
166 * @param string unclean_string
167 * @param integer num_leading_spaces
168 * @return string
169 * @access private
170 */
171function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
172 global $data_dir, $username;
173 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
174 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
175 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
176
177 $leading_spaces = '';
178 while ( strlen($leading_spaces) < $num_leading_spaces )
179 $leading_spaces .= ' ';
180
181 $clean_string = '';
182 while ( strlen($unclean_string) > $wrap_at )
183 {
184 $this_line = substr($unclean_string, 0, $wrap_at);
185 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
186 {
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" ));
190 }
191 else
192 {
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);
197 }
198 }
199 $clean_string .= $unclean_string;
200
201 return $clean_string;
202} /* end pf_clean_string() function */
203
204/**
205 * Displays attachment information
206 *
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.
213 */
214function pf_show_attachments($message, $exclude_id, $mailbox, $id) {
215 global $where, $what, $startMessage, $color, $passed_ent_id;
216
217 $att_ar = $message->getAttachments($exclude_id);
218
219 if (!count($att_ar)) return '';
220
221 $attachments = '';
222
223 $urlMailbox = urlencode($mailbox);
224
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);
230 $name = '';
231
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 . ']' ;
237 }
238 $from_o = $rfc822_header->from;
239 if (is_object($from_o)) {
240 $from_name = decodeHeader($from_o->getAddress(false));
241 } else {
242 $from_name = _("Unknown sender");
243 }
244 $description = '<tr>'.
245 html_tag( 'td',_("From:"), 'right') .
246 html_tag( 'td',$from_name, 'left') .
247 '</tr>';
248 } else {
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') .
254 '</tr>';
255 } else {
256 $description = '';
257 }
258 }
259
260 $display_filename = $filename;
261
262 // TODO: maybe make it nicer?
263 $attachments .= '<table cellpadding="0" cellspacing="0" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
264 '<tr border="0">'.
265 html_tag( 'td',_("Size:"), 'right') .
266 html_tag( 'td',show_readable_size($header->size), 'left') .
267 '</tr><tr>' .
268 html_tag( 'td',_("Type:"), 'right') .
269 html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left') .
270 '</tr>';
271 if (! empty($description)) {
272 $attachments .= $description;
273 }
274 $attachments .= "</table>\n";
275 }
276 return $attachments;
277}
278
279
280/* --end pf-specific functions */
281
282?>