Printable version should not use theme colors but fixed black-text-on-white-background.
[squirrelmail.git] / src / printer_friendly_bottom.php
1 <?php
2
3 /**
4 * printer_friendly_bottom.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * with javascript on, it is the bottom frame of printer_friendly_main.php
10 * else, it is alone in a new window
11 *
12 * - this is the page that does all the work, really.
13 *
14 * $Id$
15 */
16
17 /* Path for SquirrelMail required files. */
18 define('SM_PATH','../');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'include/validate.php');
22 require_once(SM_PATH . 'functions/strings.php');
23 require_once(SM_PATH . 'config/config.php');
24 require_once(SM_PATH . 'include/load_prefs.php');
25 require_once(SM_PATH . 'functions/imap.php');
26 require_once(SM_PATH . 'functions/page_header.php');
27 require_once(SM_PATH . 'functions/html.php');
28
29 /* get some of these globals */
30 sqgetGlobalVar('username', $username, SQ_SESSION);
31 sqgetGlobalVar('key', $key, SQ_COOKIE);
32 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
35 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
36
37 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
38 $passed_ent_id = '';
39 }
40 /* end globals */
41
42 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
43 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
44 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
45 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
46 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
47 } else {
48 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
49 }
50 if ($passed_ent_id) {
51 $message = &$message->getEntity($passed_ent_id);
52 }
53
54 /* --start display setup-- */
55
56 $rfc822_header = $message->rfc822_header;
57 /* From and Date are usually fine as they are... */
58 $from = $rfc822_header->getAddr_s('from');
59 $date = getLongDateString($rfc822_header->date);
60 $subject = trim($rfc822_header->subject);
61
62 /* we can clean these up if the list is too long... */
63 $cc = $rfc822_header->getAddr_s('cc');
64 $to = $rfc822_header->getAddr_s('to');
65
66 if ($show_html_default == 1) {
67 $ent_ar = $message->findDisplayEntity(array());
68 } else {
69 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
70 }
71 $body = '';
72 if ($ent_ar[0] != '') {
73 for ($i = 0; $i < count($ent_ar); $i++) {
74 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
75 $body .= '<hr noshade size="1" />';
76 }
77 $hookResults = do_hook('message_body', $body);
78 $body = $hookResults[1];
79 } else {
80 $body = _("Message not printable");
81 }
82
83 /* now, if they choose to, we clean up the display a bit... */
84
85 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
86
87 $num_leading_spaces = 9; // nine leading spaces for indentation
88
89 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
90 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
91 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
92
93 // the body should have no leading zeros
94 // disabled because it destroys html mail
95
96 // $body = pf_clean_string($body, 0);
97
98 // clean up everything else...
99 $subject = pf_clean_string($subject, $num_leading_spaces);
100 $from = pf_clean_string($from, $num_leading_spaces);
101 $date = pf_clean_string($date, $num_leading_spaces);
102
103 } // end cleanup
104
105 $to = decodeHeader($to);
106 $cc = decodeHeader($cc);
107 $from = decodeHeader($from);
108 $subject = decodeHeader($subject);
109
110 // --end display setup--
111
112
113 /* --start browser output-- */
114 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
115
116 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
117 /* headers (we use table because translations are not all the same width) */
118 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
119 html_tag( 'tr',
120 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
121 html_tag( 'td', $from, 'left' )
122 ) . "\n" .
123 html_tag( 'tr',
124 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
125 html_tag( 'td', $subject, 'left' )
126 ) . "\n" .
127 html_tag( 'tr',
128 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
129 html_tag( 'td', htmlspecialchars($date), 'left' )
130 ) . "\n" .
131 html_tag( 'tr',
132 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
133 html_tag( 'td', $to, 'left' )
134 ) . "\n";
135 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
136 echo html_tag( 'tr',
137 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
138 html_tag( 'td', $cc, 'left' )
139 );
140 }
141 /* body */
142 echo html_tag( 'tr',
143 html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
144 ) . "\n" .
145
146 '</table>' . "\n" .
147 '</body></html>';
148
149 /* --end browser output-- */
150
151
152 /* --start pf-specific functions-- */
153
154 /* $string = pf_clean_string($string, 9); */
155 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
156 global $data_dir, $username;
157 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
158 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
159 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
160
161 $leading_spaces = '';
162 while ( strlen($leading_spaces) < $num_leading_spaces )
163 $leading_spaces .= ' ';
164
165 $clean_string = '';
166 while ( strlen($unclean_string) > $wrap_at )
167 {
168 $this_line = substr($unclean_string, 0, $wrap_at);
169 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
170 {
171 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
172 $clean_string .= $leading_spaces;
173 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
174 }
175 else
176 {
177 $i = strrpos( $this_line, ' ');
178 $clean_string .= substr( $this_line, 0, $i);
179 $clean_string .= "\n" . $leading_spaces;
180 $unclean_string = substr($unclean_string, 1+$i);
181 }
182 }
183 $clean_string .= $unclean_string;
184
185 return $clean_string;
186 } /* end pf_clean_string() function */
187
188 /* --end pf-specific functions */
189
190 ?>