More global cleanup. Now all SESSION and COOKIE use sqgetglobalvar, what's
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
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. */
18define('SM_PATH','../');
19
20/* SquirrelMail required files. */
08185f2a 21require_once(SM_PATH . 'include/validate.php');
86725763 22require_once(SM_PATH . 'functions/strings.php');
23require_once(SM_PATH . 'config/config.php');
08185f2a 24require_once(SM_PATH . 'include/load_prefs.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
26require_once(SM_PATH . 'functions/page_header.php');
27require_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
37if (!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$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
d4538b25 46$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
47if (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}
52if ($passed_ent_id) {
53 $message = &$message->getEntity($passed_ent_id);
5caf2d0c 54}
32f4e318 55
56/* --start display setup-- */
57
7e1c2d41 58$rfc822_header = $message->rfc822_header;
32f4e318 59/* From and Date are usually fine as they are... */
a91189d6 60$from = $rfc822_header->getAddr_s('from');
7e1c2d41 61$date = getLongDateString($rfc822_header->date);
a91189d6 62$subject = trim($rfc822_header->subject);
32f4e318 63
64/* we can clean these up if the list is too long... */
a91189d6 65$cc = $rfc822_header->getAddr_s('cc');
66$to = $rfc822_header->getAddr_s('to');
32f4e318 67
c8d6aef3 68if ($show_html_default == 1) {
69 $ent_ar = $message->findDisplayEntity(array());
70} else {
71 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
72}
18680db6 73$body = '';
74if ($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);
d68323ff 77 $body .= '<hr noshade size="1" />';
18680db6 78 }
79 $hookResults = do_hook('message_body', $body);
80 $body = $hookResults[1];
32f4e318 81} else {
18680db6 82 $body = _("Message not printable");
32f4e318 83}
3bbf5974 84
32f4e318 85 /* now, if they choose to, we clean up the display a bit... */
18680db6 86
32f4e318 87if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
f226cba7 88
32f4e318 89 $num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 90
32f4e318 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);
f226cba7 94
32f4e318 95 // the body should have no leading zeros
5caf2d0c 96 // disabled because it destroys html mail
97
98// $body = pf_clean_string($body, 0);
f226cba7 99
32f4e318 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);
f226cba7 104
32f4e318 105} // end cleanup
18680db6 106
a91189d6 107$to = decodeHeader($to);
108$cc = decodeHeader($cc);
109$from = decodeHeader($from);
110$subject = decodeHeader($subject);
111
32f4e318 112// --end display setup--
f226cba7 113
f226cba7 114
32f4e318 115/* --start browser output-- */
116displayHtmlHeader( _("Printer Friendly"), '', FALSE );
f226cba7 117
32f4e318 118echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
ae426785 119 /* headers (we use table because translations are not all the same width) */
3c816b1a 120 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
1c663478 121 html_tag( 'tr',
7e1c2d41 122 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
a91189d6 123 html_tag( 'td', $from, 'left' )
1c663478 124 ) . "\n" .
125 html_tag( 'tr',
7e1c2d41 126 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
a91189d6 127 html_tag( 'td', $subject, 'left' )
7e1c2d41 128 ) . "\n" .
129 html_tag( 'tr',
130 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
83be314a 131 html_tag( 'td', htmlspecialchars($date), 'left' )
7e1c2d41 132 ) . "\n" .
133 html_tag( 'tr',
134 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
a91189d6 135 html_tag( 'td', $to, 'left' )
136 ) . "\n";
1c663478 137 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
138 echo html_tag( 'tr',
7e1c2d41 139 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
a91189d6 140 html_tag( 'td', $cc, 'left' )
1c663478 141 );
142 }
1c663478 143 /* body */
7e1c2d41 144 echo html_tag( 'tr',
d68323ff 145 html_tag( 'td', '<hr noshade size="1" /><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
1c663478 146 ) . "\n" .
147
148 '</table>' . "\n" .
149 '</body></html>';
f226cba7 150
32f4e318 151/* --end browser output-- */
f226cba7 152
f226cba7 153
32f4e318 154/* --start pf-specific functions-- */
f226cba7 155
32f4e318 156/* $string = pf_clean_string($string, 9); */
f226cba7 157function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
158 global $data_dir, $username;
a91189d6 159 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
f6d2358f 160 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 161 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 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);
32f4e318 171 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 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 {
a91189d6 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 }
f226cba7 184 }
185 $clean_string .= $unclean_string;
186
187 return $clean_string;
32f4e318 188} /* end pf_clean_string() function */
f226cba7 189
32f4e318 190/* --end pf-specific functions */
f226cba7 191
ae426785 192?>