зеркало из https://github.com/mozilla/gecko-dev.git
Add a way to extract headers during parsing of a message and give them back to the caller
This commit is contained in:
Родитель
aea26df0a4
Коммит
b3c684d4cf
|
@ -48,6 +48,9 @@ if (prefs) {
|
|||
|
||||
var editorDocumentListener = {
|
||||
NotifyDocumentCreated: function() {
|
||||
|
||||
CompFields2Recipients(msgCompose.compFields);
|
||||
|
||||
if (document.getElementById("msgRecipient#1").value == "")
|
||||
{
|
||||
dump("set focus on the recipient\n");
|
||||
|
@ -202,7 +205,6 @@ function ComposeStartup()
|
|||
if (args.subject)
|
||||
msgCompFields.SetSubject(args.subject);
|
||||
|
||||
CompFields2Recipients(msgCompFields);
|
||||
var subjectValue = msgCompFields.GetSubject();
|
||||
if (subjectValue != "") {
|
||||
document.getElementById("msgSubject").value = subjectValue;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsMsgSend.h"
|
||||
#include "nsMsgCreate.h"
|
||||
#include "nsMailHeaders.h"
|
||||
|
||||
// XXX temporary so we can use the current identity hack -alecf
|
||||
#include "nsIMsgMailSession.h"
|
||||
|
@ -77,14 +78,14 @@ nsMsgCompose::UsingOldQuotingHack(const char *compString)
|
|||
|
||||
nsMsgCompose::nsMsgCompose()
|
||||
{
|
||||
mTempComposeFileSpec = nsnull;
|
||||
mQuotingToFollow = PR_FALSE;
|
||||
mSigFileSpec = nsnull;
|
||||
mUseOldQuotingHack = PR_FALSE; // RICHIE - hack for old quoting
|
||||
mWhatHolder = 1; // RICHIE - hack for old quoting
|
||||
mQuoteURI = "";
|
||||
mDocumentListener = nsnull;
|
||||
mMsgSend = nsnull;
|
||||
mTempComposeFileSpec = nsnull;
|
||||
mQuotingToFollow = PR_FALSE;
|
||||
mSigFileSpec = nsnull;
|
||||
mUseOldQuotingHack = PR_FALSE; // RICHIE - hack for old quoting
|
||||
mWhatHolder = 1; // RICHIE - hack for old quoting
|
||||
mQuoteURI = "";
|
||||
mDocumentListener = nsnull;
|
||||
mMsgSend = nsnull;
|
||||
m_sendListener = nsnull;
|
||||
m_window = nsnull;
|
||||
m_webShell = nsnull;
|
||||
|
@ -93,6 +94,7 @@ nsMsgCompose::nsMsgCompose()
|
|||
mQuoteStreamListener=nsnull;
|
||||
m_compFields = new nsMsgCompFields;
|
||||
NS_IF_ADDREF(m_compFields);
|
||||
mType = MSGCOMP_TYPE_New;
|
||||
|
||||
// Get the default charset from pref, use this as a mail charset.
|
||||
char * default_mail_charset = nsMsgI18NGetDefaultMailCharset();
|
||||
|
@ -122,9 +124,10 @@ nsMsgCompose::nsMsgCompose()
|
|||
|
||||
nsMsgCompose::~nsMsgCompose()
|
||||
{
|
||||
if (m_editor)
|
||||
m_editor->UnregisterDocumentStateListener(mDocumentListener);
|
||||
NS_IF_RELEASE(mDocumentListener);
|
||||
if (m_editor)
|
||||
m_editor->UnregisterDocumentStateListener(mDocumentListener);
|
||||
|
||||
NS_IF_RELEASE(mDocumentListener);
|
||||
NS_IF_RELEASE(m_sendListener);
|
||||
NS_IF_RELEASE(m_compFields);
|
||||
NS_IF_RELEASE(mQuoteStreamListener);
|
||||
|
@ -609,6 +612,8 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, MSG_Compo
|
|||
|
||||
message->GetCharSet(&aCharset);
|
||||
message->GetSubject(&aString);
|
||||
|
||||
mType = type;
|
||||
switch (type)
|
||||
{
|
||||
default: break;
|
||||
|
@ -810,8 +815,70 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStartRequest(nsIChannel * /* aChann
|
|||
|
||||
NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIChannel * /* aChannel */, nsISupports * /* ctxt */, nsresult status, const PRUnichar * /* errorMsg */)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mComposeObj)
|
||||
{
|
||||
MSG_ComposeType type = mComposeObj->GetMessageType();
|
||||
|
||||
if (mHeaders && (type == MSGCOMP_TYPE_Reply || type == MSGCOMP_TYPE_ReplyAll))
|
||||
{
|
||||
nsIMsgCompFields *compFields = nsnull;
|
||||
mComposeObj->GetCompFields(&compFields); //GetCompFields will addref, you need to release when your are done with it
|
||||
if (compFields)
|
||||
{
|
||||
nsString aCharset(msgCompHeaderInternalCharset());
|
||||
nsString replyTo;
|
||||
nsString newgroups;
|
||||
nsString followUpTo;
|
||||
char *outCString;
|
||||
PRUnichar emptyUnichar = 0;
|
||||
|
||||
mHeaders->ExtractHeader(HEADER_REPLY_TO, PR_FALSE, &outCString);
|
||||
if (outCString)
|
||||
{
|
||||
// Convert fields to UTF-8
|
||||
ConvertToUnicode(aCharset, outCString, replyTo);
|
||||
PR_Free(outCString);
|
||||
}
|
||||
|
||||
mHeaders->ExtractHeader(HEADER_NEWSGROUPS, PR_FALSE, &outCString);
|
||||
if (outCString)
|
||||
{
|
||||
// Convert fields to UTF-8
|
||||
ConvertToUnicode(aCharset, outCString, newgroups);
|
||||
PR_Free(outCString);
|
||||
}
|
||||
|
||||
mHeaders->ExtractHeader(HEADER_FOLLOWUP_TO, PR_FALSE, &outCString);
|
||||
if (outCString)
|
||||
{
|
||||
// Convert fields to UTF-8
|
||||
ConvertToUnicode(aCharset, outCString, followUpTo);
|
||||
PR_Free(outCString);
|
||||
}
|
||||
|
||||
if (! replyTo.IsEmpty())
|
||||
compFields->SetTo(replyTo.GetUnicode());
|
||||
|
||||
if (! newgroups.IsEmpty())
|
||||
{
|
||||
compFields->SetNewsgroups(newgroups.GetUnicode());
|
||||
if (type == MSGCOMP_TYPE_Reply)
|
||||
compFields->SetTo(&emptyUnichar);
|
||||
}
|
||||
|
||||
if (! followUpTo.IsEmpty())
|
||||
{
|
||||
compFields->SetNewsgroups(followUpTo.GetUnicode());
|
||||
if (type == MSGCOMP_TYPE_Reply)
|
||||
compFields->SetTo(&emptyUnichar);
|
||||
}
|
||||
|
||||
NS_RELEASE(compFields);
|
||||
}
|
||||
}
|
||||
|
||||
mMsgBody += "</html></BLOCKQUOTE>";
|
||||
|
||||
// Now we have an HTML representation of the quoted message.
|
||||
|
@ -834,11 +901,17 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIChannel * /* aChanne
|
|||
mComposeObj->GetComposeHTML(&compHTML);
|
||||
mComposeObj->mTempComposeFileSpec = nsMsgCreateTempFileSpec(compHTML ? (char *)"nscomp.html" : (char *)"nscomp.txt");
|
||||
if (!mComposeObj->mTempComposeFileSpec)
|
||||
return NS_MSG_ERROR_WRITING_FILE;
|
||||
{
|
||||
rv = NS_MSG_ERROR_WRITING_FILE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
nsOutputFileStream tempFile(*(mComposeObj->mTempComposeFileSpec));
|
||||
if (!tempFile.is_open())
|
||||
return NS_MSG_ERROR_WRITING_FILE;
|
||||
{
|
||||
rv = NS_MSG_ERROR_WRITING_FILE;
|
||||
goto done;
|
||||
}
|
||||
tempFile.write(nsAutoCString(mMsgBody), mMsgBody.Length());
|
||||
mComposeObj->ProcessSignature(&tempFile);
|
||||
tempFile.close();
|
||||
|
@ -848,13 +921,16 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIChannel * /* aChanne
|
|||
nsIEditorShell *editor;
|
||||
|
||||
mComposeObj->GetEditor(&editor);
|
||||
|
||||
if (editor)
|
||||
editor->LoadUrl(urlStr.GetUnicode());
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(mComposeObj); //We are done with it, therefore release it.
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP QuotingOutputStreamListener::OnDataAvailable(nsIChannel * /* aChannel */,
|
||||
|
@ -888,11 +964,24 @@ QuotingOutputStreamListener::SetComposeObj(nsMsgCompose *obj)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
QuotingOutputStreamListener::SetMimeHeaders(nsIMimeHeaders * headers)
|
||||
{
|
||||
mHeaders = headers;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(QuotingOutputStreamListener, nsCOMTypeInfo<nsIStreamListener>::GetIID());
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// END OF QUOTING LISTENER
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MSG_ComposeType nsMsgCompose::GetMessageType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgCompose::QuoteOriginalMessage(const PRUnichar *originalMsgURI, PRInt32 what) // New template
|
||||
{
|
||||
|
@ -934,7 +1023,8 @@ nsMsgCompose::QuoteOriginalMessage(const PRUnichar *originalMsgURI, PRInt32 what
|
|||
NS_ADDREF(this);
|
||||
mQuoteStreamListener->SetComposeObj(this);
|
||||
|
||||
return mQuote->QuoteMessage(originalMsgURI, what != 1, mQuoteStreamListener);
|
||||
rv = mQuote->QuoteMessage(originalMsgURI, what != 1, mQuoteStreamListener);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void nsMsgCompose::HackToGetBody(PRInt32 what)
|
||||
|
@ -1332,10 +1422,14 @@ nsMsgDocumentStateListener::NotifyDocumentCreated(void)
|
|||
PRUnichar *bod;
|
||||
|
||||
nsIMsgCompFields *compFields;
|
||||
mComposeObj->GetCompFields(&compFields);
|
||||
compFields->GetBody(&bod);
|
||||
mComposeObj->LoadAsQuote(nsString(bod));
|
||||
PR_FREEIF(bod);
|
||||
mComposeObj->GetCompFields(&compFields); //GetCompFields will addref, you need to release when your are done with it
|
||||
if (compFields)
|
||||
{
|
||||
compFields->GetBody(&bod);
|
||||
mComposeObj->LoadAsQuote(nsString(bod));
|
||||
PR_FREEIF(bod);
|
||||
NS_RELEASE(compFields);
|
||||
}
|
||||
}
|
||||
// RICHIE - hack! This is only if we are using the old
|
||||
// quoting hack
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include "nsIMsgSendListener.h"
|
||||
#include "nsIMsgCopyServiceListener.h"
|
||||
#include "nsIMsgSend.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIMimeHeaders.h"
|
||||
|
||||
// Forward declares
|
||||
class QuotingOutputStreamListener;
|
||||
|
@ -90,7 +92,9 @@ class nsMsgCompose : public nsIMsgCompose
|
|||
NS_IMETHOD GetWrapLength(PRInt32 *aWrapLength);
|
||||
/******/
|
||||
|
||||
// Deal with quoting issues...
|
||||
MSG_ComposeType GetMessageType();
|
||||
|
||||
// Deal with quoting issues...
|
||||
nsresult QuoteOriginalMessage(const PRUnichar * originalMsgURI, PRInt32 what); // New template
|
||||
PRBool QuotingToFollow(void);
|
||||
nsresult SetQuotingToFollow(PRBool aVal);
|
||||
|
@ -137,6 +141,7 @@ class nsMsgCompose : public nsIMsgCompose
|
|||
nsCOMPtr<nsIMsgQuote> mQuote;
|
||||
PRBool mQuotingToFollow; // Quoting indicator
|
||||
nsMsgDocumentStateListener *mDocumentListener;
|
||||
MSG_ComposeType mType; //Message type
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -163,11 +168,13 @@ public:
|
|||
|
||||
NS_IMETHOD SetComposeObj(nsMsgCompose *obj);
|
||||
NS_IMETHOD ConvertToPlainText();
|
||||
NS_IMETHOD SetMimeHeaders(nsIMimeHeaders * headers);
|
||||
|
||||
private:
|
||||
nsMsgCompose *mComposeObj;
|
||||
nsString mMsgBody;
|
||||
PRBool mQuoteHeaders;
|
||||
nsMsgCompose * mComposeObj;
|
||||
nsString mMsgBody;
|
||||
PRBool mQuoteHeaders;
|
||||
nsCOMPtr<nsIMimeHeaders> mHeaders;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,9 +40,54 @@
|
|||
#include "nsIChannel.h"
|
||||
#include "nsMsgMimeCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMsgCompose.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMsgQuoteListener, nsCOMTypeInfo<nsIMimeStreamConverterListener>::GetIID())
|
||||
|
||||
nsMsgQuoteListener::nsMsgQuoteListener() :
|
||||
mMsgQuote(nsnull)
|
||||
{
|
||||
/* the following macro is used to initialize the ref counting data */
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsMsgQuoteListener::~nsMsgQuoteListener()
|
||||
{
|
||||
}
|
||||
|
||||
void nsMsgQuoteListener::SetMsgQuote(nsMsgQuote * msgQuote)
|
||||
{
|
||||
mMsgQuote = msgQuote;
|
||||
}
|
||||
|
||||
nsresult nsMsgQuoteListener::OnHeadersReady(nsIMimeHeaders * headers)
|
||||
{
|
||||
|
||||
printf("RECEIVE CALLBACK: OnHeadersReady\n");
|
||||
|
||||
if (mMsgQuote && mMsgQuote->mStreamListener)
|
||||
{
|
||||
QuotingOutputStreamListener * quoting;
|
||||
if (NS_SUCCEEDED(mMsgQuote->mStreamListener->QueryInterface(QuotingOutputStreamListener::GetIID(), (void**)"ing)) &&
|
||||
quoting)
|
||||
{
|
||||
quoting->SetMimeHeaders(headers);
|
||||
NS_RELEASE(quoting);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
/* ducarroz: Impossible to compile the COMPtr version of this code !!!!
|
||||
nsCOMPtr<QuotingOutputStreamListener> quoting (do_QueryInterface(streamListener));
|
||||
if (quoting)
|
||||
quoting->SetMimeHeaders(headers);
|
||||
*/
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation...
|
||||
//
|
||||
|
@ -55,6 +100,7 @@ nsMsgQuote::nsMsgQuote()
|
|||
mURI = nsnull;
|
||||
mMessageService = nsnull;
|
||||
mQuoteHeaders = PR_FALSE;
|
||||
mQuoteListener = nsnull;
|
||||
}
|
||||
|
||||
nsMsgQuote::~nsMsgQuote()
|
||||
|
@ -66,6 +112,7 @@ nsMsgQuote::~nsMsgQuote()
|
|||
}
|
||||
|
||||
PR_FREEIF(mURI);
|
||||
NS_IF_RELEASE(mQuoteListener);
|
||||
}
|
||||
|
||||
/* the following macro actually implement addref, release and query interface for our component. */
|
||||
|
@ -249,7 +296,17 @@ SaveQuoteMessageCompleteCallback(nsIURI *aURL, nsresult aExitCode, void *tagData
|
|||
if (ptr->mQuoteHeaders)
|
||||
mimeConverter->SetMimeOutputType(nsMimeOutput::nsMimeMessageQuoting);
|
||||
else
|
||||
{
|
||||
mimeConverter->SetMimeOutputType(nsMimeOutput::nsMimeMessageBodyQuoting);
|
||||
|
||||
ptr->mQuoteListener = new nsMsgQuoteListener();
|
||||
if (ptr->mQuoteListener)
|
||||
{
|
||||
NS_ADDREF(ptr->mQuoteListener);
|
||||
ptr->mQuoteListener->SetMsgQuote(ptr);
|
||||
mimeConverter->SetMimeHeadersListener(ptr->mQuoteListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIChannel> dummyChannel;
|
||||
|
|
|
@ -23,11 +23,30 @@
|
|||
#include "nsIFileSpec.h"
|
||||
#include "nsIMsgMessageService.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIMimeStreamConverter.h"
|
||||
|
||||
#define NS_MSGQUOTE_CID \
|
||||
{0x1C7ABF0C, 0x21E5, 0x11d3, \
|
||||
{ 0x8E, 0xF1, 0x00, 0xA0, 0x24, 0xA7, 0xD1, 0x44 }}
|
||||
|
||||
class nsMsgQuote;
|
||||
|
||||
class nsMsgQuoteListener: public nsIMimeStreamConverterListener
|
||||
{
|
||||
public:
|
||||
nsMsgQuoteListener();
|
||||
virtual ~nsMsgQuoteListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIMimeStreamConverterListener support
|
||||
NS_DECL_NSIMIMESTREAMCONVERTERLISTENER
|
||||
|
||||
void SetMsgQuote(nsMsgQuote * msgQuote);
|
||||
private:
|
||||
nsMsgQuote * mMsgQuote;
|
||||
};
|
||||
|
||||
class nsMsgQuote: public nsIMsgQuote {
|
||||
public:
|
||||
nsMsgQuote();
|
||||
|
@ -41,10 +60,12 @@ public:
|
|||
//
|
||||
nsFileSpec *mTmpFileSpec;
|
||||
nsIFileSpec *mTmpIFileSpec;
|
||||
nsCOMPtr<nsIStreamListener> mStreamListener;
|
||||
// nsCOMPtr<nsIStreamListener> mStreamListener;
|
||||
nsIStreamListener* mStreamListener;
|
||||
char *mURI;
|
||||
nsIMsgMessageService *mMessageService;
|
||||
PRBool mQuoteHeaders;
|
||||
nsMsgQuoteListener *mQuoteListener;
|
||||
};
|
||||
|
||||
// Will be used by factory to generate a nsMsgQuote class...
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsIMimeHeaders.idl"
|
||||
|
||||
interface nsIURI;
|
||||
|
||||
|
@ -44,6 +45,11 @@ interface nsMimeOutput
|
|||
const long nsMimeUnknown = 9;
|
||||
};
|
||||
|
||||
[scriptable, uuid(FA81CAA0-6261-11d3-8311-00805F2A0107)]
|
||||
interface nsIMimeStreamConverterListener : nsISupports{
|
||||
void onHeadersReady(in nsIMimeHeaders headers);
|
||||
};
|
||||
|
||||
[scriptable, uuid(E4ED8892-3F9E-11d3-9896-001083010E9B)]
|
||||
interface nsIMimeStreamConverter : nsISupports {
|
||||
|
||||
|
@ -60,4 +66,9 @@ interface nsIMimeStreamConverter : nsISupports {
|
|||
* with this input stream
|
||||
*/
|
||||
void SetStreamURI(in nsIURI aURI);
|
||||
|
||||
/*
|
||||
* This is used to extract headers while parsing a message
|
||||
*/
|
||||
void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener);
|
||||
};
|
||||
|
|
|
@ -556,6 +556,9 @@ mime_display_stream_complete (nsMIMESession *stream)
|
|||
// Release the prefs service
|
||||
if ( (obj) && (obj->options) && (obj->options->prefs) )
|
||||
nsServiceManager::ReleaseService(kPrefCID, obj->options->prefs);
|
||||
|
||||
if (msd->headers)
|
||||
MimeHeaders_free (msd->headers);
|
||||
|
||||
PR_FREEIF(msd);
|
||||
}
|
||||
|
@ -584,6 +587,9 @@ mime_display_stream_abort (nsMIMESession *stream, int status)
|
|||
}
|
||||
}
|
||||
|
||||
if (msd->headers)
|
||||
MimeHeaders_free (msd->headers);
|
||||
|
||||
PR_FREEIF(msd);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ struct mime_stream_data { /* This struct is the state we pass around
|
|||
nsMIMESession *istream; /* Holdover - new stream we're writing out image data-if any. */
|
||||
MimeObject *obj; /* The root parser object */
|
||||
MimeDisplayOptions *options; /* Data for communicating with libmime.a */
|
||||
MimeHeaders *headers; /* Copy of outer most mime header */
|
||||
|
||||
/* These are used by FO_QUOTE_HTML_MESSAGE stuff only: */
|
||||
PRInt16 lastcsid; /* csid corresponding to above. */
|
||||
|
|
|
@ -233,13 +233,14 @@ MimeMessage_close_headers (MimeObject *obj)
|
|||
#ifdef MIME_DRAFTS
|
||||
if (outer_p &&
|
||||
obj->options &&
|
||||
obj->options->decompose_file_p &&
|
||||
(obj->options->decompose_file_p || obj->options->caller_need_root_headers) &&
|
||||
obj->options->decompose_headers_info_fn)
|
||||
{
|
||||
#ifdef MOZ_SECURITY
|
||||
HG09091
|
||||
#endif /* MOZ_SECURITY */
|
||||
status = obj->options->decompose_headers_info_fn (
|
||||
if (!obj->options->caller_need_root_headers || (obj == obj->options->state->root))
|
||||
status = obj->options->decompose_headers_info_fn (
|
||||
obj->options->stream_closure,
|
||||
msg->hdrs );
|
||||
}
|
||||
|
|
|
@ -372,6 +372,10 @@ struct MimeDisplayOptions
|
|||
PRBool signed_p; /* to tell draft this is a signed
|
||||
message */
|
||||
|
||||
PRBool caller_need_root_headers; /* set it to true to receive the message main
|
||||
headers through the callback
|
||||
decompose_headers_info_fn */
|
||||
|
||||
/* Callback to gather the outer most headers so we could use the
|
||||
information to initialize the addressing/subject/newsgroups fields
|
||||
for the composition window. */
|
||||
|
|
|
@ -49,6 +49,9 @@ static NS_DEFINE_CID(kCMsgHeaderParserCID, NS_MSGHEADERPARSER_CID);
|
|||
#include "nsMimeURLUtils.h"
|
||||
static NS_DEFINE_CID(kCIMimeURLUtilsCID, NS_IMIME_URLUTILS_CID);
|
||||
|
||||
#include "nsIMimeHeaders.h"
|
||||
static NS_DEFINE_CID(kCIMimeHeadersCID, NS_IMIMEHEADERS_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -157,6 +160,10 @@ nsresult nsMimeFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, v
|
|||
{
|
||||
return res = NS_NewStreamConverter(aIID, aResult);
|
||||
}
|
||||
else if (mClassID.Equals(kCIMimeHeadersCID))
|
||||
{
|
||||
return res = NS_NewMimeHeaders(aIID, aResult);
|
||||
}
|
||||
|
||||
// End of checking the interface ID code....
|
||||
if (inst)
|
||||
|
@ -249,6 +256,13 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *
|
|||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) finalResult = rv;
|
||||
|
||||
// The interface for URL utils
|
||||
rv = compMgr->RegisterComponent(kCIMimeHeadersCID,
|
||||
"Mime Headers",
|
||||
nsnull,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) finalResult = rv;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
|
@ -270,6 +284,8 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char
|
|||
if (NS_FAILED(rv)) finalResult = rv;
|
||||
rv = compMgr->UnregisterComponent(kCStreamConverterCID, path);
|
||||
if (NS_FAILED(rv)) finalResult = rv;
|
||||
rv = compMgr->UnregisterComponent(kCIMimeHeadersCID, path);
|
||||
if (NS_FAILED(rv)) finalResult = rv;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,49 @@ bridge_new_new_uri(void *bridgeStream, nsIURI *aURI)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
mime_headers_callback ( void *closure, MimeHeaders *headers )
|
||||
{
|
||||
struct mime_stream_data *msd = (struct mime_stream_data *)closure;
|
||||
|
||||
PR_ASSERT ( msd && headers );
|
||||
|
||||
if ( !msd || ! headers )
|
||||
return 0;
|
||||
|
||||
PR_ASSERT ( msd->headers == NULL );
|
||||
msd->headers = MimeHeaders_copy ( headers );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
bridge_set_mime_stream_converter_listener(void *bridgeStream, nsIMimeStreamConverterListener* listener)
|
||||
{
|
||||
nsMIMESession *session = (nsMIMESession *)bridgeStream;
|
||||
|
||||
if (session)
|
||||
{
|
||||
struct mime_stream_data *msd = (struct mime_stream_data *)session->data_object;
|
||||
if (msd)
|
||||
{
|
||||
if (listener)
|
||||
{
|
||||
msd->options->caller_need_root_headers = PR_TRUE;
|
||||
msd->options->decompose_headers_info_fn = mime_headers_callback;
|
||||
}
|
||||
else
|
||||
{
|
||||
msd->options->caller_need_root_headers = PR_FALSE;
|
||||
msd->options->decompose_headers_info_fn = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Utility routines needed by this interface...
|
||||
//
|
||||
|
@ -283,6 +326,7 @@ nsStreamConverter::nsStreamConverter()
|
|||
mOutputFormat = PL_strdup("text/html");
|
||||
mDoneParsing = PR_FALSE;
|
||||
mAlreadyKnowOutputType = PR_FALSE;
|
||||
mMimeStreamConverterListener = nsnull;
|
||||
}
|
||||
|
||||
nsStreamConverter::~nsStreamConverter()
|
||||
|
@ -438,7 +482,12 @@ NS_IMETHODIMP nsStreamConverter::Init(nsIURI *aURI, nsIStreamListener * aOutList
|
|||
if (!mBridgeStream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
else
|
||||
{
|
||||
//Do we need to setup an Mime Stream Converter Listener?
|
||||
if (mMimeStreamConverterListener)
|
||||
bridge_set_mime_stream_converter_listener((nsMIMESession *)mBridgeStream, mMimeStreamConverterListener);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsStreamConverter::GetContentType(char **aOutputContentType)
|
||||
|
@ -494,6 +543,14 @@ nsStreamConverter::SetStreamURI(nsIURI *aURI)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsStreamConverter::SetMimeHeadersListener(nsIMimeStreamConverterListener *listener)
|
||||
{
|
||||
mMimeStreamConverterListener = listener;
|
||||
bridge_set_mime_stream_converter_listener((nsMIMESession *)mBridgeStream, listener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Methods for nsIStreamListener...
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -596,6 +653,30 @@ nsStreamConverter::OnStopRequest(nsIChannel * aChannel, nsISupports *ctxt, nsres
|
|||
if (mBridgeStream)
|
||||
{
|
||||
nsMIMESession *tSession = (nsMIMESession *) mBridgeStream;
|
||||
|
||||
if (mMimeStreamConverterListener)
|
||||
{
|
||||
struct mime_stream_data *msd = (struct mime_stream_data *)tSession->data_object;
|
||||
if (msd)
|
||||
{
|
||||
static NS_DEFINE_CID(kCIMimeHeadersCID, NS_IMIMEHEADERS_CID);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMimeHeaders> mimeHeaders;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kCIMimeHeadersCID,
|
||||
nsnull, nsCOMTypeInfo<nsIMimeHeaders>::GetIID(),
|
||||
(void **) getter_AddRefs(mimeHeaders));
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
mimeHeaders->Initialize(msd->headers->all_headers);
|
||||
mMimeStreamConverterListener->OnHeadersReady(mimeHeaders);
|
||||
}
|
||||
else
|
||||
mMimeStreamConverterListener->OnHeadersReady(nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
tSession->complete((nsMIMESession *)mBridgeStream);
|
||||
}
|
||||
|
||||
|
@ -617,6 +698,7 @@ nsStreamConverter::OnStopRequest(nsIChannel * aChannel, nsISupports *ctxt, nsres
|
|||
// forward on top request to any listeners
|
||||
if (mOutListener)
|
||||
mOutListener->OnStopRequest(mOutgoingChannel, ctxt, status, errorMsg);
|
||||
|
||||
|
||||
mAlreadyKnowOutputType = PR_FALSE;
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
NS_IMETHOD SetMimeOutputType(nsMimeOutputType aType);
|
||||
NS_IMETHOD GetMimeOutputType(nsMimeOutputType *aOutFormat);
|
||||
NS_IMETHOD SetStreamURI(nsIURI *aURI);
|
||||
NS_IMETHOD SetMimeHeadersListener(nsIMimeStreamConverterListener* listener);
|
||||
|
||||
// nsIStreamConverter methods
|
||||
NS_DECL_NSISTREAMCONVERTER
|
||||
|
@ -81,6 +82,7 @@ private:
|
|||
PRBool mWrapperOutput; // Should we output the frame split message display
|
||||
PRBool mDoneParsing; // If this is true, we've already been told by libmime to stop sending
|
||||
// data so don't feed the parser any more!
|
||||
nsIMimeStreamConverterListener* mMimeStreamConverterListener;
|
||||
};
|
||||
|
||||
// factory method
|
||||
|
|
Загрузка…
Ссылка в новой задаче