4 ** printer_friendly_bottom.php
6 ** Copyright (c) 1999-2000 The SquirrelMail development team
7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
9 ** with javascript on, it is the bottom frame of printer_friendly_main.php
10 ** else, it is alone in a new window
12 ** - this is the page that does all the work, really.
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');
25 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
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);
32 // --start display setup--
34 // From and Date are usually fine as they are...
35 $from = decodeHeader($message->header
->from
);
36 $date = getLongDateString($message->header
->date
);
38 // we can clean these up if the list is too long...
39 $cc = decodeHeader(getLineOfAddrs($message->header
->cc
));
40 $to = decodeHeader(getLineOfAddrs($message->header
->to
));
42 // and Body and Subject could easily stream off the page...
43 $body = mime_fetch_body($imap_stream, $passed_id, $passed_ent_id);
44 $body = str_replace("\n", "\n", trim(decodeBody($body, $message->header
->encoding
)));
45 $subject = trim(decodeHeader($message->header
->subject
));
47 // now, if they choose to, we clean up the display a bit...
48 if ( empty($pf_cleandisplay) ||
$pf_cleandisplay != 'no' )
51 $num_leading_spaces = 9; // nine leading spaces for indentation
53 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
54 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
55 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
57 // the body should have no leading zeros
58 $body = pf_clean_string($body, 0);
60 // clean up everything else...
61 $subject = pf_clean_string($subject, $num_leading_spaces);
62 $from = pf_clean_string($from, $num_leading_spaces);
63 $date = pf_clean_string($date, $num_leading_spaces);
67 // --end display setup--
70 // --start browser output--
71 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
73 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
74 // headers (we use table becasue translations are not all the same width)
76 '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></td>\n".
77 '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></td>\n";
78 if ( strlen($cc) > 0 ) { // only show CC: if it's there...
79 echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></td>\n";
81 echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></td>\n".
82 '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></td>\n".
88 echo "<hr noshade size=1>\n";
89 echo htmlentities($body);
91 // --end browser output--
100 // --start pf-specific functions--
103 // $string = pf_clean_string($string, 9);
104 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
105 global $data_dir, $username;
107 $wrap_at = getPref($data_dir, $username, 'wrap_at');
108 $wrap_at = $wrap_at - $num_leading_spaces; // header stuff
110 $leading_spaces = '';
111 while ( strlen($leading_spaces) < $num_leading_spaces )
112 $leading_spaces .= ' ';
115 while ( strlen($unclean_string) > $wrap_at )
117 $this_line = substr($unclean_string, 0, $wrap_at);
118 if ( strrpos( $this_line, "\n" ) ) // this should NEVER happen with anything but the $body
120 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
121 $clean_string .= $leading_spaces;
122 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
126 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
127 $clean_string .= "\n" . $leading_spaces;
128 $unclean_string = substr($unclean_string, (1+
strrpos( $this_line, ' ' )));
131 $clean_string .= $unclean_string;
133 return $clean_string;
134 } // end pf_clean_string() function
136 // --end pf-specific functions