From: kink Date: Mon, 21 Nov 2005 20:11:48 +0000 (+0000) Subject: * Centralise the attachment deleting code into the Message class X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c077ffeb31033c67acc441a1d0314a9e1896d6fc;p=squirrelmail.git * Centralise the attachment deleting code into the Message class * 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 --- diff --git a/ChangeLog b/ChangeLog index 5f06406d..bb68cf21 100644 --- 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 ------------------------------- diff --git a/class/mime/Message.class.php b/class/mime/Message.class.php index 1e516d54..4a82be71 100644 --- a/class/mime/Message.class.php +++ b/class/mime/Message.class.php @@ -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 +?> diff --git a/src/compose.php b/src/compose.php index 66ddf4c3..a0ca704c 100644 --- a/src/compose.php +++ b/src/compose.php @@ -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 = '
'.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); diff --git a/src/read_body.php b/src/read_body.php index e15be367..de7b9c43 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -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'); ?> - \ No newline at end of file + diff --git a/src/signout.php b/src/signout.php index 83fd6fae..8706ed96 100644 --- a/src/signout.php +++ b/src/signout.php @@ -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', ?> - \ No newline at end of file +