squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

printer_friendly_bottom.php
Go to the documentation of this file.
1 <?php
2 
18 define('PAGE_NAME', 'printer_friendly_bottom');
19 
24 define('SM_PATH','../');
25 
26 /* SquirrelMail required files. */
27 require_once(SM_PATH . 'include/validate.php');
28 require_once(SM_PATH . 'functions/imap.php');
29 
30 /* get some of these globals */
31 sqgetGlobalVar('username', $username, SQ_SESSION);
32 sqgetGlobalVar('key', $key, SQ_COOKIE);
33 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
34 sqgetGlobalVar('messages', $messages, SQ_SESSION);
35 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
37 
38 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ||
39  ! preg_match('/^\d+(\.\d+)*$/', $passed_ent_id) ) {
40  $passed_ent_id = '';
41 }
42 /* end globals */
43 
44 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay', false);
47 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
48  $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id];
49 } else {
51 }
52 if ($passed_ent_id) {
53  $message = $message->getEntity($passed_ent_id);
54 }
55 
56 /* --start display setup-- */
57 
58 $rfc822_header = $message->rfc822_header;
59 /* From and Date are usually fine as they are... */
60 $from = $rfc822_header->getAddr_s('from');
62 $subject = trim($rfc822_header->subject);
63 
64 /* we can clean these up if the list is too long... */
65 $cc = $rfc822_header->getAddr_s('cc');
66 $to = $rfc822_header->getAddr_s('to');
67 
68 if ($show_html_default == 1) {
69  $ent_ar = $message->findDisplayEntity(array());
70 } else {
71  $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
72 }
73 $body = '';
74 if ($ent_ar[0] != '') {
75  for ($i = 0; $i < count($ent_ar); $i++) {
76  $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, true);
77  $body .= '<hr noshade size="1" />';
78  }
79  $hookResults = do_hook('message_body', $body);
80  $body = $hookResults[1];
81 } else {
82  $body = _("Message not printable");
83 }
84 
85  /* now, if they choose to, we clean up the display a bit... */
86 
87 if ($pf_cleandisplay) {
88 
89  $num_leading_spaces = 9; // nine leading spaces for indentation
90 
91  // sometimes I see ',,' instead of ',' seperating addresses *shrug*
92  $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
93  $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
94 
95  // the body should have no leading zeros
96  // disabled because it destroys html mail
97 
98 // $body = pf_clean_string($body, 0);
99 
100  // clean up everything else...
101  $subject = pf_clean_string($subject, $num_leading_spaces);
102  $from = pf_clean_string($from, $num_leading_spaces);
103  $date = pf_clean_string($date, $num_leading_spaces);
104 
105 } // end cleanup
106 
107 $to = decodeHeader($to);
108 $cc = decodeHeader($cc);
111 
112 // load attachments
114 
115 // --end display setup--
116 
117 
118 /* --start browser output-- */
119 displayHtmlHeader( $subject, '', FALSE );
120 
121 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
122  /* headers (we use table because translations are not all the same width) */
123  html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
124  html_tag( 'tr',
125  html_tag( 'td', _("From").':&nbsp;', 'left' ,'','valign="top"') .
126  html_tag( 'td', $from, 'left' )
127  ) . "\n" .
128  html_tag( 'tr',
129  html_tag( 'td', _("Subject").':&nbsp;', 'left','','valign="top"' ) .
130  html_tag( 'td', $subject, 'left' )
131  ) . "\n" .
132  html_tag( 'tr',
133  html_tag( 'td', _("Date").':&nbsp;', 'left' ) .
134  html_tag( 'td', htmlspecialchars($date), 'left' )
135  ) . "\n" .
136  html_tag( 'tr',
137  html_tag( 'td', _("To").':&nbsp;', 'left','','valign="top"' ) .
138  html_tag( 'td', $to, 'left' )
139  ) . "\n";
140  if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
141  echo html_tag( 'tr',
142  html_tag( 'td', _("Cc").':&nbsp;', 'left','','valign="top"' ) .
143  html_tag( 'td', $cc, 'left' )
144  );
145  }
146  /* body */
147  echo html_tag( 'tr',
148  html_tag( 'td', '<hr noshade size="1" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
149  ) . "\n";
150 
151  if (! empty($attachments)) {
152  // attachments title
153  echo html_tag( 'tr',
154  html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' )
155  ) . "\n" ;
156  // list of attachments
157  echo html_tag( 'tr',
158  html_tag( 'td',$attachments, 'left', '', 'colspan="2"' )
159  ) . "\n" ;
160  // add separator line
161  echo html_tag( 'tr',
162  html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' )
163  ) . "\n" ;
164  }
165 
166  echo '</table>' . "\n" .
167  '</body></html>';
168 
169 /* --end browser output-- */
170 
171 
172 /* --start pf-specific functions-- */
173 
184 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
185  global $data_dir, $username;
186  $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
187  $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
188  $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
189 
190  $leading_spaces = '';
191  while ( strlen($leading_spaces) < $num_leading_spaces )
192  $leading_spaces .= ' ';
193 
194  $clean_string = '';
195  while ( strlen($unclean_string) > $wrap_at )
196  {
197  $this_line = substr($unclean_string, 0, $wrap_at);
198  if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
199  {
200  $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
201  $clean_string .= $leading_spaces;
202  $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
203  }
204  else
205  {
206  $i = strrpos( $this_line, ' ');
207  $clean_string .= substr( $this_line, 0, $i);
208  $clean_string .= "\n" . $leading_spaces;
209  $unclean_string = substr($unclean_string, 1+$i);
210  }
211  }
212  $clean_string .= $unclean_string;
213 
214  return $clean_string;
215 } /* end pf_clean_string() function */
216 
228 function pf_show_attachments($message, $exclude_id, $mailbox, $id) {
229  global $where, $what, $startMessage, $color, $passed_ent_id;
230 
231  $att_ar = $message->getAttachments($exclude_id);
232 
233  if (!count($att_ar)) return '';
234 
235  $attachments = '';
236 
237  $urlMailbox = urlencode($mailbox);
238 
239  foreach ($att_ar as $att) {
240  $ent = $att->entity_id;
241  $header = $att->header;
242  $type0 = strtolower($header->type0);
243  $type1 = strtolower($header->type1);
244  $name = '';
245 
246  if ($type0 =='message' && $type1 == 'rfc822') {
247  $rfc822_header = $att->rfc822_header;
248  $filename = $rfc822_header->subject;
249  if (trim( $filename ) == '') {
250  $filename = 'untitled-[' . $ent . ']' ;
251  }
252  $from_o = $rfc822_header->from;
253  if (is_object($from_o)) {
254  $from_name = decodeHeader($from_o->getAddress(true));
255  } else {
256  $from_name = _("Unknown sender");
257  }
258  $description = '<tr>'.
259  html_tag( 'td',_("From:"), 'right') .
260  html_tag( 'td',$from_name, 'left') .
261  '</tr>';
262  } else {
263  $filename = $att->getFilename();
264  if ($header->description) {
265  $description = '<tr>'.
266  html_tag( 'td',_("Info:"), 'right') .
267  html_tag( 'td',decodeHeader($header->description), 'left') .
268  '</tr>';
269  } else {
270  $description = '';
271  }
272  }
273 
274  $display_filename = $filename;
275 
276  // TODO: maybe make it nicer?
277  $attachments .= '<table cellpadding="0" cellspacing="0" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
278  '<tr border="0">'.
279  html_tag( 'td',_("Size:"), 'right') .
280  html_tag( 'td',show_readable_size($header->size), 'left') .
281  '</tr><tr>' .
282  html_tag( 'td',_("Type:"), 'right') .
283  html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left') .
284  '</tr>';
285  if (! empty($description)) {
286  $attachments .= $description;
287  }
288  $attachments .= "</table>\n";
289  }
290  return $attachments;
291 }
292 
293 
294 /* --end pf-specific functions */
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
formatBody
formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox='INBOX', $clean=false)
Definition: mime.php:306
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
$date
$date
Definition: printer_friendly_bottom.php:61
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
$from
$from
Definition: printer_friendly_bottom.php:60
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
$body
$body
Definition: printer_friendly_bottom.php:73
$show_html_default
$show_html_default
Definition: load_prefs.php:222
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$id
$id
Definition: move_messages.php:190
$mailbox
$mailbox
Definition: options.php:28
$username
global $username
Definition: validate.php:55
do_hook
do_hook($name)
Definition: plugin.php:42
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$mbx_response
$mbx_response
Definition: printer_friendly_bottom.php:46
$message
$message
Definition: download.php:54
$subject
$subject
Definition: printer_friendly_bottom.php:62
pf_clean_string
pf_clean_string( $unclean_string, $num_leading_spaces)
Definition: printer_friendly_bottom.php:184
pf_show_attachments
pf_show_attachments($message, $exclude_id, $mailbox, $id)
Definition: printer_friendly_bottom.php:228
$attachments
$attachments
Definition: printer_friendly_bottom.php:113
SM_PATH
const SM_PATH
Definition: printer_friendly_bottom.php:24
getLongDateString
getLongDateString( $stamp, $fallback='')
Definition: date.php:309
SQ_GET
const SQ_GET
Definition: global.php:16
show_readable_size
show_readable_size($bytes)
Definition: strings.php:582
$pf_cleandisplay
if(! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET)||! preg_match('/^\d+(\.\d+) *$/', $passed_ent_id) $pf_cleandisplay)
Definition: printer_friendly_bottom.php:44
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
decodeHeader
decodeHeader($string, $utfencode=true, $htmlsave=true, $decide=false)
Definition: mime.php:633
$filename
if(isset($override_type0)) if(isset($override_type1)) $filename
Definition: download.php:97
$wrap_at
$wrap_at
Definition: load_prefs.php:132
_
_($str)
Definition: gettext.php:160
$type0
$type0
Definition: view_text.php:65
sqimap_get_message
sqimap_get_message($imap_stream, $id, $mailbox)
Definition: imap_messages.php:1050
$rfc822_header
if($passed_ent_id) $rfc822_header
Definition: printer_friendly_bottom.php:58
$to
$to
Definition: printer_friendly_bottom.php:66
$imapConnection
$imapConnection
Definition: printer_friendly_bottom.php:45
$imapPort
$imapPort
Definition: config_default.php:210
$cc
$cc
Definition: printer_friendly_bottom.php:65
$color
$color
Definition: load_prefs.php:28
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$type1
$type1
Definition: download.php:80
$header
$header
Definition: message_details_bottom.php:81