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