Fix for bug 155671. Pass the originalMsgURI received by message compose service to msgDraft down to mime and back to the compose window. Did some cleanup too which fix some memory leak. R=kaie, SR=bienvenu

This commit is contained in:
ducarroz%netscape.com 2002-07-04 23:28:07 +00:00
Родитель 37eb04a7f7
Коммит 25f190e698
10 изменённых файлов: 117 добавлений и 112 удалений

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

@ -37,7 +37,6 @@
#include "nsISupports.idl"
#include "nsIOutputStream.idl"
#include "nsIMsgIdentity.idl"
#include "nsIMsgHdr.idl"
interface nsIMsgWindow;
@ -49,10 +48,9 @@ interface nsIMsgDraft : nsISupports
* This is the primary interface for drafts and templates, loaded by
* a URI
*/
void OpenDraftMsg(in string msgURI, out nsIMsgDBHdr aMsgToReplace,
in nsIMsgIdentity identity, in PRBool addInlineHeaders, in nsIMsgWindow aMsgWindow);
void OpenDraftMsg(in string msgURI, in string originalMsgURI, in nsIMsgIdentity identity,
in PRBool addInlineHeaders, in nsIMsgWindow aMsgWindow);
void OpenEditorTemplate(in string msgURI, out nsIMsgDBHdr aMsgReplace,
in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow);
void OpenEditorTemplate(in string msgURI, in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow);
};

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

@ -1413,11 +1413,15 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI,
// If we don't have an original message URI, nothing else to do...
if (!originalMsgURI || *originalMsgURI == 0)
return rv;
// store the original message URI so we can extract it after we send the message to properly
// mark any disposition flags like replied or forwarded on the message.
mOriginalMsgURI = originalMsgURI;
// If we are forwarding inline, mime did already setup the compose fields therefore we should stop now
if (type == nsIMsgCompType::ForwardInline )
return rv;
char *uriList = PL_strdup(originalMsgURI);
if (!uriList)
return NS_ERROR_OUT_OF_MEMORY;

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

@ -397,13 +397,13 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, const ch
switch(type)
{
case nsIMsgCompType::ForwardInline:
rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_TRUE, aMsgWindow);
rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), originalMsgURI, identity, PR_TRUE, aMsgWindow);
break;
case nsIMsgCompType::Draft:
rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_FALSE, aMsgWindow);
break;
case nsIMsgCompType::Template:
rv = pMsgDraft->OpenEditorTemplate(uriToOpen.get(), nsnull, identity, aMsgWindow);
rv = pMsgDraft->OpenEditorTemplate(uriToOpen.get(), identity, aMsgWindow);
break;
}
}

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

@ -99,7 +99,7 @@ static NS_DEFINE_CID(kStreamConverterCID, NS_MAILNEWS_MIME_STREAM_CONVERTER_C
nsresult
nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType aOutType,
nsIMsgIdentity * identity, nsIMsgDBHdr **aMsgToReplace, nsIMsgWindow *aMsgWindow)
nsIMsgIdentity * identity, const char *originalMsgURI, nsIMsgWindow *aMsgWindow)
{
nsresult rv;
@ -140,9 +140,10 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType
nsCOMPtr<nsIMimeStreamConverter> mimeConverter = do_QueryInterface(mimeParser);
if (mimeConverter)
{
mimeConverter->SetMimeOutputType(mOutType); // Set the type of output for libmime
mimeConverter->SetForwardInline(mAddInlineHeaders);
mimeConverter->SetIdentity(identity);
mimeConverter->SetMimeOutputType(mOutType); // Set the type of output for libmime
mimeConverter->SetForwardInline(mAddInlineHeaders);
mimeConverter->SetIdentity(identity);
mimeConverter->SetOriginalMsgURI(originalMsgURI);
}
nsCOMPtr<nsIStreamListener> convertedListener = do_QueryInterface(mimeParser);
@ -192,10 +193,6 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType
return NS_ERROR_UNEXPECTED;
}
// Make sure we return this if requested!
if (aMsgToReplace)
GetMsgDBHdrFromURI(msgURI, aMsgToReplace);
// Now, just plug the two together and get the hell out of the way!
rv = mMessageService->DisplayMessage(mURI, convertedListener, aMsgWindow, nsnull, mailCharset, nsnull);
@ -209,8 +206,8 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType
}
nsresult
nsMsgDraft::OpenDraftMsg(const char *msgURI, nsIMsgDBHdr **aMsgToReplace,
nsIMsgIdentity * identity, PRBool addInlineHeaders, nsIMsgWindow *aMsgWindow)
nsMsgDraft::OpenDraftMsg(const char *msgURI, const char *originalMsgURI, nsIMsgIdentity * identity,
PRBool addInlineHeaders, nsIMsgWindow *aMsgWindow)
{
// We should really never get here, but if we do, just return
// with an error
@ -219,14 +216,13 @@ nsMsgDraft::OpenDraftMsg(const char *msgURI, nsIMsgDBHdr **aMsgToReplace,
mAddInlineHeaders = addInlineHeaders;
return ProcessDraftOrTemplateOperation(msgURI, nsMimeOutput::nsMimeMessageDraftOrTemplate,
identity, aMsgToReplace, aMsgWindow);
identity, originalMsgURI, aMsgWindow);
}
nsresult
nsMsgDraft::OpenEditorTemplate(const char *msgURI, nsIMsgDBHdr **aMsgToReplace,
nsIMsgIdentity * identity, nsIMsgWindow *aMsgWindow)
nsMsgDraft::OpenEditorTemplate(const char *msgURI, nsIMsgIdentity * identity, nsIMsgWindow *aMsgWindow)
{
return ProcessDraftOrTemplateOperation(msgURI, nsMimeOutput::nsMimeMessageEditorTemplate,
identity, aMsgToReplace, aMsgWindow);
identity, nsnull, aMsgWindow);
}

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

