Source for file download.php

Documentation is available at download.php

  1. <?php
  2.  
  3. /**
  4.  * download.php
  5.  *
  6.  * Handles attachment downloads to the users computer.
  7.  * Also allows displaying of attachments when possible.
  8.  *
  9.  * @copyright 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: download.php 14840 2020-01-07 07:42:38Z pdontthink $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /** This is the download page */
  16. define('PAGE_NAME''download');
  17.  
  18. /**
  19.  * Path for SquirrelMail required files.
  20.  * @ignore
  21.  */
  22. define('SM_PATH','../');
  23.  
  24. /* SquirrelMail required files. */
  25. require_once(SM_PATH 'include/validate.php');
  26. require_once(SM_PATH 'functions/imap.php');
  27. require_once(SM_PATH 'functions/mime.php');
  28.  
  29. header('Pragma: ');
  30. header('Cache-Control: cache');
  31.  
  32. /* globals */
  33. sqgetGlobalVar('key',        $key,          SQ_COOKIE);
  34. sqgetGlobalVar('username',   $username,     SQ_SESSION);
  35. sqgetGlobalVar('onetimepad'$onetimepad,   SQ_SESSION);
  36. sqgetGlobalVar('messages',   $messages,     SQ_SESSION);
  37. sqgetGlobalVar('mailbox',    $mailbox,      SQ_GET);
  38. sqgetGlobalVar('ent_id',     $ent_id,       SQ_GET);
  39. sqgetGlobalVar('absolute_dl',$absolute_dl,  SQ_GET);
  40. if sqgetGlobalVar('passed_id'$tempSQ_GET) ) {
  41.     $passed_id = (int) $temp;
  42. }
  43.  
  44. global $default_charset;
  45.  
  46. /* end globals */
  47.  
  48. global $uid_support;
  49.  
  50. global $imap_stream_options// in case not defined in config
  51. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  52. $mbx_response =  sqimap_mailbox_select($imapConnection$mailbox);
  53.  
  54. $message '';
  55.  
  56. if (isset($messages[$mbx_response['UIDVALIDITY']]["$passed_id"])) {
  57.     $message $messages[$mbx_response['UIDVALIDITY']]["$passed_id"];
  58. }
  59.  
  60. if (!is_object($message)) {
  61.     $message sqimap_get_message($imapConnection,$passed_id$mailbox);
  62. }
  63.  
  64. $subject $message->rfc822_header->subject;
  65. if ($ent_id{
  66.     $message $message->getEntity($ent_id);
  67.     $header $message->header;
  68.  
  69.     if ($message->rfc822_header{
  70.        $subject $message->rfc822_header->subject;
  71.     else {
  72.        $header $message->header;
  73.     }
  74.     $type0 $header->type0;
  75.     $type1 $header->type1;
  76.     $encoding strtolower($header->encoding);
  77. else {
  78.     /* raw message */
  79.     $type0 'message';
  80.     $type1 'rfc822';
  81.     $encoding '7bit';
  82.     $header $message->header;
  83. }
  84.  
  85. /*
  86.  * lets redefine message as this particular entity that we wish to display.
  87.  * it should hold only the header for this entity.  We need to fetch the body
  88.  * yet before we can display anything.
  89.  */
  90.  
  91. if (isset($override_type0)) {
  92.     $type0 $override_type0;
  93. }
  94. if (isset($override_type1)) {
  95.     $type1 $override_type1;
  96. }
  97. $filename '';
  98. if (is_object($message->header->disposition)) {
  99.     $filename $header->disposition->getProperty('filename');
  100.     if (!$filename{
  101.         $filename $header->disposition->getProperty('name');
  102.     }
  103.     if (!$filename{
  104.         $filename $header->getParameter('name');
  105.     }
  106. else {
  107.     $filename $header->getParameter('name');
  108. }
  109.  
  110. $filename decodeHeader($filename,true,false);
  111. $filename charset_encode($filename,$default_charset,false);
  112.  
  113. // If name is not set, use subject of email
  114. if (strlen($filename1{
  115.     $filename decodeHeader($subjecttruetrue);
  116.     $filename charset_encode($filename,$default_charset,false);
  117.     if ($type1 == 'plain' && $type0 == 'text')
  118.         $suffix 'txt';
  119.     else if ($type1 == 'richtext' && $type0 == 'text')
  120.         $suffix 'rtf';
  121.     else if ($type1 == 'postscript' && $type0 == 'application')
  122.         $suffix 'ps';
  123.     else if ($type1 == 'rfc822' && $type0 == 'message')
  124.         $suffix 'msg';
  125.     else
  126.         $suffix $type1;
  127.  
  128.     if ($filename == '')
  129.         $filename 'untitled' strip_tags($ent_id);
  130.     $filename $filename '.' $suffix;
  131. }
  132.  
  133. /**
  134.  * Close session in order to prevent script locking on larger
  135.  * downloads. SendDownloadHeaders() and mime_print_body_lines()
  136.  * don't write information to session. mime_print_body_lines()
  137.  * call duration depends on size of attachment and script can
  138.  * cause interface lockups, if session is not closed.
  139.  */
  140.  
  141. /*
  142.  * Note:
  143.  *    The following sections display the attachment in different
  144.  *    ways depending on how they choose.  The first way will download
  145.  *    under any circumstance.  This sets the Content-type to be
  146.  *    applicatin/octet-stream, which should be interpreted by the
  147.  *    browser as "download me".
  148.  *      The second method (view) is used for images or other formats
  149.  *    that should be able to be handled by the browser.  It will
  150.  *    most likely display the attachment inline inside the browser.
  151.  *      And finally, the third one will be used by default.  If it
  152.  *    is displayable (text or html), it will load them up in a text
  153.  *    viewer (built in to squirrelmail).  Otherwise, it sets the
  154.  *    content-type as application/octet-stream
  155.  */
  156. if (isset($absolute_dl&& $absolute_dl{
  157.     SendDownloadHeaders($type0$type1$filename1);
  158. else {
  159.     SendDownloadHeaders($type0$type1$filename0);
  160. }
  161. /* be aware that any warning caused by download.php will corrupt the
  162.  * attachment in case of ERROR reporting = E_ALL and the output is the screen */
  163. mime_print_body_lines ($imapConnection$passed_id$ent_id$encoding);

Documentation generated on Mon, 13 Jan 2020 04:24:34 +0100 by phpDocumentor 1.4.3