f226cba7 |
1 | <?php |
2 | |
35586184 |
3 | /** |
4 | * printer_friendly_bottom.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 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 | * |
14 | * $Id$ |
15 | */ |
16 | |
86725763 |
17 | /* Path for SquirrelMail required files. */ |
18 | define('SM_PATH','../'); |
19 | |
20 | /* SquirrelMail required files. */ |
08185f2a |
21 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
22 | require_once(SM_PATH . 'functions/strings.php'); |
23 | require_once(SM_PATH . 'config/config.php'); |
08185f2a |
24 | require_once(SM_PATH . 'include/load_prefs.php'); |
86725763 |
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'); |
f226cba7 |
28 | |
0b97a708 |
29 | /* get some of these globals */ |
f38b7cf0 |
30 | sqgetGlobalVar('username', $username, SQ_SESSION); |
31 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
32 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
0b97a708 |
33 | |
f38b7cf0 |
34 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
35 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
d4538b25 |
36 | |
f38b7cf0 |
37 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
38 | $passed_ent_id = ''; |
f38b7cf0 |
39 | } |
0b97a708 |
40 | /* end globals */ |
41 | |
32f4e318 |
42 | $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay'); |
18680db6 |
43 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
d4538b25 |
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); |
5caf2d0c |
52 | } |
32f4e318 |
53 | |
54 | /* --start display setup-- */ |
55 | |
7e1c2d41 |
56 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
57 | /* From and Date are usually fine as they are... */ |
a91189d6 |
58 | $from = $rfc822_header->getAddr_s('from'); |
7e1c2d41 |
59 | $date = getLongDateString($rfc822_header->date); |
a91189d6 |
60 | $subject = trim($rfc822_header->subject); |
32f4e318 |
61 | |
62 | /* we can clean these up if the list is too long... */ |
a91189d6 |
63 | $cc = $rfc822_header->getAddr_s('cc'); |
64 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
65 | |
c8d6aef3 |
66 | if ($show_html_default == 1) { |
67 | $ent_ar = $message->findDisplayEntity(array()); |
68 | } else { |
69 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
70 | } |
18680db6 |
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); |
d68323ff |
75 | $body .= '<hr noshade size="1" />'; |
18680db6 |
76 | } |
77 | $hookResults = do_hook('message_body', $body); |
78 | $body = $hookResults[1]; |
32f4e318 |
79 | } else { |
18680db6 |
80 | $body = _("Message not printable"); |
32f4e318 |
81 | } |
3bbf5974 |
82 | |
32f4e318 |
83 | /* now, if they choose to, we clean up the display a bit... */ |
18680db6 |
84 | |
32f4e318 |
85 | if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) { |
f226cba7 |
86 | |
32f4e318 |
87 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
88 | |
32f4e318 |
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); |
f226cba7 |
92 | |
32f4e318 |
93 | // the body should have no leading zeros |
5caf2d0c |
94 | // disabled because it destroys html mail |
95 | |
96 | // $body = pf_clean_string($body, 0); |
f226cba7 |
97 | |
32f4e318 |
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); |
f226cba7 |
102 | |
32f4e318 |
103 | } // end cleanup |
18680db6 |
104 | |
a91189d6 |
105 | $to = decodeHeader($to); |
106 | $cc = decodeHeader($cc); |
107 | $from = decodeHeader($from); |
108 | $subject = decodeHeader($subject); |
109 | |
32f4e318 |
110 | // --end display setup-- |
f226cba7 |
111 | |
f226cba7 |
112 | |
32f4e318 |
113 | /* --start browser output-- */ |
04628296 |
114 | displayHtmlHeader( $subject, '', FALSE ); |
f226cba7 |
115 | |
eb6d43d8 |
116 | echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" . |
ae426785 |
117 | /* headers (we use table because translations are not all the same width) */ |
3c816b1a |
118 | html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) . |
1c663478 |
119 | html_tag( 'tr', |
7e1c2d41 |
120 | html_tag( 'td', _("From").' ', 'left' ,'','valign="top"') . |
a91189d6 |
121 | html_tag( 'td', $from, 'left' ) |
1c663478 |
122 | ) . "\n" . |
123 | html_tag( 'tr', |
7e1c2d41 |
124 | html_tag( 'td', _("Subject").' ', 'left','','valign="top"' ) . |
a91189d6 |
125 | html_tag( 'td', $subject, 'left' ) |
7e1c2d41 |
126 | ) . "\n" . |
127 | html_tag( 'tr', |
128 | html_tag( 'td', _("Date").' ', 'left' ) . |
83be314a |
129 | html_tag( 'td', htmlspecialchars($date), 'left' ) |
7e1c2d41 |
130 | ) . "\n" . |
131 | html_tag( 'tr', |
132 | html_tag( 'td', _("To").' ', 'left','','valign="top"' ) . |
a91189d6 |
133 | html_tag( 'td', $to, 'left' ) |
134 | ) . "\n"; |
1c663478 |
135 | if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */ |
136 | echo html_tag( 'tr', |
7e1c2d41 |
137 | html_tag( 'td', _("CC").' ', 'left','','valign="top"' ) . |
a91189d6 |
138 | html_tag( 'td', $cc, 'left' ) |
1c663478 |
139 | ); |
140 | } |
1c663478 |
141 | /* body */ |
7e1c2d41 |
142 | echo html_tag( 'tr', |
d68323ff |
143 | html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' ) |
1c663478 |
144 | ) . "\n" . |
145 | |
146 | '</table>' . "\n" . |
147 | '</body></html>'; |
f226cba7 |
148 | |
32f4e318 |
149 | /* --end browser output-- */ |
f226cba7 |
150 | |
f226cba7 |
151 | |
32f4e318 |
152 | /* --start pf-specific functions-- */ |
f226cba7 |
153 | |
32f4e318 |
154 | /* $string = pf_clean_string($string, 9); */ |
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 | { |
a91189d6 |
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 */ |
f226cba7 |
189 | |
ae426785 |
190 | ?> |