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