f226cba7 |
1 | <?php |
2 | |
35586184 |
3 | /** |
4 | * printer_friendly_bottom.php |
5 | * |
82d304a0 |
6 | * Copyright (c) 1999-2004 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/strings.php'); |
27 | require_once(SM_PATH . 'config/config.php'); |
08185f2a |
28 | require_once(SM_PATH . 'include/load_prefs.php'); |
86725763 |
29 | require_once(SM_PATH . 'functions/imap.php'); |
30 | require_once(SM_PATH . 'functions/page_header.php'); |
31 | require_once(SM_PATH . 'functions/html.php'); |
f226cba7 |
32 | |
0b97a708 |
33 | /* get some of these globals */ |
f38b7cf0 |
34 | sqgetGlobalVar('username', $username, SQ_SESSION); |
35 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
36 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
0b97a708 |
37 | |
f38b7cf0 |
38 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
39 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
d4538b25 |
40 | |
f38b7cf0 |
41 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
42 | $passed_ent_id = ''; |
f38b7cf0 |
43 | } |
0b97a708 |
44 | /* end globals */ |
45 | |
32f4e318 |
46 | $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay'); |
18680db6 |
47 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
d4538b25 |
48 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
49 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
50 | $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
51 | } else { |
52 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
53 | } |
54 | if ($passed_ent_id) { |
55 | $message = &$message->getEntity($passed_ent_id); |
5caf2d0c |
56 | } |
32f4e318 |
57 | |
58 | /* --start display setup-- */ |
59 | |
7e1c2d41 |
60 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
61 | /* From and Date are usually fine as they are... */ |
a91189d6 |
62 | $from = $rfc822_header->getAddr_s('from'); |
7e1c2d41 |
63 | $date = getLongDateString($rfc822_header->date); |
a91189d6 |
64 | $subject = trim($rfc822_header->subject); |
32f4e318 |
65 | |
66 | /* we can clean these up if the list is too long... */ |
a91189d6 |
67 | $cc = $rfc822_header->getAddr_s('cc'); |
68 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
69 | |
c8d6aef3 |
70 | if ($show_html_default == 1) { |
71 | $ent_ar = $message->findDisplayEntity(array()); |
72 | } else { |
73 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
74 | } |
18680db6 |
75 | $body = ''; |
76 | if ($ent_ar[0] != '') { |
77 | for ($i = 0; $i < count($ent_ar); $i++) { |
78 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
d68323ff |
79 | $body .= '<hr noshade size="1" />'; |
18680db6 |
80 | } |
81 | $hookResults = do_hook('message_body', $body); |
82 | $body = $hookResults[1]; |
32f4e318 |
83 | } else { |
18680db6 |
84 | $body = _("Message not printable"); |
32f4e318 |
85 | } |
3bbf5974 |
86 | |
32f4e318 |
87 | /* now, if they choose to, we clean up the display a bit... */ |
18680db6 |
88 | |
32f4e318 |
89 | if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) { |
f226cba7 |
90 | |
32f4e318 |
91 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
92 | |
32f4e318 |
93 | // sometimes I see ',,' instead of ',' seperating addresses *shrug* |
94 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
95 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
f226cba7 |
96 | |
32f4e318 |
97 | // the body should have no leading zeros |
5caf2d0c |
98 | // disabled because it destroys html mail |
99 | |
100 | // $body = pf_clean_string($body, 0); |
f226cba7 |
101 | |
32f4e318 |
102 | // clean up everything else... |
103 | $subject = pf_clean_string($subject, $num_leading_spaces); |
104 | $from = pf_clean_string($from, $num_leading_spaces); |
105 | $date = pf_clean_string($date, $num_leading_spaces); |
f226cba7 |
106 | |
32f4e318 |
107 | } // end cleanup |
18680db6 |
108 | |
a91189d6 |
109 | $to = decodeHeader($to); |
110 | $cc = decodeHeader($cc); |
111 | $from = decodeHeader($from); |
112 | $subject = decodeHeader($subject); |
113 | |
32f4e318 |
114 | // --end display setup-- |
f226cba7 |
115 | |
f226cba7 |
116 | |
32f4e318 |
117 | /* --start browser output-- */ |
04628296 |
118 | displayHtmlHeader( $subject, '', FALSE ); |
f226cba7 |
119 | |
eb6d43d8 |
120 | echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" . |
ae426785 |
121 | /* headers (we use table because translations are not all the same width) */ |
3c816b1a |
122 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
1c663478 |
123 | html_tag( 'tr', |
7e1c2d41 |
124 | html_tag( 'td', _("From").' ', 'left' ,'','valign="top"') . |
a91189d6 |
125 | html_tag( 'td', $from, 'left' ) |
1c663478 |
126 | ) . "\n" . |
127 | html_tag( 'tr', |
7e1c2d41 |
128 | html_tag( 'td', _("Subject").' ', 'left','','valign="top"' ) . |
a91189d6 |
129 | html_tag( 'td', $subject, 'left' ) |
7e1c2d41 |
130 | ) . "\n" . |
131 | html_tag( 'tr', |
132 | html_tag( 'td', _("Date").' ', 'left' ) . |
83be314a |
133 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
7e1c2d41 |
134 | ) . "\n" . |
135 | html_tag( 'tr', |
136 | html_tag( 'td', _("To").' ', 'left','','valign="top"' ) . |
a91189d6 |
137 | html_tag( 'td', $to, 'left' ) |
138 | ) . "\n"; |
1c663478 |
139 | if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */ |
140 | echo html_tag( 'tr', |
7e1c2d41 |
141 | html_tag( 'td', _("CC").' ', 'left','','valign="top"' ) . |
a91189d6 |
142 | html_tag( 'td', $cc, 'left' ) |
1c663478 |
143 | ); |
144 | } |
1c663478 |
145 | /* body */ |
7e1c2d41 |
146 | echo html_tag( 'tr', |
d68323ff |
147 | html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' ) |
1c663478 |
148 | ) . "\n" . |
149 | |
150 | '</table>' . "\n" . |
151 | '</body></html>'; |
f226cba7 |
152 | |
32f4e318 |
153 | /* --end browser output-- */ |
f226cba7 |
154 | |
f226cba7 |
155 | |
32f4e318 |
156 | /* --start pf-specific functions-- */ |
f226cba7 |
157 | |
32f4e318 |
158 | /* $string = pf_clean_string($string, 9); */ |
f226cba7 |
159 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
160 | global $data_dir, $username; |
a91189d6 |
161 | $unclean_string = str_replace(' ',' ',$unclean_string); |
f6d2358f |
162 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
32f4e318 |
163 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
f226cba7 |
164 | |
165 | $leading_spaces = ''; |
166 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
167 | $leading_spaces .= ' '; |
168 | |
169 | $clean_string = ''; |
170 | while ( strlen($unclean_string) > $wrap_at ) |
171 | { |
172 | $this_line = substr($unclean_string, 0, $wrap_at); |
32f4e318 |
173 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
f226cba7 |
174 | { |
175 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" )); |
176 | $clean_string .= $leading_spaces; |
177 | $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" )); |
178 | } |
179 | else |
180 | { |
a91189d6 |
181 | $i = strrpos( $this_line, ' '); |
182 | $clean_string .= substr( $this_line, 0, $i); |
183 | $clean_string .= "\n" . $leading_spaces; |
184 | $unclean_string = substr($unclean_string, 1+$i); |
185 | } |
f226cba7 |
186 | } |
187 | $clean_string .= $unclean_string; |
188 | |
189 | return $clean_string; |
32f4e318 |
190 | } /* end pf_clean_string() function */ |
f226cba7 |
191 | |
32f4e318 |
192 | /* --end pf-specific functions */ |
f226cba7 |
193 | |
ae426785 |
194 | ?> |