f226cba7 |
1 | <?php |
2 | |
35586184 |
3 | /** |
4 | * printer_friendly_bottom.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
35586184 |
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 | * |
30967a1e |
14 | * @version $Id$ |
8f6f9ba5 |
15 | * @package squirrelmail |
35586184 |
16 | */ |
17 | |
30967a1e |
18 | /** |
19 | * Path for SquirrelMail required files. |
20 | * @ignore |
21 | */ |
86725763 |
22 | define('SM_PATH','../'); |
23 | |
24 | /* SquirrelMail required files. */ |
08185f2a |
25 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
26 | require_once(SM_PATH . 'functions/imap.php'); |
f226cba7 |
27 | |
0b97a708 |
28 | /* get some of these globals */ |
f38b7cf0 |
29 | sqgetGlobalVar('username', $username, SQ_SESSION); |
30 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
31 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
0b97a708 |
32 | |
f38b7cf0 |
33 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
34 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
d4538b25 |
35 | |
f38b7cf0 |
36 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
37 | $passed_ent_id = ''; |
91e0dccc |
38 | } |
0b97a708 |
39 | /* end globals */ |
40 | |
18680db6 |
41 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
d4538b25 |
42 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
43 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
44 | $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
45 | } else { |
46 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
47 | } |
48 | if ($passed_ent_id) { |
49 | $message = &$message->getEntity($passed_ent_id); |
5caf2d0c |
50 | } |
32f4e318 |
51 | |
52 | /* --start display setup-- */ |
53 | |
91e0dccc |
54 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
55 | /* From and Date are usually fine as they are... */ |
a91189d6 |
56 | $from = $rfc822_header->getAddr_s('from'); |
7e1c2d41 |
57 | $date = getLongDateString($rfc822_header->date); |
a91189d6 |
58 | $subject = trim($rfc822_header->subject); |
32f4e318 |
59 | |
60 | /* we can clean these up if the list is too long... */ |
a91189d6 |
61 | $cc = $rfc822_header->getAddr_s('cc'); |
62 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
63 | |
c8d6aef3 |
64 | if ($show_html_default == 1) { |
65 | $ent_ar = $message->findDisplayEntity(array()); |
66 | } else { |
67 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
68 | } |
18680db6 |
69 | $body = ''; |
70 | if ($ent_ar[0] != '') { |
71 | for ($i = 0; $i < count($ent_ar); $i++) { |
a2bfcbce |
72 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE); |
83ae18bc |
73 | $body .= '<hr style="height: 1px;" />'; |
18680db6 |
74 | } |
75 | $hookResults = do_hook('message_body', $body); |
76 | $body = $hookResults[1]; |
32f4e318 |
77 | } else { |
18680db6 |
78 | $body = _("Message not printable"); |
32f4e318 |
79 | } |
3bbf5974 |
80 | |
2b0f4faf |
81 | /* now we clean up the display a bit... */ |
91e0dccc |
82 | |
2b0f4faf |
83 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
84 | |
2b0f4faf |
85 | // sometimes I see ',,' instead of ',' seperating addresses *shrug* |
86 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
87 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
f226cba7 |
88 | |
2b0f4faf |
89 | // clean up everything else... |
90 | $subject = pf_clean_string($subject, $num_leading_spaces); |
91 | $from = pf_clean_string($from, $num_leading_spaces); |
92 | $date = pf_clean_string($date, $num_leading_spaces); |
f226cba7 |
93 | |
2b0f4faf |
94 | // end cleanup |
18680db6 |
95 | |
a91189d6 |
96 | $to = decodeHeader($to); |
97 | $cc = decodeHeader($cc); |
98 | $from = decodeHeader($from); |
99 | $subject = decodeHeader($subject); |
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"' ) |
1c663478 |
135 | ) . "\n" . |
136 | |
137 | '</table>' . "\n" . |
138 | '</body></html>'; |
f226cba7 |
139 | |
32f4e318 |
140 | /* --end browser output-- */ |
f226cba7 |
141 | |
f226cba7 |
142 | |
32f4e318 |
143 | /* --start pf-specific functions-- */ |
f226cba7 |
144 | |
b5cd24a8 |
145 | /** |
146 | * Function should clean layout of printed messages when user |
147 | * enables "Printer Friendly Clean Display" option. |
9dbdf00b |
148 | * For example: $string = pf_clean_string($string, 9); |
b5cd24a8 |
149 | * |
150 | * @param string unclean_string |
151 | * @param integer num_leading_spaces |
152 | * @return string |
91e0dccc |
153 | * @access private |
b5cd24a8 |
154 | */ |
f226cba7 |
155 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
156 | global $data_dir, $username; |
a91189d6 |
157 | $unclean_string = str_replace(' ',' ',$unclean_string); |
f6d2358f |
158 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
32f4e318 |
159 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
f226cba7 |
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); |
32f4e318 |
169 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
f226cba7 |
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 | { |
134e4174 |
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 | } |
f226cba7 |
182 | } |
183 | $clean_string .= $unclean_string; |
184 | |
185 | return $clean_string; |
32f4e318 |
186 | } /* end pf_clean_string() function */ |
f226cba7 |
187 | |
32f4e318 |
188 | /* --end pf-specific functions */ |
a2b193bc |
189 | |
f8a1ed5a |
190 | ?> |