Source for file printer_friendly_bottom.php

Documentation is available at printer_friendly_bottom.php

  1. <?php
  2.  
  3. /**
  4.  * printer_friendly_bottom.php
  5.  *
  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.  *
  11.  * @copyright 1999-2020 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: printer_friendly_bottom.php 14840 2020-01-07 07:42:38Z pdontthink $
  14.  * @package squirrelmail
  15.  */
  16.  
  17. /** This is the printer_friendly_bottom page */
  18. define('PAGE_NAME''printer_friendly_bottom');
  19.  
  20. /**
  21.  * Path for SquirrelMail required files.
  22.  * @ignore
  23.  */
  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'$usernameSQ_SESSION);
  32. sqgetGlobalVar('key'$keySQ_COOKIE);
  33. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  34. sqgetGlobalVar('messages'$messagesSQ_SESSION);
  35. sqgetGlobalVar('passed_id'$passed_idSQ_GET);
  36. sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  37.  
  38. if (sqgetGlobalVar('passed_ent_id'$passed_ent_idSQ_GET||
  39.     preg_match('/^\d+(\.\d+)*$/'$passed_ent_id) ) {
  40.     $passed_ent_id '';
  41. /* end globals */
  42.  
  43. $pf_cleandisplay getPref($data_dir$username'pf_cleandisplay'false);
  44. global $imap_stream_options// in case not defined in config
  45. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  46. $mbx_response sqimap_mailbox_select($imapConnection$mailbox);
  47. if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
  48.     $message $messages[$mbx_response['UIDVALIDITY']][$passed_id];
  49. else {
  50.     $message sqimap_get_message($imapConnection$passed_id$mailbox);
  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');
  61. $date getLongDateString($rfc822_header->date$rfc822_header->date_unparsed);
  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$mailboxtrue);
  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);
  109. $from decodeHeader($from);
  110. $subject decodeHeader($subject);
  111.  
  112. // load attachments
  113. $attachments pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
  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'sm_encode_html_special_chars($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/* 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.  
  174. /**
  175.  * Function should clean layout of printed messages when user
  176.  * enables "Printer Friendly Clean Display" option.
  177.  *
  178.  * @param string unclean_string
  179.  * @param integer num_leading_spaces
  180.  * @return string 
  181.  * @example $string = pf_clean_string($string, 9);
  182.  * @access private
  183.  */
  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_string0$wrap_at);
  198.         if strrpos$this_line"\n" ) ) /* this should NEVER happen with anything but the $body */
  199.         {
  200.             $clean_string .= substr$this_line0strrpos$this_line"\n" ));
  201.             $clean_string .= $leading_spaces;
  202.             $unclean_string substr($unclean_stringstrrpos$this_line"\n" ));
  203.         }
  204.         else
  205.         {
  206.             $i strrpos$this_line' ');
  207.             $clean_string .= substr$this_line0$i);
  208.             $clean_string .= "\n" $leading_spaces;
  209.             $unclean_string substr($unclean_string1+$i);
  210.         }
  211.     }
  212.     $clean_string .= $unclean_string;
  213.  
  214.     return $clean_string;
  215. /* end pf_clean_string() function */
  216.  
  217. /**
  218.  * Displays attachment information
  219.  *
  220.  * Stripped version of formatAttachments() function from functions/mime.php.
  221.  * @param object $message SquirrelMail message object
  222.  * @param array $exclude_id message parts that are not attachments.
  223.  * @param string $mailbox mailbox name
  224.  * @param integer $id message id
  225.  * @since 1.5.1 and 1.4.6
  226.  * @return string html formated attachment information.
  227.  */
  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',sm_encode_html_special_chars($type0).'/'.sm_encode_html_special_chars($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 */

Documentation generated on Mon, 13 Jan 2020 04:25:11 +0100 by phpDocumentor 1.4.3