squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

download.php
Go to the documentation of this file.
1 <?php
2 
16 define('PAGE_NAME', 'download');
17 
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', $temp, SQ_GET) ) {
41  $passed_id = (int) $temp;
42 }
43 
44 global $default_charset;
46 
47 /* end globals */
48 
49 global $uid_support;
50 
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)) {
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);
112 
113 // If name is not set, use subject of email
114 if (strlen($filename) < 1) {
115  $filename = decodeHeader($subject, true, true);
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 
140 session_write_close();
141 
142 /*
143  * Note:
144  * The following sections display the attachment in different
145  * ways depending on how they choose. The first way will download
146  * under any circumstance. This sets the Content-type to be
147  * applicatin/octet-stream, which should be interpreted by the
148  * browser as "download me".
149  * The second method (view) is used for images or other formats
150  * that should be able to be handled by the browser. It will
151  * most likely display the attachment inline inside the browser.
152  * And finally, the third one will be used by default. If it
153  * is displayable (text or html), it will load them up in a text
154  * viewer (built in to squirrelmail). Otherwise, it sets the
155  * content-type as application/octet-stream
156  */
157 if (isset($absolute_dl) && $absolute_dl) {
159 } else {
161 }
162 /* be aware that any warning caused by download.php will corrupt the
163  * attachment in case of ERROR reporting = E_ALL and the output is the screen */
164 mime_print_body_lines ($imapConnection, $passed_id, $ent_id, $encoding);
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$uid_support
global $uid_support
Definition: download.php:49
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
charset_encode
charset_encode($string, $charset, $htmlencode=true)
Definition: i18n.php:220
SendDownloadHeaders
SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0)
Definition: mime.php:2536
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$header
$header
Definition: download.php:82
$mailbox
$mailbox
Definition: options.php:28
$username
global $username
Definition: validate.php:55
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$message
$message
Definition: download.php:54
$mbx_response
$mbx_response
Definition: download.php:52
mime_print_body_lines
mime_print_body_lines($imap_stream, $id, $ent_id=1, $encoding, $rStream='php://stdout')
Definition: mime.php:164
$imapConnection
$imapConnection
Definition: download.php:51
SQ_GET
const SQ_GET
Definition: global.php:16
decodeHeader
decodeHeader($string, $utfencode=true, $htmlsave=true, $decide=false)
Definition: mime.php:633
$filename
if(isset($override_type0)) if(isset($override_type1)) $filename
Definition: download.php:97
$type0
$type0
Definition: view_text.php:65
set_my_charset
set_my_charset()
Definition: i18n.php:511
$subject
if(isset($messages[$mbx_response['UIDVALIDITY']]["$passed_id"])) if(!is_object($message)) $subject
Definition: download.php:64
sqimap_get_message
sqimap_get_message($imap_stream, $id, $mailbox)
Definition: imap_messages.php:1050
$imapPort
$imapPort
Definition: config_default.php:210
$default_charset
if(sqgetGlobalVar('passed_id', $temp, SQ_GET)) global $default_charset
Definition: download.php:40
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$encoding
$encoding
Definition: download.php:81
SM_PATH
const SM_PATH
Definition: download.php:22
$type1
$type1
Definition: download.php:80