NO it's not a habit from me.
[squirrelmail.git] / src / draft_actions.php
index a7295a91e45fcf50b32748e617fe55d89f17d5f1..db4032785be25f612a0a3bb2f68a07ba96e12941 100644 (file)
@@ -9,14 +9,31 @@
  * $Id$
  */
 
-require_once ('../src/validate.php');
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
 
 /* Print all the needed RFC822 headers */
 function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, $session) {
-    global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
-    global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
-    global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
-    global $REMOTE_HOST, $identity;
+    global $data_dir, $username, $popuser, $domain, $version, $useSendmail,
+           $default_charset, $identity, $_SERVER;
+
+    /* get those globals */
+    $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
+    $SERVER_NAME = $_SERVER['SERVER_NAME'];
+    $REMOTE_PORT = $_SERVER['REMOTE_PORT'];
+
+    if(isset($_SERVER['REMOTE_HOST'])) {
+        $REMOTE_HOST = $_SERVER['REMOTE_HOST'];
+    }
+    if(isset($_SERVER['HTTP_VIA'])) {
+        $HTTP_VIA = $_SERVER['HTTP_VIA'];
+    }
+    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+        $HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR'];
+    }
 
     /* Storing the header to make sure the header is the same */
     /* everytime the header is printed. */
@@ -125,7 +142,7 @@ function writeBodyForDraft ($fp, $passedBody, $session) {
         $body .= $passedBody . "\r\n\r\n";
         fputs ($fp, $body);
 
-        $attachmentlength = attachFiles($fp);
+        $attachmentlength = attachFiles($fp, $session);
 
         if (!isset($postbody)) $postbody = "";
         $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
@@ -143,11 +160,14 @@ function writeBodyForDraft ($fp, $passedBody, $session) {
 
 function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $session) {
     global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
-           $data_dir, $username, $domain, $key, $version, $sent_folder,
+           $data_dir, $domain, $version, $sent_folder,
            $imapServerAddress, $imapPort, $draft_folder, $attachment_dir,
-           $default_use_priority;
+           $default_use_priority, $_SESSION, $_COOKIE;
     $more_headers = Array();
 
+    $username = $_SESSION['username'];
+    $key = $_COOKIE['key'];
+
     if ($default_use_priority) {
         $more_headers = array_merge($more_headers, createPriorityHeaders($prio));
     }
@@ -162,11 +182,11 @@ function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $
          $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
          $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
     }
-    $fp = fopen($full_tmpDraftFile, 'w');
+    $fp = fopen($full_tmpDraftFile, 'wb');
 
     $headerlength = write822HeaderForDraft
-        ($fp, $t, $c, $b, $subject, $more_headers, FALSE, $session);
-    $bodylength = writeBodyForDraft ($fp, $body, FALSE, $session);
+        ($fp, $t, $c, $b, $subject, $more_headers, $session);
+    $bodylength = writeBodyForDraft ($fp, $body, $session);
     fclose($fp);
 
     $length = ($headerlength + $bodylength);
@@ -174,8 +194,8 @@ function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $
     if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
         sqimap_append ($imap_stream, $draft_folder, $length);
         write822HeaderForDraft
-            ($imap_stream, $t, $c, $b, $subject, $more_headers, TRUE, $session);
-        writeBodyForDraft ($imap_stream, $body, TRUE, $session);
+            ($imap_stream, $t, $c, $b, $subject, $more_headers, $session);
+        writeBodyForDraft ($imap_stream, $body, $session);
         sqimap_append_done ($imap_stream);
     }
     sqimap_logout($imap_stream);
@@ -187,4 +207,5 @@ function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $
     }
     return $length;
 }
+
 ?>