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-2012 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: download.php 14248 2012-01-02 00:18:17Z 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. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0);
  51. $mbx_response =  sqimap_mailbox_select($imapConnection$mailbox);
  52.  
  53. $message '';
  54.  
  55. if (isset($messages[$mbx_response['UIDVALIDITY']]["$passed_id"])) {
  56.     $message $messages[$mbx_response['UIDVALIDITY']]["$passed_id"];
  57. }
  58.  
  59. if (!is_object($message)) {
  60.     $message sqimap_get_message($imapConnection,$passed_id$mailbox);
  61. }
  62.  
  63. $subject $message->rfc822_header->subject;
  64. if ($ent_id{
  65.     $message $message->getEntity($ent_id);
  66.     $header $message->header;
  67.  
  68.     if ($message->rfc822_header{
  69.        $subject $message->rfc822_header->subject;
  70.     else {
  71.        $header $message->header;
  72.     }
  73.     $type0 $header->type0;
  74.     $type1 $header->type1;
  75.     $encoding strtolower($header->encoding);
  76. else {
  77.     /* raw message */
  78.     $type0 'message';
  79.     $type1 'rfc822';
  80.     $encoding '7bit';
  81.     $header $message->header;
  82. }
  83.  
  84. /*
  85.  * lets redefine message as this particular entity that we wish to display.
  86.  * it should hold only the header for this entity.  We need to fetch the body
  87.  * yet before we can display anything.
  88.  */
  89.  
  90. if (isset($override_type0)) {
  91.     $type0 $override_type0;
  92. }
  93. if (isset($override_type1)) {
  94.     $type1 $override_type1;
  95. }
  96. $filename '';
  97. if (is_object($message->header->disposition)) {
  98.     $filename $header->disposition->getProperty('filename');
  99.     if (!$filename{
  100.         $filename $header->disposition->getProperty('name');
  101.     }
  102.     if (!$filename{
  103.         $filename $header->getParameter('name');
  104.     }
  105. else {
  106.     $filename $header->getParameter('name');
  107. }
  108.  
  109. $filename decodeHeader($filename,true,false);
  110. $filename charset_encode($filename,$default_charset,false);
  111.  
  112. // If name is not set, use subject of email
  113. if (strlen($filename1{
  114.     $filename decodeHeader($subjecttruetrue);
  115.     $filename charset_encode($filename,$default_charset,false);
  116.     if ($type1 == 'plain' && $type0 == 'text')
  117.         $suffix 'txt';
  118.     else if ($type1 == 'richtext' && $type0 == 'text')
  119.         $suffix 'rtf';
  120.     else if ($type1 == 'postscript' && $type0 == 'application')
  121.         $suffix 'ps';
  122.     else if ($type1 == 'rfc822' && $type0 == 'message')
  123.         $suffix 'msg';
  124.     else
  125.         $suffix $type1;
  126.  
  127.     if ($filename == '')
  128.         $filename 'untitled' strip_tags($ent_id);
  129.     $filename $filename '.' $suffix;
  130. }
  131.  
  132. /**
  133.  * Close session in order to prevent script locking on larger
  134.  * downloads. SendDownloadHeaders() and mime_print_body_lines()
  135.  * don't write information to session. mime_print_body_lines()
  136.  * call duration depends on size of attachment and script can
  137.  * cause interface lockups, if session is not closed.
  138.  */
  139.  
  140. /*
  141.  * Note:
  142.  *    The following sections display the attachment in different
  143.  *    ways depending on how they choose.  The first way will download
  144.  *    under any circumstance.  This sets the Content-type to be
  145.  *    applicatin/octet-stream, which should be interpreted by the
  146.  *    browser as "download me".
  147.  *      The second method (view) is used for images or other formats
  148.  *    that should be able to be handled by the browser.  It will
  149.  *    most likely display the attachment inline inside the browser.
  150.  *      And finally, the third one will be used by default.  If it
  151.  *    is displayable (text or html), it will load them up in a text
  152.  *    viewer (built in to squirrelmail).  Otherwise, it sets the
  153.  *    content-type as application/octet-stream
  154.  */
  155. if (isset($absolute_dl&& $absolute_dl{
  156.     SendDownloadHeaders($type0$type1$filename1);
  157. else {
  158.     SendDownloadHeaders($type0$type1$filename0);
  159. }
  160. /* be aware that any warning caused by download.php will corrupt the
  161.  * attachment in case of ERROR reporting = E_ALL and the output is the screen */
  162. mime_print_body_lines ($imapConnection$passed_id$ent_id$encoding);

Documentation generated on Fri, 24 May 2013 04:22:04 +0200 by phpDocumentor 1.4.3