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