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

Documentation generated on Sat, 07 Oct 2006 16:31:02 +0300 by phpDocumentor 1.3.0RC6