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