4 * printer_friendly_bottom.php
6 * Copyright (c) 1999-2002 The SquirrelMail Project 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 /*****************************************************************/
18 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
19 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
20 /*** + Base level indent should begin at left margin, as ***/
21 /*** the require_once below looks. ***/
22 /*** + All identation should consist of four space blocks ***/
23 /*** + Tab characters are evil. ***/
24 /*** + all comments should use "slash-star ... star-slash" ***/
25 /*** style -- no pound characters, no slash-slash style ***/
26 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
27 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
28 /*** + Please use ' instead of ", when possible. Note " ***/
29 /*** should always be used in _( ) function calls. ***/
30 /*** Thank you for your help making the SM code more readable. ***/
31 /*****************************************************************/
33 require_once('../src/validate.php');
34 require_once('../functions/strings.php');
35 require_once('../config/config.php');
36 require_once('../src/load_prefs.php');
37 require_once('../functions/imap.php');
38 require_once('../functions/page_header.php');
40 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
42 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 sqimap_mailbox_select($imap_stream, $mailbox);
44 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
47 // --start display setup--
49 // From and Date are usually fine as they are...
50 $from = decodeHeader($message->header
->from
);
51 $date = getLongDateString($message->header
->date
);
53 // we can clean these up if the list is too long...
54 $cc = decodeHeader(getLineOfAddrs($message->header
->cc
));
55 $to = decodeHeader(getLineOfAddrs($message->header
->to
));
57 // and Body and Subject could easily stream off the page...
58 $body = mime_fetch_body($imap_stream, $passed_id, $passed_ent_id);
59 $body = str_replace("\n", "\n", trim(decodeBody($body, $message->header
->encoding
)));
60 $subject = trim(decodeHeader($message->header
->subject
));
62 // now, if they choose to, we clean up the display a bit...
63 if ( empty($pf_cleandisplay) ||
$pf_cleandisplay != 'no' )
66 $num_leading_spaces = 9; // nine leading spaces for indentation
68 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
69 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
70 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
72 // the body should have no leading zeros
73 $body = pf_clean_string($body, 0);
75 // clean up everything else...
76 $subject = pf_clean_string($subject, $num_leading_spaces);
77 $from = pf_clean_string($from, $num_leading_spaces);
78 $date = pf_clean_string($date, $num_leading_spaces);
82 // --end display setup--
85 // --start browser output--
86 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
88 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
89 // headers (we use table becasue translations are not all the same width)
91 '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></td>\n".
92 '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></td>\n";
93 if ( strlen($cc) > 0 ) { // only show CC: if it's there...
94 echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></td>\n";
96 echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></td>\n".
97 '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></td>\n".
103 echo "<hr noshade size=1>\n";
104 echo htmlentities($body);
106 // --end browser output--
115 // --start pf-specific functions--
118 // $string = pf_clean_string($string, 9);
119 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
120 global $data_dir, $username;
122 $wrap_at = getPref($data_dir, $username, 'wrap_at');
123 $wrap_at = $wrap_at - $num_leading_spaces; // header stuff
125 $leading_spaces = '';
126 while ( strlen($leading_spaces) < $num_leading_spaces )
127 $leading_spaces .= ' ';
130 while ( strlen($unclean_string) > $wrap_at )
132 $this_line = substr($unclean_string, 0, $wrap_at);
133 if ( strrpos( $this_line, "\n" ) ) // this should NEVER happen with anything but the $body
135 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
136 $clean_string .= $leading_spaces;
137 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
141 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
142 $clean_string .= "\n" . $leading_spaces;
143 $unclean_string = substr($unclean_string, (1+
strrpos( $this_line, ' ' )));
146 $clean_string .= $unclean_string;
148 return $clean_string;
149 } // end pf_clean_string() function
151 // --end pf-specific functions