Source for file download.php

Documentation is available at download.php

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

Documentation generated on 2020年1月13日 04:24:34 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /