Fix missing $username when rg=0
[squirrelmail.git] / src / download.php
index 899aacaf919a2d293c892d257739539a2f077101..092940a2b3e7c8faa880cc755511d09549bd93c5 100644 (file)
  * $Id$
  */
 
-require_once('../src/validate.php');
-require_once('../functions/imap.php');
-require_once('../functions/mime.php');
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/mime.php');
 
 header('Pragma: ');
 header('Cache-Control: cache');
 
-function get_extract_to_target_list($imapConnection) {
-    $boxes = sqimap_mailbox_list($imapConnection);
-    for ($i = 0; $i < count($boxes); $i++) {  
-        if (!in_array('noselect', $boxes[$i]['flags'])) {
-            $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
-            if ( $box2 == 'INBOX' ) {
-                $box2 = _("INBOX");
-            }
-            echo "<option value=\"$box\">$box2</option>\n";
-        }
-    }
+/* globals */
+
+$key = $_COOKIE['key'];
+$username = $_SESSION['username'];
+$onetimepad = $_SESSION['onetimepad'];
+$mailbox = $_GET['mailbox'];
+$passed_id = $_GET['passed_id'];
+$messages = $_SESSION['messages'];
+if (!isset($passed_ent_id)) {
+   $passed_ent_id = '';
+} else {
+    $passed_ent_id = $_GET['passed_ent_id'];
 }
+
+/* end globals */
+
 $mailbox = decodeHeader($mailbox);
 
-global $messages, $uid_support;
+global $uid_support;
 
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $mbx_response =  sqimap_mailbox_select($imapConnection, $mailbox);
-if (!isset($passed_ent_id)) {
-   $passed_ent_id = '';
-}
 
 $message = &$messages[$mbx_response['UIDVALIDITY']]["$passed_id"];
+if (!is_object($message)) {
+    $message = sqimap_get_message($imapConnection,$passed_id, $mailbox);
+}
 $subject = $message->rfc822_header->subject;
 $message = &$message->getEntity($ent_id);
 $header = $message->header;
@@ -57,28 +64,6 @@ $type0 = $header->type0;
 $type1 = $header->type1;
 $encoding = strtolower($header->encoding);
 
-/*
-$extracted = false;
-if (isset($extract_message) && $extract_message) {
-  $cmd = "FETCH $passed_id BODY[$passed_ent_id]";
-  $read = sqimap_run_command ($imapConnection, $cmd, true, $response, $message, $uid_support);
-  $cnt = count($read);
-  $body = '';
-  $length = 0;
-  for ($i=1;$i<$cnt;$i++) {
-      $length = $length + strlen($read[$i]);
-      $body .= $read[$i];
-  }
-  if (isset($targetMailbox) && $length>0) {
-      sqimap_append ($imapConnection, $targetMailbox, $length);
-      fputs($imapConnection,$body);
-      sqimap_append_done ($imapConnection);
-      $extracted = true;
-  }
-}   
-
-
-*/
 /*
  * lets redefine message as this particular entity that we wish to display.
  * it should hold only the header for this entity.  We need to fetch the body
@@ -146,17 +131,16 @@ if (isset($absolute_dl) && $absolute_dl == 'true') {
  * attachment in case of ERROR reporting = E_ALL and the output is the screen */
 mime_print_body_lines ($imapConnection, $passed_id, $ent_id, $encoding);
 
-$message = &$message->getEntity('');
-$messages[$mbx_response['UIDVALIDITY']]["$passed_id"] = &$message;
-
 /*
  * This function is verified to work with Netscape and the *very latest*
  * version of IE.  I don't know if it works with Opera, but it should now.
  */
 function DumpHeaders($type0, $type1, $filename, $force) {
-    global $HTTP_USER_AGENT;
+    global $_SERVER, $languages, $squirrelmail_language;
     $isIE = 0;
 
+    $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
+
     if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&
         strstr($HTTP_USER_AGENT, 'Opera') === false) {
         $isIE = 1;
@@ -167,7 +151,13 @@ function DumpHeaders($type0, $type1, $filename, $force) {
         $isIE6 = 1;
     }
 
-    $filename = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename);
+    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+        $filename = 
+            $languages[$squirrelmail_language]['XTRA_CODE']('downloadfilename', $filename, $HTTP_USER_AGENT);
+    } else {
+       $filename = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename);
+    }
 
     // A Pox on Microsoft and it's Office!
     if (! $force) {