* Centralise the attachment deleting code into the Message class
authorkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 21 Nov 2005 20:11:48 +0000 (20:11 +0000)
committerkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 21 Nov 2005 20:11:48 +0000 (20:11 +0000)
* Use this from the various places in the code where this was duplicated
* Fix the broken code in signout.php to cleanup lingering attachments
  by using this same function.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@10387 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
class/mime/Message.class.php
src/compose.php
src/read_body.php
src/signout.php

index 5f06406dabdaa25b34f7aa05cb60fa8177eccec3..bb68cf2124b14acbfabf0af522e5af3d76e64bfa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -487,7 +487,7 @@ Version 1.5.1 -- CVS
   - Support for LIST-SUBSCRIBED extension. This speeds up the retrieval of
     the subscribed mailbox-list.
   - Properly clean up temporary attachment files when saving as Draft
-    (#1358407)
+    (#1358407) and fix attachment cleaning code on logout.
 
 Version 1.5.0 - 2 February 2004
 -------------------------------
index 1e516d54dfdea766557479f9e4e499a4bec0fc04..4a82be71a7fbf20484e1a4d8db4d1226cf0efeb4 100644 (file)
@@ -1056,6 +1056,20 @@ class Message {
         $attachment->mime_header = $mime_header;
         $this->entities[]=$attachment;
     }
+
+    /**
+     * Delete all attachments from this object from disk.
+     * @since 1.5.1
+     */
+    function purgeAttachments() {
+        if ($this->att_local_name && file_exists($this->att_local_name)) {
+            unlink($this->att_local_name);
+        }
+        // recursively delete attachments from entities contained in this object
+        for ($i=0, $entCount=count($this->entities);$i< $entCount; ++$i) {
+            $this->entities[$i]->purgeAttachments();
+        }
+    }
 }
 
-?>
\ No newline at end of file
+?>
index 66ddf4c3e319b76328642b92b1726222811805d0..a0ca704ca04bcb8ac2a12abf55d7fda8059c3684 100644 (file)
@@ -390,6 +390,7 @@ if ($draft) {
             }
             sqimap_logout($imap_stream);
         }
+        session_write_close();
         if ($compose_new_win == '1') {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
                 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
@@ -470,6 +471,7 @@ if ($send) {
             exit();
         }
         unset($compose_messages[$session]);
+        
         /* if it is resumed draft, delete draft message */
         if ( isset($delete_draft)) {
             $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, false);
@@ -483,6 +485,7 @@ if ($send) {
             }
             sqimap_logout($imap_stream);
         }
+        session_write_close();
         if ($compose_new_win == '1') {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
                 Header("Location: $location/compose.php?mail_sent=yes");
@@ -595,10 +598,7 @@ elseif (isset($sigappend)) {
         $composeMessage = $compose_messages[$session];
         foreach($delete as $index) {
             if (!empty($composeMessage->entities) && isset($composeMessage->entities[$index])) {
-                $attached_file = $composeMessage->entities[$index]->att_local_name;
-                if (file_exists($attached_file)) {
-                    unlink ($attached_file);
-                }
+                $composeMessage->entities[$index]->purgeAttachments();
                 unset ($composeMessage->entities[$index]);
             }
         }
@@ -767,7 +767,6 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
         } else {
             $mailprio = '';
         }
-        //ClearAttachments($session);
 
         $identity = '';
         $from_o = $orig_header->from;
@@ -1428,7 +1427,7 @@ function checkInput ($show) {
 
 /* True if FAILURE */
 function saveAttachedFiles($session) {
-    global $_FILES, $attachment_dir, $attachments, $username,
+    global $_FILES, $attachment_dir, $username,
         $data_dir, $compose_messages;
 
     /* get out of here if no file was attached at all */
@@ -1459,22 +1458,6 @@ function saveAttachedFiles($session) {
     sqsession_register($compose_messages , 'compose_messages');
 }
 
-/**
- * Given a composeMessage, recursively delete all temporary files in the
- * attachment dir for each body part of that message.
- */
-function ClearAttachments($composeMessage) {
-    if ($composeMessage->att_local_name) {
-        $attached_file = $composeMessage->att_local_name;
-        if (file_exists($attached_file)) {
-            unlink($attached_file);
-        }
-    }
-    for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) {
-        ClearAttachments($composeMessage->entities[$i]);
-    }
-}
-
 /* parse values like 8M and 2k into bytes */
 function getByteSize($ini_size) {
 
@@ -1646,7 +1629,7 @@ function deliverMessage($composeMessage, $draft=false) {
             sqimap_append_done ($imap_stream, $draft_folder);
             sqimap_logout($imap_stream);
             unset ($imap_deliver);
-            ClearAttachments($composeMessage);
+            $composeMessage->purgeAttachments();
             return $length;
         } else {
             $msg  = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
@@ -1707,7 +1690,7 @@ function deliverMessage($composeMessage, $draft=false) {
 
         global $passed_id, $mailbox, $action, $what, $iAccount,$startMessage;
 
-        ClearAttachments($composeMessage);
+        $composeMessage->purgeAttachments();
         if ($action == 'reply' || $action == 'reply_all') {
             $aMailbox = sqm_api_mailbox_select($imap_stream, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
             //sqimap_mailbox_select ($imap_stream, $mailbox);
index e15be367f74b0803cb593dee27b1e9c0de12eeb3..de7b9c43a480084b35c73b3166dc44351b0b4282 100644 (file)
@@ -288,27 +288,6 @@ function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
                                 $readmessage, TRUE);
 }
 
-function ClearAttachments() {
-    global $username, $attachments, $attachment_dir;
-
-    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
-
-    $rem_attachments = array();
-    if (isset($attachments)) {
-        foreach ($attachments as $info) {
-            if ($info['session'] == -1) {
-                $attached_file = "$hashed_attachment_dir/$info[localfilename]";
-                if (file_exists($attached_file)) {
-                    unlink($attached_file);
-                }
-            } else {
-                $rem_attachments[] = $info;
-            }
-        }
-    }
-    $attachments = $rem_attachments;
-}
-
 function formatRecipientString($recipients, $item ) {
     global $show_more_cc, $show_more, $show_more_bcc,
            $PHP_SELF;
@@ -954,7 +933,6 @@ if (isset($sendreceipt)) {
          $message->is_mdnsent = true;
          $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
       }
-      ClearAttachments();
    }
 }
 /***********************************************/
@@ -1052,4 +1030,4 @@ $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
 sqsession_register($mailbox_cache,'mailbox_cache');
 
 ?>
-</body></html>
\ No newline at end of file
+</body></html>
index 83fd6fae60b17b7729d4e8a3dffda5a114192030..8706ed9656c218a2ab94cb98af894c6b82c75d8a 100644 (file)
@@ -24,15 +24,9 @@ require_once(SM_PATH . 'functions/strings.php');
 require_once(SM_PATH . 'functions/html.php');
 
 /* Erase any lingering attachments */
-if (isset($attachments) && is_array($attachments)
-    && sizeof($attachments)){
-    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
-    foreach ($attachments as $info) {
-        $attached_file = "$hashed_attachment_dir/$info[localfilename]";
-        if (file_exists($attached_file)) {
-            unlink($attached_file);
-        }
-    }
+sqgetGlobalVar('compose_messages',  $compose_messages,  SQ_SESSION);
+foreach($compose_messages as $composeMessage) {
+    $composeMessage->purgeAttachments();
 }
 
 if (!isset($frame_top)) {
@@ -97,4 +91,4 @@ html_tag( 'table',
 
 ?>
 </body>
-</html>
\ No newline at end of file
+</html>