Code Cleaning
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
35586184 3/**
4 * printer_friendly_bottom.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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/*****************************************************************/
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/*****************************************************************/
32
33require_once('../src/validate.php');
34require_once('../functions/strings.php');
35require_once('../config/config.php');
36require_once('../src/load_prefs.php');
37require_once('../functions/imap.php');
38require_once('../functions/page_header.php');
f226cba7 39
40 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
41
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);
45
46
47// --start display setup--
48
49 // From and Date are usually fine as they are...
50 $from = decodeHeader($message->header->from);
51 $date = getLongDateString($message->header->date);
52
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));
56
57 // and Body and Subject could easily stream off the page...
3bbf5974 58 $id = $message->header->id;
59 $ent_num = findDisplayEntity ($message, 0);
60 $body_message = getEntity($message, $ent_num);
61 if (($body_message->header->type0 == 'text') ||
62 ($body_message->header->type0 == 'rfc822')) {
63 $body = mime_fetch_body ($imap_stream, $id, $ent_num);
64 $body = decodeBody($body, $body_message->header->encoding);
65 $hookResults = do_hook("message_body", $body);
66 $body = $hookResults[1];
67 if ($body_message->header->type1 == 'html') {
68 if( $show_html_default <> 1 ) {
69 $body = strip_tags( $body );
70 translateText($body, $wrap_at, $body_message->header->charset);
71 } else {
72 $body = MagicHTML( $body, $id );
73 }
74 } else {
75 translateText($body, $wrap_at, $body_message->header->charset);
76 }
77 } else {
78 $body = _("Message not printable");
79 }
80
f226cba7 81 $subject = trim(decodeHeader($message->header->subject));
82
83 // now, if they choose to, we clean up the display a bit...
3bbf5974 84 /*
85 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
f226cba7 86
87 $num_leading_spaces = 9; // nine leading spaces for indentation
88
89 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
90 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
91 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
92
93 // the body should have no leading zeros
94 $body = pf_clean_string($body, 0);
95
96 // clean up everything else...
97 $subject = pf_clean_string($subject, $num_leading_spaces);
98 $from = pf_clean_string($from, $num_leading_spaces);
99 $date = pf_clean_string($date, $num_leading_spaces);
100
101 } // end cleanup
3bbf5974 102 */
692155b7 103 // --end display setup--
f226cba7 104
105
692155b7 106 // --start browser output--
107 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
f226cba7 108
692155b7 109 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
110 // headers (we use table becasue translations are not all the same width)
111 '<table>'.
112 '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></td>\n".
113 '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></td>\n";
114 if ( strlen($cc) > 0 ) { // only show CC: if it's there...
115 echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></td>\n";
f226cba7 116 }
692155b7 117 echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></td>\n".
118 '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></td>\n".
119 '</table>'.
3bbf5974 120 "\n";
f226cba7 121 // body
122 echo "<hr noshade size=1>\n";
3bbf5974 123 echo $body;
f226cba7 124
125// --end browser output--
126
127
128?></pre>
129 </body>
130</html>
131
132<?
133
134// --start pf-specific functions--
135
136
137 // $string = pf_clean_string($string, 9);
138function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
139 global $data_dir, $username;
140
f6d2358f 141 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
f226cba7 142 $wrap_at = $wrap_at - $num_leading_spaces; // header stuff
143
144 $leading_spaces = '';
145 while ( strlen($leading_spaces) < $num_leading_spaces )
146 $leading_spaces .= ' ';
147
148 $clean_string = '';
149 while ( strlen($unclean_string) > $wrap_at )
150 {
151 $this_line = substr($unclean_string, 0, $wrap_at);
152 if ( strrpos( $this_line, "\n" ) ) // this should NEVER happen with anything but the $body
153 {
154 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
155 $clean_string .= $leading_spaces;
156 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
157 }
158 else
159 {
160 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
161 $clean_string .= "\n" . $leading_spaces;
162 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
163 }
164 }
165 $clean_string .= $unclean_string;
166
167 return $clean_string;
168} // end pf_clean_string() function
169
170// --end pf-specific functions
171
3bbf5974 172?>