whoops, missed a line.
[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
35586184 17require_once('../src/validate.php');
18require_once('../functions/strings.php');
19require_once('../config/config.php');
20require_once('../src/load_prefs.php');
21require_once('../functions/imap.php');
22require_once('../functions/page_header.php');
1c663478 23require_once('../functions/html.php');
f226cba7 24
32f4e318 25$pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
26
27$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
28sqimap_mailbox_select($imap_stream, $mailbox);
29$message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
30
31/* --start display setup-- */
32
33/* From and Date are usually fine as they are... */
34$from = decodeHeader($message->header->from);
35$date = getLongDateString($message->header->date);
36
37/* we can clean these up if the list is too long... */
38$cc = decodeHeader(getLineOfAddrs($message->header->cc));
39$to = decodeHeader(getLineOfAddrs($message->header->to));
40
41/* and Body and Subject could easily stream off the page... */
42$id = $message->header->id;
32886992 43$ent_ar = findDisplayEntity ($message, 0);
44$ent_num = $ent_ar[0];
45
32f4e318 46$body_message = getEntity($message, $ent_num);
47if (($body_message->header->type0 == 'text') ||
48 ($body_message->header->type0 == 'rfc822')) {
49 $body = mime_fetch_body ($imap_stream, $id, $ent_num);
50 $body = decodeBody($body, $body_message->header->encoding);
51 $hookResults = do_hook('message_body', $body);
52 $body = $hookResults[1];
53 if ($body_message->header->type1 == 'html') {
54 if( $show_html_default <> 1 ) {
55 $body = strip_tags( $body );
3bbf5974 56 translateText($body, $wrap_at, $body_message->header->charset);
3bbf5974 57 } else {
32886992 58 $body = MagicHTML( $body, $id, $message );
3bbf5974 59 }
32f4e318 60 } else {
61 translateText($body, $wrap_at, $body_message->header->charset);
62 }
63} else {
64 $body = _("Message not printable");
65}
3bbf5974 66
32f4e318 67$subject = trim(decodeHeader($message->header->subject));
f226cba7 68
32f4e318 69 /* now, if they choose to, we clean up the display a bit... */
70 /*
71if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
f226cba7 72
32f4e318 73 $num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 74
32f4e318 75 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
76 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
77 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
f226cba7 78
32f4e318 79 // the body should have no leading zeros
80 $body = pf_clean_string($body, 0);
f226cba7 81
32f4e318 82 // clean up everything else...
83 $subject = pf_clean_string($subject, $num_leading_spaces);
84 $from = pf_clean_string($from, $num_leading_spaces);
85 $date = pf_clean_string($date, $num_leading_spaces);
f226cba7 86
32f4e318 87} // end cleanup
88*/
89// --end display setup--
f226cba7 90
f226cba7 91
32f4e318 92/* --start browser output-- */
93displayHtmlHeader( _("Printer Friendly"), '', FALSE );
f226cba7 94
32f4e318 95echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
ae426785 96 /* headers (we use table because translations are not all the same width) */
1c663478 97 html_tag( 'table', '', '', '', 'width="100%" cellspacing="0" cellpadding="0" border="0"' ) .
98 html_tag( 'tr',
99 html_tag( 'td', _("From"), 'left' ) .
100 html_tag( 'td', htmlentities($from), 'left' )
101 ) . "\n" .
102 html_tag( 'tr',
103 html_tag( 'td', _("To"), 'left' ) .
104 html_tag( 'td', htmlentities($to), 'left' )
105 ) . "\n";
106 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
107 echo html_tag( 'tr',
108 html_tag( 'td', _("CC"), 'left' ) .
109 html_tag( 'td', htmlentities($cc), 'left' )
110 );
111 }
112 echo html_tag( 'tr',
113 html_tag( 'td', _("Date"), 'left' ) .
114 html_tag( 'td', htmlentities($date), 'left' )
115 ) . "\n" .
116 html_tag( 'tr',
117 html_tag( 'td', _("Subject"), 'left' ) .
118 html_tag( 'td', htmlentities($subject), 'left' )
119 ) . "\n" .
120
121 /* body */
122 html_tag( 'tr',
123 html_tag( 'td', '<hr noshade size=1><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
124 ) . "\n" .
125
126 '</table>' . "\n" .
127 '</body></html>';
f226cba7 128
32f4e318 129/* --end browser output-- */
f226cba7 130
f226cba7 131
32f4e318 132/* --start pf-specific functions-- */
f226cba7 133
32f4e318 134/* $string = pf_clean_string($string, 9); */
f226cba7 135function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
136 global $data_dir, $username;
137
f6d2358f 138 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 139 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 140
141 $leading_spaces = '';
142 while ( strlen($leading_spaces) < $num_leading_spaces )
143 $leading_spaces .= ' ';
144
145 $clean_string = '';
146 while ( strlen($unclean_string) > $wrap_at )
147 {
148 $this_line = substr($unclean_string, 0, $wrap_at);
32f4e318 149 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 150 {
151 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
152 $clean_string .= $leading_spaces;
153 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
154 }
155 else
156 {
157 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
158 $clean_string .= "\n" . $leading_spaces;
159 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
160 }
161 }
32f4e318 162
f226cba7 163 $clean_string .= $unclean_string;
164
165 return $clean_string;
32f4e318 166} /* end pf_clean_string() function */
f226cba7 167
32f4e318 168/* --end pf-specific functions */
f226cba7 169
ae426785 170?>