List separator i18n. Complements RisuMail Team - risumail.jp
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
35586184 3/**
4 * printer_friendly_bottom.php
5 *
35586184 6 * with javascript on, it is the bottom frame of printer_friendly_main.php
7 * else, it is alone in a new window
8 *
9 * - this is the page that does all the work, really.
10 *
4b5049de 11 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 13 * @version $Id$
8f6f9ba5 14 * @package squirrelmail
35586184 15 */
16
ebd2391c 17/** This is the printer_friendly_bottom page */
18define('PAGE_NAME', 'printer_friendly_bottom');
19
30967a1e 20/**
202bcbcc 21 * Include the SquirrelMail initialization file.
30967a1e 22 */
202bcbcc 23require('../include/init.php');
86725763 24
25/* SquirrelMail required files. */
202bcbcc 26require_once(SM_PATH . 'functions/imap_general.php');
27require_once(SM_PATH . 'functions/imap_messages.php');
28require_once(SM_PATH . 'functions/date.php');
29require_once(SM_PATH . 'functions/mime.php');
30require_once(SM_PATH . 'functions/url_parser.php');
f226cba7 31
0b97a708 32/* get some of these globals */
f38b7cf0 33sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
d4538b25 35
f38b7cf0 36if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
d4538b25 37 $passed_ent_id = '';
91e0dccc 38}
4c8986b4 39sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM);
0b97a708 40/* end globals */
41
906f7e9f 42$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
d4538b25 43$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
44if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
7f6171be 45 $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id];
d4538b25 46} else {
47 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
48}
49if ($passed_ent_id) {
7f6171be 50 $message = $message->getEntity($passed_ent_id);
5caf2d0c 51}
32f4e318 52
53/* --start display setup-- */
54
91e0dccc 55$rfc822_header = $message->rfc822_header;
32f4e318 56/* From and Date are usually fine as they are... */
a91189d6 57$from = $rfc822_header->getAddr_s('from');
3aaa3214 58$date = getLongDateString($rfc822_header->date, $rfc822_header->date_unparsed);
a91189d6 59$subject = trim($rfc822_header->subject);
32f4e318 60
61/* we can clean these up if the list is too long... */
a91189d6 62$cc = $rfc822_header->getAddr_s('cc');
63$to = $rfc822_header->getAddr_s('to');
32f4e318 64
c8d6aef3 65if ($show_html_default == 1) {
66 $ent_ar = $message->findDisplayEntity(array());
67} else {
68 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
69}
18680db6 70$body = '';
71if ($ent_ar[0] != '') {
72 for ($i = 0; $i < count($ent_ar); $i++) {
a2bfcbce 73 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
be7a2943 74 if ($i < count($ent_ar)-1) {
75 $body .= '<hr />';
76 }
18680db6 77 }
6e515418 78 /* Note that $body is passed to this hook (and modified) by reference as of 1.5.2 */
79 do_hook('message_body', $body);
32f4e318 80} else {
18680db6 81 $body = _("Message not printable");
32f4e318 82}
3bbf5974 83
2b0f4faf 84/* now we clean up the display a bit... */
91e0dccc 85
2b0f4faf 86$num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 87
d3c4749f 88// sometimes I see ',,' instead of ',' separating addresses *shrug*
2b0f4faf 89$cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
90$to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
f226cba7 91
2b0f4faf 92// clean up everything else...
93$subject = pf_clean_string($subject, $num_leading_spaces);
94$from = pf_clean_string($from, $num_leading_spaces);
95$date = pf_clean_string($date, $num_leading_spaces);
f226cba7 96
2b0f4faf 97// end cleanup
18680db6 98
a91189d6 99$to = decodeHeader($to);
100$cc = decodeHeader($cc);
101$from = decodeHeader($from);
102$subject = decodeHeader($subject);
103
32f4e318 104// --end display setup--
f226cba7 105
f226cba7 106
32f4e318 107/* --start browser output-- */
be7a2943 108displayHtmlHeader($subject);
f226cba7 109
be7a2943 110$aHeaders = array();
111$aHeaders[ _("From") ] = $from;
112$aHeaders[ _("Subject") ] = $subject;
113$aHeaders[ _("Date") ] = htmlspecialchars($date);
114$aHeaders[ _("To") ] = $to;
115$aHeaders[ _("Cc") ] = $cc;
5c4ff7bf 116
be7a2943 117$attachments_ar = buildAttachmentArray($message, $ent_ar, $mailbox, $passed_id);
118
119$oTemplate->assign('headers', $aHeaders);
120$oTemplate->assign('message_body', $body);
121$oTemplate->assign('attachments', $attachments_ar);
1c663478 122
be7a2943 123$oTemplate->display('printer_friendly_bottom.tpl');
5c4ff7bf 124$oTemplate->display('footer.tpl');
f226cba7 125
32f4e318 126/* --end browser output-- */
f226cba7 127
f226cba7 128
32f4e318 129/* --start pf-specific functions-- */
f226cba7 130
b5cd24a8 131/**
132 * Function should clean layout of printed messages when user
133 * enables "Printer Friendly Clean Display" option.
9dbdf00b 134 * For example: $string = pf_clean_string($string, 9);
b5cd24a8 135 *
136 * @param string unclean_string
137 * @param integer num_leading_spaces
138 * @return string
91e0dccc 139 * @access private
b5cd24a8 140 */
f226cba7 141function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
142 global $data_dir, $username;
a91189d6 143 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
f6d2358f 144 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 145 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 146
147 $leading_spaces = '';
148 while ( strlen($leading_spaces) < $num_leading_spaces )
149 $leading_spaces .= ' ';
150
151 $clean_string = '';
152 while ( strlen($unclean_string) > $wrap_at )
153 {
154 $this_line = substr($unclean_string, 0, $wrap_at);
32f4e318 155 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 156 {
157 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
158 $clean_string .= $leading_spaces;
159 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
160 }
161 else
162 {
134e4174 163 $i = strrpos( $this_line, ' ');
164 $clean_string .= substr( $this_line, 0, $i);
165 $clean_string .= "\n" . $leading_spaces;
166 $unclean_string = substr($unclean_string, 1+$i);
167 }
f226cba7 168 }
169 $clean_string .= $unclean_string;
170
171 return $clean_string;
32f4e318 172} /* end pf_clean_string() function */