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 | * |
47ccfad4 |
11 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
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 | /** |
202bcbcc |
18 | * Include the SquirrelMail initialization file. |
30967a1e |
19 | */ |
202bcbcc |
20 | require('../include/init.php'); |
86725763 |
21 | |
22 | /* SquirrelMail required files. */ |
202bcbcc |
23 | require_once(SM_PATH . 'functions/imap_general.php'); |
24 | require_once(SM_PATH . 'functions/imap_messages.php'); |
25 | require_once(SM_PATH . 'functions/date.php'); |
26 | require_once(SM_PATH . 'functions/mime.php'); |
27 | require_once(SM_PATH . 'functions/url_parser.php'); |
f226cba7 |
28 | |
0b97a708 |
29 | /* get some of these globals */ |
f38b7cf0 |
30 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
31 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
d4538b25 |
32 | |
f38b7cf0 |
33 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
34 | $passed_ent_id = ''; |
91e0dccc |
35 | } |
4c8986b4 |
36 | sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM); |
0b97a708 |
37 | /* end globals */ |
38 | |
906f7e9f |
39 | $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); |
d4538b25 |
40 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
41 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
7f6171be |
42 | $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
d4538b25 |
43 | } else { |
44 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
45 | } |
46 | if ($passed_ent_id) { |
7f6171be |
47 | $message = $message->getEntity($passed_ent_id); |
5caf2d0c |
48 | } |
32f4e318 |
49 | |
50 | /* --start display setup-- */ |
51 | |
91e0dccc |
52 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
53 | /* From and Date are usually fine as they are... */ |
a91189d6 |
54 | $from = $rfc822_header->getAddr_s('from'); |
7e1c2d41 |
55 | $date = getLongDateString($rfc822_header->date); |
a91189d6 |
56 | $subject = trim($rfc822_header->subject); |
32f4e318 |
57 | |
58 | /* we can clean these up if the list is too long... */ |
a91189d6 |
59 | $cc = $rfc822_header->getAddr_s('cc'); |
60 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
61 | |
c8d6aef3 |
62 | if ($show_html_default == 1) { |
63 | $ent_ar = $message->findDisplayEntity(array()); |
64 | } else { |
65 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
66 | } |
18680db6 |
67 | $body = ''; |
68 | if ($ent_ar[0] != '') { |
69 | for ($i = 0; $i < count($ent_ar); $i++) { |
a2bfcbce |
70 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE); |
83ae18bc |
71 | $body .= '<hr style="height: 1px;" />'; |
18680db6 |
72 | } |
73 | $hookResults = do_hook('message_body', $body); |
74 | $body = $hookResults[1]; |
32f4e318 |
75 | } else { |
18680db6 |
76 | $body = _("Message not printable"); |
32f4e318 |
77 | } |
3bbf5974 |
78 | |
2b0f4faf |
79 | /* now we clean up the display a bit... */ |
91e0dccc |
80 | |
2b0f4faf |
81 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
82 | |
d3c4749f |
83 | // sometimes I see ',,' instead of ',' separating addresses *shrug* |
2b0f4faf |
84 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
85 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
f226cba7 |
86 | |
2b0f4faf |
87 | // clean up everything else... |
88 | $subject = pf_clean_string($subject, $num_leading_spaces); |
89 | $from = pf_clean_string($from, $num_leading_spaces); |
90 | $date = pf_clean_string($date, $num_leading_spaces); |
f226cba7 |
91 | |
2b0f4faf |
92 | // end cleanup |
18680db6 |
93 | |
a91189d6 |
94 | $to = decodeHeader($to); |
95 | $cc = decodeHeader($cc); |
96 | $from = decodeHeader($from); |
97 | $subject = decodeHeader($subject); |
98 | |
d3c4749f |
99 | $attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id); |
100 | |
32f4e318 |
101 | // --end display setup-- |
f226cba7 |
102 | |
f226cba7 |
103 | |
32f4e318 |
104 | /* --start browser output-- */ |
04628296 |
105 | displayHtmlHeader( $subject, '', FALSE ); |
f226cba7 |
106 | |
eb6d43d8 |
107 | echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" . |
ae426785 |
108 | /* headers (we use table because translations are not all the same width) */ |
3c816b1a |
109 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
1c663478 |
110 | html_tag( 'tr', |
a2bfcbce |
111 | html_tag( 'td', '<b>'._("From").':</b> ', 'left' ,'','valign="top"') . |
a91189d6 |
112 | html_tag( 'td', $from, 'left' ) |
1c663478 |
113 | ) . "\n" . |
114 | html_tag( 'tr', |
a2bfcbce |
115 | html_tag( 'td', '<b>'._("Subject").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
116 | html_tag( 'td', $subject, 'left' ) |
7e1c2d41 |
117 | ) . "\n" . |
118 | html_tag( 'tr', |
a2bfcbce |
119 | html_tag( 'td', '<b>'._("Date").':</b> ', 'left' ) . |
83be314a |
120 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
7e1c2d41 |
121 | ) . "\n" . |
122 | html_tag( 'tr', |
a2bfcbce |
123 | html_tag( 'td', '<b>'._("To").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
124 | html_tag( 'td', $to, 'left' ) |
125 | ) . "\n"; |
48027e89 |
126 | if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */ |
1c663478 |
127 | echo html_tag( 'tr', |
a2bfcbce |
128 | html_tag( 'td', '<b>'._("Cc").':</b> ', 'left','','valign="top"' ) . |
a91189d6 |
129 | html_tag( 'td', $cc, 'left' ) |
1c663478 |
130 | ); |
131 | } |
1c663478 |
132 | /* body */ |
7e1c2d41 |
133 | echo html_tag( 'tr', |
83ae18bc |
134 | html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' ) |
d3c4749f |
135 | ) . "\n" ; |
5c4ff7bf |
136 | |
d3c4749f |
137 | if (! empty($attachments)) { |
138 | // attachments title |
139 | echo html_tag( 'tr', |
f369f2c0 |
140 | html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' ) |
d3c4749f |
141 | ) . "\n" ; |
142 | // list of attachments |
143 | echo html_tag( 'tr', |
144 | html_tag( 'td',$attachments, 'left', '', 'colspan="2"' ) |
145 | ) . "\n" ; |
146 | // add separator line |
147 | echo html_tag( 'tr', |
148 | html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' ) |
149 | ) . "\n" ; |
150 | } |
1c663478 |
151 | |
5c4ff7bf |
152 | echo '</table>' . "\n"; |
153 | $oTemplate->display('footer.tpl'); |
f226cba7 |
154 | |
32f4e318 |
155 | /* --end browser output-- */ |
f226cba7 |
156 | |
f226cba7 |
157 | |
32f4e318 |
158 | /* --start pf-specific functions-- */ |
f226cba7 |
159 | |
b5cd24a8 |
160 | /** |
161 | * Function should clean layout of printed messages when user |
162 | * enables "Printer Friendly Clean Display" option. |
9dbdf00b |
163 | * For example: $string = pf_clean_string($string, 9); |
b5cd24a8 |
164 | * |
165 | * @param string unclean_string |
166 | * @param integer num_leading_spaces |
167 | * @return string |
91e0dccc |
168 | * @access private |
b5cd24a8 |
169 | */ |
f226cba7 |
170 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
171 | global $data_dir, $username; |
a91189d6 |
172 | $unclean_string = str_replace(' ',' ',$unclean_string); |
f6d2358f |
173 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
32f4e318 |
174 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
f226cba7 |
175 | |
176 | $leading_spaces = ''; |
177 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
178 | $leading_spaces .= ' '; |
179 | |
180 | $clean_string = ''; |
181 | while ( strlen($unclean_string) > $wrap_at ) |
182 | { |
183 | $this_line = substr($unclean_string, 0, $wrap_at); |
32f4e318 |
184 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
f226cba7 |
185 | { |
186 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" )); |
187 | $clean_string .= $leading_spaces; |
188 | $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" )); |
189 | } |
190 | else |
191 | { |
134e4174 |
192 | $i = strrpos( $this_line, ' '); |
193 | $clean_string .= substr( $this_line, 0, $i); |
194 | $clean_string .= "\n" . $leading_spaces; |
195 | $unclean_string = substr($unclean_string, 1+$i); |
196 | } |
f226cba7 |
197 | } |
198 | $clean_string .= $unclean_string; |
199 | |
200 | return $clean_string; |
32f4e318 |
201 | } /* end pf_clean_string() function */ |
f226cba7 |
202 | |
d3c4749f |
203 | /** |
204 | * Displays attachment information |
205 | * |
206 | * Stripped version of formatAttachments() function from functions/mime.php. |
207 | * @param object $message SquirrelMail message object |
208 | * @param array $exclude_id message parts that are not attachments. |
209 | * @param string $mailbox mailbox name |
210 | * @param integer $id message id |
211 | * @return string html formated attachment information. |
212 | */ |
213 | function pf_show_attachments($message, $exclude_id, $mailbox, $id) { |
214 | global $where, $what, $startMessage, $color, $passed_ent_id; |
215 | |
216 | $att_ar = $message->getAttachments($exclude_id); |
217 | |
218 | if (!count($att_ar)) return ''; |
219 | |
220 | $attachments = ''; |
221 | |
222 | $urlMailbox = urlencode($mailbox); |
223 | |
224 | foreach ($att_ar as $att) { |
225 | $ent = $att->entity_id; |
226 | $header = $att->header; |
227 | $type0 = strtolower($header->type0); |
228 | $type1 = strtolower($header->type1); |
229 | $name = ''; |
230 | |
231 | if ($type0 =='message' && $type1 == 'rfc822') { |
232 | $rfc822_header = $att->rfc822_header; |
233 | $filename = $rfc822_header->subject; |
234 | if (trim( $filename ) == '') { |
235 | $filename = 'untitled-[' . $ent . ']' ; |
236 | } |
237 | $from_o = $rfc822_header->from; |
238 | if (is_object($from_o)) { |
434fb973 |
239 | $from_name = decodeHeader($from_o->getAddress(true)); |
d3c4749f |
240 | } else { |
241 | $from_name = _("Unknown sender"); |
242 | } |
243 | $description = '<tr>'. |
244 | html_tag( 'td',_("From:"), 'right') . |
245 | html_tag( 'td',$from_name, 'left') . |
246 | '</tr>'; |
247 | } else { |
248 | $filename = $att->getFilename(); |
249 | if ($header->description) { |
250 | $description = '<tr>'. |
f369f2c0 |
251 | html_tag( 'td',_("Info:"), 'right') . |
d3c4749f |
252 | html_tag( 'td',decodeHeader($header->description), 'left') . |
253 | '</tr>'; |
254 | } else { |
255 | $description = ''; |
256 | } |
257 | } |
258 | |
259 | $display_filename = $filename; |
260 | |
261 | // TODO: maybe make it nicer? |
179aed24 |
262 | $attachments .= '<table cellpadding="1" cellspacing="0" width="100%" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' . |
5c4ff7bf |
263 | '<tr>'. |
264 | html_tag( 'td',_("Size:"), 'right', '', 'width="25%"') . |
179aed24 |
265 | html_tag( 'td',show_readable_size($header->size), 'left', '', 'width="75%"') . |
266 | '</tr><tr>' . "\n" . |
267 | html_tag( 'td',_("Type:"), 'right', '', 'width="25%"') . |
5c4ff7bf |
268 | html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left', '', 'width="75%"') . |
d3c4749f |
269 | '</tr>'; |
270 | if (! empty($description)) { |
271 | $attachments .= $description; |
272 | } |
273 | $attachments .= "</table>\n"; |
274 | } |
275 | return $attachments; |
276 | } |
277 | |
278 | |
32f4e318 |
279 | /* --end pf-specific functions */ |
a2b193bc |
280 | |
7f6171be |
281 | ?> |