@ -55,7 +55,7 @@ public:
NS_DECL_NSIMSGDRAFT
nsresult ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType aOutType,
nsIMsgIdentity * identity, nsIMsgDBHdr **aMsgToReplace, nsIMsgWindow *aMsgWindow);
nsIMsgIdentity * identity, const char *originalMsgURI, nsIMsgWindow *aMsgWindow);
//
// Implementation data...

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

@ -83,25 +83,25 @@ interface nsIMimeStreamConverter : nsISupports {
void GetMimeOutputType(out nsMimeOutputType aOutFormat);
/*
* This is needed by libmime for MHTML link processing...the url is the URL string associated
* with this input stream
*/
void SetStreamURI(in nsIURI aURI);
/*
* This is used to extract headers while parsing a message
*/
void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener, in nsMimeOutputType aType);
/*
* This is needed by libmime for MHTML link processing...the url is the URL string associated
* with this input stream
*/
void SetStreamURI(in nsIURI aURI);
/*
* This is used for forward inline
*/
attribute PRBool forwardInline;
/*
* This is used for OpenDraft, OpenEditorTemplate and Forward inline (which use OpenDraft)
*/
/*
* This is used to extract headers while parsing a message
*/
void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener, in nsMimeOutputType aType);
attribute nsIMsgIdentity identity;
/*
* This is used for forward inline
*/
attribute PRBool forwardInline;
/*
* This is used for OpenDraft, OpenEditorTemplate and Forward inline (which use OpenDraft)
*/
attribute nsIMsgIdentity identity;
attribute string originalMsgURI;
};

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

