From f972eb466c6678220bd89b217d7904ce7ae3072e Mon Sep 17 00:00:00 2001 From: fidian Date: Wed, 28 Mar 2001 20:21:02 +0000 Subject: [PATCH] * I really didn't like the old attachment code * Information is now saved in the session instead of .info files * Local filenames are no longer transferred to the client (YEAY) * The client can no longer delete arbitrary files on the system (by setting a delete[] = "username.pref" or delete[] = "../index.php") (Untested, but the code looked like it would happily oblige) * Attachments are now cleared when a new mail message is started * Attachments are now cleared when a new mail message is forwarded * No more silly errors when deleting a single attachment Food for Thought: * If the attachment information was saved in the preferences, the next time the user logs in, old un-deleted attachments could be trashed (or a very simple cron job could be made) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1207 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/smtp.php | 25 +++++------- src/compose.php | 98 ++++++++++++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 54 deletions(-) diff --git a/functions/smtp.php b/functions/smtp.php index 4c15c2c9..0c66f44e 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -62,27 +62,22 @@ $length = 0; if (isMultipart()) { - reset($attachments); - while (list($localname, $remotename) = each($attachments)) { - // This is to make sure noone is giving a filename in another - // directory - $localname = ereg_replace ("\\/", '', $localname); - - $fileinfo = fopen ($attachment_dir.$localname.'.info', 'r'); - $filetype = fgets ($fileinfo, 8192); - fclose ($fileinfo); - $filetype = trim ($filetype); - if ($filetype=='') + foreach ($attachments as $info) + { + $filetype = $info['type']; + if ($filetype == '') $filetype = 'application/octet-stream'; $header = '--'.mimeBoundary()."\r\n"; - $header .= "Content-Type: $filetype;name=\"$remotename\"\r\n"; - $header .= "Content-Disposition: attachment; filename=\"$remotename\"\r\n"; + $header .= "Content-Type: $filetype; name=\"" . + $info['remotefilename'] . "\"\r\n"; + $header .= "Content-Disposition: attachment; filename=\"" . + $info['remotefilename'] . "\"\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; fputs ($fp, $header); $length += strlen($header); - $file = fopen ($attachment_dir.$localname, 'r'); + $file = fopen ($attachment_dir . $info['localfilename'], 'r'); while ($tmp = fread($file, 570)) { $encoded = chunk_split(base64_encode($tmp)); $length += strlen($encoded); @@ -556,7 +551,7 @@ } sqimap_logout($imap_stream); // Delete the files uploaded for attaching (if any). - deleteAttachments(); + ClearAttachments(); } ?> diff --git a/src/compose.php b/src/compose.php index 078acf66..80a62db6 100644 --- a/src/compose.php +++ b/src/compose.php @@ -41,7 +41,10 @@ include("../src/load_prefs.php"); if (!isset($attachments)) + { $attachments = array(); + session_register('attachments'); + } // This function is used when not sending or adding attachments function newMail () { @@ -155,7 +158,7 @@ function getAttachments($message) { global $mailbox, $attachments, $attachment_dir, $imapConnection, $ent_num, $forward_id; - + if (!$message) { sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $forward_id, @@ -170,23 +173,22 @@ $filename = "untitled-".$message->header->entity_id; $localfilename = GenerateRandomString(32, '', 7); - while (isset($attachments[$localfilename])) + while (file_exists($attachment_dir . $localfilename)) $localfilename = GenerateRandomString(32, '', 7); - - // Write File Info - $fp = fopen ($attachment_dir.$localfilename.".info", "w"); - fputs ($fp, strtolower($message->header->type0)."/". - strtolower($message->header->type1)."\n".$filename."\n"); - fclose ($fp); + + $newAttachment['localfilename'] = $localfilename; + $newAttachment['remotefilename'] = $filename; + $newAttachment['type0'] = strtolower($message->header->type0 . + '/' . $message->header->type1); // Write Attachment to file - $fp = fopen ($attachment_dir.$localfilename, "w"); + $fp = fopen ($attachment_dir.$localfilename, 'w'); fputs ($fp, decodeBody(mime_fetch_body($imapConnection, $forward_id, $message->header->entity_id), $message->header->encoding)); fclose ($fp); - $attachments[$localfilename] = $filename; + $attachments[] = $newAttachment; } } else { for ($i = 0; $i < count($message->entities); $i++) { @@ -265,11 +267,10 @@ printf(" ", htmlspecialchars($reply_subj)); } else if ($forward_subj) { - $forward_subj = str_replace("\"", "'", $forward_subj); $forward_subj = trim($forward_subj); - if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") && - (substr(strtolower($forward_subj), 0, 5) != "[fwd:") && - (substr(strtolower($forward_subj), 0, 6) != "[ fwd:")) + if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') && + (substr(strtolower($forward_subj), 0, 5) != '[fwd:') && + (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) $forward_subj = "[Fwd: $forward_subj]"; printf(" ", htmlspecialchars($forward_subj)); @@ -311,13 +312,14 @@ echo " value=\"" . _("Add") ."\">\n"; echo " \n"; echo " \n"; - if (count($attachments) > 0) { + if (count($attachments)) + { echo "\n"; echo " "; echo ""; - while (list($localname, $remotename) = each($attachments)) { - echo "\n"; - echo "$remotename
\n"; + foreach ($attachments as $key => $info) { + echo "\n"; + echo $info['remotefilename'] . "
\n"; } echo "\n"; @@ -332,6 +334,7 @@ function showComposeButtonRow() { global $use_javascript_addr_book; + echo " \n \n"; if ($use_javascript_addr_book) { echo "