Fix requirements to reflect actual requirements according to Marc.
[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 $mailbox = urldecode($mailbox);
46 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
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);
55 }
56
57 /* --start display setup-- */
58
59 $rfc822_header = $message->rfc822_header;
60 /* From and Date are usually fine as they are... */
61 $from = $rfc822_header->getAddr_s('from');
62 $date = getLongDateString($rfc822_header->date);
63 $subject = trim($rfc822_header->subject);
64
65 /* we can clean these up if the list is too long... */
66 $cc = $rfc822_header->getAddr_s('cc');
67 $to = $rfc822_header->getAddr_s('to');
68
69 if ($show_html_default == 1) {
70 $ent_ar = $message->findDisplayEntity(array());
71 } else {
72 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
73 }
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);
78 $body .= '<hr noshade size="1" />';
79 }
80 $hookResults = do_hook('message_body', $body);
81 $body = $hookResults[1];
82 } else {
83 $body = _("Message not printable");
84 }
85
86 /* now, if they choose to, we clean up the display a bit... */
87
88 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
89
90 $num_leading_spaces = 9; // nine leading spaces for indentation
91
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);
95
96 // the body should have no leading zeros
97 // disabled because it destroys html mail
98
99 // $body = pf_clean_string($body, 0);
100
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);
105
106 } // end cleanup
107
108 $to = decodeHeader($to);
109 $cc = decodeHeader($cc);
110 $from = decodeHeader($from);
111 $subject = decodeHeader($subject);
112
113 // --end display setup--
114
115
116 /* --start browser output-- */
117 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
118
119 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
120 /* headers (we use table because translations are not all the same width) */
121 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
122 html_tag( 'tr',
123 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
124 html_tag( 'td', $from, 'left' )
125 ) . "\n" .
126 html_tag( 'tr',
127 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
128 html_tag( 'td', $subject, 'left' )
129 ) . "\n" .
130 html_tag( 'tr',
131 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
132 html_tag( 'td', htmlspecialchars($date), 'left' )
133 ) . "\n" .
134 html_tag( 'tr',
135 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
136 html_tag( 'td', $to, 'left' )
137 ) . "\n";
138 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
139 echo html_tag( 'tr',
140 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
141 html_tag( 'td', $cc, 'left' )
142 );
143 }
144 /* body */
145 echo html_tag( 'tr',
146 html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
147 ) . "\n" .
148
149 '</table>' . "\n" .
150 '</body></html>';
151
152 /* --end browser output-- */
153
154
155 /* --start pf-specific functions-- */
156
157 /* $string = pf_clean_string($string, 9); */
158 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
159 global $data_dir, $username;
160 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
161 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
162 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
163
164 $leading_spaces = '';
165 while ( strlen($leading_spaces) < $num_leading_spaces )
166 $leading_spaces .= ' ';
167
168 $clean_string = '';
169 while ( strlen($unclean_string) > $wrap_at )
170 {
171 $this_line = substr($unclean_string, 0, $wrap_at);
172 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
173 {
174 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
175 $clean_string .= $leading_spaces;
176 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
177 }
178 else
179 {
180 $i = strrpos( $this_line, ' ');
181 $clean_string .= substr( $this_line, 0, $i);
182 $clean_string .= "\n" . $leading_spaces;
183 $unclean_string = substr($unclean_string, 1+$i);
184 }
185 }
186 $clean_string .= $unclean_string;
187
188 return $clean_string;
189 } /* end pf_clean_string() function */
190
191 /* --end pf-specific functions */
192
193 ?>