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