Add base url to output of configtest.php.
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
35586184 3/**
4 * printer_friendly_bottom.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 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 *
30967a1e 14 * @version $Id$
8f6f9ba5 15 * @package squirrelmail
35586184 16 */
17
30967a1e 18/**
19 * Path for SquirrelMail required files.
20 * @ignore
21 */
86725763 22define('SM_PATH','../');
23
24/* SquirrelMail required files. */
08185f2a 25require_once(SM_PATH . 'include/validate.php');
86725763 26require_once(SM_PATH . 'functions/imap.php');
f226cba7 27
0b97a708 28/* get some of these globals */
f38b7cf0 29sqgetGlobalVar('username', $username, SQ_SESSION);
30sqgetGlobalVar('key', $key, SQ_COOKIE);
31sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
0b97a708 32
f38b7cf0 33sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
d4538b25 35
f38b7cf0 36if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
d4538b25 37 $passed_ent_id = '';
91e0dccc 38}
0b97a708 39/* end globals */
40
b5cd24a8 41$pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay', false);
18680db6 42$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
d4538b25 43$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
44if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
45 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
46} else {
47 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
48}
49if ($passed_ent_id) {
50 $message = &$message->getEntity($passed_ent_id);
5caf2d0c 51}
32f4e318 52
53/* --start display setup-- */
54
91e0dccc 55$rfc822_header = $message->rfc822_header;
32f4e318 56/* From and Date are usually fine as they are... */
a91189d6 57$from = $rfc822_header->getAddr_s('from');
7e1c2d41 58$date = getLongDateString($rfc822_header->date);
a91189d6 59$subject = trim($rfc822_header->subject);
32f4e318 60
61/* we can clean these up if the list is too long... */
a91189d6 62$cc = $rfc822_header->getAddr_s('cc');
63$to = $rfc822_header->getAddr_s('to');
32f4e318 64
c8d6aef3 65if ($show_html_default == 1) {
66 $ent_ar = $message->findDisplayEntity(array());
67} else {
68 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
69}
18680db6 70$body = '';
71if ($ent_ar[0] != '') {
72 for ($i = 0; $i < count($ent_ar); $i++) {
a2bfcbce 73 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
83ae18bc 74 $body .= '<hr style="height: 1px;" />';
18680db6 75 }
76 $hookResults = do_hook('message_body', $body);
77 $body = $hookResults[1];
32f4e318 78} else {
18680db6 79 $body = _("Message not printable");
32f4e318 80}
3bbf5974 81
32f4e318 82 /* now, if they choose to, we clean up the display a bit... */
91e0dccc 83
b5cd24a8 84if ($pf_cleandisplay) {
f226cba7 85
32f4e318 86 $num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 87
32f4e318 88 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
89 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
90 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
f226cba7 91
32f4e318 92 // the body should have no leading zeros
5caf2d0c 93 // disabled because it destroys html mail
94
95// $body = pf_clean_string($body, 0);
f226cba7 96
32f4e318 97 // clean up everything else...
98 $subject = pf_clean_string($subject, $num_leading_spaces);
99 $from = pf_clean_string($from, $num_leading_spaces);
100 $date = pf_clean_string($date, $num_leading_spaces);
f226cba7 101
32f4e318 102} // end cleanup
18680db6 103
a91189d6 104$to = decodeHeader($to);
105$cc = decodeHeader($cc);
106$from = decodeHeader($from);
107$subject = decodeHeader($subject);
108
32f4e318 109// --end display setup--
f226cba7 110
f226cba7 111
32f4e318 112/* --start browser output-- */
04628296 113displayHtmlHeader( $subject, '', FALSE );
f226cba7 114
eb6d43d8 115echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
ae426785 116 /* headers (we use table because translations are not all the same width) */
3c816b1a 117 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
1c663478 118 html_tag( 'tr',
a2bfcbce 119 html_tag( 'td', '<b>'._("From").':</b>&nbsp;', 'left' ,'','valign="top"') .
a91189d6 120 html_tag( 'td', $from, 'left' )
1c663478 121 ) . "\n" .
122 html_tag( 'tr',
a2bfcbce 123 html_tag( 'td', '<b>'._("Subject").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 124 html_tag( 'td', $subject, 'left' )
7e1c2d41 125 ) . "\n" .
126 html_tag( 'tr',
a2bfcbce 127 html_tag( 'td', '<b>'._("Date").':</b>&nbsp;', 'left' ) .
83be314a 128 html_tag( 'td', htmlspecialchars($date), 'left' )
7e1c2d41 129 ) . "\n" .
130 html_tag( 'tr',
a2bfcbce 131 html_tag( 'td', '<b>'._("To").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 132 html_tag( 'td', $to, 'left' )
133 ) . "\n";
48027e89 134 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
1c663478 135 echo html_tag( 'tr',
a2bfcbce 136 html_tag( 'td', '<b>'._("Cc").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 137 html_tag( 'td', $cc, 'left' )
1c663478 138 );
139 }
1c663478 140 /* body */
7e1c2d41 141 echo html_tag( 'tr',
83ae18bc 142 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
1c663478 143 ) . "\n" .
144
145 '</table>' . "\n" .
146 '</body></html>';
f226cba7 147
32f4e318 148/* --end browser output-- */
f226cba7 149
f226cba7 150
32f4e318 151/* --start pf-specific functions-- */
f226cba7 152
b5cd24a8 153/**
154 * Function should clean layout of printed messages when user
155 * enables "Printer Friendly Clean Display" option.
9dbdf00b 156 * For example: $string = pf_clean_string($string, 9);
b5cd24a8 157 *
158 * @param string unclean_string
159 * @param integer num_leading_spaces
160 * @return string
91e0dccc 161 * @access private
b5cd24a8 162 */
f226cba7 163function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
164 global $data_dir, $username;
a91189d6 165 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
f6d2358f 166 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 167 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 168
169 $leading_spaces = '';
170 while ( strlen($leading_spaces) < $num_leading_spaces )
171 $leading_spaces .= ' ';
172
173 $clean_string = '';
174 while ( strlen($unclean_string) > $wrap_at )
175 {
176 $this_line = substr($unclean_string, 0, $wrap_at);
32f4e318 177 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 178 {
179 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
180 $clean_string .= $leading_spaces;
181 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
182 }
183 else
184 {
134e4174 185 $i = strrpos( $this_line, ' ');
186 $clean_string .= substr( $this_line, 0, $i);
187 $clean_string .= "\n" . $leading_spaces;
188 $unclean_string = substr($unclean_string, 1+$i);
189 }
f226cba7 190 }
191 $clean_string .= $unclean_string;
192
193 return $clean_string;
32f4e318 194} /* end pf_clean_string() function */
f226cba7 195
32f4e318 196/* --end pf-specific functions */
a2bfcbce 197?>