fix for #75317. temp files created when forwarding a message with attachments are not being

deleted.  fix by cavin@netscape.com.  r=ducarroz, sr=sspitzer
This commit is contained in:
sspitzer%netscape.com 2001-04-13 08:13:48 +00:00
Родитель 6a89af54bb
Коммит 0230808749
3 изменённых файлов: 97 добавлений и 0 удалений

Просмотреть файл

@ -61,6 +61,8 @@ interface nsIMsgCompFields : nsISupports {
attribute wstring otherRandomHeaders;
attribute wstring body;
attribute string temporaryFiles; // a list of temp files to remove
/* some utility functions */
nsIMsgRecipientArray SplitRecipients(in wstring recipients, in boolean emailAddressOnly);

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsMsgRecipientArray.h"
#include "nsIMsgHeaderParser.h"
#include "nsMsgCompUtils.h"
#include "nsIFileChannel.h"
static NS_DEFINE_CID(kHeaderParserCID, NS_MSGHEADERPARSER_CID);
@ -63,6 +64,9 @@ nsMsgCompFields::nsMsgCompFields()
nsMsgCompFields::~nsMsgCompFields()
{
// Clean up temp files first if set
CleanUpTempFiles();
PRInt16 i;
for (i = 0; i < MSG_MAX_HEADERS; i ++)
PR_FREEIF(m_headers[i]);
@ -95,6 +99,81 @@ nsresult nsMsgCompFields::Copy(nsIMsgCompFields* pMsgCompFields)
return NS_OK;
}
nsresult nsMsgCompFields::CleanUpTempFiles()
{
nsresult rv;
char *attachmentList;
rv = GetTemporaryFiles(&attachmentList);
NS_ENSURE_SUCCESS(rv,rv);
if ((!attachmentList) || (!*attachmentList))
return NS_OK;
// parse the attachment list
#ifdef DEBUG_cavin
printf("In CleanUpTempFiles(), attachments to delete list = %s\n", (const char*)attachmentList);
#endif
char *token = nsnull;
char *rest = attachmentList;
nsCAutoString url;
token = nsCRT::strtok(rest, ",", &rest);
while (token && *token)
{
url = token;
url.StripWhitespace();
// Only deal with temp files (ie, starting with "file://")
if (!url.IsEmpty() && url.CompareWithConversion(kFileURLPrefix, PR_TRUE, 7) == 0)
{
nsCOMPtr<nsIFileURL> tempFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
if (NS_FAILED(rv))
{
NS_ASSERTION(0, "Can't creat nsIFileURL interface");
continue;
}
rv = tempFileURL->SetSpec(url);
if (NS_FAILED(rv))
{
NS_ASSERTION(0, "Can't set file spec in nsIFileURL interface");
continue;
}
nsCOMPtr<nsIFile> urlFile;
rv = tempFileURL->GetFile(getter_AddRefs(urlFile));
if (NS_FAILED(rv))
{
NS_ASSERTION(0, "Can't get nsIFile interface from nsIFileURL interface");
continue;
}
PRBool isDir;
rv = urlFile->IsDirectory(&isDir);
if (NS_FAILED(rv))
{
NS_ASSERTION(0, "IsDirectory() call failed!");
continue;
}
if (isDir)
{
NS_ASSERTION(0, "The temporary file is not supposed to be a directory!");
continue;
}
// remove it if not a dir
urlFile->Delete(PR_FALSE);
}
token = nsCRT::strtok(rest, ",", &rest);
}
nsCRT::free(attachmentList);
return NS_OK;
}
nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value)
{
NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!");
@ -265,12 +344,23 @@ NS_IMETHODIMP nsMsgCompFields::SetAttachments(const char *value)
return SetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID, value);
}
NS_IMETHODIMP nsMsgCompFields::SetTemporaryFiles(const char *value)
{
return SetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID, value);
}
NS_IMETHODIMP nsMsgCompFields::GetAttachments(char **_retval)
{
*_retval = nsCRT::strdup(GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP nsMsgCompFields::GetTemporaryFiles(char **_retval)
{
*_retval = nsCRT::strdup(GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP nsMsgCompFields::SetOrganization(const PRUnichar *value)
{
return SetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, value);

Просмотреть файл

@ -62,6 +62,7 @@ public:
MSG_MESSAGE_ID_HEADER_ID,
MSG_X_TEMPLATE_HEADER_ID,
MSG_DRAFT_ID_HEADER_ID,
MSG_TEMPORARY_FILES_HEADER_ID,
MSG_MAX_HEADERS //Must be the last one.
} MsgHeaderID;
@ -112,6 +113,8 @@ public:
const char* GetAttachments() {return GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID);}
const char* GetTemporaryFiles() {return GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID);}
nsresult SetOrganization(const char *value) {return SetAsciiHeader(MSG_ORGANIZATION_HEADER_ID, value);}
const char* GetOrganization() {return GetAsciiHeader(MSG_ORGANIZATION_HEADER_ID);}
@ -147,6 +150,8 @@ public:
PRInt32 GetReturnReceiptType() { return m_receiptType; };
void SetReturnReceiptType(PRInt32 type) {m_receiptType = type;};
nsresult CleanUpTempFiles();
protected:
char* m_headers[MSG_MAX_HEADERS];
char* m_body;