f226cba7 |
1 | <?php |
2 | |
3 | /** |
4 | ** printer_friendly_bottom.php |
5 | ** |
895905c0 |
6 | ** Copyright (c) 1999-2001 The SquirrelMail development team |
f226cba7 |
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'); |
692155b7 |
22 | require_once('../functions/page_header.php'); |
f226cba7 |
23 | |
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 | |
32 | // --start display setup-- |
33 | |
34 | // From and Date are usually fine as they are... |
35 | $from = decodeHeader($message->header->from); |
36 | $date = getLongDateString($message->header->date); |
37 | |
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)); |
41 | |
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)); |
46 | |
47 | // now, if they choose to, we clean up the display a bit... |
48 | if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) |
49 | { |
50 | |
51 | $num_leading_spaces = 9; // nine leading spaces for indentation |
52 | |
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); |
56 | |
57 | // the body should have no leading zeros |
58 | $body = pf_clean_string($body, 0); |
59 | |
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); |
64 | |
65 | } // end cleanup |
66 | |
692155b7 |
67 | // --end display setup-- |
f226cba7 |
68 | |
69 | |
692155b7 |
70 | // --start browser output-- |
71 | displayHtmlHeader( _("Printer Friendly"), '', FALSE ); |
f226cba7 |
72 | |
692155b7 |
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) |
75 | '<table>'. |
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"; |
f226cba7 |
80 | } |
692155b7 |
81 | echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></td>\n". |
82 | '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></td>\n". |
83 | '</table>'. |
84 | "\n<pre>"; |
f226cba7 |
85 | |
f226cba7 |
86 | |
87 | // body |
88 | echo "<hr noshade size=1>\n"; |
89 | echo htmlentities($body); |
90 | |
91 | // --end browser output-- |
92 | |
93 | |
94 | ?></pre> |
95 | </body> |
96 | </html> |
97 | |
98 | <? |
99 | |
100 | // --start pf-specific functions-- |
101 | |
102 | |
103 | // $string = pf_clean_string($string, 9); |
104 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
105 | global $data_dir, $username; |
106 | |
107 | $wrap_at = getPref($data_dir, $username, 'wrap_at'); |
108 | $wrap_at = $wrap_at - $num_leading_spaces; // header stuff |
109 | |
110 | $leading_spaces = ''; |
111 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
112 | $leading_spaces .= ' '; |
113 | |
114 | $clean_string = ''; |
115 | while ( strlen($unclean_string) > $wrap_at ) |
116 | { |
117 | $this_line = substr($unclean_string, 0, $wrap_at); |
118 | if ( strrpos( $this_line, "\n" ) ) // this should NEVER happen with anything but the $body |
119 | { |
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" )); |
123 | } |
124 | else |
125 | { |
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, ' ' ))); |
129 | } |
130 | } |
131 | $clean_string .= $unclean_string; |
132 | |
133 | return $clean_string; |
134 | } // end pf_clean_string() function |
135 | |
136 | // --end pf-specific functions |
137 | |
138 | ?> |