f226cba7 |
1 | <?php |
2 | |
35586184 |
3 | /** |
4 | * printer_friendly_bottom.php |
5 | * |
35586184 |
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 | * |
4b4abf93 |
11 | * @copyright © 1999-2005 The SquirrelMail Project Team |
12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
13 | * @version $Id$ |
8f6f9ba5 |
14 | * @package squirrelmail |
35586184 |
15 | */ |
16 | |
30967a1e |
17 | /** |
18 | * Path for SquirrelMail required files. |
19 | * @ignore |
20 | */ |
86725763 |
21 | define('SM_PATH','../'); |
22 | |
23 | /* SquirrelMail required files. */ |
08185f2a |
24 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
25 | require_once(SM_PATH . 'functions/imap.php'); |
f226cba7 |
26 | |
0b97a708 |
27 | /* get some of these globals */ |
f38b7cf0 |
28 | sqgetGlobalVar('username', $username, SQ_SESSION); |
29 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
30 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
0b97a708 |
31 | |
f38b7cf0 |
32 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
33 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
d4538b25 |
34 | |
f38b7cf0 |
35 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
36 | $passed_ent_id = ''; |
91e0dccc |
37 | } |
0b97a708 |
38 | /* end globals */ |
39 | |
18680db6 |
40 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
d4538b25 |
41 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
42 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
7f6171be |
43 | $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
d4538b25 |
44 | } else { |
45 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
46 | } |
47 | if ($passed_ent_id) { |
7f6171be |
48 | $message = $message->getEntity($passed_ent_id); |
5caf2d0c |
49 | } |
32f4e318 |
50 | |
51 | /* --start display setup-- */ |
52 | |
91e0dccc |
53 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
54 | /* From and Date are usually fine as they are... */ |
a91189d6 |
55 | $from = $rfc822_header->getAddr_s('from'); |
7e1c2d41 |
56 | $date = getLongDateString($rfc822_header->date); |
a91189d6 |
57 | $subject = trim($rfc822_header->subject); |
32f4e318 |
58 | |
59 | /* we can clean these up if the list is too long... */ |
a91189d6 |
60 | $cc = $rfc822_header->getAddr_s('cc'); |
61 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
62 | |
c8d6aef3 |
63 | if ($show_html_default == 1) { |
64 | $ent_ar = $message->findDisplayEntity(array()); |
65 | } else { |
66 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
67 | } |
18680db6 |
68 | $body = ''; |
69 | if ($ent_ar[0] != '') { |
70 | for ($i = 0; $i < count($ent_ar); $i++) { |
a2bfcbce |
71 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE); |
83ae18bc |
72 | $body .= '<hr style="height: 1px;" />'; |
18680db6 |
73 | } |
74 | $hookResults = do_hook('message_body', $body); |
75 | $body = $hookResults[1]; |
32f4e318 |
76 | } else { |
18680db6 |
77 | $body = _("Message not printable"); |
32f4e318 |
78 | } |
3bbf5974 |
79 | |
2b0f4faf |
80 | /* now we clean up the display a bit... */ |
91e0dccc |
81 | |
2b0f4faf |
82 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
83 | |
d3c4749f |
84 | // sometimes I see ',,' instead of ',' separating addresses *shrug* |
2b0f4faf |
85 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
86 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
f226cba7 |
87 | |
2b0f4faf |
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); |
f226cba7 |
92 | |
2b0f4faf |
93 | // end cleanup |
18680db6 |
94 | |
a91189d6 |
95 | $to = decodeHeader($to); |
96 | $cc = decodeHeader($cc); |
97 | $from = decodeHeader($from); |
98 | $subject = decodeHeader($subject); |
99 | |
d3c4749f |
100 | $attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id); |
101 | |
32f4e318 |
102 | // --end display setup-- |
f226cba7 |
103 | |
f226cba7 |
104 | |
32f4e318 |
105 | /* --start browser output-- */ |
04628296 |
106 | displayHtmlHeader( $subject, '', FALSE ); |
f226cba7 |
107 | |
eb6d43d8 |
108 | echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" . |
ae426785 |
109 | /* headers (we use table because translations are not all the same width) */ |
3c816b1a |
110 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
1c663478 |
111 | html_tag( 'tr', |
a2bfcbce |
112 | html_tag( 'td', '<b>'._("From").':</b> ', 'left' ,'','valign="top"') . |
a91189d6 |
113 | html_tag( 'td', $from, 'left' ) |
1c663478 |
114 | ) . "\n" . |
115 | html_tag( 'tr', |
a2bfcbce |
116 | html_tag( 'td', '<b>'._("Subject").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
117 | html_tag( 'td', $subject, 'left' ) |
7e1c2d41 |
118 | ) . "\n" . |
119 | html_tag( 'tr', |
a2bfcbce |
120 | html_tag( 'td', '<b>'._("Date").':</b> ', 'left' ) . |
83be314a |
121 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
7e1c2d41 |
122 | ) . "\n" . |
123 | html_tag( 'tr', |
a2bfcbce |
124 | html_tag( 'td', '<b>'._("To").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
125 | html_tag( 'td', $to, 'left' ) |
126 | ) . "\n"; |
48027e89 |
127 | if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */ |
1c663478 |
128 | echo html_tag( 'tr', |
a2bfcbce |
129 | html_tag( 'td', '<b>'._("Cc").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
130 | html_tag( 'td', $cc, 'left' ) |
1c663478 |
131 | ); |
132 | } |
1c663478 |
133 | /* body */ |
7e1c2d41 |
134 | echo html_tag( 'tr', |
83ae18bc |
135 | html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' ) |
d3c4749f |
136 | ) . "\n" ; |
137 | |
138 | if (! empty($attachments)) { |
139 | // attachments title |
140 | echo html_tag( 'tr', |
f369f2c0 |
141 | html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' ) |
d3c4749f |
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 | } |
1c663478 |
152 | |
d3c4749f |
153 | echo '</table>' . "\n" . |
1c663478 |
154 | '</body></html>'; |
f226cba7 |
155 | |
32f4e318 |
156 | /* --end browser output-- */ |
f226cba7 |
157 | |
f226cba7 |
158 | |
32f4e318 |
159 | /* --start pf-specific functions-- */ |
f226cba7 |
160 | |
b5cd24a8 |
161 | /** |
162 | * Function should clean layout of printed messages when user |
163 | * enables "Printer Friendly Clean Display" option. |
9dbdf00b |
164 | * For example: $string = pf_clean_string($string, 9); |
b5cd24a8 |
165 | * |
166 | * @param string unclean_string |
167 | * @param integer num_leading_spaces |
168 | * @return string |
91e0dccc |
169 | * @access private |
b5cd24a8 |
170 | */ |
f226cba7 |
171 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
172 | global $data_dir, $username; |
a91189d6 |
173 | $unclean_string = str_replace(' ',' ',$unclean_string); |
f6d2358f |
174 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
32f4e318 |
175 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
f226cba7 |
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); |
32f4e318 |
185 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
f226cba7 |
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 | { |
134e4174 |
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 | } |
f226cba7 |
198 | } |
199 | $clean_string .= $unclean_string; |
200 | |
201 | return $clean_string; |
32f4e318 |
202 | } /* end pf_clean_string() function */ |
f226cba7 |
203 | |
d3c4749f |
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 | */ |
214 | function 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)) { |
434fb973 |
240 | $from_name = decodeHeader($from_o->getAddress(true)); |
d3c4749f |
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>'. |
f369f2c0 |
252 | html_tag( 'td',_("Info:"), 'right') . |
d3c4749f |
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? |
179aed24 |
263 | $attachments .= '<table cellpadding="1" cellspacing="0" width="100%" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' . |
264 | '<tr>'. |
265 | html_tag( 'td',_("Size:"), 'right', '', 'width="25%"') . |
266 | html_tag( 'td',show_readable_size($header->size), 'left', '', 'width="75%"') . |
267 | '</tr><tr>' . "\n" . |
268 | html_tag( 'td',_("Type:"), 'right', '', 'width="25%"') . |
269 | html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left', '', 'width="75%"') . |
d3c4749f |
270 | '</tr>'; |
271 | if (! empty($description)) { |
272 | $attachments .= $description; |
273 | } |
274 | $attachments .= "</table>\n"; |
275 | } |
276 | return $attachments; |
277 | } |
278 | |
279 | |
32f4e318 |
280 | /* --end pf-specific functions */ |
a2b193bc |
281 | |
7f6171be |
282 | ?> |