4 * printer_friendly_bottom.php
6 * with javascript on, it is the bottom frame of printer_friendly_main.php
7 * else, it is alone in a new window
9 * - this is the page that does all the work, really.
11 * @copyright © 1999-2007 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * @package squirrelmail
18 * Include the SquirrelMail initialization file.
20 require('../include/init.php');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'functions/imap_general.php');
24 require_once(SM_PATH
. 'functions/imap_messages.php');
25 require_once(SM_PATH
. 'functions/date.php');
26 require_once(SM_PATH
. 'functions/mime.php');
27 require_once(SM_PATH
. 'functions/url_parser.php');
29 /* get some of these globals */
30 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
31 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
33 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET
) ) {
36 sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM
);
39 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
40 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
41 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
42 $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id];
44 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
47 $message = $message->getEntity($passed_ent_id);
50 /* --start display setup-- */
52 $rfc822_header = $message->rfc822_header
;
53 /* From and Date are usually fine as they are... */
54 $from = $rfc822_header->getAddr_s('from');
55 $date = getLongDateString($rfc822_header->date
, $rfc822_header->date_unparsed
);
56 $subject = trim($rfc822_header->subject
);
58 /* we can clean these up if the list is too long... */
59 $cc = $rfc822_header->getAddr_s('cc');
60 $to = $rfc822_header->getAddr_s('to');
62 if ($show_html_default == 1) {
63 $ent_ar = $message->findDisplayEntity(array());
65 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
68 if ($ent_ar[0] != '') {
69 for ($i = 0; $i < count($ent_ar); $i++
) {
70 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
71 if ($i < count($ent_ar)-1) {
75 /* Note that $body is passed to this hook (and modified) by reference as of 1.5.2 */
76 do_hook('message_body', $body);
78 $body = _("Message not printable");
81 /* now we clean up the display a bit... */
83 $num_leading_spaces = 9; // nine leading spaces for indentation
85 // sometimes I see ',,' instead of ',' separating addresses *shrug*
86 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
87 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
89 // clean up everything else...
90 $subject = pf_clean_string($subject, $num_leading_spaces);
91 $from = pf_clean_string($from, $num_leading_spaces);
92 $date = pf_clean_string($date, $num_leading_spaces);
96 $to = decodeHeader($to);
97 $cc = decodeHeader($cc);
98 $from = decodeHeader($from);
99 $subject = decodeHeader($subject);
101 // --end display setup--
104 /* --start browser output-- */
105 displayHtmlHeader($subject);
108 $aHeaders[ _("From") ] = $from;
109 $aHeaders[ _("Subject") ] = $subject;
110 $aHeaders[ _("Date") ] = htmlspecialchars($date);
111 $aHeaders[ _("To") ] = $to;
112 $aHeaders[ _("Cc") ] = $cc;
114 $attachments_ar = buildAttachmentArray($message, $ent_ar, $mailbox, $passed_id);
116 $oTemplate->assign('headers', $aHeaders);
117 $oTemplate->assign('message_body', $body);
118 $oTemplate->assign('attachments', $attachments_ar);
120 $oTemplate->display('printer_friendly_bottom.tpl');
121 $oTemplate->display('footer.tpl');
123 /* --end browser output-- */
126 /* --start pf-specific functions-- */
129 * Function should clean layout of printed messages when user
130 * enables "Printer Friendly Clean Display" option.
131 * For example: $string = pf_clean_string($string, 9);
133 * @param string unclean_string
134 * @param integer num_leading_spaces
138 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
139 global $data_dir, $username;
140 $unclean_string = str_replace(' ',' ',$unclean_string);
141 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
142 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
144 $leading_spaces = '';
145 while ( strlen($leading_spaces) < $num_leading_spaces )
146 $leading_spaces .= ' ';
149 while ( strlen($unclean_string) > $wrap_at )
151 $this_line = substr($unclean_string, 0, $wrap_at);
152 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
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" ));
160 $i = strrpos( $this_line, ' ');
161 $clean_string .= substr( $this_line, 0, $i);
162 $clean_string .= "\n" . $leading_spaces;
163 $unclean_string = substr($unclean_string, 1+
$i);
166 $clean_string .= $unclean_string;
168 return $clean_string;
169 } /* end pf_clean_string() function */