integrated printer_friendly into the core
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
3 /**
4 ** printer_friendly_bottom.php
5 **
6 ** Copyright (c) 1999-2000 The SquirrelMail development 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
23
24 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
25
26 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
27 sqimap_mailbox_select($imap_stream, $mailbox);
28 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
29
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 $body = mime_fetch_body($imap_stream, $passed_id, $passed_ent_id);
43 $body = str_replace("\n", "\n", trim(decodeBody($body, $message->header->encoding)));
44 $subject = trim(decodeHeader($message->header->subject));
45
46 // now, if they choose to, we clean up the display a bit...
47 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' )
48 {
49
50 $num_leading_spaces = 9; // nine leading spaces for indentation
51
52 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
53 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
54 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
55
56 // the body should have no leading zeros
57 $body = pf_clean_string($body, 0);
58
59 // clean up everything else...
60 $subject = pf_clean_string($subject, $num_leading_spaces);
61 $from = pf_clean_string($from, $num_leading_spaces);
62 $date = pf_clean_string($date, $num_leading_spaces);
63
64 } // end cleanup
65
66// --end display setup--
67
68
69// --start browser output--
70
71?>
72
73<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
74<html>
75<head><title>
76 <?php echo _("Printable View"); ?>
77</title></head>
78
79<?php
80
81 if ($theme_css != "")
82 {
83 printf ('<LINK REL="stylesheet" TYPE="text/css" HREF="%s">', $theme_css);
84 echo "\n";
85 }
86
87 printf('<body text="%s" bgcolor="%s" link="%s" vlink="%s" alink="%s">',
88 $color[8], $color[4], $color[7], $color[7], $color[7]);
89
90 echo "\n<pre>";
91
92 // headers
93 echo " " . _("From") . ': ' . htmlentities($from) . "\n";
94 echo " " . _("To") . ': ' . htmlentities($to) . "\n";
95 if ( strlen($cc) > 0 ) // only show CC: if it's there...
96 echo " " . _("CC") . ': ' . htmlentities($cc) . "\n";
97 echo " " . _("Date") . ': ' . htmlentities($date) . "\n";
98 echo _("Subject") . ': ' . htmlentities($subject) . "\n\n";
99
100 // body
101 echo "<hr noshade size=1>\n";
102 echo htmlentities($body);
103
104// --end browser output--
105
106
107?></pre>
108 </body>
109</html>
110
111<?
112
113// --start pf-specific functions--
114
115
116 // $string = pf_clean_string($string, 9);
117function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
118 global $data_dir, $username;
119
120 $wrap_at = getPref($data_dir, $username, 'wrap_at');
121 $wrap_at = $wrap_at - $num_leading_spaces; // header stuff
122
123 $leading_spaces = '';
124 while ( strlen($leading_spaces) < $num_leading_spaces )
125 $leading_spaces .= ' ';
126
127 $clean_string = '';
128 while ( strlen($unclean_string) > $wrap_at )
129 {
130 $this_line = substr($unclean_string, 0, $wrap_at);
131 if ( strrpos( $this_line, "\n" ) ) // this should NEVER happen with anything but the $body
132 {
133 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
134 $clean_string .= $leading_spaces;
135 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
136 }
137 else
138 {
139 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
140 $clean_string .= "\n" . $leading_spaces;
141 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
142 }
143 }
144 $clean_string .= $unclean_string;
145
146 return $clean_string;
147} // end pf_clean_string() function
148
149// --end pf-specific functions
150
151?>