r2l by Yoav
[squirrelmail.git] / src / printer_friendly_bottom.php
1 <?php
2
3 /**
4 * printer_friendly_bottom.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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
17 require_once('../src/validate.php');
18 require_once('../functions/strings.php');
19 require_once('../config/config.php');
20 require_once('../src/load_prefs.php');
21 require_once('../functions/imap.php');
22 require_once('../functions/page_header.php');
23 require_once('../functions/html.php');
24
25 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
26
27 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
28 sqimap_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;
43 $ent_ar = findDisplayEntity ($message, 0);
44 $ent_num = $ent_ar[0];
45
46 $body_message = getEntity($message, $ent_num);
47 if (($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 );
56 translateText($body, $wrap_at, $body_message->header->charset);
57 } else {
58 $body = MagicHTML( $body, $id, $message );
59 }
60 } else {
61 translateText($body, $wrap_at, $body_message->header->charset);
62 }
63 } else {
64 $body = _("Message not printable");
65 }
66
67 $subject = trim(decodeHeader($message->header->subject));
68
69 /* now, if they choose to, we clean up the display a bit... */
70 /*
71 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
72
73 $num_leading_spaces = 9; // nine leading spaces for indentation
74
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);
78
79 // the body should have no leading zeros
80 $body = pf_clean_string($body, 0);
81
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);
86
87 } // end cleanup
88 */
89 // --end display setup--
90
91
92 /* --start browser output-- */
93 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
94
95 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
96 /* headers (we use table because translations are not all the same width) */
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>';
128
129 /* --end browser output-- */
130
131
132 /* --start pf-specific functions-- */
133
134 /* $string = pf_clean_string($string, 9); */
135 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
136 global $data_dir, $username;
137
138 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
139 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
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);
149 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
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 }
162
163 $clean_string .= $unclean_string;
164
165 return $clean_string;
166 } /* end pf_clean_string() function */
167
168 /* --end pf-specific functions */
169
170 ?>