@ -205,14 +205,14 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields,
MSG_ComposeType composeType,
MSG_ComposeFormat composeFormat,
nsIMsgIdentity * identity,
char * originalMsgURI
const char * originalMsgURI
)
{
nsresult rv;
MSG_ComposeFormat format = nsIMsgCompFormat::Default;
nsresult rv;
MSG_ComposeFormat format = nsIMsgCompFormat::Default;
#ifdef NS_DEBUG
mime_dump_attachments ( attachmentList );
mime_dump_attachments ( attachmentList );
#endif
nsMsgAttachmentData *curAttachment = attachmentList;
@ -274,14 +274,8 @@ mime_dump_attachments ( attachmentList );
pMsgComposeParams->SetFormat(format);
pMsgComposeParams->SetIdentity(identity);
pMsgComposeParams->SetComposeFields(compFields);
//Lets cleanup the URI
nsCAutoString msgURI(originalMsgURI);
PRInt32 i = msgURI.FindChar('?');
if (i != kNotFound)
msgURI.Truncate(i);
NS_UnescapeURL(msgURI);
pMsgComposeParams->SetOriginalMsgURI(msgURI.get());
if (originalMsgURI)
pMsgComposeParams->SetOriginalMsgURI(originalMsgURI);
rv = msgComposeService->OpenComposeWindowWithParams(nsnull /* default chrome */, pMsgComposeParams);
}
@ -1305,7 +1299,7 @@ mime_parse_stream_complete (nsMIMESession *stream)
mdd->mailcharset = nsCRT::strdup(mdd->options->default_charset);
}
// mscott: aren't we leaking a bunch of trings here like the charset strings and such?
// mscott: aren't we leaking a bunch of strings here like the charset strings and such?
delete mdd->options;
mdd->options = 0;
}
@ -1546,7 +1540,7 @@ mime_parse_stream_complete (nsMIMESession *stream)
#ifdef NS_DEBUG
printf("RICHIE: Time to create the EDITOR with this template - HAS a body!!!!\n");
#endif
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, composeFormat, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, composeFormat, mdd->identity, nsnull);
}
else
{
@ -1554,11 +1548,11 @@ mime_parse_stream_complete (nsMIMESession *stream)
printf("Time to create the composition window WITH a body!!!!\n");
#endif
if (mdd->forwardInline)
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity, mdd->url_name);
else
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity, mdd->originalMsgURI);
else
{
fields->SetDraftId(mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity, nsnull);
}
}
}
@ -1573,7 +1567,7 @@ mime_parse_stream_complete (nsMIMESession *stream)
#ifdef NS_DEBUG
printf("RICHIE: Time to create the EDITOR with this template - NO body!!!!\n");
#endif
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, nsIMsgCompFormat::Default, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, nsIMsgCompFormat::Default, mdd->identity, nsnull);
}
else
{
@ -1581,11 +1575,11 @@ mime_parse_stream_complete (nsMIMESession *stream)
printf("Time to create the composition window WITHOUT a body!!!!\n");
#endif
if (mdd->forwardInline)
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, nsIMsgCompFormat::Default, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, nsIMsgCompFormat::Default, mdd->identity, mdd->originalMsgURI);
else
{
fields->SetDraftId(mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, nsIMsgCompFormat::Default, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, nsIMsgCompFormat::Default, mdd->identity, nsnull);
}
}
}
@ -1599,7 +1593,7 @@ mime_parse_stream_complete (nsMIMESession *stream)
mdd->mailcharset,
getter_AddRefs(fields));
if (fields)
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::New, nsIMsgCompFormat::Default, mdd->identity, mdd->url_name);
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::New, nsIMsgCompFormat::Default, mdd->identity, nsnull);
}
if ( mdd->headers )
@ -1644,7 +1638,9 @@ mime_parse_stream_complete (nsMIMESession *stream)
nsServiceManager::ReleaseService(kPrefCID, obj->options->prefs);
mdd->identity = nsnull;
PR_Free (mdd);
PR_Free(mdd->url_name)
PR_Free(mdd->originalMsgURI)
PR_Free(mdd);
PR_FREEIF(host);
PR_FREEIF(to_and_cc);
@ -2033,7 +2029,7 @@ mime_bridge_create_draft_stream(
int status = 0;
nsMIMESession *stream = nsnull;
struct mime_draft_data *mdd = nsnull;
MimeObject *obj;
MimeObject *obj = nsnull;
if ( !uri )
return nsnull;
@ -2042,42 +2038,38 @@ mime_bridge_create_draft_stream(
if (!mdd)
return nsnull;
// first, convert the rdf msg uri into a url that represents the message...
nsCAutoString turl;
if (NS_FAILED(uri->GetSpec(turl)))
return nsnull;
nsCOMPtr <nsIMsgMessageService> msgService;
nsresult rv = GetMessageServiceFromURI(turl.get(), getter_AddRefs(msgService));
if (NS_FAILED(rv))
return nsnull;
nsCOMPtr<nsIURI> aURL;
nsCAutoString urlString;
nsresult rv;
// first, convert the rdf msg uri into a url that represents the message...
if (NS_FAILED(uri->GetSpec(turl)))
goto FAIL;
rv = GetMessageServiceFromURI(turl.get(), getter_AddRefs(msgService));
if (NS_FAILED(rv))
goto FAIL;
rv = msgService->GetUrlForUri(turl.get(), getter_AddRefs(aURL), nsnull);
if (NS_FAILED(rv))
return nsnull;
goto FAIL;
nsCAutoString urlString;
if (NS_SUCCEEDED(aURL->GetSpec(urlString)))
{
mdd->url_name = ToNewCString(urlString);
if (!(mdd->url_name))
{
PR_FREEIF(mdd);
return nsnull;
}
goto FAIL;
}
newPluginObj2->GetForwardInline(&mdd->forwardInline);
newPluginObj2->GetIdentity(getter_AddRefs(mdd->identity));
newPluginObj2->GetOriginalMsgURI(&mdd->originalMsgURI);
mdd->format_out = format_out;
mdd->options = new MimeDisplayOptions ;
if ( !mdd->options )
{
PR_FREEIF(mdd->url_name);
PR_FREEIF(mdd);
return nsnull;
}
if (!mdd->options)
goto FAIL;
mdd->options->url = nsCRT::strdup(mdd->url_name);
mdd->options->format_out = format_out; // output format
@ -2091,10 +2083,7 @@ mime_bridge_create_draft_stream(
rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**)&(mdd->options->prefs));
if (! (mdd->options->prefs && NS_SUCCEEDED(rv)))
{
PR_FREEIF(mdd);
return nsnull;
}
goto FAIL;
#ifdef FO_MAIL_MESSAGE_TO
/* If we're attaching a message (for forwarding) then we must eradicate all
@ -2107,25 +2096,14 @@ mime_bridge_create_draft_stream(
obj = mime_new ( (MimeObjectClass *) &mimeMessageClass, (MimeHeaders *) NULL, MESSAGE_RFC822 );
if ( !obj )
{
PR_FREEIF(mdd->url_name);
delete mdd->options;
PR_FREEIF(mdd );
return nsnull;
}
goto FAIL;
obj->options = mdd->options;
mdd->obj = obj;
stream = PR_NEWZAP ( nsMIMESession );
if ( !stream )
{
PR_FREEIF(mdd->url_name);
delete mdd->options;
PR_FREEIF ( mdd );
PR_FREEIF ( obj );
return nsnull;
}
goto FAIL;
stream->name = "MIME To Draft Converter Stream";
stream->complete = mime_parse_stream_complete;
@ -2136,15 +2114,22 @@ mime_bridge_create_draft_stream(
status = obj->clazz->initialize ( obj );
if ( status >= 0 )
status = obj->clazz->parse_begin ( obj );
if ( status < 0 )
{
PR_FREEIF(mdd->url_name);
PR_FREEIF ( stream );
delete mdd->options;
PR_FREEIF ( mdd );
PR_FREEIF ( obj );
return nsnull;
}
if ( status < 0 )
goto FAIL;
return stream;
FAIL:
if (mdd)
{
PR_Free(mdd->url_name);
PR_Free(mdd->originalMsgURI);
if (mdd->options)
delete mdd->options;
PR_Free ( mdd );
}
PR_Free ( stream );
PR_Free ( obj );
return nsnull;
}

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

@ -136,6 +136,11 @@ struct mime_stream_data { /* This struct is the state we pass around
//
struct mime_draft_data
{
/* WARNING: You cannot use a c++ object, in that structure, which is dependent on its constructor or
destructor as mime_draft_data is not created using the new operator. nsCOMPtr however are ok
to use as long you set it to null before the structure get freed.
*/
char *url_name; // original url name */
nsMimeOutputType format_out; // intended output format; should be FO_OPEN_DRAFT */
nsMIMESession *stream; // not used for now
@ -154,6 +159,7 @@ struct mime_draft_data
char *mailcharset; // get it from CHARSET of Content-Type
PRBool forwardInline;
nsCOMPtr<nsIMsgIdentity> identity;
char *originalMsgURI; // the original URI of the message we are currently processing
};
////////////////////////////////////////////////////////////////
@ -180,7 +186,7 @@ extern "C" nsresult mimeEmitterAddAllHeaders(MimeDisplayOptions *opt, const
extern "C" nsresult mimeEmitterStartAttachment(MimeDisplayOptions *opt, const char *name, const char *contentType, const char *url,
PRBool aNotDownloaded);
extern "C" nsresult mimeEmitterEndAttachment(MimeDisplayOptions *opt);
extern "C" nsresult mimeEmitterEndAllAttachments(MimeDisplayOptions *opt);
extern "C" nsresult mimeEmitterEndAllAttachments(MimeDisplayOptions *opt);
extern "C" nsresult mimeEmitterStartBody(MimeDisplayOptions *opt, PRBool bodyOnly, const char *msgID, const char *outCharset);
extern "C" nsresult mimeEmitterEndBody(MimeDisplayOptions *opt);
extern "C" nsresult mimeEmitterEndHeader(MimeDisplayOptions *opt);

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

@ -850,6 +850,20 @@ nsStreamConverter::SetIdentity(nsIMsgIdentity * aIdentity)
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverter::SetOriginalMsgURI(const char * originalMsgURI)
{
mOriginalMsgURI = originalMsgURI;
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverter::GetOriginalMsgURI(char ** result)
{
if (!result) return NS_ERROR_NULL_POINTER;
*result = ToNewCString(mOriginalMsgURI);
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////////
// Methods for nsIStreamListener...

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

@ -107,6 +107,8 @@ private:
nsCOMPtr<nsIMimeStreamConverterListener> mMimeStreamConverterListener;
PRBool mForwardInline;
nsCOMPtr<nsIMsgIdentity> mIdentity;
nsCString mOriginalMsgURI;
#ifdef DEBUG_mscott
PRTime mConvertContentTime;
#endif