diff --git a/mailnews/compose/build/makefile.win b/mailnews/compose/build/makefile.win index 98f483d4c4d..1dcd1e9f5a0 100644 --- a/mailnews/compose/build/makefile.win +++ b/mailnews/compose/build/makefile.win @@ -104,6 +104,7 @@ LINCS=$(LINCS) -I, \ -I$(PUBLIC)\dom \ -I$(PUBLIC)\appcores \ -I$(PUBLIC)\mime \ + -I$(PUBLIC)\security \ $(NULL) #//------------------------------------------------------------------------ diff --git a/mailnews/compose/public/MsgCompGlue.h b/mailnews/compose/public/MsgCompGlue.h index d75677046af..1825451ae0c 100644 --- a/mailnews/compose/public/MsgCompGlue.h +++ b/mailnews/compose/public/MsgCompGlue.h @@ -264,18 +264,6 @@ public: #define FE_Alert(a, b) printf("ALERT: %s", b) -/* The three ways to deliver a message. - */ -typedef enum -{ - MSG_DeliverNow, - MSG_QueueForLater, - MSG_Save, - MSG_SaveAs, - MSG_SaveAsDraft, - MSG_SaveAsTemplate -} MSG_Deliver_Mode; - #define msg_InterruptContext(a, b) /*NYI*/ #define msg_GetDummyEnvelope() NULL #define msg_IsSummaryValid(a, b) PR_FALSE diff --git a/mailnews/compose/public/nsIDOMComposeAppCore.h b/mailnews/compose/public/nsIDOMComposeAppCore.h index 793fbe9535b..6bd9757f772 100644 --- a/mailnews/compose/public/nsIDOMComposeAppCore.h +++ b/mailnews/compose/public/nsIDOMComposeAppCore.h @@ -47,8 +47,8 @@ class nsIDOMComposeAppCore : public nsIDOMBaseAppCore { /* void NewMessage (in nsAutoString url, in nsAutoString args, in nsIDOMXULTreeElement tree, in nsIDOMNodeList node, in nsIDOMMsgAppCore msgAppCore, in long messageType); */ NS_IMETHOD NewMessage(nsAutoString& url, nsAutoString& args, nsIDOMXULTreeElement *tree, nsIDOMNodeList *node, nsIDOMMsgAppCore *msgAppCore, PRInt32 messageType) = 0; - /* void SendMessage (in nsAutoString addrTo, in nsAutoString addrCc, in nsAutoString addrBcc, in nsAutoString newsgroup, in nsAutoString subject, in nsAutoString msg); */ - NS_IMETHOD SendMessage(nsAutoString& addrTo, nsAutoString& addrCc, nsAutoString& addrBcc, nsAutoString& newsgroup, nsAutoString& subject, nsAutoString& msg) = 0; + /* void SendMsg (in nsAutoString addrTo, in nsAutoString addrCc, in nsAutoString addrBcc, in nsAutoString newsgroup, in nsAutoString subject, in nsAutoString msg); */ + NS_IMETHOD SendMsg(nsAutoString& addrTo, nsAutoString& addrCc, nsAutoString& addrBcc, nsAutoString& newsgroup, nsAutoString& subject, nsAutoString& msg) = 0; /* long SendMessage2 (); */ NS_IMETHOD SendMessage2(PRInt32 *_retval) = 0; diff --git a/mailnews/compose/public/nsIMsgSend.h b/mailnews/compose/public/nsIMsgSend.h index 06e5c32d686..cb97095844b 100644 --- a/mailnews/compose/public/nsIMsgSend.h +++ b/mailnews/compose/public/nsIMsgSend.h @@ -8,11 +8,111 @@ #include "nsISupports.h" /* interface nsISupports */ #include "nsIMsgCompFields.h" /* interface nsIMsgCompFields */ #include "nsID.h" /* interface nsID */ +#include "rosetta.h" #ifdef XPIDL_JS_STUBS #include "jsapi.h" #endif +typedef enum +{ + nsMsgDeliverNow, + nsMsgQueueForLater, + nsMsgSave, + nsMsgSaveAs, + nsMsgSaveAsDraft, + nsMsgSaveAsTemplate +} nsMsgDeliverMode; + +struct nsMsgAttachmentData +{ + char *url; /* The URL to attach. + This should be 0 to signify "end of list". + */ + + char *desired_type; /* The type to which this document should be + converted. Legal values are NULL, TEXT_PLAIN + and APPLICATION_POSTSCRIPT (which are macros + defined in net.h); other values are ignored. + */ + + char *real_type; /* The type of the URL if known, otherwise NULL. + For example, if you were attaching a temp file + which was known to contain HTML data, you would + pass in TEXT_HTML as the real_type, to override + whatever type the name of the tmp file might + otherwise indicate. + */ + char *real_encoding; /* Goes along with real_type */ + + char *real_name; /* The original name of this document, which will + eventually show up in the Content-Disposition + header. For example, if you had copied a + document to a tmp file, this would be the + original, human-readable name of the document. + */ + + char *description; /* If you put a string here, it will show up as + the Content-Description header. This can be + any explanatory text; it's not a file name. + */ + + char *x_mac_type, *x_mac_creator; + /* Mac-specific data that should show up as optional parameters + to the content-type header. + */ +}; + + +/* This structure is the interface between compose.c and composew.c. + When we have downloaded a URL to a tmp file for attaching, this + represents everything we learned about it (and did to it) in the + process. + */ +/* Used by libmime -- mimedrft.c + * Front end shouldn't use this structure. + */ +typedef struct nsMsgAttachedFile +{ + char *orig_url; /* Where it came from on the network (or even elsewhere + on the local disk.) + */ + char *file_name; /* The tmp file in which the (possibly converted) data + now resides. + */ + char *type; /* The type of the data in file_name (not necessarily + the same as the type of orig_url.) + */ + char *encoding; /* Likewise, the encoding of the tmp file. + This will be set only if the original document had + an encoding already; we don't do base64 encoding and + so forth until it's time to assemble a full MIME + message of all parts. + */ + + /* #### I'm not entirely sure where this data is going to come from... + */ + char *description; /* For Content-Description header */ + char *x_mac_type, *x_mac_creator; /* mac-specific info */ + char *real_name; /* The real name of the file. */ + + /* Some statistics about the data that was written to the file, so that when + it comes time to compose a MIME message, we can make an informed decision + about what Content-Transfer-Encoding would be best for this attachment. + (If it's encoded already, we ignore this information and ship it as-is.) + */ + uint32 size; + uint32 unprintable_count; + uint32 highbit_count; + uint32 ctl_count; + uint32 null_count; + uint32 max_line_length; + + HG68452 + +} nsMsgAttachedFile; + + /* starting interface: nsIMsgSend */ /* {9E9BD970-C5D6-11d2-8297-000000000000} */ @@ -25,8 +125,20 @@ class nsIMsgSend : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMSGSEND_IID) - /* void SendMessage (in nsIMsgCompFields fields, in string smtp); */ - NS_IMETHOD SendMessage(nsIMsgCompFields *fields, const char *smtp) = 0; + NS_IMETHOD SendMessage( + nsIMsgCompFields *fields, + const char *smtp, + PRBool digest_p, + PRBool dont_deliver_p, + PRInt32 mode, + const char *attachment1_type, + const char *attachment1_body, + PRUint32 attachment1_body_length, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, + void *relatedPart, /* nsMsgSendPart */ + void (*message_delivery_done_callback)(void *context, void *fe_data, + int status, const char *error_message)) = 0; #ifdef XPIDL_JS_STUBS static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx); diff --git a/mailnews/compose/src/msgCompGlue.cpp b/mailnews/compose/src/msgCompGlue.cpp index d850baa4aec..73ffa30007e 100644 --- a/mailnews/compose/src/msgCompGlue.cpp +++ b/mailnews/compose/src/msgCompGlue.cpp @@ -24,7 +24,6 @@ void FE_UpdateCompToolbar(MSG_Pane*) {return;} void FE_SetWindowLoading(MWContext *, URL_Struct *,Net_GetUrlExitFunc **) {return;} XP_Bool NET_AreThereActiveConnectionsForWindow(MWContext *) {return PR_FALSE;} int NET_SilentInterruptWindow(MWContext * window_id) {return 0;} -int NET_ScanForURLs(MSG_Pane*, const char *, PRInt32,char *, int, PRBool) {return nsnull;} void NET_FreeURLStruct (URL_Struct *) {return;} URL_Struct *NET_CreateURLStruct (const char *, NET_ReloadMethod) {return NULL;} char * NET_ParseURL (const char *, int ) {return NULL;} @@ -32,7 +31,6 @@ int NET_URL_Type (const char *) {return nsnull;} XP_Bool NET_IsLocalFileURL(char *address) {return PR_TRUE;} int NET_InterruptWindow(MWContext * window_id) {return 0;} XP_Bool NET_IsOffline() {return PR_FALSE;} -char* NET_ScanHTMLForURLs(const char* input) {return NULL;} XP_FILE_URL_PATH XP_PlatformFileToURL (const XP_FILE_NATIVE_PATH ) {return NULL;} MWContext *XP_FindContextOfType(MWContext *, MWContextType) {return NULL;} diff --git a/mailnews/compose/src/nsComposeAppCore.cpp b/mailnews/compose/src/nsComposeAppCore.cpp index 1d8bf6e8a2e..2db0ef09c6e 100644 --- a/mailnews/compose/src/nsComposeAppCore.cpp +++ b/mailnews/compose/src/nsComposeAppCore.cpp @@ -27,6 +27,7 @@ #include "nsIDOMXULDocument.h" #include "nsIDOMNodeList.h" #include "nsIScriptContextOwner.h" +#include "nsMsgSend.h" /* rhp - for access to webshell */ #include "prmem.h" @@ -137,7 +138,7 @@ public: nsIDOMNodeList *nodeList, nsIDOMMsgAppCore * msgAppCore, PRInt32 messageType); - NS_IMETHOD SendMessage(nsAutoString& aAddrTo, nsAutoString& aAddrCc, + NS_IMETHOD SendMsg(nsAutoString& aAddrTo, nsAutoString& aAddrCc, nsAutoString& aAddrBcc, nsAutoString& aAddrNewsgroup, nsAutoString& aSubject, @@ -767,12 +768,12 @@ done: } -NS_IMETHODIMP nsComposeAppCore::SendMessage(nsAutoString& aAddrTo, - nsAutoString& aAddrCc, - nsAutoString& aAddrBcc, - nsAutoString& aAddrNewsgroup, - nsAutoString& aSubject, - nsAutoString& aMsg) +NS_IMETHODIMP nsComposeAppCore::SendMsg(nsAutoString& aAddrTo, + nsAutoString& aAddrCc, + nsAutoString& aAddrBcc, + nsAutoString& aAddrNewsgroup, + nsAutoString& aSubject, + nsAutoString& aMsg) { nsMsgCompPrefs pCompPrefs; char* pUserEmail = nsnull; @@ -855,7 +856,21 @@ NS_IMETHODIMP nsComposeAppCore::SendMessage(nsAutoString& aAddrTo, mMsgCompFields->SetBody(nsAutoCString(aMsg), NULL); if (mMsgSend) - mMsgSend->SendMessage(mMsgCompFields, NULL); + { + mMsgSend->SendMessage(mMsgCompFields, + "", // const char *smtp, + PR_FALSE, // PRBool digest_p, + PR_FALSE, // PRBool dont_deliver_p, + nsMsgDeliverNow, // nsMsgDeliverMode mode, + TEXT_HTML, // const char *attachment1_type, + nsAutoCString(aMsg), // const char *attachment1_body, + PL_strlen(nsAutoCString(aMsg)), // PRUint32 attachment1_body_length, + NULL, // const struct nsMsgAttachmentData *attachments, + NULL, // const struct nsMsgAttachedFile *preloaded_attachments, + NULL, // nsMsgSendPart *relatedPart, + NULL); // void (*message_delivery_done_callback)(MWContext *context, void *fe_data, + // int status, const char *error_message)) + } } if (nsnull != mScriptContext) { const char* url = ""; @@ -928,7 +943,7 @@ NS_IMETHODIMP nsComposeAppCore::SendMessage2(PRInt32 * _retval) if (mEditor) { mEditor->GetContentsAsText(msgBody); - SendMessage(msgTo, msgCc, msgBcc, msgNewsgroup, msgSubject, msgBody); + SendMsg(msgTo, msgCc, msgBcc, msgNewsgroup, msgSubject, msgBody); } } } diff --git a/mailnews/compose/src/nsJSComposeAppCore.cpp b/mailnews/compose/src/nsJSComposeAppCore.cpp index 1d831009355..321382da516 100644 --- a/mailnews/compose/src/nsJSComposeAppCore.cpp +++ b/mailnews/compose/src/nsJSComposeAppCore.cpp @@ -346,7 +346,7 @@ ComposeAppCoreSendMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, nsJSUtils::nsConvertJSValToString(b4, cx, argv[4]); nsJSUtils::nsConvertJSValToString(b5, cx, argv[5]); - if (NS_OK != nativeThis->SendMessage(b0, b1, b2, b3, b4, b5)) { + if (NS_OK != nativeThis->SendMsg(b0, b1, b2, b3, b4, b5)) { return JS_FALSE; } diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index eee1fd3fe77..3f230f7e396 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -18,48 +18,17 @@ #include "rosetta_mailnews.h" #include "nsMsgSend.h" +#include "nsMsgSendPart.h" #include "nsMsgComposeFact.h" #include "nsMsgCompPrefs.h" #include "nsMsgCompose.h" #include "nsEscape.h" #include "nsIMsgHeaderParser.h" +#include "nsIMimeURLUtils.h" +#include "nsQuickSort.h" static NS_DEFINE_CID(kCMsgHeaderParserCID, NS_MSGHEADERPARSER_CID); - -/*JFD -#include "msg.h" -#include "errcode.h" -#include "dberror.h" - -#include "mime.h" -#include "shist.h" -#include "xlate.h" -#include "bkmks.h" -#include "libi18n.h" -#include "xpgetstr.h" - -#include "msgsec.h" -#include "msgcpane.h" -#include "msgprefs.h" -#include "msgsec.h" -#include "msgcflds.h" -#include "msgimap.h" -#include "msgurlq.h" -#include "maildb.h" -#include "abcom.h" -#include "dirprefs.h" - -#include "edt.h" // to invoke save on the html compose pane -#include "mhtmlstm.h" - -#include "prefapi.h" -#include "htmldlgs.h" -#include "hosttbl.h" -#include "newshost.h" -#include "intl_csi.h" -*/ - -#include "nsQuickSort.h" +static NS_DEFINE_CID(kCMimeURLUtilsCID, NS_IMIME_URLUTILS_CID); #ifdef UNREADY_CODE HJ04305 @@ -322,13 +291,13 @@ MSG_HTMLRecipients::FreeChangedList(char** list) } -static void msg_free_attachment_list(struct MSG_AttachmentData *list); +static void msg_free_attachment_list(struct nsMsgAttachmentData *list); /*JFD static void -msg_delete_attached_files(struct MSG_AttachedFile *attachments) +msg_delete_attached_files(struct nsMsgAttachedFile *attachments) { - struct MSG_AttachedFile *tmp; + struct nsMsgAttachedFile *tmp; if (!attachments) return; for (tmp = attachments; tmp->orig_url; tmp++) { PR_FREEIF(tmp->orig_url); @@ -371,7 +340,7 @@ nsMsgCompose::nsMsgCompose() m_deliveryInProgress = PR_FALSE; m_attachmentInProgress = PR_FALSE; m_pendingAttachmentsCount = 0; - m_deliver_mode = MSG_DeliverNow; + m_deliver_mode = nsMsgDeliverNow; m_cited = PR_FALSE; m_duplicatePost = PR_FALSE; m_htmlaction = MSG_HTMLAskUser; @@ -443,7 +412,7 @@ nsresult nsMsgCompose::Initialize(/*MWContext**/PRInt32 old_context, nsIMsgCompF InitializeHeaders((MWContext*)old_context, fields); m_visible_headers = GetInterestingHeaders(); - m_deliver_mode = MSG_DeliverNow; + m_deliver_mode = nsMsgDeliverNow; m_haveAttachedVcard = PR_FALSE; m_fields->SetForcePlainText(PR_FALSE); // Coming into us, this field meant @@ -588,43 +557,43 @@ int nsMsgCompose::CreateVcardAttachment () char * origurl = XP_PlatformFileToURL (vCardFileName); int datacount = 0, filecount = 0; - for (MSG_AttachmentData *tmp1 = m_attachData; tmp1 && tmp1->url; tmp1++) datacount++; - for (MSG_AttachedFile *tmp = m_attachedFiles; tmp && tmp->orig_url; tmp++) filecount++; + for (nsMsgAttachmentData *tmp1 = m_attachData; tmp1 && tmp1->url; tmp1++) datacount++; + for (nsMsgAttachedFile *tmp = m_attachedFiles; tmp && tmp->orig_url; tmp++) filecount++; - MSG_AttachmentData *alist; + nsMsgAttachmentData *alist; if (datacount) { - alist = (MSG_AttachmentData *) - PR_REALLOC(m_attachData, (datacount + 2) * sizeof(MSG_AttachmentData)); + alist = (nsMsgAttachmentData *) + PR_REALLOC(m_attachData, (datacount + 2) * sizeof(nsMsgAttachmentData)); } else { - alist = (MSG_AttachmentData *) - PR_Malloc((datacount + 2) * sizeof(MSG_AttachmentData)); + alist = (nsMsgAttachmentData *) + PR_Malloc((datacount + 2) * sizeof(nsMsgAttachmentData)); } if (!alist) return MK_OUT_OF_MEMORY; m_attachData = alist; - memset (m_attachData + datacount, 0, 2 * sizeof (MSG_AttachmentData)); + memset (m_attachData + datacount, 0, 2 * sizeof (nsMsgAttachmentData)); m_attachData[datacount].url = fileurl; m_attachData[datacount].real_type = PL_strdup(vCardMimeFormat); m_attachData[datacount].description = PL_strdup (buf); m_attachData[datacount].real_name = PL_strdup (vCardFileName); m_attachData[datacount + 1].url = NULL; - MSG_AttachedFile *aflist; + nsMsgAttachedFile *aflist; if (filecount) { - aflist = (struct MSG_AttachedFile *) - PR_REALLOC(m_attachedFiles, (filecount + 2) * sizeof(MSG_AttachedFile)); + aflist = (struct nsMsgAttachedFile *) + PR_REALLOC(m_attachedFiles, (filecount + 2) * sizeof(nsMsgAttachedFile)); } else { - aflist = (struct MSG_AttachedFile *) - PR_Malloc((filecount + 2) * sizeof(MSG_AttachedFile)); + aflist = (struct nsMsgAttachedFile *) + PR_Malloc((filecount + 2) * sizeof(nsMsgAttachedFile)); } if (!aflist) return MK_OUT_OF_MEMORY; m_attachedFiles = aflist; - memset (m_attachedFiles + filecount, 0, 2 * sizeof (MSG_AttachedFile)); + memset (m_attachedFiles + filecount, 0, 2 * sizeof (nsMsgAttachedFile)); m_attachedFiles[filecount].orig_url = origurl; m_attachedFiles[filecount].file_name = filename; m_attachedFiles[filecount].type = PL_strdup(vCardMimeFormat); @@ -742,7 +711,7 @@ nsMsgCompose::GetCommandStatus(MSG_CommandType command, if (m_attachmentInProgress || m_deliveryInProgress) selectable_p = PR_FALSE; break; - case MSG_Save: + case nsMsgSave: case MSG_SaveDraft: case MSG_SaveDraftThenClose: #ifdef UNREADY_CODE @@ -879,7 +848,7 @@ nsMsgCompose::DoCommand(MSG_CommandType command, nsMsgViewIndex* indices, case MSG_SendMessageLater: status = QueueMessageForLater();/* ###tw Error-return-type mismatch! */ break; - case MSG_Save: + case nsMsgSave: status = SaveMessage(); break; case MSG_SaveDraft: @@ -1029,8 +998,8 @@ nsMsgCompose::InitializeHeaders(MWContext* old_context, const nsIMsgCompFields* if (count > 0) { // if forwarding one or more messages PR_ASSERT(*attachment == '\0'); - MSG_AttachmentData *alist = (struct MSG_AttachmentData *) - PR_Malloc((count + 1) * sizeof(MSG_AttachmentData)); + nsMsgAttachmentData *alist = (struct nsMsgAttachmentData *) + PR_Malloc((count + 1) * sizeof(nsMsgAttachmentData)); if (alist) { memset(alist, 0, (count + 1) * sizeof(*alist)); for (count--; count >= 0; count--) { @@ -1045,10 +1014,10 @@ nsMsgCompose::InitializeHeaders(MWContext* old_context, const nsIMsgCompFields* } else if (*attachment) { // forwarding a single url // typically a web page - MSG_AttachmentData *alist; + nsMsgAttachmentData *alist; count = 1; - alist = (struct MSG_AttachmentData *) - PR_Malloc((count + 1) * sizeof(MSG_AttachmentData)); + alist = (struct nsMsgAttachmentData *) + PR_Malloc((count + 1) * sizeof(nsMsgAttachmentData)); if (alist) { memset(alist, 0, (count + 1) * sizeof(*alist)); alist[0].url = (char *)attachment; @@ -1620,9 +1589,17 @@ QuotePlainIntoHTML::QuoteLine(char* line, PRUint32 length) delete [] m_outbuf; m_outbuf = new char [m_outbufsize]; } - if (m_outbuf) { + if (m_outbuf) + { + nsCOMPtr myURLUtil; + int res = nsComponentManager::CreateInstance(kCMimeURLUtilsCID, + NULL, nsIMimeURLUtils::GetIID(), + (void **) getter_AddRefs(myURLUtil)); + if (!NS_SUCCEEDED(res)) + return 0; + *m_outbuf = '\0'; -//JFD NET_ScanForURLs(NULL, line, length, m_outbuf, m_outbufsize, PR_TRUE); + myURLUtil->ScanForURLs(line, length, m_outbuf, m_outbufsize, PR_TRUE); EDT_PasteQuote(m_context, m_outbuf); } return 0; @@ -1879,11 +1856,11 @@ nsMsgCompose::PastePlaintextQuotation(const char* str) int -nsMsgCompose::SetAttachmentList(struct MSG_AttachmentData* list) +nsMsgCompose::SetAttachmentList(struct nsMsgAttachmentData* list) { int count = 0; - MSG_AttachmentData *tmp; - MSG_AttachmentData *tmp2; + nsMsgAttachmentData *tmp; + nsMsgAttachmentData *tmp2; int status = 0; ClearCompositionMessageID(); /* Since the attachment list has changed, @@ -1897,8 +1874,8 @@ nsMsgCompose::SetAttachmentList(struct MSG_AttachmentData* list) for (tmp = list; tmp && tmp->url; tmp++) count++; if (count > 0) { - m_attachData = (MSG_AttachmentData*) - PR_Malloc((count + 1) * sizeof(MSG_AttachmentData)); + m_attachData = (nsMsgAttachmentData*) + PR_Malloc((count + 1) * sizeof(nsMsgAttachmentData)); if (!m_attachData) { #ifdef UNREADY_CODE FE_Alert(m_context, XP_GetString(MK_OUT_OF_MEMORY)); @@ -1906,7 +1883,7 @@ nsMsgCompose::SetAttachmentList(struct MSG_AttachmentData* list) return MK_OUT_OF_MEMORY; } - memset(m_attachData, 0, (count + 1) * sizeof(MSG_AttachmentData)); + memset(m_attachData, 0, (count + 1) * sizeof(nsMsgAttachmentData)); } if (count > 0) { @@ -1945,7 +1922,7 @@ nsMsgCompose::NoPendingAttachments() const return (m_pendingAttachmentsCount == 0); } -const struct MSG_AttachmentData * +const struct nsMsgAttachmentData * nsMsgCompose::GetAttachmentList() { if (m_attachData && m_attachData[0].url != NULL) return m_attachData; @@ -1954,9 +1931,9 @@ nsMsgCompose::GetAttachmentList() static void -msg_free_attachment_list(struct MSG_AttachmentData *list) +msg_free_attachment_list(struct nsMsgAttachmentData *list) { - MSG_AttachmentData* tmp; + nsMsgAttachmentData* tmp; if (!list) return; for (tmp = list ; tmp->url ; tmp++) { PR_Free((char*) tmp->url); @@ -1977,8 +1954,8 @@ msg_free_attachment_list(struct MSG_AttachmentData *list) URL (in source and type-conversion.) */ static PRBool -msg_attachments_match (MSG_AttachmentData *attachment, - MSG_AttachedFile *file) +msg_attachments_match (nsMsgAttachmentData *attachment, + nsMsgAttachedFile *file) { const char *dt; PR_ASSERT(attachment && file); @@ -2015,9 +1992,9 @@ nsMsgCompose::DownloadAttachments() int attachment_count = 0; int new_download_count = 0; int download_overlap_count = 0; - MSG_AttachmentData *tmp; - MSG_AttachmentData *downloads = 0; - MSG_AttachedFile *tmp2; + nsMsgAttachmentData *tmp; + nsMsgAttachmentData *downloads = 0; + nsMsgAttachedFile *tmp2; int returnValue = 0; // *** Relax the rule a little bit to enable resume downloading at @@ -2081,11 +2058,11 @@ nsMsgCompose::DownloadAttachments() /* Now download any new files that are in the list. */ if (download_overlap_count != attachment_count) { - MSG_AttachmentData *dfp; + nsMsgAttachmentData *dfp; new_download_count = attachment_count - download_overlap_count; m_pendingAttachmentsCount = new_download_count; - downloads = (MSG_AttachmentData *) - PR_Malloc(sizeof(MSG_AttachmentData) * (new_download_count + 1)); + downloads = (nsMsgAttachmentData *) + PR_Malloc(sizeof(nsMsgAttachmentData) * (new_download_count + 1)); if (!downloads) { #ifdef UNREADY_CODE FE_Alert(m_context, XP_GetString(MK_OUT_OF_MEMORY)); @@ -2119,7 +2096,7 @@ nsMsgCompose::DownloadAttachments() /*JFD returnValue = msg_DownloadAttachments(this, this, downloads, #ifdef XP_OS2 - (void (_Optlink*) (MWContext*,void*,int,const char*,MSG_AttachedFile*)) + (void (_Optlink*) (MWContext*,void*,int,const char*,nsMsgAttachedFile*)) #endif nsMsgCompose::DownloadAttachmentsDone_S); */ @@ -2133,7 +2110,7 @@ nsMsgCompose::DownloadAttachmentsDone_S(MWContext *context, void *fe_data, int status, const char *error_message, - struct MSG_AttachedFile *attachments) + struct nsMsgAttachedFile *attachments) { ((nsMsgCompose*) fe_data)->DownloadAttachmentsDone(context, status, error_message, @@ -2143,14 +2120,14 @@ nsMsgCompose::DownloadAttachmentsDone_S(MWContext *context, void nsMsgCompose::DownloadAttachmentsDone(MWContext* context, int status, const char* error_message, - struct MSG_AttachedFile *attachments) + struct nsMsgAttachedFile *attachments) { PR_ASSERT(context == m_context); int i, old_count = 0; int new_count = 0; - struct MSG_AttachedFile *tmp; - MSG_AttachedFile *newd; + struct nsMsgAttachedFile *tmp; + nsMsgAttachedFile *newd; // *** Relax the rule a little bit to enable resume downloading at // *** send time. @@ -2174,10 +2151,10 @@ nsMsgCompose::DownloadAttachmentsDone(MWContext* context, int status, } if (old_count + new_count == 0) goto FAIL; - newd = (MSG_AttachedFile *) + newd = (nsMsgAttachedFile *) PR_REALLOC(m_attachedFiles, ((old_count + new_count + 1) - * sizeof(MSG_AttachedFile))); + * sizeof(nsMsgAttachedFile))); if (!newd) { status = MK_OUT_OF_MEMORY; @@ -2190,7 +2167,7 @@ nsMsgCompose::DownloadAttachmentsDone(MWContext* context, int status, memcpy(newd + old_count, attachments, - sizeof(MSG_AttachedFile) * (new_count + 1)); + sizeof(nsMsgAttachedFile) * (new_count + 1)); // memcpy doesn't allocate string, so do it for(i=0; im_folderInfo->SummaryChanged(); JFD*/ - if (m_deliver_mode == MSG_DeliverNow) + if (m_deliver_mode == nsMsgDeliverNow) { // If we're delivering the mail right now, tell the FE // the Sent folder has new counts @@ -2898,7 +2875,7 @@ JFD*/ folder->SummaryChanged(); */ } - else if (m_deliver_mode == MSG_QueueForLater) + else if (m_deliver_mode == nsMsgQueueForLater) { // If we're delivering the mail into the Outbox/queue folder, // tell the FE the Outbox folder has new counts @@ -2962,7 +2939,7 @@ nsMsgCompose::GetHTMLMarkup(void) } int -nsMsgCompose::DoneComposeMessage( MSG_Deliver_Mode deliver_mode ) +nsMsgCompose::DoneComposeMessage( nsMsgDeliverMode deliver_mode ) { int attachment_count = 0; PRBool digest_p = PR_FALSE; @@ -2978,9 +2955,9 @@ nsMsgCompose::DoneComposeMessage( MSG_Deliver_Mode deliver_mode ) if (groups && *groups && !m_host) m_host = InferNewsHost (groups); - if (m_markup && (deliver_mode != MSG_SaveAs && - deliver_mode != MSG_SaveAsDraft && - deliver_mode != MSG_SaveAsTemplate)) { + if (m_markup && (deliver_mode != nsMsgSaveAs && + deliver_mode != nsMsgSaveAsDraft && + deliver_mode != nsMsgSaveAsTemplate)) { MSG_HTMLComposeAction action = DetermineHTMLAction(); if (action == MSG_HTMLAskUser) { @@ -3059,7 +3036,7 @@ nsMsgCompose::DoneComposeMessage( MSG_Deliver_Mode deliver_mode ) ; if (m_attachData && m_attachData[0].url && m_attachData[1].url ) { - MSG_AttachmentData* s; + nsMsgAttachmentData* s; digest_p = PR_TRUE; for (s = m_attachData ; s->url ; s++) { /* When there are attachments, start out assuming it is a digest, @@ -3143,23 +3120,23 @@ nsMsgCompose::SendMessageNow() { PREF_SetBoolPref("network.online", PR_TRUE); // make sure we're online. // remember if we're queued so we know which folder - m_deliver_mode = MSG_DeliverNow; + m_deliver_mode = nsMsgDeliverNow; if (m_fields->GetAttachVCard()) CreateVcardAttachment(); // counts we need to update. - return DoneComposeMessage(MSG_DeliverNow); + return DoneComposeMessage(nsMsgDeliverNow); } int nsMsgCompose::QueueMessageForLater() { // remember if we're queued so we know which folder - m_deliver_mode = MSG_QueueForLater; + m_deliver_mode = nsMsgQueueForLater; if (m_fields->GetAttachVCard()) CreateVcardAttachment(); // counts we need to update. - return DoneComposeMessage(MSG_QueueForLater); + return DoneComposeMessage(nsMsgQueueForLater); } int @@ -3177,7 +3154,7 @@ nsMsgCompose::SaveMessage() else */ { - m_deliver_mode = MSG_SaveAsDraft; + m_deliver_mode = nsMsgSaveAsDraft; } return DoneComposeMessage(m_deliver_mode); @@ -3186,7 +3163,7 @@ nsMsgCompose::SaveMessage() MSG_CommandType nsMsgCompose::PreviousSaveCommand() { - if (m_deliver_mode == MSG_SaveAsTemplate) + if (m_deliver_mode == nsMsgSaveAsTemplate) return MSG_SaveTemplate; else return MSG_SaveDraft; @@ -3211,8 +3188,8 @@ nsMsgCompose::SaveMessageAsDraft() (MSG_FOLDER_FLAG_DRAFTS, PR_FALSE); } */ - m_deliver_mode = MSG_SaveAsDraft; - return DoneComposeMessage(MSG_SaveAsDraft); + m_deliver_mode = nsMsgSaveAsDraft; + return DoneComposeMessage(nsMsgSaveAsDraft); } int @@ -3231,7 +3208,7 @@ nsMsgCompose::SaveMessageAsTemplate() (MSG_FOLDER_FLAG_TEMPLATES, PR_FALSE); } */ - m_deliver_mode = MSG_SaveAsTemplate; + m_deliver_mode = nsMsgSaveAsTemplate; #ifdef SUPPORT_X_TEMPLATE_NAME char *defaultName = NULL; @@ -3248,7 +3225,7 @@ nsMsgCompose::SaveMessageAsTemplate() } #endif /* SUPPORT_X_TEMPLATE_NAME */ - return DoneComposeMessage(MSG_SaveAsTemplate); + return DoneComposeMessage(nsMsgSaveAsTemplate); } static int @@ -3487,8 +3464,8 @@ HJ53211 int nsMsgCompose::SetPreloadedAttachments ( MWContext *context, - struct MSG_AttachmentData *attachmentData, - struct MSG_AttachedFile *attachments, + struct nsMsgAttachmentData *attachmentData, + struct nsMsgAttachedFile *attachments, int attachments_count ) { PR_ASSERT ( context == m_context ); @@ -3500,8 +3477,8 @@ nsMsgCompose::SetPreloadedAttachments ( MWContext *context, PR_ASSERT ( m_attachData == NULL ); - m_attachData = (MSG_AttachmentData *) PR_Malloc ( (attachments_count+1) * - sizeof (MSG_AttachmentData) ); + m_attachData = (nsMsgAttachmentData *) PR_Malloc ( (attachments_count+1) * + sizeof (nsMsgAttachmentData) ); if ( !m_attachData ) { #ifdef UNREADY_CODE FE_Alert ( m_context, XP_GetString ( MK_OUT_OF_MEMORY ) ); @@ -3509,10 +3486,10 @@ nsMsgCompose::SetPreloadedAttachments ( MWContext *context, return MK_OUT_OF_MEMORY; } - memset (m_attachData, 0, (attachments_count +1) * sizeof (MSG_AttachmentData)); + memset (m_attachData, 0, (attachments_count +1) * sizeof (nsMsgAttachmentData)); memcpy ( m_attachData, attachmentData, - sizeof (MSG_AttachmentData) * attachments_count ); + sizeof (nsMsgAttachmentData) * attachments_count ); m_pendingAttachmentsCount = attachments_count; m_attachmentInProgress = PR_TRUE; @@ -3525,9 +3502,9 @@ nsMsgCompose::SetPreloadedAttachments ( MWContext *context, void nsMsgCompose::SetIMAPMessageUID ( nsMsgKey key ) { - PR_ASSERT (m_deliver_mode == MSG_SaveAsDraft || - m_deliver_mode == MSG_SaveAs || - m_deliver_mode == MSG_SaveAsTemplate); + PR_ASSERT (m_deliver_mode == nsMsgSaveAsDraft || + m_deliver_mode == nsMsgSaveAs || + m_deliver_mode == nsMsgSaveAsTemplate); PR_ASSERT(key != nsMsgKey_None); if (key == nsMsgKey_None) diff --git a/mailnews/compose/src/nsMsgCompose.h b/mailnews/compose/src/nsMsgCompose.h index 08a8ddc90ca..e69de29bb2d 100644 --- a/mailnews/compose/src/nsMsgCompose.h +++ b/mailnews/compose/src/nsMsgCompose.h @@ -1,317 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef _MsgCompose_H_ -#define _MsgCompose_H_ - - -#include "msgCore.h" -#include "prprf.h" /* should be defined into msgCore.h? */ -#include "net.h" /* should be defined into msgCore.h? */ -#include "MailNewsTypes.h" -#include "intl_csi.h" -#include "msgcom.h" - -#include "MsgCompGlue.h" - -//#include "nsMsgPtrArray.h" -#include "nsMsgHeaderMasks.h" -#include "nsMsgFolderFlags.h" - -#include "nsMsgCompFields.h" -#include "nsIMsgCompose.h" - -/*JFD -#include "msg.h" -#include "msgpane.h" -#include "xlate.h" -*/ - - -/* The MSG_REPLY_TYPE shares the same space as MSG_CommandType, to avoid - possible weird errors, but is restricted to the `composition' commands - (MSG_ReplyToSender through MSG_ForwardMessage.) - */ -typedef MSG_CommandType MSG_REPLY_TYPE; - - -struct MSG_AttachedFile; -typedef struct PrintSetup_ PrintSetup; -typedef struct _XPDialogState XPDialogState; - -HJ08142 -class MSG_NewsHost; -class MSG_HTMLRecipients; - -class nsMsgCompose : public nsIMsgCompose, public MSG_Pane { -public: - - nsMsgCompose(); - virtual ~nsMsgCompose(); - - /* this macro defines QueryInterface, AddRef and Release for this class */ - NS_DECL_ISUPPORTS - - NS_IMETHOD CreateAndInitialize(/*MWContext* */PRInt32 a_context, /* MWContext* */PRInt32 old_context, - /* MSG_Prefs* */PRInt32 prefs, nsIMsgCompFields* initfields, - /* MSG_Master* */PRInt32 master); - - // Or, if you prefer, construct using below constructor and be sure to - // soon call the Initialize() method: - - NS_IMETHOD Create(/* MWContext* */PRInt32 a_context, /* MSG_Prefs* */PRInt32 prefs, - /* MSG_Master* */PRInt32 master); - NS_IMETHOD Initialize(/* MWContext* */PRInt32 old_context, nsIMsgCompFields* initfields); - - NS_IMETHOD Dispose(); - - virtual MSG_PaneType GetPaneType(); - - virtual void NotifyPrefsChange(NotifyCode code); - - MSG_CommandType PreviousSaveCommand(); - - virtual nsresult GetCommandStatus(MSG_CommandType command, - const nsMsgViewIndex* indices, - PRInt32 numindices, - PRBool *selectable_p, - MSG_COMMAND_CHECK_STATE *selected_p, - const char **display_string, - PRBool * plural_p); - virtual nsresult DoCommand(MSG_CommandType command, - nsMsgViewIndex* indices, PRInt32 numindices); - - const char* GetDefaultURL(); - virtual void SetDefaultURL(const char *defaultUrl = NULL, - const char *htmlPart = NULL); - - - int SetCallbacks(MSG_CompositionPaneCallbacks* callbacks, void* closure); - - nsIMsgCompFields* GetInitialFields(); - - - MSG_HEADER_SET GetInterestingHeaders(); - int SetAttachmentList(struct MSG_AttachmentData*); - PRBool NoPendingAttachments() const; - char* GetAttachmentString(); - PRBool ShouldAutoQuote(); - const char* GetCompHeader(MSG_HEADER_SET); - PRInt32 SetCompHeader(MSG_HEADER_SET, const char*); - PRBool GetCompBoolHeader(MSG_BOOL_HEADER_SET); - PRInt32 SetCompBoolHeader(MSG_BOOL_HEADER_SET, PRBool); - const char* GetCompBody(); - int SetCompBody(const char*); - void ToggleCompositionHeader(PRUint32 header); - PRBool ShowingAllCompositionHeaders(); - PRBool ShowingCompositionHeader(PRUint32 mask); - PRBool GetHTMLMarkup(void); - void SetHTMLMarkup(PRBool flag); - nsresult QuoteMessage(int (*func)(void* closure, const char* data), - void* closure); - int PastePlaintextQuotation(const char* str); - const struct MSG_AttachmentData *GetAttachmentList(); - int DownloadAttachments(); - char* UpdateHeaderContents(MSG_HEADER_SET which_header, const char* value); - const char* GetWindowTitle(); - void SetBodyEdited(PRBool value); - void MailCompositionAllConnectionsComplete(); - void CheckExpansion(MSG_HEADER_SET header); - PRBool DeliveryInProgress(); - - int SendMessageNow(); - int QueueMessageForLater(); - int SaveMessage(); - int SaveMessageAsDraft(); - int SaveMessageAsTemplate(); - - PRBool IsDuplicatePost(); - const char* GetCompositionMessageID(); - void ClearCompositionMessageID(); - HJ13591 - HJ86782 - HJ02278 - HJ95534 - - int RemoveNoCertRecipients(); - - PRBool SanityCheckNewsgroups (const char *newsgroups); - int SanityCheck(int skippast); - - HJ42055 - - /* draft */ - int SetPreloadedAttachments ( MWContext *context, - struct MSG_AttachmentData *attachmentData, - struct MSG_AttachedFile *attachments, - int attachments_count ); - - virtual void SetIMAPMessageUID (nsMsgKey key); - - int RetrieveStandardHeaders(MSG_HeaderEntry ** return_list); - int SetHeaderEntries(MSG_HeaderEntry * in_list,int count); - void ClearComposeHeaders(); - - HJ37212 - HJ42256 - - int SetHTMLAction(MSG_HTMLComposeAction action) { - m_htmlaction = action; - return 0; - } - MSG_HTMLComposeAction GetHTMLAction() {return m_htmlaction;} - - int PutUpRecipientsDialog(void *pWnd = NULL); - - int ResultsRecipients(PRBool cancelled, PRInt32* nohtml, PRInt32* htmlok); - - PRBool m_confirmed_uuencode_p; // Have we confirmed sending uuencoded data? - - // For qutoing plain text to html then convert back to plain text - void SetLineWidth(int width) { m_lineWidth = width; } - int GetLineWidth() { return m_lineWidth; } - // #$@%&* - -protected: - static void QuoteHTMLDone_S(URL_Struct* url, - int status, MWContext* context); - - void InitializeHeaders(MWContext* old_context, const nsIMsgCompFields* fields); - - char* FigureBcc(PRBool newsBcc); - const char* CheckForLosingFcc(const char* fcc); - - static void GetUrlDone_S(PrintSetup*); - void GetUrlDone(PrintSetup*); - - static void DownloadAttachmentsDone_S(MWContext *context, - void *fe_data, - int status, - const char *error_message, - struct MSG_AttachedFile *attachmnts); - - void DownloadAttachmentsDone(MWContext* context, int status, - const char* error_message, - struct MSG_AttachedFile *attachments); - - int DoneComposeMessage(MSG_Deliver_Mode deliver_mode); - - static void DeliveryDoneCB_s(MWContext *context, void *fe_data, int status, - const char *error_message); - void DeliveryDoneCB(MWContext* context, int status, - const char* error_message); - - int RemoveNoCertRecipientsFromList(MSG_HEADER_SET header); - - PRBool HasNoMarkup(); - MSG_HTMLComposeAction DetermineHTMLAction(); - int MungeThroughRecipients(PRBool* someNonHTML, PRBool* groupNonHTML); - - static PRBool AskDialogDone_s(XPDialogState *state, char **argv, int argc, - unsigned int button); - PRBool AskDialogDone(XPDialogState *state, char **argv, int argc, - unsigned int button); - static PRBool RecipientDialogDone_s(XPDialogState *state, char **argv, - int argc, unsigned int button); - PRBool RecipientDialogDone(XPDialogState *state, char **argv, int argc, - unsigned int button); - - int CreateVcardAttachment (); - - MSG_NewsHost *InferNewsHost (const char *groups); - - MSG_REPLY_TYPE m_replyType; /* The kind of message composition in - progress (reply, forward, etc.) */ - - PRBool m_markup; /* Whether we should generate messages - whose first part is text/html rather - than text/plain. */ - - MSG_AttachmentData *m_attachData; /* null-terminated list of the URLs and - desired types currently scheduled - for attachment. */ - MSG_AttachedFile *m_attachedFiles; /* The attachments which have already - been downloaded, and some info about - them. */ - - char *m_defaultUrl; /* Default URL for attaching, etc. */ - - nsMsgCompFields* m_initfields; // What all the fields were, - // initially. - nsMsgCompFields* m_fields; // Current value of all the fields. - - char* m_messageId; // Message-Id to use for composition. - - char* m_attachmentString; // Storage for string to display in UI for - // the list of attachments. - char* m_quotedText; // The results of quoting the original text. - - /* Stuff used while quoting a message. */ - PrintSetup* m_print; - MWContext *m_textContext; - MWContext *m_oldContext; - char* m_quoteUrl; - URL_Struct *m_dummyUrl; - Net_GetUrlExitFunc *m_exitQuoting; - int (*m_quotefunc)(void* closure, const char* data); - void* m_quoteclosure; - PRBool m_deliveryInProgress; /* True while mail is being sent. */ - PRBool m_attachmentInProgress; /* True while attachments being - saved. */ - int m_pendingAttachmentsCount; - - MSG_Deliver_Mode m_deliver_mode; /* MSG_DelverNow, MSG_QueueForLater, - * MSG_SaveAs, - * MSG_SaveAsDraft, MSG_SaveAsTemplate - */ - - HJ21695 - - PRBool m_cited; - - PRBool m_duplicatePost; /* Whether we seem to be trying for a - second time to post the same message. - (If this is true, then we know to ignore - 435 errors from the newsserver.) */ - - HJ92535 - - MSG_HTMLComposeAction m_htmlaction; - MSG_HTMLRecipients* m_htmlrecip; - - int m_status; - // I'm sure this isn't what Terry had in mind... // ### dmb - MSG_HEADER_SET m_visible_headers; - - MSG_NewsHost* m_host; // Which newshost we're posting to. This is - // lazily evaluated, so a NULL does necessarily - // mean we have no news host specified. - - PRBool m_closeAfterSave; - - PRBool m_haveQuoted; - PRBool m_haveAttachedVcard; - - MSG_CompositionPaneCallbacks m_callbacks; - void* m_callbackclosure; - int m_lineWidth; // for quoting plain text to html then convert back - // to plain text -}; - - -#endif /* _MsgCompose_H_ */ diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 16b641809c6..a5d191821f4 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -72,7 +72,6 @@ static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID); #include "prefapi.h" #include "abdefn.h" #include "prsembst.h" -#include "secrng.h" /* for RNG_GenerateGlobalRandomBytes() */ #include "addrbook.h" #include "imaphost.h" #include "imapoff.h" @@ -394,7 +393,7 @@ nsMsgSendMimeDeliveryState::nsMsgSendMimeDeliveryState() m_fields = NULL; /* Where to send the message once it's done */ m_dont_deliver_p = PR_FALSE; - m_deliver_mode = MSG_DeliverNow; + m_deliver_mode = nsMsgDeliverNow; m_attachments_only_p = PR_FALSE; m_pre_snarfed_attachments_p = PR_FALSE; @@ -433,45 +432,35 @@ nsMsgSendMimeDeliveryState::~nsMsgSendMimeDeliveryState() /* the following macro actually implement addref, release and query interface for our component. */ NS_IMPL_ISUPPORTS(nsMsgSendMimeDeliveryState, nsIMsgSend::GetIID()); -nsresult nsMsgSendMimeDeliveryState::SendMessage(nsIMsgCompFields *fields, const char *smtp) +nsresult nsMsgSendMimeDeliveryState::SendMessage( + nsIMsgCompFields *fields, + const char *smtp, + PRBool digest_p, + PRBool dont_deliver_p, + PRInt32 mode, + const char *attachment1_type, + const char *attachment1_body, + PRUint32 attachment1_body_length, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, + void *relatedPart, + void (*message_delivery_done_callback)(void *context, void *fe_data, + int status, const char *error_message)) { - const char* pBody; - PRInt32 nBodyLength; - pSmtpServer = smtp; - if (fields) { - pBody = ((nsMsgCompFields *)fields)->GetBody(); - if (pBody) - nBodyLength = PL_strlen(pBody); - else - nBodyLength = 0; - - StartMessageDelivery(NULL, NULL, (nsMsgCompFields *)fields, PR_FALSE, PR_FALSE, - MSG_DeliverNow, TEXT_PLAIN, pBody, nBodyLength, 0, NULL, NULL, NULL); - -/********** -void nsMsgSendMimeDeliveryState::StartMessageDelivery( - MSG_Pane *pane, - void *fe_data, - nsMsgCompFields *fields, - PRBool digest_p, - PRBool dont_deliver_p, - MSG_Deliver_Mode mode, - const char *attachment1_type, - const char *attachment1_body, - PRUint32 attachment1_body_length, - const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments, - nsMsgSendPart *relatedPart, - void (*message_delivery_done_callback) - (MWContext *context, - void *fe_data, - int status, - const char *error_message)) -**********/ - - } + StartMessageDelivery(NULL, NULL, + (nsMsgCompFields *)fields, + digest_p, + dont_deliver_p, + (nsMsgDeliverMode) mode, + attachment1_type, + attachment1_body, + attachment1_body_length, + attachments, + preloaded_attachments, + (nsMsgSendPart *)relatedPart, + NULL /*message_delivery_done_callback*/); return NS_OK; } @@ -495,7 +484,7 @@ static int mime_sanity_check_fields (const char *from, const char *other_random_headers); static char *mime_generate_headers (nsMsgCompFields *fields, const char *charset, - MSG_Deliver_Mode deliver_mode); + nsMsgDeliverMode deliver_mode); static char *mime_generate_attachment_headers (const char *type, const char *encoding, const char *description, @@ -2315,7 +2304,7 @@ int nsMsgSendMimeDeliveryState::GatherMimeAttachments () /* If we get here, we shouldn't have the "generating a message" cb. */ NS_ASSERTION(!m_dont_deliver_p && !m_message_delivery_done_callback, "Shouldn't be here"); if (m_attachments_done_callback) { - struct MSG_AttachedFile *attachments; + struct nsMsgAttachedFile *attachments; NS_ASSERTION(m_attachment_count > 0, "not more attachment"); if (m_attachment_count <= 0) { @@ -2325,7 +2314,7 @@ int nsMsgSendMimeDeliveryState::GatherMimeAttachments () goto FAIL; } - attachments = (struct MSG_AttachedFile *)PR_Malloc((m_attachment_count + 1) * sizeof(*attachments)); + attachments = (struct nsMsgAttachedFile *)PR_Malloc((m_attachment_count + 1) * sizeof(*attachments)); if (!attachments) goto FAILMEM; @@ -2474,7 +2463,7 @@ int nsMsgSendMimeDeliveryState::GatherMimeAttachments () } if (NET_IsOffline() && IsSaveMode()) { - status = InitImapOfflineDB( m_deliver_mode == MSG_SaveAsTemplate ? + status = InitImapOfflineDB( m_deliver_mode == nsMsgSaveAsTemplate ? MSG_FOLDER_FLAG_TEMPLATES : MSG_FOLDER_FLAG_DRAFTS ); if (status < 0) { @@ -2673,9 +2662,12 @@ int nsMsgSendMimeDeliveryState::GatherMimeAttachments () goto FAIL; if (!m_crypto_closure) { #ifdef UNREADY_CODE - status = toppart->SetBuffer(XP_GetString (MK_MIME_MULTIPART_BLURB)); + status = toppart->SetBuffer(XP_GetString (MK_MIME_MULTIPART_BLURB)); #else - status = toppart->SetBuffer("string not implemented yet"); +// RICHIE +#define MIME_MULTIPART_BLURB "This is a multi-part message in MIME format." + + status = toppart->SetBuffer(MIME_MULTIPART_BLURB); #endif if (status < 0) @@ -2993,10 +2985,7 @@ char * msg_generate_message_id (void) const char *host = 0; const char *from = pCompPrefs.GetUserEmail(); -#ifdef UNREADY_CODE - RNG_GenerateGlobalRandomBytes((void *) &salt, sizeof(salt)); -#endif - + GenerateGlobalRandomBytes((unsigned char *) &salt, sizeof(salt)); if (from) { host = PL_strchr (from, '@'); if (host) { @@ -3021,13 +3010,13 @@ char * msg_generate_message_id (void) static char * mime_generate_headers (nsMsgCompFields *fields, const char *charset, - MSG_Deliver_Mode deliver_mode) + nsMsgDeliverMode deliver_mode) { int size = 0; char *buffer = 0, *buffer_tail = 0; - PRBool isDraft = deliver_mode == MSG_SaveAsDraft || - deliver_mode == MSG_SaveAsTemplate || - deliver_mode == MSG_QueueForLater; + PRBool isDraft = deliver_mode == nsMsgSaveAsDraft || + deliver_mode == nsMsgSaveAsTemplate || + deliver_mode == nsMsgQueueForLater; const char* pFrom; const char* pTo; @@ -3086,8 +3075,8 @@ static char * mime_generate_headers (nsMsgCompFields *fields, if (fields->GetReturnReceipt() && (fields->GetReturnReceiptType() == 2 || fields->GetReturnReceiptType() == 3) && - (deliver_mode != MSG_SaveAsDraft && - deliver_mode != MSG_SaveAsTemplate)) + (deliver_mode != nsMsgSaveAsDraft && + deliver_mode != nsMsgSaveAsTemplate)) { PRInt32 receipt_header_type = 0; @@ -3778,7 +3767,7 @@ int MIME_GenerateMailtoFormPostHeaders (const char *old_post_url, fields->SetDefaultBody(body, NULL); - *headers_return = mime_generate_headers (fields, 0, MSG_DeliverNow); + *headers_return = mime_generate_headers (fields, 0, nsMsgDeliverNow); if (*headers_return == 0) { status = MK_OUT_OF_MEMORY; @@ -4283,8 +4272,8 @@ msg_pick_real_name (MSG_DeliverMimeAttachment *attachment, const char *charset) int nsMsgSendMimeDeliveryState::HackAttachments( - const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments) + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments) { INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(GetContext()); if (preloaded_attachments) @@ -4464,12 +4453,12 @@ void nsMsgSendMimeDeliveryState::StartMessageDelivery( nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, //#ifdef MSG_SEND_MULTIPART_RELATED nsMsgSendPart *relatedPart, //#endif @@ -4535,13 +4524,13 @@ nsMsgSendMimeDeliveryState::Init( nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, //#ifdef MSG_SEND_MULTIPART_RELATED nsMsgSendPart *relatedPart, //#endif @@ -4675,7 +4664,7 @@ nsMsgSendMimeDeliveryState::Init( /* Check the fields for legitimacy, and run the callback if they're not ok. */ - if (mode != MSG_SaveAsDraft && mode != MSG_SaveAsTemplate ) { + if (mode != nsMsgSaveAsDraft && mode != nsMsgSaveAsTemplate ) { failure = mime_sanity_check_fields (m_fields->GetFrom(), m_fields->GetReplyTo(), m_fields->GetTo(), m_fields->GetCc(), m_fields->GetBcc(), m_fields->GetFcc(), @@ -4718,7 +4707,7 @@ nsMsgSendMimeDeliveryState::Init( if all attachments are provided externally. Subsequent attachments are provided as URLs to load, described in the - MSG_AttachmentData structures. + nsMsgAttachmentData structures. If `dont_deliver_p' is false, then we actually deliver the message to the SMTP and/or NNTP server, and the message_delivery_done_callback will be @@ -4744,7 +4733,7 @@ MSG_StartMessageDelivery (MSG_Pane *pane, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachmentData *attachments, + const struct nsMsgAttachmentData *attachments, void *relatedPart, void (*message_delivery_done_callback) (MWContext *context, @@ -4776,11 +4765,11 @@ msg_StartMessageDeliveryWithAttachments (MSG_Pane *pane, nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachedFile *attachments, + const struct nsMsgAttachedFile *attachments, //#ifdef MSG_SEND_MULTIPART_RELATED void *relatedPart, //#endif @@ -4808,12 +4797,12 @@ msg_StartMessageDeliveryWithAttachments (MSG_Pane *pane, extern "C" int msg_DownloadAttachments (MSG_Pane *pane, void *fe_data, - const struct MSG_AttachmentData *attachments, + const struct nsMsgAttachmentData *attachments, void (*attachments_done_callback) (MWContext *context, void *fe_data, int status, const char *error_message, - struct MSG_AttachedFile *attachments)) + struct nsMsgAttachedFile *attachments)) { nsMsgSendMimeDeliveryState *state = 0; int failure = 0; @@ -4838,7 +4827,7 @@ msg_DownloadAttachments (MSG_Pane *pane, state->m_attachments_done_callback = #ifdef XP_OS2 //DSR040297 - see comment above about 'Casting away extern "C"' - (void(*)(MWContext*,void*,int,const char*,MSG_AttachedFile*)) + (void(*)(MWContext*,void*,int,const char*,nsMsgAttachedFile*)) #endif attachments_done_callback; @@ -4979,19 +4968,19 @@ void nsMsgSendMimeDeliveryState::DeliverMessage () PRBool news_p = (m_fields->GetNewsgroups() && *(m_fields->GetNewsgroups()) ? PR_TRUE : PR_FALSE); - if ( m_deliver_mode != MSG_SaveAsDraft && - m_deliver_mode != MSG_SaveAsTemplate ) + if ( m_deliver_mode != nsMsgSaveAsDraft && + m_deliver_mode != nsMsgSaveAsTemplate ) NS_ASSERTION(mail_p || news_p, "message without destination"); - if (m_deliver_mode == MSG_QueueForLater) { + if (m_deliver_mode == nsMsgQueueForLater) { QueueForLater(); return; } - else if (m_deliver_mode == MSG_SaveAsDraft) { + else if (m_deliver_mode == nsMsgSaveAsDraft) { SaveAsDraft(); return; } - else if (m_deliver_mode == MSG_SaveAsTemplate) { + else if (m_deliver_mode == nsMsgSaveAsTemplate) { SaveAsTemplate(); return; } @@ -5277,7 +5266,7 @@ static int mime_do_fcc_1 (MSG_Pane *pane, const char *input_file_name, XP_FileType input_file_type, const char *output_name, XP_FileType output_file_type, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *bcc_header, const char *fcc_header, const char *news_url) @@ -5370,13 +5359,13 @@ mime_do_fcc_1 (MSG_Pane *pane, MK_MSG_COULDNT_OPEN_FCC_FILE */ switch (mode) { - case MSG_SaveAsDraft: + case nsMsgSaveAsDraft: status = MK_MSG_UNABLE_TO_SAVE_DRAFT; break; - case MSG_SaveAsTemplate: + case nsMsgSaveAsTemplate: status = MK_MSG_UNABLE_TO_SAVE_TEMPLATE; break; - case MSG_DeliverNow: + case nsMsgDeliverNow: default: status = MK_MSG_COULDNT_OPEN_FCC_FILE; break; @@ -5445,9 +5434,9 @@ mime_do_fcc_1 (MSG_Pane *pane, For FCC files, we don't necessarily need one, but we might as well put one in so that it's marked as read already. */ - if (mode == MSG_QueueForLater || - mode == MSG_SaveAsDraft || - mode == MSG_SaveAsTemplate || + if (mode == nsMsgQueueForLater || + mode == nsMsgSaveAsDraft || + mode == nsMsgSaveAsTemplate || mark_as_read) { char *buf = 0; @@ -5455,7 +5444,7 @@ mime_do_fcc_1 (MSG_Pane *pane, mark_as_read = PR_TRUE; flags |= MSG_FLAG_READ; - if (mode == MSG_QueueForLater ) + if (mode == nsMsgQueueForLater ) flags |= MSG_FLAG_QUEUED; buf = PR_smprintf(X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, flags); if (buf) @@ -5467,7 +5456,7 @@ mime_do_fcc_1 (MSG_Pane *pane, } PRUint32 flags2 = 0; - if (mode == MSG_SaveAsTemplate) + if (mode == nsMsgSaveAsTemplate) flags2 |= MSG_FLAG_TEMPLATE; buf = PR_smprintf(X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, flags2); if (buf) @@ -5506,9 +5495,9 @@ mime_do_fcc_1 (MSG_Pane *pane, folder, and that message is forwarded to someone, then the attachment code will strip out the BCC header before forwarding it.) */ - if ((mode == MSG_QueueForLater || - mode == MSG_SaveAsDraft || - mode == MSG_SaveAsTemplate) && + if ((mode == nsMsgQueueForLater || + mode == nsMsgSaveAsDraft || + mode == nsMsgSaveAsTemplate) && fcc_header && *fcc_header) { PRInt32 L = PL_strlen(fcc_header) + 20; @@ -5553,9 +5542,9 @@ mime_do_fcc_1 (MSG_Pane *pane, Convert a URL like "snews://host:123/" to the form "host:123/secure" or "news://user@host:222" to simply "host:222". */ - if ((mode == MSG_QueueForLater || - mode == MSG_SaveAsDraft || - mode == MSG_SaveAsTemplate) && news_url && *news_url) + if ((mode == nsMsgQueueForLater || + mode == nsMsgSaveAsDraft || + mode == nsMsgSaveAsTemplate) && news_url && *news_url) { PRBool secure_p = (news_url[0] == 's' || news_url[0] == 'S'); char *orig_hap = NET_ParseURL (news_url, GET_HOST_PART); @@ -5685,7 +5674,7 @@ mime_do_fcc_1 (MSG_Pane *pane, } if (mail_db != NULL && status >= 0) { - if ( mode == MSG_SaveAsDraft || mode == MSG_SaveAsTemplate ) + if ( mode == nsMsgSaveAsDraft || mode == nsMsgSaveAsTemplate ) { MSG_PostDeliveryActionInfo *actionInfo = pane->GetPostDeliveryActionInfo(); @@ -5795,7 +5784,7 @@ msg_DoFCC (MSG_Pane *pane, return mime_do_fcc_1 (pane, input_file, input_file_type, output_file, output_file_type, - MSG_DeliverNow, bcc_header_value, + nsMsgDeliverNow, bcc_header_value, fcc_header_value, 0); } @@ -5863,9 +5852,9 @@ nsMsgSendMimeDeliveryState::GetOnlineFolderName(PRUint32 flag, const char PRBool nsMsgSendMimeDeliveryState::IsSaveMode() { - return (m_deliver_mode == MSG_SaveAsDraft || - m_deliver_mode == MSG_SaveAsTemplate || - m_deliver_mode == MSG_SaveAs); + return (m_deliver_mode == nsMsgSaveAsDraft || + m_deliver_mode == nsMsgSaveAsTemplate || + m_deliver_mode == nsMsgSaveAs); } @@ -6406,15 +6395,15 @@ PRUint32 nsMsgSendMimeDeliveryState::GetFolderFlagAndDefaultName( switch (m_deliver_mode) { - case MSG_SaveAsDraft: + case nsMsgSaveAsDraft: *defaultName = DRAFTS_FOLDER_NAME; flag = MSG_FOLDER_FLAG_DRAFTS; break; - case MSG_SaveAsTemplate: + case nsMsgSaveAsTemplate: *defaultName = TEMPLATES_FOLDER_NAME; flag = MSG_FOLDER_FLAG_TEMPLATES; break; - case MSG_DeliverNow: + case nsMsgDeliverNow: *defaultName = SENT_FOLDER_NAME; flag = MSG_FOLDER_FLAG_SENTMAIL; break; @@ -6478,7 +6467,7 @@ nsMsgSendMimeDeliveryState::PostListImapMailboxFolder ( URL_Struct *url, { /* rhp- This is to handle failed copy operation BUT only if we are trying to send the message. If not, then this was not a Send operation and this prompt doesn't make sense. */ - if (state->m_deliver_mode == MSG_DeliverNow) + if (state->m_deliver_mode == nsMsgDeliverNow) { #ifdef UNREADY_CODE if (FE_Confirm(state->GetContext(), XP_GetString(MK_MSG_FAILED_COPY_OPERATION))) diff --git a/mailnews/compose/src/nsMsgSend.h b/mailnews/compose/src/nsMsgSend.h index 7e909d5d026..43f8c6a3a6c 100644 --- a/mailnews/compose/src/nsMsgSend.h +++ b/mailnews/compose/src/nsMsgSend.h @@ -54,11 +54,11 @@ msg_StartMessageDeliveryWithAttachments (MSG_Pane *pane, nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachedFile *attachments, + const struct nsMsgAttachedFile *attachments, //#ifdef MSG_SEND_MULTIPART_RELATED void *relatedPart, //#endif @@ -80,20 +80,18 @@ public: /* this macro defines QueryInterface, AddRef and Release for this class */ NS_DECL_ISUPPORTS - NS_IMETHOD SendMessage(nsIMsgCompFields *fields, const char *smtp); - - void StartMessageDelivery(MSG_Pane *pane, + void StartMessageDelivery(MSG_Pane *pane, void *fe_data, nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachmentData + const struct nsMsgAttachmentData *attachments, - const struct MSG_AttachedFile + const struct nsMsgAttachedFile *preloaded_attachments, //#ifdef MSG_SEND_MULTIPART_RELATED nsMsgSendPart *relatedPart, @@ -104,17 +102,32 @@ public: int status, const char *error_message)); + NS_IMETHOD SendMessage( + nsIMsgCompFields *fields, + const char *smtp, + PRBool digest_p, + PRBool dont_deliver_p, + PRInt32 mode, + const char *attachment1_type, + const char *attachment1_body, + PRUint32 attachment1_body_length, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, + void *relatedPart, + void (*message_delivery_done_callback)(void *context, void *fe_data, + int status, const char *error_message)); + int Init(MSG_Pane *pane, void *fe_data, nsMsgCompFields *fields, PRBool digest_p, PRBool dont_deliver_p, - MSG_Deliver_Mode mode, + nsMsgDeliverMode mode, const char *attachment1_type, const char *attachment1_body, PRUint32 attachment1_body_length, - const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments, + const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments, //#ifdef MSG_SEND_MULTIPART_RELATED nsMsgSendPart *relatedPart, //#endif @@ -159,8 +172,8 @@ public: int DoFcc(); - int HackAttachments(const struct MSG_AttachmentData *attachments, - const struct MSG_AttachedFile *preloaded_attachments); + int HackAttachments(const struct nsMsgAttachmentData *attachments, + const struct nsMsgAttachedFile *preloaded_attachments); void DeliverFileAsMail(); void DeliverFileAsNews(); @@ -183,15 +196,15 @@ public: we created, instead of actually delivering this message. */ - MSG_Deliver_Mode m_deliver_mode; /* MSG_DeliverNow, MSG_QueueForLater, - MSG_SaveAsDraft, MSG_SaveAsTemplate + nsMsgDeliverMode m_deliver_mode; /* nsMsgDeliverNow, nsMsgQueueForLater, + nsMsgSaveAsDraft, nsMsgSaveAsTemplate */ PRBool m_attachments_only_p; /* If set, then we don't construct a complete MIME message; instead, we just retrieve the attachments from the network, store them in tmp files, and return a list of - MSG_AttachedFile structs which describe + nsMsgAttachedFile structs which describe them. */ PRBool m_pre_snarfed_attachments_p; /* If true, then the attachments were @@ -251,7 +264,7 @@ public: void (*m_attachments_done_callback) (MWContext *context, void * fe_data, int status, const char * error_msg, - struct MSG_AttachedFile *attachments); + struct nsMsgAttachedFile *attachments); char *m_msg_file_name; /* Our temporary file */ nsOutputFileStream * m_msg_file; diff --git a/mailnews/compose/src/nsMsgSendPart.cpp b/mailnews/compose/src/nsMsgSendPart.cpp index 2b5d5892e99..90e19587e36 100644 --- a/mailnews/compose/src/nsMsgSendPart.cpp +++ b/mailnews/compose/src/nsMsgSendPart.cpp @@ -22,21 +22,11 @@ #include "nsMsgSend.h" #include "nsMsgSendPart.h" #include "nsIMimeConverter.h" +#include "nsFileStream.h" +#include "nsIMimeURLUtils.h" #include "MsgCompGlue.h" -#if 0 //JFD - -#include "msg.h" -#include "ntypes.h" -#include "xlate.h" // Needed to compile msgsend.h, sigh... ### -#include "msgsend.h" -#include "msgsendp.h" -#include "libi18n.h" -#include "intl_csi.h" - -#endif //JFD - // defined in msgCompGlue.cpp extern int MIME_EncoderDestroy(MimeEncoderData *data, PRBool abort_p); static char *mime_mailto_stream_read_buffer = 0; @@ -44,6 +34,7 @@ static char *mime_mailto_stream_read_buffer = 0; PRInt32 nsMsgSendPart::M_counter = 0; static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID); +static NS_DEFINE_CID(kCMimeURLUtilsCID, NS_IMIME_URLUTILS_CID); int MIME_EncoderWrite(MimeEncoderData *data, const char *buffer, PRInt32 size) { @@ -51,7 +42,7 @@ int MIME_EncoderWrite(MimeEncoderData *data, const char *buffer, PRInt32 size) nsIMimeConverter *converter; PRInt32 written = 0; nsresult res = nsComponentManager::CreateInstance(kCMimeConverterCID, nsnull, - nsIMimeConverter::GetIID(), (void **)&converter); + nsIMimeConverter::GetIID(), (void **)&converter); if (NS_SUCCEEDED(res) && nsnull != converter) { res = converter->EncoderWrite(data, buffer, size, &written); NS_RELEASE(converter); @@ -62,26 +53,26 @@ int MIME_EncoderWrite(MimeEncoderData *data, const char *buffer, PRInt32 size) nsMsgSendPart::nsMsgSendPart(nsMsgSendMimeDeliveryState* state, const char *part_charset) { PL_strcpy(m_charset_name, part_charset ? part_charset : "us-ascii"); - m_children = NULL; - m_numchildren = 0; - - SetMimeDeliveryState(state); - - m_parent = NULL; - m_filename = NULL; - m_filetype = (XP_FileType)0; - m_buffer = NULL; - m_type = NULL; - m_other = NULL; - m_strip_sensitive_headers = PR_FALSE; - m_encoder_data = NULL; - - m_firstBlock = PR_FALSE; - m_needIntlConversion = PR_FALSE; - m_intlDocToMailConverter = NULL; - - m_mainpart = PR_FALSE; - m_just_hit_CR = PR_FALSE; + m_children = NULL; + m_numchildren = 0; + + SetMimeDeliveryState(state); + + m_parent = NULL; + m_filename = NULL; + m_filetype = (XP_FileType)0; + m_buffer = NULL; + m_type = NULL; + m_other = NULL; + m_strip_sensitive_headers = PR_FALSE; + m_encoder_data = NULL; + + m_firstBlock = PR_FALSE; + m_needIntlConversion = PR_FALSE; + m_intlDocToMailConverter = NULL; + + m_mainpart = PR_FALSE; + m_just_hit_CR = PR_FALSE; } @@ -104,62 +95,62 @@ nsMsgSendPart::~nsMsgSendPart() int nsMsgSendPart::CopyString(char** dest, const char* src) { - NS_ASSERTION(src, "src null"); - - PR_FREEIF(*dest); - if (!src) - *dest = PL_strdup(""); - else - *dest = PL_strdup(src); - - return *dest? 0 : MK_OUT_OF_MEMORY; + NS_ASSERTION(src, "src null"); + + PR_FREEIF(*dest); + if (!src) + *dest = PL_strdup(""); + else + *dest = PL_strdup(src); + + return *dest? 0 : MK_OUT_OF_MEMORY; } int nsMsgSendPart::SetFile(const char* filename, XP_FileType type) { - NS_ASSERTION(m_filename == NULL, "not-null m_filename"); - int status = CopyString(&m_filename, filename); - if (status < 0) - return status; - m_filetype = type; + NS_ASSERTION(m_filename == NULL, "not-null m_filename"); + int status = CopyString(&m_filename, filename); + if (status < 0) return status; + m_filetype = type; + return status; } int nsMsgSendPart::SetBuffer(const char* buffer) { - NS_ASSERTION(m_buffer == NULL, "not-null m_buffer"); - return CopyString(&m_buffer, buffer); + NS_ASSERTION(m_buffer == NULL, "not-null m_buffer"); + return CopyString(&m_buffer, buffer); } int nsMsgSendPart::SetType(const char* type) { - PR_FREEIF(m_type); - m_type = PL_strdup(type); - return m_type ? 0 : MK_OUT_OF_MEMORY; + PR_FREEIF(m_type); + m_type = PL_strdup(type); + return m_type ? 0 : MK_OUT_OF_MEMORY; } int nsMsgSendPart::SetOtherHeaders(const char* other) { - return CopyString(&m_other, other); + return CopyString(&m_other, other); } int nsMsgSendPart::SetMimeDeliveryState(nsMsgSendMimeDeliveryState *state) { - m_state = state; - if (GetNumChildren() > 0) - { - for (int i = 0; i < GetNumChildren(); i++) - { - nsMsgSendPart *part = GetChild(i); - if (part) - part->SetMimeDeliveryState(state); - } - } - return 0; + m_state = state; + if (GetNumChildren() > 0) + { + for (int i = 0; i < GetNumChildren(); i++) + { + nsMsgSendPart *part = GetChild(i); + if (part) + part->SetMimeDeliveryState(state); + } + } + return 0; } int nsMsgSendPart::AppendOtherHeaders(const char* more) @@ -185,626 +176,650 @@ int nsMsgSendPart::AppendOtherHeaders(const char* more) int nsMsgSendPart::SetEncoderData(MimeEncoderData* data) { - m_encoder_data = data; - return 0; + m_encoder_data = data; + return 0; } int nsMsgSendPart::SetMainPart(PRBool value) { - m_mainpart = value; - return 0; + m_mainpart = value; + return 0; } int nsMsgSendPart::AddChild(nsMsgSendPart* child) { - m_numchildren++; - nsMsgSendPart** tmp = new nsMsgSendPart* [m_numchildren]; - if (tmp == NULL) return MK_OUT_OF_MEMORY; - for (int i=0 ; im_parent = this; - return 0; + m_numchildren++; + nsMsgSendPart** tmp = new nsMsgSendPart* [m_numchildren]; + if (tmp == NULL) return MK_OUT_OF_MEMORY; + for (int i=0 ; im_parent = this; + return 0; } nsMsgSendPart * nsMsgSendPart::DetachChild(PRInt32 whichOne) { - nsMsgSendPart *returnValue = NULL; - - NS_ASSERTION(whichOne >= 0 && whichOne < m_numchildren, "parameter out of range"); - if (whichOne >= 0 && whichOne < m_numchildren) - { - returnValue = m_children[whichOne]; - - if (m_numchildren > 1) - { - nsMsgSendPart** tmp = new nsMsgSendPart* [m_numchildren-1]; - if (tmp != NULL) - { - // move all the other kids over - for (int i=0 ; i= whichOne) - tmp[i] = m_children[i+1]; - else - tmp[i] = m_children[i]; - } - delete [] m_children; - m_children = tmp; - m_numchildren--; - } - } - else - { - delete [] m_children; - m_children = NULL; - m_numchildren = 0; - } + nsMsgSendPart *returnValue = NULL; + + NS_ASSERTION(whichOne >= 0 && whichOne < m_numchildren, "parameter out of range"); + if (whichOne >= 0 && whichOne < m_numchildren) + { + returnValue = m_children[whichOne]; + + if (m_numchildren > 1) + { + nsMsgSendPart** tmp = new nsMsgSendPart* [m_numchildren-1]; + if (tmp != NULL) + { + // move all the other kids over + for (int i=0 ; i= whichOne) + tmp[i] = m_children[i+1]; + else + tmp[i] = m_children[i]; + } + delete [] m_children; + m_children = tmp; + m_numchildren--; + } } - - if (returnValue) - returnValue->m_parent = NULL; - - return returnValue; + else + { + delete [] m_children; + m_children = NULL; + m_numchildren = 0; + } + } + + if (returnValue) + returnValue->m_parent = NULL; + + return returnValue; } nsMsgSendPart* nsMsgSendPart::GetChild(PRInt32 which) { - NS_ASSERTION(which >= 0 && which < m_numchildren, "parameter out of range"); - if (which >= 0 && which < m_numchildren) { - return m_children[which]; - } - return NULL; + NS_ASSERTION(which >= 0 && which < m_numchildren, "parameter out of range"); + if (which >= 0 && which < m_numchildren) { + return m_children[which]; + } + return NULL; } int nsMsgSendPart::PushBody(char* buffer, PRInt32 length) { - int status = 0; - char* encoded_data = buffer; - - /* if this is the first block, create the conversion object + int status = 0; + char* encoded_data = buffer; + + /* if this is the first block, create the conversion object */ - if (m_firstBlock) { - if (m_needIntlConversion) { - m_intlDocToMailConverter = - INTL_CreateDocToMailConverter(m_state->GetContext(), - (!PL_strcasecmp(m_type, - TEXT_HTML)), - (unsigned char*) buffer, - length); - - // No conversion is done when mail_csid (ToCSID for the converter) is JIS - // and type is HTML (usually csid is SJIS or EUC for Japanese HTML) - // in order to avoid mismatch META_TAG (bug#104255). - if (m_intlDocToMailConverter != NULL) { - PRBool Base64HtmlNoChconv = ((INTL_GetCCCToCSID(m_intlDocToMailConverter) == CS_JIS) && - !PL_strcasecmp(m_type, TEXT_HTML) && - (m_encoder_data != NULL)); - if (Base64HtmlNoChconv) { - INTL_DestroyCharCodeConverter(m_intlDocToMailConverter); - m_intlDocToMailConverter = NULL; - } - } - } - m_firstBlock = PR_FALSE; /* No longer the first block */ - } - - if (m_intlDocToMailConverter) { - encoded_data = - (char*)INTL_CallCharCodeConverter(m_intlDocToMailConverter, - (unsigned char*)buffer, - length); - /* the return buffer is different from the */ - /* origional one. The size needs to be change */ - if(encoded_data && encoded_data != buffer) { - length = PL_strlen(encoded_data); - } - } - - if (m_encoder_data) { - status = MIME_EncoderWrite(m_encoder_data, encoded_data, length); - } else { - // Merely translate all linebreaks to CRLF. - int status = 0; - const char *in = encoded_data; - const char *end = in + length; - char *buffer, *out; - - - buffer = mime_get_stream_write_buffer(); - if (!buffer) return MK_OUT_OF_MEMORY; - - NS_ASSERTION(encoded_data != buffer, "encoded_data == buffer"); - out = buffer; - - for (; in < end; in++) { - if (m_just_hit_CR) { - m_just_hit_CR = PR_FALSE; - if (*in == LF) { - // The last thing we wrote was a CRLF from hitting a CR. - // So, we don't want to do anything from a following LF; - // we want to ignore it. - continue; - } - } - if (*in == CR || *in == LF) { - /* Write out the newline. */ - *out++ = CR; - *out++ = LF; - - status = mime_write_message_body(m_state, buffer, - out - buffer); - if (status < 0) return status; - out = buffer; - - if (*in == CR) { - m_just_hit_CR = PR_TRUE; - } - - out = buffer; - } else { - - /* Fix for bug #95985. We can't assume that all lines are shorter - than 4096 chars (MIME_BUFFER_SIZE), so we need to test - for this here. sfraser. - */ - if (out - buffer >= MIME_BUFFER_SIZE) - { - status = mime_write_message_body(m_state, buffer, out - buffer); - if (status < 0) return status; - - out = buffer; - } - - *out++ = *in; - } - } - - /* Flush the last line. */ - if (out > buffer) { - status = mime_write_message_body(m_state, buffer, out - buffer); - if (status < 0) return status; - out = buffer; - } - } - - if (encoded_data && encoded_data != buffer) { - PR_Free(encoded_data); - } - - return status; + if (m_firstBlock) { + if (m_needIntlConversion) { + m_intlDocToMailConverter = + INTL_CreateDocToMailConverter(m_state->GetContext(), + (!PL_strcasecmp(m_type, + TEXT_HTML)), + (unsigned char*) buffer, + length); + + // No conversion is done when mail_csid (ToCSID for the converter) is JIS + // and type is HTML (usually csid is SJIS or EUC for Japanese HTML) + // in order to avoid mismatch META_TAG (bug#104255). + if (m_intlDocToMailConverter != NULL) { + PRBool Base64HtmlNoChconv = ((INTL_GetCCCToCSID(m_intlDocToMailConverter) == CS_JIS) && + !PL_strcasecmp(m_type, TEXT_HTML) && + (m_encoder_data != NULL)); + if (Base64HtmlNoChconv) { + INTL_DestroyCharCodeConverter(m_intlDocToMailConverter); + m_intlDocToMailConverter = NULL; + } + } + } + m_firstBlock = PR_FALSE; /* No longer the first block */ + } + + if (m_intlDocToMailConverter) { + encoded_data = + (char*)INTL_CallCharCodeConverter(m_intlDocToMailConverter, + (unsigned char*)buffer, + length); + /* the return buffer is different from the */ + /* origional one. The size needs to be change */ + if(encoded_data && encoded_data != buffer) { + length = PL_strlen(encoded_data); + } + } + + if (m_encoder_data) { + status = MIME_EncoderWrite(m_encoder_data, encoded_data, length); + } else { + // Merely translate all linebreaks to CRLF. + int status = 0; + const char *in = encoded_data; + const char *end = in + length; + char *buffer, *out; + + + buffer = mime_get_stream_write_buffer(); + if (!buffer) return MK_OUT_OF_MEMORY; + + NS_ASSERTION(encoded_data != buffer, "encoded_data == buffer"); + out = buffer; + + for (; in < end; in++) { + if (m_just_hit_CR) { + m_just_hit_CR = PR_FALSE; + if (*in == LF) { + // The last thing we wrote was a CRLF from hitting a CR. + // So, we don't want to do anything from a following LF; + // we want to ignore it. + continue; + } + } + if (*in == CR || *in == LF) { + /* Write out the newline. */ + *out++ = CR; + *out++ = LF; + + status = mime_write_message_body(m_state, buffer, + out - buffer); + if (status < 0) return status; + out = buffer; + + if (*in == CR) { + m_just_hit_CR = PR_TRUE; + } + + out = buffer; + } else { + + /* Fix for bug #95985. We can't assume that all lines are shorter + than 4096 chars (MIME_BUFFER_SIZE), so we need to test + for this here. sfraser. + */ + if (out - buffer >= MIME_BUFFER_SIZE) + { + status = mime_write_message_body(m_state, buffer, out - buffer); + if (status < 0) return status; + + out = buffer; + } + + *out++ = *in; + } + } + + /* Flush the last line. */ + if (out > buffer) { + status = mime_write_message_body(m_state, buffer, out - buffer); + if (status < 0) return status; + out = buffer; + } + } + + if (encoded_data && encoded_data != buffer) { + PR_Free(encoded_data); + } + + return status; } /* Partition the headers into those which apply to the message as a whole; - those which apply to the message's contents; and the Content-Type header - itself. (This relies on the fact that all body-related headers begin with - "Content-".) - - (How many header parsers are in this program now?) - */ -static int divide_content_headers(const char *headers, - char **message_headers, - char **content_headers, - char **content_type_header) -{ - const char *tail; - char *message_tail, *content_tail, *type_tail; - int L = 0; - if (headers) - L = PL_strlen(headers); - - if (L == 0) - return 0; - - *message_headers = (char *)PR_Malloc(L+1); - if (!*message_headers) - return MK_OUT_OF_MEMORY; - - *content_headers = (char *)PR_Malloc(L+1); - if (!*content_headers) { - PR_Free(*message_headers); - return MK_OUT_OF_MEMORY; - } - - *content_type_header = (char *)PR_Malloc(L+1); - if (!*content_type_header) { - PR_Free(*message_headers); - PR_Free(*content_headers); - return MK_OUT_OF_MEMORY; - } - - message_tail = *message_headers; - content_tail = *content_headers; - type_tail = *content_type_header; - tail = headers; - - while (*tail) - { - const char *head = tail; - char **out; - while(PR_TRUE) { - /* Loop until we reach a newline that is not followed by whitespace. - */ - if (tail[0] == 0 || - ((tail[0] == CR || tail[0] == LF) && - !(tail[1] == ' ' || tail[1] == '\t' || tail[1] == LF))) - { - /* Swallow the whole newline. */ - if (tail[0] == CR && tail[1] == LF) - tail++; - if (*tail) - tail++; - break; - } - tail++; - } - - /* Decide which block this header goes into. - */ - if (!PL_strncasecmp(head, "Content-Type:", 13)) - out = &type_tail; - else - if (!PL_strncasecmp(head, "Content-", 8)) - out = &content_tail; - else - out = &message_tail; - - memcpy(*out, head, (tail-head)); - *out += (tail-head); - } - - *message_tail = 0; - *content_tail = 0; - *type_tail = 0; - - if (!**message_headers) { - PR_Free(*message_headers); - *message_headers = 0; - } - - if (!**content_headers) { - PR_Free(*content_headers); - *content_headers = 0; - } - - if (!**content_type_header) { - PR_Free(*content_type_header); - *content_type_header = 0; - } +those which apply to the message's contents; and the Content-Type header +itself. (This relies on the fact that all body-related headers begin with +"Content-".) + (How many header parsers are in this program now?) + */ + static int divide_content_headers(const char *headers, + char **message_headers, + char **content_headers, + char **content_type_header) + { + const char *tail; + char *message_tail, *content_tail, *type_tail; + int L = 0; + if (headers) + L = PL_strlen(headers); + + if (L == 0) + return 0; + + *message_headers = (char *)PR_Malloc(L+1); + if (!*message_headers) + return MK_OUT_OF_MEMORY; + + *content_headers = (char *)PR_Malloc(L+1); + if (!*content_headers) { + PR_Free(*message_headers); + return MK_OUT_OF_MEMORY; + } + + *content_type_header = (char *)PR_Malloc(L+1); + if (!*content_type_header) { + PR_Free(*message_headers); + PR_Free(*content_headers); + return MK_OUT_OF_MEMORY; + } + + message_tail = *message_headers; + content_tail = *content_headers; + type_tail = *content_type_header; + tail = headers; + + while (*tail) + { + const char *head = tail; + char **out; + while(PR_TRUE) { + /* Loop until we reach a newline that is not followed by whitespace. + */ + if (tail[0] == 0 || + ((tail[0] == CR || tail[0] == LF) && + !(tail[1] == ' ' || tail[1] == '\t' || tail[1] == LF))) + { + /* Swallow the whole newline. */ + if (tail[0] == CR && tail[1] == LF) + tail++; + if (*tail) + tail++; + break; + } + tail++; + } + + /* Decide which block this header goes into. + */ + if (!PL_strncasecmp(head, "Content-Type:", 13)) + out = &type_tail; + else + if (!PL_strncasecmp(head, "Content-", 8)) + out = &content_tail; + else + out = &message_tail; + + memcpy(*out, head, (tail-head)); + *out += (tail-head); + } + + *message_tail = 0; + *content_tail = 0; + *type_tail = 0; + + if (!**message_headers) { + PR_Free(*message_headers); + *message_headers = 0; + } + + if (!**content_headers) { + PR_Free(*content_headers); + *content_headers = 0; + } + + if (!**content_type_header) { + PR_Free(*content_type_header); + *content_type_header = 0; + } + #ifdef DEBUG - // ### mwelch Because of the extreme difficulty we've had with - // duplicate part headers, I'm going to put in an - // ASSERT here which makes sure that no duplicate - // Content-Type or Content-Transfer-Encoding headers - // leave here undetected. - const char* tmp; - if (*content_type_header) { - tmp = PL_strstr(*content_type_header, "Content-Type"); - if (tmp) { - tmp++; // get past the first occurrence - NS_ASSERTION(!PL_strstr(tmp, "Content-Type"), "Content-part already present"); - } - } - - if (*content_headers) { - tmp = PL_strstr(*content_headers, "Content-Transfer-Encoding"); - if (tmp) { - tmp++; // get past the first occurrence - NS_ASSERTION(!PL_strstr(tmp, "Content-Transfer-Encoding"), "Content-Transfert already present"); - } - } + // ### mwelch Because of the extreme difficulty we've had with + // duplicate part headers, I'm going to put in an + // ASSERT here which makes sure that no duplicate + // Content-Type or Content-Transfer-Encoding headers + // leave here undetected. + const char* tmp; + if (*content_type_header) { + tmp = PL_strstr(*content_type_header, "Content-Type"); + if (tmp) { + tmp++; // get past the first occurrence + NS_ASSERTION(!PL_strstr(tmp, "Content-Type"), "Content-part already present"); + } + } + + if (*content_headers) { + tmp = PL_strstr(*content_headers, "Content-Transfer-Encoding"); + if (tmp) { + tmp++; // get past the first occurrence + NS_ASSERTION(!PL_strstr(tmp, "Content-Transfer-Encoding"), "Content-Transfert already present"); + } + } #endif // DEBUG - - return 0; + + return 0; } extern "C" { -extern char *mime_make_separator(const char *prefix); + extern char *mime_make_separator(const char *prefix); } int nsMsgSendPart::Write() { - int status = 0; - char *separator = 0; - PRFileDesc *file = NULL; - + int status = 0; + char *separator = 0; + PRFileDesc *file = NULL; + #define PUSHLEN(str, length) \ - do { \ + do { \ status = mime_write_message_body(m_state, str, length); \ - if (status < 0) goto FAIL; \ - } while (0) \ - + if (status < 0) goto FAIL; \ + } while (0) \ + #define PUSH(str) PUSHLEN(str, PL_strlen(str)) + + if (m_mainpart && m_type && PL_strcmp(m_type, TEXT_HTML) == 0) { + if (m_filename) { + // The "insert HTML links" code requires a memory buffer, + // so read the file into memory. + NS_ASSERTION(m_buffer == NULL, "not-null buffer"); + PRInt32 length = 0; + nsFileSpec mySpec(m_filename); - if (m_mainpart && m_type && PL_strcmp(m_type, TEXT_HTML) == 0) { - if (m_filename) { - // The "insert HTML links" code requires a memory buffer, - // so read the file into memory. - NS_ASSERTION(m_buffer == NULL, "not-null buffer"); - XP_StatStruct st; - st.st_size = 0; - XP_Stat (m_filename, &st, m_filetype); - PRInt32 length = st.st_size; - m_buffer = new char[length + 1]; - if (m_buffer) { - file = PR_Open(m_filename, PR_RDONLY, 0); - if (file) { - PR_Read(file, m_buffer, length); - PR_Close(file); - m_buffer[length] = '\0'; - file = NULL; - if (m_filename) - delete [] m_filename; - m_filename = NULL; - } - else { - delete [] m_buffer; - m_buffer = NULL; - } - } - } - if (m_buffer) { - char* tmp = NET_ScanHTMLForURLs(m_buffer); - if (tmp) { - SetBuffer(tmp); - PR_Free(tmp); - } - } - } + if (mySpec.Valid()) + length = mySpec.GetFileSize(); - if (m_parent && m_parent->m_type && + m_buffer = new char[length + 1]; + if (m_buffer) { + file = PR_Open(m_filename, PR_RDONLY, 0); + if (file) { + PR_Read(file, m_buffer, length); + PR_Close(file); + m_buffer[length] = '\0'; + file = NULL; + if (m_filename) + delete [] m_filename; + m_filename = NULL; + } + else { + delete [] m_buffer; + m_buffer = NULL; + } + } + } + if (m_buffer) + { + nsCOMPtr myURLUtil; + char *tmp = NULL; + + int res = nsComponentManager::CreateInstance(kCMimeURLUtilsCID, + NULL, nsIMimeURLUtils::GetIID(), + (void **) getter_AddRefs(myURLUtil)); + if (!NS_SUCCEEDED(res)) + goto FAIL; + + myURLUtil->ScanHTMLForURLs(m_buffer, &tmp); + if (tmp) { + SetBuffer(tmp); + PR_Free(tmp); + } + } + } + + if (m_parent && m_parent->m_type && !PL_strcasecmp(m_parent->m_type, MULTIPART_DIGEST) && - m_type && - (!PL_strcasecmp(m_type, MESSAGE_RFC822) || - !PL_strcasecmp(m_type, MESSAGE_NEWS))) { - /* If we're in a multipart/digest, and this document is of type - message/rfc822, then it's appropriate to emit no - headers. - */ - } - else { - char *message_headers = 0; - char *content_headers = 0; - char *content_type_header = 0; - status = divide_content_headers(m_other, - &message_headers, - &content_headers, - &content_type_header); - if (status < 0) - goto FAIL; - - /* First, write out all of the headers that refer to the message - itself (From, Subject, MIME-Version, etc.) - */ - if (message_headers) { - PUSH(message_headers); - PR_Free(message_headers); - message_headers = 0; - } - - /* Now allow the crypto library to (potentially) insert some text - (it may want to wrap the body in an envelope.) - */ - if (!m_parent) { - HJ67078 - } + m_type && + (!PL_strcasecmp(m_type, MESSAGE_RFC822) || + !PL_strcasecmp(m_type, MESSAGE_NEWS))) { + /* If we're in a multipart/digest, and this document is of type + message/rfc822, then it's appropriate to emit no + headers. + */ + } + else { + char *message_headers = 0; + char *content_headers = 0; + char *content_type_header = 0; + status = divide_content_headers(m_other, + &message_headers, + &content_headers, + &content_type_header); + if (status < 0) + goto FAIL; + + /* First, write out all of the headers that refer to the message + itself (From, Subject, MIME-Version, etc.) + */ + if (message_headers) { + PUSH(message_headers); + PR_Free(message_headers); + message_headers = 0; + } + + /* Now allow the crypto library to (potentially) insert some text + (it may want to wrap the body in an envelope.) + */ + if (!m_parent) { + HJ67078 + } - /* Now make sure there's a Content-Type header. - */ - if (!content_type_header) { - NS_ASSERTION(m_type && *m_type, "null ptr"); - PRBool needsCharset = mime_type_needs_charset(m_type ? m_type : TEXT_PLAIN); - if (needsCharset) { - content_type_header = - PR_smprintf("Content-Type: %s; charset=%s" CRLF, - (m_type ? m_type : TEXT_PLAIN), m_charset_name); - } - else - content_type_header = - PR_smprintf("Content-Type: %s" CRLF, - (m_type ? m_type : TEXT_PLAIN)); + /* Now make sure there's a Content-Type header. + */ + if (!content_type_header) { + NS_ASSERTION(m_type && *m_type, "null ptr"); + PRBool needsCharset = mime_type_needs_charset(m_type ? m_type : TEXT_PLAIN); + if (needsCharset) { + content_type_header = + PR_smprintf("Content-Type: %s; charset=%s" CRLF, + (m_type ? m_type : TEXT_PLAIN), m_charset_name); + } + else + content_type_header = + PR_smprintf("Content-Type: %s" CRLF, + (m_type ? m_type : TEXT_PLAIN)); + + if (!content_type_header) { + if (content_headers) + PR_Free(content_headers); + status = MK_OUT_OF_MEMORY; + goto FAIL; + } + } + + /* If this is a compound object, tack a boundary string onto the + Content-Type header. + */ + if (m_numchildren > 0) + { + int L; + char *ct2; + NS_ASSERTION(m_type, "null ptr"); + if (!separator) { + separator = mime_make_separator(""); + if (!separator) { + status = MK_OUT_OF_MEMORY; + goto FAIL; + } + } + L = PL_strlen(content_type_header); + + if (content_type_header[L-1] == LF) + content_type_header[--L] = 0; + if (content_type_header[L-1] == CR) + content_type_header[--L] = 0; + + ct2 = PR_smprintf("%s;\r\n boundary=\"%s\"" CRLF, + content_type_header, separator); + PR_Free(content_type_header); + if (!ct2) { + if (content_headers) + PR_Free(content_headers); + status = MK_OUT_OF_MEMORY; + goto FAIL; + } + + content_type_header = ct2; + } + + /* Now write out the Content-Type header... + */ + NS_ASSERTION(content_type_header && *content_type_header, "null ptr"); + PUSH(content_type_header); + PR_Free(content_type_header); + content_type_header = 0; + + /* ...followed by all of the other headers that refer to the body of + the message (Content-Transfer-Encoding, Content-Dispositon, etc.) + */ + if (content_headers) { + PUSH(content_headers); + PR_Free(content_headers); + content_headers = 0; + } + } + + PUSH(CRLF); // A blank line, to mark the end of headers. + + m_firstBlock = PR_TRUE; + /* only convert if we need to tag charset */ + m_needIntlConversion = mime_type_needs_charset(m_type); + m_intlDocToMailConverter = NULL; + + + if (m_buffer) { + NS_ASSERTION(!m_filename, "not-null m_filename"); + status = PushBody(m_buffer, PL_strlen(m_buffer)); + if (status < 0) + goto FAIL; + } + else if (m_filename) { + nsFileSpec mySpec(m_filename); + nsIOFileStream myStream(mySpec); - if (!content_type_header) { - if (content_headers) - PR_Free(content_headers); - status = MK_OUT_OF_MEMORY; - goto FAIL; - } - } - - /* If this is a compound object, tack a boundary string onto the - Content-Type header. - */ - if (m_numchildren > 0) - { - int L; - char *ct2; - NS_ASSERTION(m_type, "null ptr"); - if (!separator) { - separator = mime_make_separator(""); - if (!separator) { - status = MK_OUT_OF_MEMORY; - goto FAIL; - } - } - L = PL_strlen(content_type_header); - - if (content_type_header[L-1] == LF) - content_type_header[--L] = 0; - if (content_type_header[L-1] == CR) - content_type_header[--L] = 0; - - ct2 = PR_smprintf("%s;\r\n boundary=\"%s\"" CRLF, - content_type_header, separator); - PR_Free(content_type_header); - if (!ct2) { - if (content_headers) - PR_Free(content_headers); - status = MK_OUT_OF_MEMORY; - goto FAIL; - } - - content_type_header = ct2; - } - - /* Now write out the Content-Type header... - */ - NS_ASSERTION(content_type_header && *content_type_header, "null ptr"); - PUSH(content_type_header); - PR_Free(content_type_header); - content_type_header = 0; - - /* ...followed by all of the other headers that refer to the body of - the message (Content-Transfer-Encoding, Content-Dispositon, etc.) - */ - if (content_headers) { - PUSH(content_headers); - PR_Free(content_headers); - content_headers = 0; - } - } - - PUSH(CRLF); // A blank line, to mark the end of headers. - - m_firstBlock = PR_TRUE; - /* only convert if we need to tag charset */ - m_needIntlConversion = mime_type_needs_charset(m_type); - m_intlDocToMailConverter = NULL; - - - if (m_buffer) { - NS_ASSERTION(!m_filename, "not-null m_filename"); - status = PushBody(m_buffer, PL_strlen(m_buffer)); - if (status < 0) - goto FAIL; - } - else if (m_filename) { - file = PR_Open(m_filename, PR_RDONLY, 0); - if (!file) { - status = -1; // ### Better error code for a temp file - // mysteriously disappearing? - goto FAIL; - } - /* Kludge to avoid having to allocate memory on the toy computers... */ - if (!mime_mailto_stream_read_buffer) { - mime_mailto_stream_read_buffer = (char *) - PR_Malloc(MIME_BUFFER_SIZE); - if (!mime_mailto_stream_read_buffer) { - status = MK_OUT_OF_MEMORY; - goto FAIL; - } - } - char* buffer = mime_mailto_stream_read_buffer; - - if (m_strip_sensitive_headers) { - /* We are attaching a message, so we should be careful to - strip out certain sensitive internal header fields. + if (!myStream.is_open()) + { + status = -1; // ### Better error code for a temp file + // mysteriously disappearing? + goto FAIL; + } + /* Kludge to avoid having to allocate memory on the toy computers... */ + if (!mime_mailto_stream_read_buffer) { + mime_mailto_stream_read_buffer = (char *) + PR_Malloc(MIME_BUFFER_SIZE); + if (!mime_mailto_stream_read_buffer) { + status = MK_OUT_OF_MEMORY; + goto FAIL; + } + } + char* buffer = mime_mailto_stream_read_buffer; + + if (m_strip_sensitive_headers) { + /* We are attaching a message, so we should be careful to + strip out certain sensitive internal header fields. */ - PRBool skipping = PR_FALSE; - NS_ASSERTION(MIME_BUFFER_SIZE > 1000, "buffer size out of range"); /* SMTP (RFC821) limit */ + PRBool skipping = PR_FALSE; + NS_ASSERTION(MIME_BUFFER_SIZE > 1000, "buffer size out of range"); /* SMTP (RFC821) limit */ + + while (1) + { + char *line; - while (1) { - char *line = /*JFD XP_FileReadLine(buffer, MIME_BUFFER_SIZE-3, file)*/ NULL; - if (!line) - break; /* EOF */ - - if (skipping) { - if (*line == ' ' || *line == '\t') - continue; - else - skipping = PR_FALSE; - } - - int hdrLen = PL_strlen(buffer); - if ((hdrLen < 2) || (buffer[hdrLen-2] != CR)) { // if the line doesn't end with CRLF, - // ... make it end with CRLF. - if ( (hdrLen == 0) || ((buffer[hdrLen-1] != CR) && (buffer[hdrLen-1] != LF)) ) - hdrLen++; - buffer[hdrLen-1] = '\015'; - buffer[hdrLen] = '\012'; - buffer[hdrLen+1] = '\0'; - } - - if (!PL_strncasecmp(line, "BCC:", 4) || - !PL_strncasecmp(line, "FCC:", 4) || - !PL_strncasecmp(line, CONTENT_LENGTH ":", + if (myStream.eof()) + line = NULL; + else + { + buffer[0] = '\0'; + myStream.readline(buffer, MIME_BUFFER_SIZE-3); + line = buffer; + } + + if (!line) + break; /* EOF */ + + if (skipping) { + if (*line == ' ' || *line == '\t') + continue; + else + skipping = PR_FALSE; + } + + int hdrLen = PL_strlen(buffer); + if ((hdrLen < 2) || (buffer[hdrLen-2] != CR)) { // if the line doesn't end with CRLF, + // ... make it end with CRLF. + if ( (hdrLen == 0) || ((buffer[hdrLen-1] != CR) && (buffer[hdrLen-1] != LF)) ) + hdrLen++; + buffer[hdrLen-1] = '\015'; + buffer[hdrLen] = '\012'; + buffer[hdrLen+1] = '\0'; + } + + if (!PL_strncasecmp(line, "BCC:", 4) || + !PL_strncasecmp(line, "FCC:", 4) || + !PL_strncasecmp(line, CONTENT_LENGTH ":", CONTENT_LENGTH_LEN + 1) || - !PL_strncasecmp(line, "Lines:", 6) || - !PL_strncasecmp(line, "Status:", 7) || - !PL_strncasecmp(line, X_MOZILLA_STATUS ":", - X_MOZILLA_STATUS_LEN+1) || - !PL_strncasecmp(line, X_MOZILLA_NEWSHOST ":", - X_MOZILLA_NEWSHOST_LEN+1) || - !PL_strncasecmp(line, X_UIDL ":", X_UIDL_LEN+1) || - !PL_strncasecmp(line, "X-VM-", 5)) /* hi Kyle */ - { - skipping = PR_TRUE; - continue; - } - - PUSH(line); - - if (*line == CR || *line == LF) { - break; // Now can do normal reads for the body. - } - } - } - - - while (PR_TRUE) { - status = PR_Read(file, buffer, MIME_BUFFER_SIZE); - if (status < 0) - goto FAIL; - else if (status == 0) - break; - - status = PushBody(buffer, status); - if (status < 0) - goto FAIL; - } - } - - if (m_encoder_data) { - status = MIME_EncoderDestroy(m_encoder_data, PR_FALSE); - m_encoder_data = NULL; - if (status < 0) - goto FAIL; - } - - if (m_numchildren > 0) { - NS_ASSERTION(separator, "Null separator"); - for (int i = 0 ; i < m_numchildren ; i ++) { - PUSH(CRLF); - PUSH("--"); - PUSH(separator); - PUSH(CRLF); - status = m_children[i]->Write(); - if (status < 0) - goto FAIL; - } - PUSH(CRLF); - PUSH("--"); - PUSH(separator); - PUSH("--"); - PUSH(CRLF); - } - - - + !PL_strncasecmp(line, "Lines:", 6) || + !PL_strncasecmp(line, "Status:", 7) || + !PL_strncasecmp(line, X_MOZILLA_STATUS ":", + X_MOZILLA_STATUS_LEN+1) || + !PL_strncasecmp(line, X_MOZILLA_NEWSHOST ":", + X_MOZILLA_NEWSHOST_LEN+1) || + !PL_strncasecmp(line, X_UIDL ":", X_UIDL_LEN+1) || + !PL_strncasecmp(line, "X-VM-", 5)) /* hi Kyle */ + { + skipping = PR_TRUE; + continue; + } + + PUSH(line); + + if (*line == CR || *line == LF) { + break; // Now can do normal reads for the body. + } + } + } + + while (!myStream.eof()) + { + if ((status = myStream.read(buffer, MIME_BUFFER_SIZE)) < 0) + goto FAIL; + + status = PushBody(buffer, status); + if (status < 0) + goto FAIL; + } + } + + if (m_encoder_data) { + status = MIME_EncoderDestroy(m_encoder_data, PR_FALSE); + m_encoder_data = NULL; + if (status < 0) + goto FAIL; + } + + if (m_numchildren > 0) { + NS_ASSERTION(separator, "Null separator"); + for (int i = 0 ; i < m_numchildren ; i ++) { + PUSH(CRLF); + PUSH("--"); + PUSH(separator); + PUSH(CRLF); + status = m_children[i]->Write(); + if (status < 0) + goto FAIL; + } + PUSH(CRLF); + PUSH("--"); + PUSH(separator); + PUSH("--"); + PUSH(CRLF); + } + + + FAIL: - PR_FREEIF(separator); - if (file) - PR_Close(file); - if (m_intlDocToMailConverter) { - INTL_DestroyCharCodeConverter(m_intlDocToMailConverter); - m_intlDocToMailConverter = NULL; - } - return status; + PR_FREEIF(separator); + if (file) + PR_Close(file); + if (m_intlDocToMailConverter) { + INTL_DestroyCharCodeConverter(m_intlDocToMailConverter); + m_intlDocToMailConverter = NULL; + } + return status; } + diff --git a/mailnews/compose/src/nsMsgSendPart.h b/mailnews/compose/src/nsMsgSendPart.h index 17a7ac24e33..521c83852a8 100644 --- a/mailnews/compose/src/nsMsgSendPart.h +++ b/mailnews/compose/src/nsMsgSendPart.h @@ -19,10 +19,6 @@ #ifndef _MsgSendPart_H_ #define _MsgSendPart_H_ -/*JFD -#include "msgzap.h" -#include "mimeenc.h" -*/ #include "msgCore.h" #include "prprf.h" /* should be defined into msgCore.h? */ #include "net.h" /* should be defined into msgCore.h? */ @@ -36,7 +32,6 @@ class nsMsgSendMimeDeliveryState; typedef int (*MSG_SendPartWriteFunc)(const char* line, PRInt32 size, PRBool isheader, void* closure); - class nsMsgSendPart : public MSG_ZapIt { public: nsMsgSendPart(nsMsgSendMimeDeliveryState* state, const char *part_charset = NULL);