ee49b2fb802923ca665b1a395f43f972ce36e1e7
[squirrelmail.git] / src / printer_friendly_bottom.php
1 <?php
2
3 /**
4 * printer_friendly_bottom.php
5 *
6 * Copyright (c) 1999-2004 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 * @version $Id$
15 * @package squirrelmail
16 */
17
18 /**
19 * Path for SquirrelMail required files.
20 * @ignore
21 */
22 define('SM_PATH','../');
23
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'include/validate.php');
26 require_once(SM_PATH . 'functions/strings.php');
27 require_once(SM_PATH . 'config/config.php');
28 require_once(SM_PATH . 'include/load_prefs.php');
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');
32
33 /* get some of these globals */
34 sqgetGlobalVar('username', $username, SQ_SESSION);
35 sqgetGlobalVar('key', $key, SQ_COOKIE);
36 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
37
38 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
39 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
40
41 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
42 $passed_ent_id = '';
43 }
44 /* end globals */
45
46 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
47 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
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);
56 }
57
58 /* --start display setup-- */
59
60 $rfc822_header = $message->rfc822_header;
61 /* From and Date are usually fine as they are... */
62 $from = $rfc822_header->getAddr_s('from');
63 $date = getLongDateString($rfc822_header->date);
64 $subject = trim($rfc822_header->subject);
65
66 /* we can clean these up if the list is too long... */
67 $cc = $rfc822_header->getAddr_s('cc');
68 $to = $rfc822_header->getAddr_s('to');
69
70 if ($show_html_default == 1) {
71 $ent_ar = $message->findDisplayEntity(array());
72 } else {
73 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
74 }
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);
79 $body .= '<hr noshade size="1" />';
80 }
81 $hookResults = do_hook('message_body', $body);
82 $body = $hookResults[1];
83 } else {
84 $body = _("Message not printable");
85 }
86
87 /* now, if they choose to, we clean up the display a bit... */
88
89 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
90
91 $num_leading_spaces = 9; // nine leading spaces for indentation
92
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);
96
97 // the body should have no leading zeros
98 // disabled because it destroys html mail
99
100 // $body = pf_clean_string($body, 0);
101
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);
106
107 } // end cleanup
108
109 $to = decodeHeader($to);
110 $cc = decodeHeader($cc);
111 $from = decodeHeader($from);
112 $subject = decodeHeader($subject);
113
114 // --end display setup--
115
116
117 /* --start browser output-- */
118 displayHtmlHeader( $subject, '', FALSE );
119
120 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
121 /* headers (we use table because translations are not all the same width) */
122 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
123 html_tag( 'tr',
124 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
125 html_tag( 'td', $from, 'left' )
126 ) . "\n" .
127 html_tag( 'tr',
128 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
129 html_tag( 'td', $subject, 'left' )
130 ) . "\n" .
131 html_tag( 'tr',
132 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
133 html_tag( 'td', htmlspecialchars($date), 'left' )
134 ) . "\n" .
135 html_tag( 'tr',
136 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
137 html_tag( 'td', $to, 'left' )
138 ) . "\n";
139 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
140 echo html_tag( 'tr',
141 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
142 html_tag( 'td', $cc, 'left' )
143 );
144 }
145 /* body */
146 echo html_tag( 'tr',
147 html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
148 ) . "\n" .
149
150 '</table>' . "\n" .
151 '</body></html>';
152
153 /* --end browser output-- */
154
155
156 /* --start pf-specific functions-- */
157
158 /* $string = pf_clean_string($string, 9); */
159 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
160 global $data_dir, $username;
161 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
162 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
163 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
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);
173 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
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 {
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 }
186 }
187 $clean_string .= $unclean_string;
188
189 return $clean_string;
190 } /* end pf_clean_string() function */
191
192 /* --end pf-specific functions */
193
194 ?>