diff --git a/mozilla/mailnews/addrbook/resources/content/abCommon.js b/mozilla/mailnews/addrbook/resources/content/abCommon.js index 9783671549e..04ad593999a 100644 --- a/mozilla/mailnews/addrbook/resources/content/abCommon.js +++ b/mozilla/mailnews/addrbook/resources/content/abCommon.js @@ -180,9 +180,20 @@ function AbNewMessage() var msgComposFormat = Components.interfaces.nsIMsgCompFormat; var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService(); msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService); - msgComposeService.OpenComposeWindowWithValues(null, msgComposeType.New, msgComposFormat.Default, - GetSelectedAddresses(), null, null, - null, null, null, null, null); + + params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams); + if (params) + { + params.type = msgComposeType.New; + params.format = msgComposFormat.Default; + composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields); + if (composeFields) + { + composeFields.to = GetSelectedAddresses(); + params.composeFields = composeFields; + msgComposeService.OpenComposeWindowWithParams(null, params); + } + } } function GetSelectedAddresses() diff --git a/mozilla/mailnews/compose/build/nsMsgCompCID.h b/mozilla/mailnews/compose/build/nsMsgCompCID.h index a4a488ccbb1..a660602a76d 100644 --- a/mozilla/mailnews/compose/build/nsMsgCompCID.h +++ b/mozilla/mailnews/compose/build/nsMsgCompCID.h @@ -45,12 +45,12 @@ // // nsMsgComposeService // -#define NS_MSGCOMPOSESERVICE_CID \ +#define NS_MSGCOMPOSESERVICE_CID \ { /* 588595FE-1ADA-11d3-A715-0060B0EB39B5 */ \ 0x588595fe, 0x1ada, 0x11d3, \ {0xa7, 0x15, 0x0, 0x60, 0xb0, 0xeb, 0x39, 0xb5}} -#define NS_MSGCOMPOSESERVICE_CONTRACTID \ +#define NS_MSGCOMPOSESERVICE_CONTRACTID \ "@mozilla.org/messengercompose;1" #define NS_MSGCOMPOSESTARTUPHANDLER_CONTRACTID \ "@mozilla.org/commandlinehandler/general-startup;1?type=compose" @@ -58,7 +58,7 @@ // // nsMsgComposeContentHandler // -#define NS_MSGCOMPOSECONTENTHANDLER_CID \ +#define NS_MSGCOMPOSECONTENTHANDLER_CID \ { /* 0B63FB80-BBBA-11D4-9DAA-91B657EB313C */ \ 0x0b63fb80, 0xbbba, 0x11d4, \ {0x9d, 0xaa, 0x91, 0xb6, 0x57, 0xeb, 0x31, 0x3c}} @@ -72,7 +72,7 @@ #define NS_MSGCOMPOSE_CONTRACTID \ "@mozilla.org/messengercompose/compose;1" -#define NS_MSGCOMPOSE_CID \ +#define NS_MSGCOMPOSE_CID \ { /* EB5BDAF8-BBC6-11d2-A6EC-0060B0EB39B5 */ \ 0xeb5bdaf8, 0xbbc6, 0x11d2, \ {0xa6, 0xec, 0x0, 0x60, 0xb0, 0xeb, 0x39, 0xb5}} @@ -83,7 +83,7 @@ #define NS_MSGCOMPOSEPARAMS_CONTRACTID \ "@mozilla.org/messengercompose/composeparams;1" -#define NS_MSGCOMPOSEPARAMS_CID \ +#define NS_MSGCOMPOSEPARAMS_CID \ { /* CB998A00-C079-11D4-9DAA-8DF64BAB2EFC */ \ 0xcb998a00, 0xc079, 0x11d4, \ {0x9d, 0xaa, 0x8d, 0xf6, 0x4b, 0xab, 0x2e, 0xfc}} @@ -94,7 +94,7 @@ #define NS_MSGCOMPOSESENDLISTENER_CONTRACTID \ "@mozilla.org/messengercompose/composesendlistener;1" -#define NS_MSGCOMPOSESENDLISTENER_CID \ +#define NS_MSGCOMPOSESENDLISTENER_CID \ { /* acc72781-2cea-11d5-9daa-bacdeac1eefc */ \ 0xacc72781, 0x2cea, 0x11d5, \ {0x9d, 0xaa, 0xba, 0xcd, 0xea, 0xc1, 0xee, 0xfc}} @@ -105,7 +105,7 @@ #define NS_MSGCOMPOSEPROGRESSPARAMS_CONTRACTID \ "@mozilla.org/messengercompose/composeprogressparameters;1" -#define NS_MSGCOMPOSEPROGRESSPARAMS_CID \ +#define NS_MSGCOMPOSEPROGRESSPARAMS_CID \ { /* 1e0e7c01-3e4c-11d5-9daa-f88d288130fc */ \ 0x1e0e7c01, 0x3e4c, 0x11d5, \ {0x9d, 0xaa, 0xf8, 0x8d, 0x28, 0x81, 0x30, 0xfc}} @@ -116,18 +116,29 @@ #define NS_MSGCOMPFIELDS_CONTRACTID \ "@mozilla.org/messengercompose/composefields;1" -#define NS_MSGCOMPFIELDS_CID \ +#define NS_MSGCOMPFIELDS_CID \ { /* 6D222BA0-BD46-11d2-8293-000000000000 */ \ 0x6d222ba0, 0xbd46, 0x11d2, \ {0x82, 0x93, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}} +// +// nsMsgAttachment +// +#define NS_MSGATTACHMENT_CONTRACTID \ + "@mozilla.org/messengercompose/attachment;1" + +#define NS_MSGATTACHMENT_CID \ +{ /* 27B8D045-8D9F-4fa8-BFB6-8A0F8D09CE89 */ \ + 0x27b8d045, 0x8d9f, 0x4fa8, \ + {0xbf, 0xb6, 0x8a, 0xf, 0x8d, 0x9, 0xce, 0x89}} + // // nsMsgSend // #define NS_MSGSEND_CONTRACTID \ "@mozilla.org/messengercompose/send;1" -#define NS_MSGSEND_CID \ +#define NS_MSGSEND_CID \ { /* 935284E0-C5D8-11d2-8297-000000000000 */ \ 0x935284e0, 0xc5d8, 0x11d2, \ {0x82, 0x97, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}} @@ -135,10 +146,10 @@ // // nsMsgSendLater // -#define NS_MSGSENDLATER_CONTRACTID \ +#define NS_MSGSENDLATER_CONTRACTID \ "@mozilla.org/messengercompose/sendlater;1" -#define NS_MSGSENDLATER_CID \ +#define NS_MSGSENDLATER_CID \ { /* E15C83F1-1CF4-11d3-8EF0-00A024A7D144 */ \ 0xe15c83f1, 0x1cf4, 0x11d3, \ {0x8e, 0xf0, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 }} @@ -173,7 +184,7 @@ #define NS_SMTPSERVER_CID \ { /* 60dc861a-56ce-11d3-9118-00a0c900d445 */ \ - 0x60dc861a,0x56ce,0x11d3, \ + 0x60dc861a,0x56ce,0x11d3, \ {0x91,0x18, 0x0, 0xa0, 0xc9, 0x0, 0xd4, 0x45 }} // @@ -185,7 +196,7 @@ #define NS_MAILTOHANDLER_CONTRACTID \ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "mailto" -#define NS_SMTPSERVICE_CID \ +#define NS_SMTPSERVICE_CID \ { /* 5B6419F1-CA9B-11d2-8063-006008128C4E */ \ 0x5b6419f1, 0xca9b, 0x11d2, \ {0x80, 0x63, 0x0, 0x60, 0x8, 0x12, 0x8c, 0x4e}} diff --git a/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp b/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp index 2d854925619..7365854c76f 100644 --- a/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp +++ b/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp @@ -58,6 +58,7 @@ #include "nsMsgCompose.h" #include "nsMsgComposeParams.h" #include "nsMsgComposeProgressParams.h" +#include "nsMsgAttachment.h" #include "nsMsgSend.h" #include "nsMsgQuote.h" #include "nsIMsgDraft.h" @@ -77,6 +78,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeParams); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeSendListener); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeProgressParams); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgCompFields); +NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgAttachment); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeAndSend); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgSendLater); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgDraft) @@ -132,6 +134,10 @@ static nsModuleComponentInfo components[] = NS_MSGCOMPFIELDS_CID, NS_MSGCOMPFIELDS_CONTRACTID, nsMsgCompFieldsConstructor }, + { "Msg Compose Attachment", + NS_MSGATTACHMENT_CID, + NS_MSGATTACHMENT_CONTRACTID, + nsMsgAttachmentConstructor }, { "Msg Draft", NS_MSGDRAFT_CID, NS_MSGDRAFT_CONTRACTID, diff --git a/mozilla/mailnews/compose/macbuild/msgCompose.mcp b/mozilla/mailnews/compose/macbuild/msgCompose.mcp index 06438ca8e86..c04f03e76bf 100644 Binary files a/mozilla/mailnews/compose/macbuild/msgCompose.mcp and b/mozilla/mailnews/compose/macbuild/msgCompose.mcp differ diff --git a/mozilla/mailnews/compose/macbuild/msgComposeIDL.mcp b/mozilla/mailnews/compose/macbuild/msgComposeIDL.mcp index 286e92c9f54..e12f23d761a 100644 Binary files a/mozilla/mailnews/compose/macbuild/msgComposeIDL.mcp and b/mozilla/mailnews/compose/macbuild/msgComposeIDL.mcp differ diff --git a/mozilla/mailnews/compose/public/Makefile.in b/mozilla/mailnews/compose/public/Makefile.in index 1feed540f08..b33fdc98e82 100644 --- a/mozilla/mailnews/compose/public/Makefile.in +++ b/mozilla/mailnews/compose/public/Makefile.in @@ -32,6 +32,7 @@ EXPORTS = \ $(NULL) XPIDLSRCS = \ + nsIMsgAttachment.idl \ nsIMsgComposeProgressParams.idl \ nsIMsgComposeParams.idl \ nsIMsgComposeService.idl \ diff --git a/mozilla/mailnews/compose/public/makefile.win b/mozilla/mailnews/compose/public/makefile.win index 3c013d03a84..16c5eeffd5e 100644 --- a/mozilla/mailnews/compose/public/makefile.win +++ b/mozilla/mailnews/compose/public/makefile.win @@ -23,6 +23,7 @@ DEPTH=..\..\.. MODULE=msgcompo XPIDLSRCS = \ + .\nsIMsgAttachment.idl \ .\nsIMsgComposeProgressParams.idl \ .\nsIMsgComposeParams.idl \ .\nsIMsgComposeService.idl \ diff --git a/mozilla/mailnews/compose/public/nsIMsgAttachment.idl b/mozilla/mailnews/compose/public/nsIMsgAttachment.idl new file mode 100644 index 00000000000..6b65f82934f --- /dev/null +++ b/mozilla/mailnews/compose/public/nsIMsgAttachment.idl @@ -0,0 +1,104 @@ +/* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +[scriptable, uuid(5FB62950-9A0B-41b4-8D11-F6888DFF835E)] +interface nsIMsgAttachment : nsISupports { + + /** + * name attribute + * + * @Attachment real name, will be sent with the attachment's header. + * @If no name has been provided, a name will be generated using the url. + */ + attribute wstring name; + + /** + * url attribute + * + * @specify where the attachment live (localy or remotely) + */ + attribute string url; + + /** + * temporary attribute + * + * @If set to true, the file pointed by the url will be destroyed when tis object is destroyed. + * @This is only for local attachment. + */ + attribute boolean temporary; + + /** + * contentLocation attribute + * + * @Specify the origin url of the attachment, used normaly when attaching a locally saved html document. + */ + attribute string contentLocation; + + /** + * contentType attribute + * + * @Specify the content-type of the attachment + * @If ommitted, it will be determined base on either the url or the content of the file. + */ + attribute string contentType; + + + /** + * macType attribute + * + * @Specify the Mac file type of the attachment + * @If omitted, will be determined automatically on Macintosh OS. + */ + attribute string macType; + + /** + * macCreator attribute + * + * @Specify the Mac file creator of the attachment + * @If omitted, will be determined automatically on Macintosh OS. + */ + attribute string macCreator; + + /** + * equalsUrl + * + * @ determines if both attachments have the same url. + */ + boolean equalsUrl(in nsIMsgAttachment attachment); +}; diff --git a/mozilla/mailnews/compose/public/nsIMsgCompFields.idl b/mozilla/mailnews/compose/public/nsIMsgCompFields.idl index d8b1fdcefef..9730f9b0dfb 100644 --- a/mozilla/mailnews/compose/public/nsIMsgCompFields.idl +++ b/mozilla/mailnews/compose/public/nsIMsgCompFields.idl @@ -37,49 +37,68 @@ #include "nsISupports.idl" #include "nsIMsgRecipientArray.idl" +#include "nsIMsgAttachment.idl" +#include "nsISupportsArray.idl" [scriptable, uuid(3E89CAE3-BD2D-11d2-8293-000000000000)] interface nsIMsgCompFields : nsISupports { - attribute wstring from; - attribute wstring replyTo; - attribute wstring to; - attribute wstring cc; - attribute wstring bcc; - - attribute wstring fcc; - attribute wstring fcc2; - - attribute string newsgroups; - attribute string newshost; - attribute string newspostUrl; - attribute string followupTo; + attribute wstring from; + attribute wstring replyTo; + attribute wstring to; + attribute wstring cc; + attribute wstring bcc; + + attribute wstring fcc; + attribute wstring fcc2; + + attribute string newsgroups; + attribute string newshost; + attribute string newspostUrl; + attribute string followupTo; - attribute wstring subject; - attribute string attachments; - attribute wstring organization; - attribute string references; + attribute wstring subject; + + /** + * attachments + * + * @OBSOLETE, DO NOT USE ANYMORE + */ + attribute string attachments; + + attribute wstring organization; + attribute string references; attribute string priority; - attribute string messageId; - attribute string characterSet; + attribute string messageId; + attribute string characterSet; - attribute wstring templateName; - attribute string draftId; + attribute wstring templateName; + attribute string draftId; - attribute boolean returnReceipt; - attribute boolean attachVCard; + attribute boolean returnReceipt; + attribute boolean attachVCard; attribute boolean forcePlainText; attribute boolean useMultipartAlternative; attribute boolean uuEncodeAttachments; attribute wstring otherRandomHeaders; - attribute wstring body; + attribute wstring body; - attribute string temporaryFiles; // a list of temp files to remove - - /* some utility functions */ + /** + * temporaryFiles + * + * @OBSOLETE, DO NOT USE ANYMORE + */ + attribute string temporaryFiles; + + readonly attribute nsISupportsArray attachmentsArray; + void addAttachment(in nsIMsgAttachment attachment); + void removeAttachment(in nsIMsgAttachment attachment); + void removeAttachments(); + + /* some utility functions */ nsIMsgRecipientArray SplitRecipients(in wstring recipients, in boolean emailAddressOnly); void ConvertBodyToPlainText(); }; diff --git a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl index 07b724e390b..e77cf65c0b0 100644 --- a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl +++ b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl @@ -48,35 +48,45 @@ interface nsIMsgWindow; [scriptable, uuid(B004F4AE-1AC2-11d3-A715-0060B0EB39B5)] interface nsIMsgComposeService : nsISupports { - /* we need a msg window because when we forward inline we may need progress */ - void OpenComposeWindow(in string msgComposeWindowURL, in string originalMsgURI, in MSG_ComposeType type, in MSG_ComposeFormat format, - in nsIMsgIdentity identity, + /* we need a msg window because when we forward inline we may need progress */ + void OpenComposeWindow(in string msgComposeWindowURL, in string originalMsgURI, in MSG_ComposeType type, in MSG_ComposeFormat format, + in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow); /* use this method to invoke a compose window given a mailto url. - aMsgComposeWindowURL --> can be null in most cases. If you have your own chrome - url you want to use in brining up a compose window, pass it in here. - aURI --> the mailto url you want to use as the foundation for the data inside - the compose window */ - void OpenComposeWindowWithURI(in string msgComposeWindowURL, in nsIURI aURI); + aMsgComposeWindowURL --> can be null in most cases. If you have your own chrome + url you want to use in brining up a compose window, pass it in here. + aURI --> the mailto url you want to use as the foundation for the data inside + the compose window */ + void OpenComposeWindowWithURI(in string msgComposeWindowURL, in nsIURI aURI); - /* ... */ - void OpenComposeWindowWithValues(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, - in wstring to, in wstring cc, in wstring bcc, in string newsgroups, - in wstring subject, in wstring body, in string attachment, in nsIMsgIdentity identity); + /** + * OpenComposeWindowWithValues + * + * @NOT SUPPORTED ANYMORE, USE OpenComposeWindowWithParams INSTEAD. + * @THIS API WILL BE REMOVED + */ + void OpenComposeWindowWithValues(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, + in wstring to, in wstring cc, in wstring bcc, in string newsgroups, + in wstring subject, in wstring body, in string attachment, in nsIMsgIdentity identity); - /* ... */ - void OpenComposeWindowWithCompFields(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, - in nsIMsgCompFields compFields, in nsIMsgIdentity identity); + /** + * OpenComposeWindowWithCompFields + * + * @NOT SUPPORTED ANYMORE, USE OpenComposeWindowWithParams INSTEAD. + * @THIS API WILL BE REMOVED + */ + void OpenComposeWindowWithCompFields(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, + in nsIMsgCompFields compFields, in nsIMsgIdentity identity); - /* ... */ - void OpenComposeWindowWithParams(in string msgComposeWindowURL, in nsIMsgComposeParams params); + /* ... */ + void OpenComposeWindowWithParams(in string msgComposeWindowURL, in nsIMsgComposeParams params); - /* ... */ - nsIMsgCompose InitCompose(in nsIDOMWindowInternal aWindow, in nsIMsgComposeParams params); + /* ... */ + nsIMsgCompose InitCompose(in nsIDOMWindowInternal aWindow, in nsIMsgComposeParams params); - /* This function is use for debugging purpose only and may go away at anytime without warning */ - void TimeStamp(in string label, in boolean resetTime); + /* This function is use for debugging purpose only and may go away at anytime without warning */ + void TimeStamp(in string label, in boolean resetTime); /* This attribute is use for debugging purposes for determining whether to PR_LOG or not */ readonly attribute boolean logComposePerformance; diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index 757030e8077..ca994178b8f 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -99,11 +99,11 @@ function enableEditableFields() } var stateListener = { - NotifyComposeFieldsReady: function() { - ComposeFieldsReady(); - }, + NotifyComposeFieldsReady: function() { + ComposeFieldsReady(); + }, - ComposeProcessDone: function(aResult) { + ComposeProcessDone: function(aResult) { dump("\n RECEIVE ComposeProcessDone\n\n"); gWindowLocked = false; CommandUpdate_MsgCompose(); @@ -119,7 +119,7 @@ var stateListener = { } gCloseWindowAfterSave = false; - }, + }, SaveInFolderDone: function(folderURI) { DisplaySaveFolderDlg(folderURI); @@ -166,7 +166,7 @@ var progressListener = { } }, - onLocationChange: function(aWebProgress, aRequest, aLocation) + onLocationChange: function(aWebProgress, aRequest, aLocation) { // we can ignore this notification }, @@ -898,7 +898,7 @@ function DoCommandClose() { var retVal; if ((retVal = ComposeCanClose())) - MsgComposeCloseWindow(); + MsgComposeCloseWindow(); return retVal; } @@ -929,67 +929,67 @@ function ToggleWindowLock() /* This function will go away soon as now arguments are passed to the window using a object of type nsMsgComposeParams instead of a string */ function GetArgs(originalData) { - var args = new Object(); + var args = new Object(); - if (originalData == "") - return null; + if (originalData == "") + return null; - var data = ""; - var separator = String.fromCharCode(1); + var data = ""; + var separator = String.fromCharCode(1); - var quoteChar = ""; - var prevChar = ""; - var nextChar = ""; - for (var i = 0; i < originalData.length; i ++, prevChar = aChar) - { - var aChar = originalData.charAt(i) - var aCharCode = originalData.charCodeAt(i) - if ( i < originalData.length - 1) - nextChar = originalData.charAt(i + 1); - else - nextChar = ""; + var quoteChar = ""; + var prevChar = ""; + var nextChar = ""; + for (var i = 0; i < originalData.length; i ++, prevChar = aChar) + { + var aChar = originalData.charAt(i) + var aCharCode = originalData.charCodeAt(i) + if ( i < originalData.length - 1) + nextChar = originalData.charAt(i + 1); + else + nextChar = ""; - if (aChar == quoteChar && (nextChar == "," || nextChar == "")) - { - quoteChar = ""; - data += aChar; - } - else if ((aCharCode == 39 || aCharCode == 34) && prevChar == "=") //quote or double quote - { - if (quoteChar == "") - quoteChar = aChar; - data += aChar; - } - else if (aChar == ",") - { - if (quoteChar == "") - data += separator; - else - data += aChar - } - else - data += aChar - } + if (aChar == quoteChar && (nextChar == "," || nextChar == "")) + { + quoteChar = ""; + data += aChar; + } + else if ((aCharCode == 39 || aCharCode == 34) && prevChar == "=") //quote or double quote + { + if (quoteChar == "") + quoteChar = aChar; + data += aChar; + } + else if (aChar == ",") + { + if (quoteChar == "") + data += separator; + else + data += aChar + } + else + data += aChar + } - var pairs = data.split(separator); -// dump("Compose: argument: {" + data + "}\n"); + var pairs = data.split(separator); +// dump("Compose: argument: {" + data + "}\n"); - for (i = pairs.length - 1; i >= 0; i--) - { - var pos = pairs[i].indexOf('='); - if (pos == -1) - continue; - var argname = pairs[i].substring(0, pos); - var argvalue = pairs[i].substring(pos + 1); - if (argvalue.charAt(0) == "'" && argvalue.charAt(argvalue.length - 1) == "'") - args[argname] = argvalue.substring(1, argvalue.length - 1); - else - try { + for (i = pairs.length - 1; i >= 0; i--) + { + var pos = pairs[i].indexOf('='); + if (pos == -1) + continue; + var argname = pairs[i].substring(0, pos); + var argvalue = pairs[i].substring(pos + 1); + if (argvalue.charAt(0) == "'" && argvalue.charAt(argvalue.length - 1) == "'") + args[argname] = argvalue.substring(1, argvalue.length - 1); + else + try { args[argname] = unescape(argvalue); } catch (e) {args[argname] = argvalue;} - dump("[" + argname + "=" + args[argname] + "]\n"); - } - return args; + dump("[" + argname + "=" + args[argname] + "]\n"); + } + return args; } function ComposeFieldsReady(msgType) @@ -1047,21 +1047,30 @@ function ComposeStartup() params.originalMsgURI = args.originalMsg; if (args.preselectid) params.identity = getIdentityForKey(args.preselectid); - if (args.to) - composeFields.to = args.to; - if (args.cc) - composeFields.cc = args.cc; - if (args.bcc) - composeFields.bcc = args.bcc; - if (args.newsgroups) - composeFields.newsgroups = args.newsgroups; - if (args.subject) - composeFields.subject = args.subject; - if (args.attachment) - composeFields.attachments = args.attachment; - if (args.newshost) - composeFields.newshost = args.newshost; - if (args.body) + if (args.to) + composeFields.to = args.to; + if (args.cc) + composeFields.cc = args.cc; + if (args.bcc) + composeFields.bcc = args.bcc; + if (args.newsgroups) + composeFields.newsgroups = args.newsgroups; + if (args.subject) + composeFields.subject = args.subject; + if (args.attachment) + { + var attachmentList = args.attachment.split(","); + var attachment; + for (var i = 0; i < attachmentList.length; i ++) + { + attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment); + attachment.url = attachmentList[i]; + composeFields.addAttachment(attachment); + } + } + if (args.newshost) + composeFields.newshost = args.newshost; + if (args.body) composeFields.body = args.body; } } @@ -1087,55 +1096,55 @@ function ComposeStartup() } } LoadIdentity(true); - if (msgComposeService) - { - msgCompose = msgComposeService.InitCompose(window, params); - if (msgCompose) - { - //Creating a Editor Shell - var editorElement = document.getElementById("content-frame"); - if (!editorElement) - { - dump("Failed to get editor element!\n"); - return; - } - var editorShell = editorElement.editorShell; - if (!editorShell) - { - dump("Failed to create editorShell!\n"); - return; - } + if (msgComposeService) + { + msgCompose = msgComposeService.InitCompose(window, params); + if (msgCompose) + { + //Creating a Editor Shell + var editorElement = document.getElementById("content-frame"); + if (!editorElement) + { + dump("Failed to get editor element!\n"); + return; + } + var editorShell = editorElement.editorShell; + if (!editorShell) + { + dump("Failed to create editorShell!\n"); + return; + } - // save the editorShell in the window. The editor JS expects to find it there. - window.editorShell = editorShell; -// dump("Created editorShell\n"); + // save the editorShell in the window. The editor JS expects to find it there. + window.editorShell = editorShell; +// dump("Created editorShell\n"); - // setEditorType MUST be call before setContentWindow - if (msgCompose.composeHTML) - { - window.editorShell.editorType = "htmlmail"; - } - else - { - //Remove HTML toolbar, format and insert menus as we are editing in plain text mode + // setEditorType MUST be call before setContentWindow + if (msgCompose.composeHTML) + { + window.editorShell.editorType = "htmlmail"; + } + else + { + //Remove HTML toolbar, format and insert menus as we are editing in plain text mode document.getElementById("outputFormatMenu").setAttribute("hidden", true); document.getElementById("FormatToolbar").setAttribute("hidden", true); document.getElementById("formatMenu").setAttribute("hidden", true); document.getElementById("insertMenu").setAttribute("hidden", true); document.getElementById("menu_showFormatToolbar").setAttribute("hidden", true); - window.editorShell.editorType = "textmail"; -// dump("editor initialized in PLAIN TEXT mode\n"); - } - window.editorShell.webShellWindow = window; - window.editorShell.contentWindow = window._content; + window.editorShell.editorType = "textmail"; +// dump("editor initialized in PLAIN TEXT mode\n"); + } + window.editorShell.webShellWindow = window; + window.editorShell.contentWindow = window._content; - // Do setup common to Message Composer and Web Composer - EditorSharedStartup(); + // Do setup common to Message Composer and Web Composer + EditorSharedStartup(); - var msgCompFields = msgCompose.compFields; - if (msgCompFields) - { + var msgCompFields = msgCompose.compFields; + if (msgCompFields) + { if (params.bodyIsLink) { var body = msgCompFields.body; @@ -1152,41 +1161,39 @@ function ComposeStartup() msgCompFields.body = "\n<" + body + ">\n"; } - var subjectValue = msgCompFields.subject; - if (subjectValue != "") { - document.getElementById("msgSubject").value = subjectValue; - } - - var attachmentValue = msgCompFields.attachments; - if (attachmentValue != "") { - var atts = attachmentValue.split(","); - for (var i=0; i < atts.length; i++) - AddAttachment(atts[i], null); + var subjectValue = msgCompFields.subject; + if (subjectValue != "") { + document.getElementById("msgSubject").value = subjectValue; } - } - // Now that we have an Editor AppCore, we can finish to initialize the Compose AppCore - msgCompose.editor = window.editorShell; + var attachments = msgCompFields.attachmentsArray; + if (attachments) + for (var i = 0; i < attachments.Count(); i ++) + AddAttachment(attachments.QueryElementAt(i, Components.interfaces.nsIMsgAttachment)); + } - msgCompose.RegisterStateListener(stateListener); + // Now that we have an Editor AppCore, we can finish to initialize the Compose AppCore + msgCompose.editor = window.editorShell; + + msgCompose.RegisterStateListener(stateListener); - } - } + } + } } function WizCallback(state) { - if (state){ - ComposeStartup(); - } - else - { - if (msgCompose) - msgCompose.CloseWindow(); - else - window.close(); -// window.tryToClose=ComposeCanClose; - } + if (state){ + ComposeStartup(); + } + else + { + if (msgCompose) + msgCompose.CloseWindow(); + else + window.close(); +// window.tryToClose=ComposeCanClose; + } } function ComposeLoad() @@ -1219,7 +1226,7 @@ function ComposeLoad() try { SetupCommandUpdateHandlers(); var wizardcallback = true; - var state = verifyAccounts(wizardcallback); // this will do migration, or create a new account if we need to. + var state = verifyAccounts(wizardcallback); // this will do migration, or create a new account if we need to. if (other_header != "") { var selectNode = document.getElementById('msgRecipientType#1'); @@ -1258,13 +1265,13 @@ function ComposeLoad() function ComposeUnload() { - dump("\nComposeUnload from XUL\n"); - RemoveMessageComposeOfflineObserver(); + dump("\nComposeUnload from XUL\n"); + RemoveMessageComposeOfflineObserver(); RemoveDirectoryServerObserver(null); RemoveDirectoryServerObserver("mail.identity." + gCurrentIdentity.key); if (currentAutocompleteDirectory) RemoveDirectorySettingsObserver(currentAutocompleteDirectory); - msgCompose.UnregisterStateListener(stateListener); + msgCompose.UnregisterStateListener(stateListener); } function SetDocumentCharacterSet(aCharset) @@ -1380,65 +1387,59 @@ function GetCharsetUIString() function GenericSendMessage( msgType ) { - dump("GenericSendMessage from XUL\n"); + dump("GenericSendMessage from XUL\n"); dump("Identity = " + getCurrentIdentity() + "\n"); - if (msgCompose != null) - { - var msgCompFields = msgCompose.compFields; - if (msgCompFields) - { - Recipients2CompFields(msgCompFields); - var subject = document.getElementById("msgSubject").value; - msgCompFields.subject = subject; - dump("attachments = " + GenerateAttachmentsString() + "\n"); - try { - msgCompFields.attachments = GenerateAttachmentsString(); - } - catch (ex) { - dump("failed to SetAttachments\n"); - } + if (msgCompose != null) + { + var msgCompFields = msgCompose.compFields; + if (msgCompFields) + { + Recipients2CompFields(msgCompFields); + var subject = document.getElementById("msgSubject").value; + msgCompFields.subject = subject; + Attachments2CompFields(msgCompFields); - if (msgType == msgCompDeliverMode.Now || msgType == msgCompDeliverMode.Later) - { - //Do we need to check the spelling? + if (msgType == msgCompDeliverMode.Now || msgType == msgCompDeliverMode.Later) + { + //Do we need to check the spelling? if (prefs.getBoolPref("mail.SpellCheckBeforeSend")) - goDoCommand('cmd_spelling'); + goDoCommand('cmd_spelling'); - //Check if we have a subject, else ask user for confirmation - if (subject == "") - { - if (!gPromptService) { - gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(); + //Check if we have a subject, else ask user for confirmation + if (subject == "") + { + if (!gPromptService) { + gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(); gPromptService = gPromptService.QueryInterface(Components.interfaces.nsIPromptService); } - if (gPromptService) - { - var result = {value:gComposeMsgsBundle.getString("defaultSubject")}; - if (gPromptService.prompt( - window, - gComposeMsgsBundle.getString("subjectDlogTitle"), - gComposeMsgsBundle.getString("subjectDlogMessage"), + if (gPromptService) + { + var result = {value:gComposeMsgsBundle.getString("defaultSubject")}; + if (gPromptService.prompt( + window, + gComposeMsgsBundle.getString("subjectDlogTitle"), + gComposeMsgsBundle.getString("subjectDlogMessage"), result, - null, - {value:0} - )) - { - msgCompFields.subject = result.value; - var subjectInputElem = document.getElementById("msgSubject"); - subjectInputElem.value = result.value; - } - else - return; - } - } + null, + {value:0} + )) + { + msgCompFields.subject = result.value; + var subjectInputElem = document.getElementById("msgSubject"); + subjectInputElem.value = result.value; + } + else + return; + } + } - // Before sending the message, check what to do with HTML message, eventually abort. + // Before sending the message, check what to do with HTML message, eventually abort. var convert = DetermineConvertibility(); var action = DetermineHTMLAction(convert); if (action == msgCompSendFormat.AskUser) - { + { var recommAction = convert == msgCompConvertible.No ? msgCompSendFormat.AskUser : msgCompSendFormat.PlainText; @@ -1448,28 +1449,28 @@ function GenericSendMessage( msgType ) window.openDialog("chrome://messenger/content/messengercompose/askSendFormat.xul", "askSendFormatDialog", "chrome,modal,titlebar,centerscreen", result2); - if (result2.abort) - return; - action = result2.action; - } - switch (action) - { - case msgCompSendFormat.PlainText: - msgCompFields.forcePlainText = true; - msgCompFields.useMultipartAlternative = false; - break; - case msgCompSendFormat.HTML: - msgCompFields.forcePlainText = false; - msgCompFields.useMultipartAlternative = false; - break; - case msgCompSendFormat.Both: - msgCompFields.forcePlainText = false; - msgCompFields.useMultipartAlternative = true; - break; - default: dump("\###SendMessage Error: invalid action value\n"); return; - } - } - try { + if (result2.abort) + return; + action = result2.action; + } + switch (action) + { + case msgCompSendFormat.PlainText: + msgCompFields.forcePlainText = true; + msgCompFields.useMultipartAlternative = false; + break; + case msgCompSendFormat.HTML: + msgCompFields.forcePlainText = false; + msgCompFields.useMultipartAlternative = false; + break; + case msgCompSendFormat.Both: + msgCompFields.forcePlainText = false; + msgCompFields.useMultipartAlternative = true; + break; + default: dump("\###SendMessage Error: invalid action value\n"); return; + } + } + try { gWindowLocked = true; CommandUpdate_MsgCompose(); disableEditableFields(); @@ -1480,24 +1481,24 @@ function GenericSendMessage( msgType ) progress.registerListener(progressListener); sendOrSaveOperationInProgress = true; } - msgCompose.SendMsg(msgType, getCurrentIdentity(), progress); - } - catch (ex) { + msgCompose.SendMsg(msgType, getCurrentIdentity(), progress); + } + catch (ex) { dump("failed to SendMsg: " + ex + "\n"); gWindowLocked = false; enableEditableFields(); CommandUpdate_MsgCompose(); - } - } - } - else - dump("###SendMessage Error: composeAppCore is null!\n"); + } + } + } + else + dump("###SendMessage Error: composeAppCore is null!\n"); } function SendMessage() { - dump("SendMessage from XUL\n"); - GenericSendMessage(msgCompDeliverMode.Now); + dump("SendMessage from XUL\n"); + GenericSendMessage(msgCompDeliverMode.Now); } function SendMessageWithCheck() @@ -1528,40 +1529,40 @@ function SendMessageWithCheck() } } - GenericSendMessage(isOffline ? msgCompDeliverMode.Later + GenericSendMessage(isOffline ? msgCompDeliverMode.Later : msgCompDeliverMode.Now); } function SendMessageLater() { - dump("SendMessageLater from XUL\n"); - GenericSendMessage(msgCompDeliverMode.Later); + dump("SendMessageLater from XUL\n"); + GenericSendMessage(msgCompDeliverMode.Later); } function Save() { - dump("Save from XUL\n"); - switch (defaultSaveOperation) - { - case "file" : SaveAsFile(false); break; - case "template" : SaveAsTemplate(false); break; - default : SaveAsDraft(false); break; - } + dump("Save from XUL\n"); + switch (defaultSaveOperation) + { + case "file" : SaveAsFile(false); break; + case "template" : SaveAsTemplate(false); break; + default : SaveAsDraft(false); break; + } } function SaveAsFile(saveAs) { - dump("SaveAsFile from XUL\n"); + dump("SaveAsFile from XUL\n"); if (msgCompose.bodyConvertible() == msgCompConvertible.Plain) - editorShell.saveDocument(saveAs, false, "text/plain"); + editorShell.saveDocument(saveAs, false, "text/plain"); else - editorShell.saveDocument(saveAs, false, "text/html"); + editorShell.saveDocument(saveAs, false, "text/html"); defaultSaveOperation = "file"; } function SaveAsDraft() { - dump("SaveAsDraft from XUL\n"); + dump("SaveAsDraft from XUL\n"); GenericSendMessage(msgCompDeliverMode.SaveAsDraft); defaultSaveOperation = "draft"; @@ -1569,7 +1570,7 @@ function SaveAsDraft() function SaveAsTemplate() { - dump("SaveAsTemplate from XUL\n"); + dump("SaveAsTemplate from XUL\n"); GenericSendMessage(msgCompDeliverMode.SaveAsTemplate); defaultSaveOperation = "template"; @@ -1578,98 +1579,98 @@ function SaveAsTemplate() function MessageFcc(menuItem) { - // Get the id for the folder we're FCC into + // Get the id for the folder we're FCC into // This is the additional FCC in addition to the // default FCC - destUri = menuItem.getAttribute('id'); - if (msgCompose) - { - var msgCompFields = msgCompose.compFields; - if (msgCompFields) - { - if (msgCompFields.fcc2 == destUri) - { - msgCompFields.fcc2 = "nocopy://"; - dump("FCC2: none\n"); - } - else - { - msgCompFields.fcc2 = destUri; - dump("FCC2: " + destUri + "\n"); - } - } - } + destUri = menuItem.getAttribute('id'); + if (msgCompose) + { + var msgCompFields = msgCompose.compFields; + if (msgCompFields) + { + if (msgCompFields.fcc2 == destUri) + { + msgCompFields.fcc2 = "nocopy://"; + dump("FCC2: none\n"); + } + else + { + msgCompFields.fcc2 = destUri; + dump("FCC2: " + destUri + "\n"); + } + } + } } function PriorityMenuSelect(target) { - dump("Set Message Priority to " + target.getAttribute('id') + "\n"); - if (msgCompose) - { - var msgCompFields = msgCompose.compFields; - if (msgCompFields) - msgCompFields.priority = target.getAttribute('id'); - } + dump("Set Message Priority to " + target.getAttribute('id') + "\n"); + if (msgCompose) + { + var msgCompFields = msgCompose.compFields; + if (msgCompFields) + msgCompFields.priority = target.getAttribute('id'); + } } function ReturnReceiptMenuSelect() { - if (msgCompose) - { - var msgCompFields = msgCompose.compFields; - if (msgCompFields) - { - if (msgCompFields.returnReceipt) - { - msgCompFields.returnReceipt = false; - } - else - { - msgCompFields.returnReceipt = true; - } - } - } + if (msgCompose) + { + var msgCompFields = msgCompose.compFields; + if (msgCompFields) + { + if (msgCompFields.returnReceipt) + { + msgCompFields.returnReceipt = false; + } + else + { + msgCompFields.returnReceipt = true; + } + } + } } function OutputFormatMenuSelect(target) { - dump("Set Message Format to " + target.getAttribute('id') + "\n"); - if (msgCompose) - { - var msgCompFields = msgCompose.compFields; + dump("Set Message Format to " + target.getAttribute('id') + "\n"); + if (msgCompose) + { + var msgCompFields = msgCompose.compFields; if (msgCompFields) { switch (target.getAttribute('id')) - { - case "1": sendFormat = msgCompSendFormat.AskUser; break; - case "2": sendFormat = msgCompSendFormat.PlainText; break; - case "3": sendFormat = msgCompSendFormat.HTML; break; + { + case "1": sendFormat = msgCompSendFormat.AskUser; break; + case "2": sendFormat = msgCompSendFormat.PlainText; break; + case "3": sendFormat = msgCompSendFormat.HTML; break; case "4": sendFormat = msgCompSendFormat.Both; break; - } + } } - } + } } function SelectAddress() { - var msgCompFields = msgCompose.compFields; + var msgCompFields = msgCompose.compFields; - Recipients2CompFields(msgCompFields); + Recipients2CompFields(msgCompFields); - var toAddress = msgCompFields.to; - var ccAddress = msgCompFields.cc; - var bccAddress = msgCompFields.bcc; + var toAddress = msgCompFields.to; + var ccAddress = msgCompFields.cc; + var bccAddress = msgCompFields.bcc; - dump("toAddress: " + toAddress + "\n"); - window.openDialog("chrome://messenger/content/addressbook/abSelectAddressesDialog.xul", - "", - "chrome,resizable,titlebar,modal", - {composeWindow:top.window, - msgCompFields:msgCompFields, - toAddress:toAddress, - ccAddress:ccAddress, - bccAddress:bccAddress}); + dump("toAddress: " + toAddress + "\n"); + window.openDialog("chrome://messenger/content/addressbook/abSelectAddressesDialog.xul", + "", + "chrome,resizable,titlebar,modal", + {composeWindow:top.window, + msgCompFields:msgCompFields, + toAddress:toAddress, + ccAddress:ccAddress, + bccAddress:bccAddress}); // We have to set focus to the addressingwidget because we seem to loose focus often // after opening the SelectAddresses Dialog- bug # 89950 AdjustFocus(); @@ -1701,20 +1702,20 @@ function fillIdentityListPopup(popup) for (var i=0; i= 0; item-- ) - body.removeChild(bucketTree.selectedItems[item]); - } - } + if ( body && bucketTree.selectedItems && bucketTree.selectedItems.length ) + { + for ( var item = bucketTree.selectedItems.length - 1; item >= 0; item-- ) + body.removeChild(bucketTree.selectedItems[item]); + } + } } function AttachVCard() { - dump("AttachVCard()\n"); + dump("AttachVCard()\n"); } function DetermineHTMLAction(convertible) @@ -2114,13 +2120,13 @@ function DetermineHTMLAction(convertible) else return msgCompSendFormat.HTML; } - else - { - try { + else + { + try { obj = new Object; msgCompose.CheckAndPopulateRecipients(true, false, obj); - } catch(ex) { dump("msgCompose.CheckAndPopulateRecipients failed: " + ex + "\n"); } - } + } catch(ex) { dump("msgCompose.CheckAndPopulateRecipients failed: " + ex + "\n"); } + } return sendFormat; } @@ -2298,11 +2304,16 @@ var attachmentBucketObserver = { } break; case "application/x-moz-file": - rawData = aData.data.URL; + rawData = aData.data.URL; break; } if (!(DuplicateFileCheck(rawData))) - AddAttachment(rawData, prettyName); + { + var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment); + attachment.url = rawData; + attachment.name = prettyName; + AddAttachment(attachment); + } else { var errorTitle = gComposeMsgsBundle.getString("DuplicateFileErrorDlogTitle"); var errorMsg = gComposeMsgsBundle.getString("DuplicateFileErrorDlogMessage"); @@ -2341,9 +2352,9 @@ var attachmentBucketObserver = { function GetMsgFolderFromUri(uri) { - try { - var RDF = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(); - RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService); + try { + var RDF = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(); + RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService); var resource = RDF.GetResource(uri); var msgfolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder); if (msgfolder && ( msgfolder.parent || msgfolder.isServer)) @@ -2366,7 +2377,7 @@ function DisplaySaveFolderDlg(folderURI) var msgfolder = GetMsgFolderFromUri(folderURI); if (!msgfolder) return; - var checkbox = {value:0}; + var checkbox = {value:0}; var SaveDlgTitle = gComposeMsgsBundle.getString("SaveDialogTitle"); var dlgMsg = gComposeMsgsBundle.getFormattedString("SaveDialogMsg", [msgfolder.name, diff --git a/mozilla/mailnews/compose/src/Makefile.in b/mozilla/mailnews/compose/src/Makefile.in index 564e2ab8836..77685b80438 100644 --- a/mozilla/mailnews/compose/src/Makefile.in +++ b/mozilla/mailnews/compose/src/Makefile.in @@ -80,6 +80,7 @@ CPPSRCS = \ nsMsgComposeStringBundle.cpp \ nsMsgEncoders.cpp \ nsMsgCompUtils.cpp \ + nsMsgAttachment.cpp \ nsMsgAttachmentHandler.cpp \ nsMsgPrompts.cpp \ nsMsgComposeService.cpp \ @@ -112,6 +113,7 @@ EXPORTS = \ nsMsgComposeContentHandler.h \ nsMsgCompose.h \ nsMsgCompFields.h \ + nsMsgAttachment.h \ nsMsgAttachmentHandler.h \ nsMsgPrompts.h \ nsMsgQuote.h \ diff --git a/mozilla/mailnews/compose/src/makefile.win b/mozilla/mailnews/compose/src/makefile.win index 445251991a6..bd0e5074263 100644 --- a/mozilla/mailnews/compose/src/makefile.win +++ b/mozilla/mailnews/compose/src/makefile.win @@ -80,6 +80,7 @@ EXPORTS= nsSmtpUrl.h \ nsMsgComposeContentHandler.h \ nsMsgCompose.h \ nsMsgCompFields.h \ + nsMsgAttachment.h \ nsMsgQuote.h \ nsMsgRecipientArray.h \ nsURLFetcher.h \ @@ -113,6 +114,7 @@ CPP_OBJS= .\$(OBJDIR)\nsMsgCompFields.obj \ .\$(OBJDIR)\nsMsgComposeStringBundle.obj \ .\$(OBJDIR)\nsMsgEncoders.obj \ .\$(OBJDIR)\nsMsgCompUtils.obj \ + .\$(OBJDIR)\nsMsgAttachment.obj \ .\$(OBJDIR)\nsMsgAttachmentHandler.obj \ .\$(OBJDIR)\nsMsgPrompts.obj \ .\$(OBJDIR)\nsMsgQuote.obj \ diff --git a/mozilla/mailnews/compose/src/nsMsgAttachment.cpp b/mozilla/mailnews/compose/src/nsMsgAttachment.cpp new file mode 100644 index 00000000000..2ef4e9228ca --- /dev/null +++ b/mozilla/mailnews/compose/src/nsMsgAttachment.cpp @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsMsgAttachment.h" +#include "nsILocalFile.h" +#include "nsReadableUtils.h" + +NS_IMPL_ISUPPORTS1(nsMsgAttachment, nsIMsgAttachment) + +nsMsgAttachment::nsMsgAttachment() +{ + NS_INIT_ISUPPORTS(); + mTemporary = PR_FALSE; +} + +nsMsgAttachment::~nsMsgAttachment() +{ + if (mTemporary) + (void)DeleteAttachment(); +} + +/* attribute wstring name; */ +NS_IMETHODIMP nsMsgAttachment::GetName(PRUnichar * *aName) +{ + NS_ENSURE_ARG_POINTER(aName); + + *aName = ToNewUnicode(mName); + return (*aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetName(const PRUnichar * aName) +{ + mName = aName; + return NS_OK; +} + +/* attribute string url; */ +NS_IMETHODIMP nsMsgAttachment::GetUrl(char * *aUrl) +{ + NS_ENSURE_ARG_POINTER(aUrl); + + *aUrl = ToNewCString(mUrl); + return (*aUrl ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetUrl(const char * aUrl) +{ + mUrl = aUrl; + return NS_OK; +} + +/* attribute boolean temporary; */ +NS_IMETHODIMP nsMsgAttachment::GetTemporary(PRBool *aTemporary) +{ + NS_ENSURE_ARG_POINTER(aTemporary); + + *aTemporary = mTemporary; + return NS_OK; +} +NS_IMETHODIMP nsMsgAttachment::SetTemporary(PRBool aTemporary) +{ + mTemporary = aTemporary; + return NS_OK; +} + +/* attribute string contentLocation; */ +NS_IMETHODIMP nsMsgAttachment::GetContentLocation(char * *aContentLocation) +{ + NS_ENSURE_ARG_POINTER(aContentLocation); + + *aContentLocation = ToNewCString(mContentLocation); + return (*aContentLocation ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetContentLocation(const char * aContentLocation) +{ + mContentLocation = aContentLocation; + return NS_OK; +} + +/* attribute string contentType; */ +NS_IMETHODIMP nsMsgAttachment::GetContentType(char * *aContentType) +{ + NS_ENSURE_ARG_POINTER(aContentType); + + *aContentType = ToNewCString(mContentType); + return (*aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetContentType(const char * aContentType) +{ + mContentType = aContentType; + /* a full content type could also contains parameters but we need to + keep only the content type alone. Therefore we need to cleanup it. + */ + PRInt32 offset = mContentType.FindChar(';'); + if (offset) + mContentType.Truncate(offset); + + return NS_OK; +} + +/* attribute string macType; */ +NS_IMETHODIMP nsMsgAttachment::GetMacType(char * *aMacType) +{ + NS_ENSURE_ARG_POINTER(aMacType); + + *aMacType = ToNewCString(mMacType); + return (*aMacType ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetMacType(const char * aMacType) +{ + mMacType = aMacType; + return NS_OK; +} + +/* attribute string macCreator; */ +NS_IMETHODIMP nsMsgAttachment::GetMacCreator(char * *aMacCreator) +{ + NS_ENSURE_ARG_POINTER(aMacCreator); + + *aMacCreator = ToNewCString(mMacCreator); + return (*aMacCreator ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} +NS_IMETHODIMP nsMsgAttachment::SetMacCreator(const char * aMacCreator) +{ + mMacCreator = aMacCreator; + return NS_OK; +} + +/* boolean equalsUrl (in nsIMsgAttachment attachment); */ +NS_IMETHODIMP nsMsgAttachment::EqualsUrl(nsIMsgAttachment *attachment, PRBool *_retval) +{ + NS_ENSURE_ARG_POINTER(attachment); + NS_ENSURE_ARG_POINTER(_retval); + + nsXPIDLCString url; + attachment->GetUrl(getter_Copies(url)); + + *_retval = mUrl.Equals(url); + return NS_OK; +} + + +nsresult nsMsgAttachment::DeleteAttachment() +{ + nsresult rv; + PRBool isAFile = PR_FALSE; + + nsCOMPtr urlFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) + { + rv = urlFile->SetURL(mUrl); + if (NS_SUCCEEDED(rv)) + { + PRBool bExists = PR_FALSE; + rv = urlFile->Exists(&bExists); + if (NS_FAILED(rv)) + {NS_ASSERTION(0, "bExists() call failed!");} + else + if (bExists) + { + rv = urlFile->IsFile(&isAFile); + if (NS_FAILED(rv)) + {NS_ASSERTION(0, "IsFile() call failed!");} + } + } + else + {NS_ASSERTION(0, "Can't set url in nsILocalFile interface");} + } + else + {NS_ASSERTION(0, "Can't creat nsIFileURL interface");} + + + // remove it if it's a valid file + if (isAFile) + rv = urlFile->Remove(PR_FALSE); + + return rv; +} diff --git a/mozilla/mailnews/compose/src/nsMsgAttachment.h b/mozilla/mailnews/compose/src/nsMsgAttachment.h new file mode 100644 index 00000000000..31bcbd40f2f --- /dev/null +++ b/mozilla/mailnews/compose/src/nsMsgAttachment.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsMsgAttachment_H_ +#define _nsMsgAttachment_H_ + +#include "nsIMsgAttachment.h" +#include "nsString.h" + +class nsMsgAttachment : public nsIMsgAttachment +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGATTACHMENT + + nsMsgAttachment(); + virtual ~nsMsgAttachment(); + +private: + nsresult DeleteAttachment(); + + nsString mName; + nsCString mUrl; + PRBool mTemporary; + nsCString mContentLocation; + nsCString mContentType; + nsCString mMacType; + nsCString mMacCreator; +}; + + +#endif /* _nsMsgAttachment_H_ */ diff --git a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp index 04e0b8b288f..a91ce4e8eb8 100644 --- a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp +++ b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp @@ -58,6 +58,7 @@ #include "nsIPrompt.h" #include "nsMsgSimulateError.h" #include "nsITextToSubURI.h" +#include "nsEscape.h" static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); @@ -67,7 +68,7 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); /////////////////////////////////////////////////////////////////////////// #ifdef XP_MAC -#define AD_WORKING_BUFF_SIZE 8192 +#define AD_WORKING_BUFF_SIZE 8192 extern void MacGetFileType(nsFileSpec *fs, PRBool *useDefault, char **type, char **encoding); @@ -90,32 +91,32 @@ nsMsgAttachmentHandler::nsMsgAttachmentHandler() mMainBody = PR_FALSE; m_charset = nsnull; - m_override_type = nsnull; - m_override_encoding = nsnull; - m_desired_type = nsnull; - m_description = nsnull; - m_encoding = nsnull; - m_real_name = nsnull; - m_encoding = nsnull; - m_already_encoded_p = PR_FALSE; - m_decrypted_p = PR_FALSE; - + m_override_type = nsnull; + m_override_encoding = nsnull; + m_desired_type = nsnull; + m_description = nsnull; + m_encoding = nsnull; + m_real_name = nsnull; + m_encoding = nsnull; + m_already_encoded_p = PR_FALSE; + m_decrypted_p = PR_FALSE; + // For analyzing the attachment file... m_file_analyzed = PR_FALSE; m_ctl_count = 0; - m_null_count = 0; - m_current_column = 0; - m_max_column = 0; - m_lines = 0; - m_unprintable_count = 0; + m_null_count = 0; + m_current_column = 0; + m_max_column = 0; + m_lines = 0; + m_unprintable_count = 0; m_highbit_count = 0; // Mime encoder... m_encoder_data = nsnull; m_done = PR_FALSE; - m_type = nsnull; - m_size = 0; + m_type = nsnull; + m_size = 0; mCompFields = nsnull; // Message composition fields for the sender mFileSpec = nsnull; @@ -123,10 +124,10 @@ nsMsgAttachmentHandler::nsMsgAttachmentHandler() mRequest = nsnull; m_x_mac_type = nsnull; - m_x_mac_creator = nsnull; + m_x_mac_creator = nsnull; #ifdef XP_MAC - mAppleFileSpec = nsnull; + mAppleFileSpec = nsnull; #endif mDeleteFile = PR_FALSE; @@ -143,6 +144,9 @@ nsMsgAttachmentHandler::~nsMsgAttachmentHandler() delete mAppleFileSpec; #endif + if (mFileSpec && mDeleteFile) + mFileSpec->Delete(PR_FALSE); + PR_FREEIF(m_uri); } @@ -152,62 +156,62 @@ nsMsgAttachmentHandler::AnalyzeDataChunk(const char *chunk, PRInt32 length) unsigned char *s = (unsigned char *) chunk; unsigned char *end = s + length; for (; s < end; s++) - { - if (*s > 126) - { - m_highbit_count++; - m_unprintable_count++; - } - else if (*s < ' ' && *s != '\t' && *s != nsCRT::CR && *s != nsCRT::LF) - { - m_unprintable_count++; - m_ctl_count++; - if (*s == 0) - m_null_count++; - } + { + if (*s > 126) + { + m_highbit_count++; + m_unprintable_count++; + } + else if (*s < ' ' && *s != '\t' && *s != nsCRT::CR && *s != nsCRT::LF) + { + m_unprintable_count++; + m_ctl_count++; + if (*s == 0) + m_null_count++; + } - if (*s == nsCRT::CR || *s == nsCRT::LF) - { - if (s+1 < end && s[0] == nsCRT::CR && s[1] == nsCRT::LF) - s++; - if (m_max_column < m_current_column) - m_max_column = m_current_column; - m_current_column = 0; - m_lines++; - } - else - { - m_current_column++; - } - } + if (*s == nsCRT::CR || *s == nsCRT::LF) + { + if (s+1 < end && s[0] == nsCRT::CR && s[1] == nsCRT::LF) + s++; + if (m_max_column < m_current_column) + m_max_column = m_current_column; + m_current_column = 0; + m_lines++; + } + else + { + m_current_column++; + } + } } void nsMsgAttachmentHandler::AnalyzeSnarfedFile(void) { - char chunk[256]; - PRInt32 numRead = 0; + char chunk[256]; + PRInt32 numRead = 0; if (m_file_analyzed) return; if (mFileSpec) - { - nsInputFileStream fileHdl(*mFileSpec, PR_RDONLY, 0); - if (fileHdl.is_open()) - { - do - { - numRead = fileHdl.read(chunk, 256); - if (numRead > 0) - AnalyzeDataChunk(chunk, numRead); - } - while (numRead > 0); + { + nsInputFileStream fileHdl(*mFileSpec, PR_RDONLY, 0); + if (fileHdl.is_open()) + { + do + { + numRead = fileHdl.read(chunk, 256); + if (numRead > 0) + AnalyzeDataChunk(chunk, numRead); + } + while (numRead > 0); fileHdl.close(); m_file_analyzed = PR_TRUE; - } - } + } + } } // @@ -230,7 +234,7 @@ nsMsgAttachmentHandler::PickEncoding(const char *charset, nsIMsgSend *mime_deliv AnalyzeSnarfedFile(); /* Allow users to override our percentage-wise guess on whether - the file is text or binary */ + the file is text or binary */ if (NS_SUCCEEDED(rv) && prefs) prefs->GetBoolPref ("mail.file_attach_binary", &forceB64); @@ -239,14 +243,14 @@ nsMsgAttachmentHandler::PickEncoding(const char *charset, nsIMsgSend *mime_deliv /* If the content-type is "image/" or something else known to be binary, always use base64 (so that we don't get confused by newline conversions.) - */ + */ needsB64 = PR_TRUE; } else { /* Otherwise, we need to pick an encoding based on the contents of the document. - */ + */ PRBool encode_p; @@ -255,7 +259,7 @@ nsMsgAttachmentHandler::PickEncoding(const char *charset, nsIMsgSend *mime_deliv else if (UseQuotedPrintable() && m_unprintable_count) encode_p = PR_TRUE; - else if (m_null_count) /* If there are nulls, we must always encode, + else if (m_null_count) /* If there are nulls, we must always encode, because sendmail will blow up. */ encode_p = PR_TRUE; else @@ -409,7 +413,7 @@ DONE: if (m_already_encoded_p) m_type = PL_strdup (APPLICATION_OCTET_STREAM); else if (m_encoding && - (!PL_strcasecmp(m_encoding, ENCODING_BASE64) || + (!PL_strcasecmp(m_encoding, ENCODING_BASE64) || !PL_strcasecmp(m_encoding, ENCODING_UUENCODE))) m_type = PL_strdup (APPLICATION_OCTET_STREAM); else @@ -461,7 +465,7 @@ FetcherURLDoneCallback(nsresult aStatus, } } - return ma->UrlExit(aStatus, aMsg); + return ma->UrlExit(aStatus, aMsg); } else return NS_OK; @@ -476,6 +480,7 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields) if (PL_strcasestr(m_uri, "_message:")) { mFileSpec = nsMsgCreateTempFileSpec("nsmail.tmp"); + mDeleteFile = PR_TRUE; mCompFields = compFields; PR_FREEIF(m_real_name); m_real_name = PL_strdup("ForwardedMessage.eml"); @@ -558,7 +563,6 @@ nsresult nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) { nsresult status = 0; - char *tempName = nsnull; nsXPIDLCString url_string; NS_ASSERTION (! m_done, "Already done"); @@ -566,67 +570,14 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) if (!mURL) return SnarfMsgAttachment(compFields); - tempName = GenerateFileNameFromURI(mURL); // Make it a sane name -#ifdef XP_WIN - if (tempName && PL_strchr(tempName, '|')) - { - PR_Free(tempName); - tempName = nsnull; - } -#endif -#ifdef XP_MAC - if (tempName && PL_strlen(tempName) >= 31) - PR_DELETE(tempName) -#endif - mCompFields = compFields; // First, get as file spec and create the stream for the // temp file where we will save this data - if ((!tempName) || (!*tempName)) mFileSpec = nsMsgCreateTempFileSpec("nsmail.tmp"); - else - mFileSpec = nsMsgCreateTempFileSpec(tempName); - - // Set a sane name for the attachment... - if (tempName) - { - if (m_real_name) - { - nsMemory::Free(m_real_name); - m_real_name = nsnull; - } - - nsCOMPtr textToSubURI = do_CreateInstance(NS_ITEXTTOSUBURI_CONTRACTID, &status); - - if (NS_SUCCEEDED(status)) - { - // URI unescape and convert to UCS2 - nsXPIDLString unescapedStr; - status = textToSubURI->UnEscapeAndConvert(NS_ConvertUCS2toUTF8(nsMsgI18NFileSystemCharset()).get(), - tempName, getter_Copies(unescapedStr)); - - if (NS_SUCCEEDED(status)) - { - // MIME encode if necessary - m_real_name = nsMsgI18NEncodeMimePartIIStr(NS_ConvertUCS2toUTF8(unescapedStr).get(), - compFields->GetCharacterSet(), - nsMsgMIMEGetConformToStandard()); - // No need to MIME encode (return value was null), use the unescaped string - if (!m_real_name) - m_real_name = nsCRT::strdup(NS_ConvertUCS2toUTF8(unescapedStr).get()); - } - } - - // failure, dup the original string - if (!m_real_name) - m_real_name = nsCRT::strdup(tempName); - } - - PR_FREEIF(tempName); - if (! mFileSpec ) - return (NS_ERROR_FAILURE); + return (NS_ERROR_FAILURE); + mDeleteFile = PR_TRUE; nsCOMPtr localFile; nsCOMPtr outputStream; @@ -647,6 +598,7 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } } + mFileSpec->Delete(PR_FALSE); delete mFileSpec; mFileSpec = nsnull; return NS_MSG_UNABLE_TO_OPEN_TMP_FILE; @@ -657,10 +609,10 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) #ifdef XP_MAC if ( !m_bogus_attachment && nsMsgIsLocalFile(url_string)) - { - // convert the apple file to AppleDouble first, and then patch the - // address in the url. - char *src_filename = nsMsgGetLocalFileFromURL (url_string); + { + // convert the apple file to AppleDouble first, and then patch the + // address in the url. + char *src_filename = nsMsgGetLocalFileFromURL (url_string); if (!src_filename) return NS_ERROR_OUT_OF_MEMORY; @@ -668,17 +620,17 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) nsFileSpec scr_fileSpec(src_filename); FSSpec fsSpec = scr_fileSpec.GetFSSpec();; FInfo info; - if (FSpGetFInfo (&fsSpec, &info) == noErr) - { - char filetype[32]; - PR_snprintf(filetype, sizeof(filetype), "%X", info.fdType); - PR_FREEIF(m_x_mac_type); - m_x_mac_type = PL_strdup(filetype); + if (FSpGetFInfo (&fsSpec, &info) == noErr) + { + char filetype[32]; + PR_snprintf(filetype, sizeof(filetype), "%X", info.fdType); + PR_FREEIF(m_x_mac_type); + m_x_mac_type = PL_strdup(filetype); - PR_snprintf(filetype, sizeof(filetype), "%X", info.fdCreator); - PR_FREEIF(m_x_mac_creator); - m_x_mac_creator = PL_strdup(filetype); - } + PR_snprintf(filetype, sizeof(filetype), "%X", info.fdCreator); + PR_FREEIF(m_x_mac_creator); + m_x_mac_creator = PL_strdup(filetype); + } PRBool sendResourceFork = PR_TRUE; PRBool sendDataFork = PR_TRUE; @@ -703,8 +655,8 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) // If InternetConfig cannot help us, then just try our best... long dataSize = 0; long resSize = 0; - - // first check if we have a resource fork + + // first check if we have a resource fork if (::FSpGetFileSize(&fsSpec, &dataSize, &resSize) == noErr) sendResourceFork = (resSize > 0); @@ -732,30 +684,30 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) } } - // Only use appledouble if we aren't uuencoding. - if( sendResourceFork && (! UseUUEncode_p()) ) - { - char *separator; + // Only use appledouble if we aren't uuencoding. + if( sendResourceFork && (! UseUUEncode_p()) ) + { + char *separator; nsInputFileStream *myInputFile = new nsInputFileStream(scr_fileSpec); if ((!myInputFile) || (!myInputFile->is_open())) return NS_ERROR_OUT_OF_MEMORY; - separator = mime_make_separator("ad"); - if (!separator) + separator = mime_make_separator("ad"); + if (!separator) { - delete myInputFile; + delete myInputFile; PR_FREEIF(src_filename); - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; } - - mAppleFileSpec = nsMsgCreateTempFileSpec("appledouble"); + + mAppleFileSpec = nsMsgCreateTempFileSpec("appledouble"); if (!mAppleFileSpec) { - delete myInputFile; + delete myInputFile; PR_FREEIF(separator); PR_FREEIF(src_filename); - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; } // @@ -771,44 +723,44 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) delete mAppleFileSpec; PR_FREEIF(src_filename); PR_FREEIF(separator); - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; } - obj->fileStream = new nsIOFileStream(*mAppleFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE)); + obj->fileStream = new nsIOFileStream(*mAppleFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE)); if ( (!obj->fileStream) || (!obj->fileStream->is_open()) ) - { - delete myInputFile; + { + delete myInputFile; PR_FREEIF(src_filename); PR_FREEIF(separator); delete obj; - return NS_ERROR_OUT_OF_MEMORY; - } + return NS_ERROR_OUT_OF_MEMORY; + } PRInt32 bSize = AD_WORKING_BUFF_SIZE; char *working_buff = nsnull; while (!working_buff && (bSize >= 512)) - { + { working_buff = (char *)PR_CALLOC(bSize); if (!working_buff) bSize /= 2; - } + } if (!working_buff) - { + { PR_FREEIF(src_filename); PR_FREEIF(separator); delete obj; - return NS_ERROR_OUT_OF_MEMORY; - } + return NS_ERROR_OUT_OF_MEMORY; + } - obj->buff = working_buff; - obj->s_buff = bSize; + obj->buff = working_buff; + obj->s_buff = bSize; - // - // Setup all the need information on the apple double encoder. - // - ap_encode_init(&(obj->ap_encode_obj), src_filename, separator); + // + // Setup all the need information on the apple double encoder. + // + ap_encode_init(&(obj->ap_encode_obj), src_filename, separator); PRInt32 count; @@ -819,20 +771,20 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) status = ap_encode_next(&(obj->ap_encode_obj), obj->buff, bSize, &count); if (status == noErr || status == errDone) { - // - // we got the encode data, so call the next stream to write it to the disk. - // - if (obj->fileStream->write(obj->buff, count) != count) - status = NS_MSG_ERROR_WRITING_FILE; + // + // we got the encode data, so call the next stream to write it to the disk. + // + if (obj->fileStream->write(obj->buff, count) != count) + status = NS_MSG_ERROR_WRITING_FILE; } } delete myInputFile; ap_encode_end(&(obj->ap_encode_obj), (status >= 0)); // if this is true, ok, false abort - if (obj->fileStream) + if (obj->fileStream) obj->fileStream->close(); - PR_FREEIF(obj->buff); /* free the working buff. */ + PR_FREEIF(obj->buff); /* free the working buff. */ PR_FREEIF(obj); @@ -847,14 +799,14 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) if (!newURLSpec) { PR_FREEIF(src_filename); - PR_FREEIF(separator); + PR_FREEIF(separator); return NS_ERROR_OUT_OF_MEMORY; } if (NS_FAILED(nsMsgNewURL(&mURL, newURLSpec))) { PR_FREEIF(src_filename); - PR_FREEIF(separator); + PR_FREEIF(separator); PR_FREEIF(newURLSpec); return NS_ERROR_OUT_OF_MEMORY; } @@ -862,45 +814,45 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) NS_ADDREF(mURL); PR_FREEIF(newURLSpec); - // Now after conversion, also patch the types. + // Now after conversion, also patch the types. char tmp[128]; - PR_snprintf(tmp, sizeof(tmp), MULTIPART_APPLEDOUBLE ";\r\n boundary=\"%s\"", separator); - PR_FREEIF(separator); - PR_FREEIF (m_type); - m_type = PL_strdup(tmp); - } - else - { + PR_snprintf(tmp, sizeof(tmp), MULTIPART_APPLEDOUBLE ";\r\n boundary=\"%s\"", separator); + PR_FREEIF(separator); + PR_FREEIF (m_type); + m_type = PL_strdup(tmp); + } + else + { if ( sendResourceFork ) - { - // The only time we want to send just the data fork of a two-fork - // Mac file is if uuencoding has been requested. - NS_ASSERTION(UseUUEncode_p(), "not UseUUEncode_p"); + { + // The only time we want to send just the data fork of a two-fork + // Mac file is if uuencoding has been requested. + NS_ASSERTION(UseUUEncode_p(), "not UseUUEncode_p"); // For now, just do the encoding, but in the old world we would ask the // user about doing this conversion printf("...we could ask the user about this conversion, but for now, nahh..\n"); - } + } - PRBool useDefault; - char *macType, *macEncoding; - if (m_type == NULL || !PL_strcasecmp (m_type, TEXT_PLAIN)) - { -# define TEXT_TYPE 0x54455854 /* the characters 'T' 'E' 'X' 'T' */ -# define text_TYPE 0x74657874 /* the characters 't' 'e' 'x' 't' */ + PRBool useDefault; + char *macType, *macEncoding; + if (m_type == NULL || !PL_strcasecmp (m_type, TEXT_PLAIN)) + { +# define TEXT_TYPE 0x54455854 /* the characters 'T' 'E' 'X' 'T' */ +# define text_TYPE 0x74657874 /* the characters 't' 'e' 'x' 't' */ - if (info.fdType != TEXT_TYPE && info.fdType != text_TYPE) - { - MacGetFileType(&scr_fileSpec, &useDefault, &macType, &macEncoding); - PR_FREEIF(m_type); - m_type = macType; - } - } - // don't bother to set the types if we failed in getting the file info. - } + if (info.fdType != TEXT_TYPE && info.fdType != text_TYPE) + { + MacGetFileType(&scr_fileSpec, &useDefault, &macType, &macEncoding); + PR_FREEIF(m_type); + m_type = macType; + } + } + // don't bother to set the types if we failed in getting the file info. + } PR_FREEIF(src_filename); - } + } #endif /* XP_MAC */ // @@ -973,7 +925,7 @@ nsMsgAttachmentHandler::Abort() if (m_mime_delivery_state) { m_mime_delivery_state->SetStatus(NS_ERROR_ABORT); - m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, NS_ERROR_ABORT, 0, nsnull); + m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, NS_ERROR_ABORT, 0, nsnull); } return NS_OK; @@ -1030,8 +982,18 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) composebundle->GetStringByID(NS_MSG_FAILURE_ON_OBJ_EMBED, getter_Copies(msg)); + if (m_real_name && *m_real_name) + printfString = nsTextFormatter::smprintf(msg, m_real_name); + else if (NS_SUCCEEDED(mURL->GetSpec(getter_Copies(turl))) && (turl)) - printfString = nsTextFormatter::smprintf(msg, (const char*)turl); + { + nsCAutoString unescapeUrl(turl); + nsUnescape (NS_CONST_CAST(char*, unescapeUrl.get())); + if (unescapeUrl.IsEmpty()) + printfString = nsTextFormatter::smprintf(msg, turl.get()); + else + printfString = nsTextFormatter::smprintf(msg, unescapeUrl.get()); + } else printfString = nsTextFormatter::smprintf(msg, "?"); @@ -1065,21 +1027,21 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) if (NS_SUCCEEDED(status) && m_type && PL_strcasecmp(m_type, TEXT_PLAIN) ) { if (m_desired_type && !PL_strcasecmp(m_desired_type, TEXT_PLAIN) ) - { - // + { + // // Conversion to plain text desired. - // + // PRInt32 width = 72; nsresult rv; nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); if (NS_SUCCEEDED(rv) && prefs) prefs->GetIntPref("mailnews.wraplength", &width); // Let sanity reign! - if (width == 0) + if (width == 0) width = 72; - else if (width < 10) + else if (width < 10) width = 10; - else if (width > 30000) + else if (width > 30000) width = 30000; // @@ -1092,10 +1054,11 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) { if (NS_SUCCEEDED(ConvertBufToPlainText(conData, UseFormatFlowed(m_charset)))) { + if (mDeleteFile) mFileSpec->Delete(PR_FALSE); nsOutputFileStream tempfile(*mFileSpec, PR_WRONLY | PR_CREATE_FILE, 00600); - if (tempfile.is_open()) + if (tempfile.is_open()) { char *tData = nsnull; nsAutoString charset; charset.AssignWithConversion(m_charset); @@ -1111,12 +1074,12 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) } } - PR_FREEIF(m_type); - m_type = m_desired_type; - m_desired_type = nsnull; - PR_FREEIF(m_encoding); - m_encoding = nsnull; - } + PR_FREEIF(m_type); + m_type = m_desired_type; + m_desired_type = nsnull; + PR_FREEIF(m_encoding); + m_encoding = nsnull; + } } PRUint32 pendingAttachmentCount = 0; @@ -1128,23 +1091,23 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) PRBool processAttachmentsSynchronously = PR_FALSE; m_mime_delivery_state->GetProcessAttachmentsSynchronously(&processAttachmentsSynchronously); if (NS_SUCCEEDED(status) && processAttachmentsSynchronously) - { - /* Find the next attachment which has not yet been loaded, - if any, and start it going. - */ - PRUint32 i; - nsMsgAttachmentHandler *next = 0; - nsMsgAttachmentHandler *attachments = nsnull; - PRUint32 attachmentCount = 0; - - m_mime_delivery_state->GetAttachmentCount(&attachmentCount); - if (attachmentCount) - m_mime_delivery_state->GetAttachmentHandlers(&attachments); - - for (i = 0; i < attachmentCount; i++) + { + /* Find the next attachment which has not yet been loaded, + if any, and start it going. + */ + PRUint32 i; + nsMsgAttachmentHandler *next = 0; + nsMsgAttachmentHandler *attachments = nsnull; + PRUint32 attachmentCount = 0; + + m_mime_delivery_state->GetAttachmentCount(&attachmentCount); + if (attachmentCount) + m_mime_delivery_state->GetAttachmentHandlers(&attachments); + + for (i = 0; i < attachmentCount; i++) { - if (!attachments[i].m_done) - { + if (!attachments[i].m_done) + { next = &attachments[i]; // // rhp: We need to get a little more understanding to failed URL @@ -1163,60 +1126,60 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) } break; - } + } } - if (next) - { - int status = next->SnarfAttachment(mCompFields); - if (NS_FAILED(status)) - { + if (next) + { + int status = next->SnarfAttachment(mCompFields); + if (NS_FAILED(status)) + { nsresult ignoreMe; - m_mime_delivery_state->Fail(status, nsnull, &ignoreMe); - m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull); - SetMimeDeliveryState(nsnull); - return NS_ERROR_UNEXPECTED; - } - } - } + m_mime_delivery_state->Fail(status, nsnull, &ignoreMe); + m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull); + SetMimeDeliveryState(nsnull); + return NS_ERROR_UNEXPECTED; + } + } + } m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount); if (pendingAttachmentCount == 0) - { - // If this is the last attachment, then either complete the - // delivery (if successful) or report the error by calling - // the exit routine and terminating the delivery. - if (NS_FAILED(status)) - { + { + // If this is the last attachment, then either complete the + // delivery (if successful) or report the error by calling + // the exit routine and terminating the delivery. + if (NS_FAILED(status)) + { nsresult ignoreMe; - m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); - m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); - SetMimeDeliveryState(nsnull); - return NS_ERROR_UNEXPECTED; - } - else - { - status = m_mime_delivery_state->GatherMimeAttachments (); - if (NS_FAILED(status)) - { + m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); + m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); + SetMimeDeliveryState(nsnull); + return NS_ERROR_UNEXPECTED; + } + else + { + status = m_mime_delivery_state->GatherMimeAttachments (); + if (NS_FAILED(status)) + { nsresult ignoreMe; - m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); - m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); - SetMimeDeliveryState(nsnull); - return NS_ERROR_UNEXPECTED; - } - } - } + m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); + m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); + SetMimeDeliveryState(nsnull); + return NS_ERROR_UNEXPECTED; + } + } + } else - { - // If this is not the last attachment, but it got an error, - // then report that error and continue - if (NS_FAILED(status)) - { + { + // If this is not the last attachment, but it got an error, + // then report that error and continue + if (NS_FAILED(status)) + { nsresult ignoreMe; - m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); - } - } + m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); + } + } SetMimeDeliveryState(nsnull); return NS_OK; diff --git a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h index 1f332bcfb99..fc18bc27442 100644 --- a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h +++ b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h @@ -35,8 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef _nsMsgAttachment_H_ -#define _nsMsgAttachment_H_ +#ifndef _nsMsgAttachmentHandler_H_ +#define _nsMsgAttachmentHandler_H_ #include "nsIURL.h" #include "nsIMimeConverter.h" @@ -52,9 +52,9 @@ typedef struct _AppledoubleEncodeObject { - appledouble_encode_object ap_encode_obj; - char *buff; // the working buff - PRInt32 s_buff; // the working buff size + appledouble_encode_object ap_encode_obj; + char *buff; // the working buff + PRInt32 s_buff; // the working buff size nsIOFileStream *fileStream; // file to hold the encoding } AppleDoubleEncodeObject; @@ -77,10 +77,10 @@ public: // public: nsresult SnarfAttachment(nsMsgCompFields *compFields); - int PickEncoding (const char *charset, nsIMsgSend* mime_delivery_state); + int PickEncoding (const char *charset, nsIMsgSend* mime_delivery_state); void AnalyzeSnarfedFile (); // Analyze a previously-snarfed file. - // (Currently only used for plaintext - // converted from HTML.) + // (Currently only used for plaintext + // converted from HTML.) nsresult Abort(); nsresult UrlExit(nsresult status, const PRUnichar* aMsg); @@ -96,7 +96,7 @@ private: // public: nsIURI *mURL; - nsFileSpec *mFileSpec; // The temp file to which we save it + nsFileSpec *mFileSpec; // The temp file to which we save it nsCOMPtr mOutFile; nsIRequest *mRequest; // The live request used while fetching an attachment nsMsgCompFields *mCompFields; // Message composition fields for the sender @@ -104,7 +104,7 @@ public: #ifdef XP_MAC nsFileSpec *mAppleFileSpec; // The temp file holds the appledouble - // encoding of the file we want to send. + // encoding of the file we want to send. #endif char *m_x_mac_type; // Mac file type char *m_x_mac_creator; // Mac file creator @@ -114,27 +114,27 @@ public: char *m_content_id; // This is for mutipart/related Content-ID's char *m_type; // The real type, once we know it. char *m_override_type; // The type we should assume it to be - // or 0, if we should get it from the - // server) + // or 0, if we should get it from the + // server) char *m_override_encoding; // Goes along with override_type - char *m_desired_type; // The type it should be converted to. + char *m_desired_type; // The type it should be converted to. char *m_description; // For Content-Description header - char *m_real_name; // The name for the headers, if different - // from the URL. - char *m_encoding; // The encoding, once we've decided. */ + char *m_real_name; // The name for the headers, if different + // from the URL. + char *m_encoding; // The encoding, once we've decided. */ PRBool m_already_encoded_p; // If we attach a document that is already - // encoded, we just pass it through. + // encoded, we just pass it through. - PRBool m_decrypted_p; /* S/MIME -- when attaching a message that was - encrypted, it's necessary to decrypt it first - (since nobody but the original recipient can - read it -- if you forward it to someone in the - raw, it will be useless to them.) This flag - indicates whether decryption occurred, so that - libmsg can issue appropriate warnings about - doing a cleartext forward of a message that was - originally encrypted. */ + PRBool m_decrypted_p; /* S/MIME -- when attaching a message that was + encrypted, it's necessary to decrypt it first + (since nobody but the original recipient can + read it -- if you forward it to someone in the + raw, it will be useless to them.) This flag + indicates whether decryption occurred, so that + libmsg can issue appropriate warnings about + doing a cleartext forward of a message that was + originally encrypted. */ PRBool mDeleteFile; // If this is true, Delete the file...its // NOT the original file! @@ -146,7 +146,7 @@ public: // // Vars for analyzing file data... // - PRUint32 m_size; /* Some state used while filtering it */ + PRUint32 m_size; /* Some state used while filtering it */ PRUint32 m_unprintable_count; PRUint32 m_highbit_count; PRUint32 m_ctl_count; @@ -166,4 +166,4 @@ private: }; -#endif /* _nsMsgAttachment_H_ */ +#endif /* _nsMsgAttachmentHandler_H_ */ diff --git a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp index 22828c9ead5..ce5e43d3709 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp @@ -36,8 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsCRT.h" #include "nsMsgCompFields.h" +#include "nsCRT.h" #include "nsIPref.h" #include "nsMsgI18N.h" #include "nsMsgComposeStringBundle.h" @@ -55,476 +55,393 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsMsgCompFields, nsIMsgCompFields) nsMsgCompFields::nsMsgCompFields() { - PRInt16 i; - for (i = 0; i < MSG_MAX_HEADERS; i ++) - m_headers[i] = nsnull; + PRInt16 i; + for (i = 0; i < MSG_MAX_HEADERS; i ++) + m_headers[i] = nsnull; - m_body = nsnull; + m_body = nsnull; + + NS_NewISupportsArray(getter_AddRefs(m_attachments)); m_attachVCard = PR_FALSE; m_forcePlainText = PR_FALSE; m_useMultipartAlternative = PR_FALSE; m_uuEncodeAttachments = PR_FALSE; - m_returnReceipt = PR_FALSE; - m_receiptType = 0; + m_returnReceipt = PR_FALSE; + m_receiptType = 0; nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); if (prefs) { prefs->GetBoolPref("mail.request.return_receipt_on", &m_returnReceipt); - prefs->GetIntPref("mail.request.return_receipt", &m_receiptType); + prefs->GetIntPref("mail.request.return_receipt", &m_receiptType); } - m_internalCharSet.AssignWithConversion(msgCompHeaderInternalCharset()); + m_internalCharSet.AssignWithConversion(msgCompHeaderInternalCharset()); - NS_INIT_REFCNT(); + // Get the default charset from pref, use this as a mail charset. + char * default_mail_charset = nsMsgI18NGetDefaultMailCharset(); + if (default_mail_charset) + { + SetCharacterSet(default_mail_charset); + PR_Free(default_mail_charset); + } + + NS_INIT_REFCNT(); } nsMsgCompFields::~nsMsgCompFields() { - // Clean up temp files first if set - CleanUpTempFiles(); - - PRInt16 i; - for (i = 0; i < MSG_MAX_HEADERS; i ++) - PR_FREEIF(m_headers[i]); + PRInt16 i; + for (i = 0; i < MSG_MAX_HEADERS; i ++) + PR_FREEIF(m_headers[i]); PR_FREEIF(m_body); } -nsresult nsMsgCompFields::Copy(nsIMsgCompFields* pMsgCompFields) -{ - nsMsgCompFields * pFields = (nsMsgCompFields*)pMsgCompFields; - - PRInt16 i; - for (i = 0; i < MSG_MAX_HEADERS; i ++) - { - if (pFields->m_headers[i]) - m_headers[i] = nsCRT::strdup(pFields->m_headers[i]); - } - - if (pFields->m_body) - m_body = nsCRT::strdup(pFields->m_body); - - m_attachVCard = pFields->m_attachVCard; - m_forcePlainText = pFields->m_forcePlainText; - m_useMultipartAlternative = pFields->m_useMultipartAlternative; - m_uuEncodeAttachments = pFields->m_uuEncodeAttachments; - m_returnReceipt = pFields->m_returnReceipt; - m_receiptType = pFields->m_receiptType; - m_internalCharSet = pFields->m_internalCharSet; - - return NS_OK; -} - -nsresult nsMsgCompFields::CleanUpTempFiles() -{ - nsresult rv; - char *attachmentList; - - rv = GetTemporaryFiles(&attachmentList); - NS_ENSURE_SUCCESS(rv,rv); - - if ((!attachmentList) || (!*attachmentList)) - return NS_OK; - - // parse the attachment list -#ifdef DEBUG_cavin - printf("In CleanUpTempFiles(), attachments to delete list = %s\n", (const char*)attachmentList); -#endif - - char *token = nsnull; - char *rest = attachmentList; - nsCAutoString url; - - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) - { - url = token; - url.StripWhitespace(); - - // Only deal with temp files (ie, starting with "file://") - if (!url.IsEmpty() && url.CompareWithConversion(kFileURLPrefix, PR_TRUE, 7) == 0) - { - PRBool isFile = PR_FALSE; - - nsCOMPtr urlFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) - { - rv = urlFile->SetURL(url.get()); - if (NS_SUCCEEDED(rv)) - { - PRBool bExists = PR_FALSE; - rv = urlFile->Exists(&bExists); - if (NS_FAILED(rv)) - {NS_ASSERTION(0, "bExists() call failed!");} - else - if (bExists) - { - rv = urlFile->IsFile(&isFile); - if (NS_FAILED(rv)) - {NS_ASSERTION(0, "IsFile() call failed!");} - } - } - else - {NS_ASSERTION(0, "Can't set file spec in nsILocalFile interface");} - } - else - {NS_ASSERTION(0, "Can't creat nsIFileURL interface");} - - - // remove it if it's a valid file - if (isFile) - urlFile->Remove(PR_FALSE); - } - - token = nsCRT::strtok(rest, ",", &rest); - } - - nsCRT::free(attachmentList); - return NS_OK; -} - nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value) { - NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); + NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); int rv = NS_OK; char* old = m_headers[header]; /* Done with careful paranoia, in case the - value given is the old value (or worse, - a substring of the old value, as does - happen here and there.) - */ + value given is the old value (or worse, + a substring of the old value, as does + happen here and there.) + */ if (value != old) { if (value) { - m_headers[header] = nsCRT::strdup(value); - if (!m_headers[header]) - rv = NS_ERROR_OUT_OF_MEMORY; - } - else + m_headers[header] = nsCRT::strdup(value); + if (!m_headers[header]) + rv = NS_ERROR_OUT_OF_MEMORY; + } + else m_headers[header] = nsnull; - PR_FREEIF(old); - } + PR_FREEIF(old); + } - return rv; + return rv; } const char* nsMsgCompFields::GetAsciiHeader(MsgHeaderID header) { - NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); + NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); return m_headers[header] ? m_headers[header] : ""; } nsresult nsMsgCompFields::SetUnicodeHeader(MsgHeaderID header, const PRUnichar *value) { - char* cString; - ConvertFromUnicode(m_internalCharSet, nsAutoString(value), &cString); - nsresult rv = SetAsciiHeader(header, cString); - PR_Free(cString); - - return rv; + char* cString; + ConvertFromUnicode(m_internalCharSet, nsAutoString(value), &cString); + nsresult rv = SetAsciiHeader(header, cString); + PR_Free(cString); + + return rv; } nsresult nsMsgCompFields::GetUnicodeHeader(MsgHeaderID header, PRUnichar **_retval) { - nsString unicodeStr; - ConvertToUnicode(m_internalCharSet, GetAsciiHeader(header), unicodeStr); - *_retval = ToNewUnicode(unicodeStr); - return NS_OK; + nsString unicodeStr; + ConvertToUnicode(m_internalCharSet, GetAsciiHeader(header), unicodeStr); + *_retval = ToNewUnicode(unicodeStr); + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetFrom(const PRUnichar *value) { - return SetUnicodeHeader(MSG_FROM_HEADER_ID, value); + return SetUnicodeHeader(MSG_FROM_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetFrom(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_FROM_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_FROM_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetReplyTo(const PRUnichar *value) { - return SetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, value); + return SetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetReplyTo(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetTo(const PRUnichar *value) { - return SetUnicodeHeader(MSG_TO_HEADER_ID, value); + return SetUnicodeHeader(MSG_TO_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetTo(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_TO_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_TO_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetCc(const PRUnichar *value) { - return SetUnicodeHeader(MSG_CC_HEADER_ID, value); + return SetUnicodeHeader(MSG_CC_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetCc(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_CC_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_CC_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetBcc(const PRUnichar *value) { - return SetUnicodeHeader(MSG_BCC_HEADER_ID, value); + return SetUnicodeHeader(MSG_BCC_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetBcc(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_BCC_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_BCC_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetFcc(const PRUnichar *value) { - return SetUnicodeHeader(MSG_FCC_HEADER_ID, value); + return SetUnicodeHeader(MSG_FCC_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetFcc(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_FCC_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_FCC_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetFcc2(const PRUnichar *value) { - return SetUnicodeHeader(MSG_FCC2_HEADER_ID, value); + return SetUnicodeHeader(MSG_FCC2_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetFcc2(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_FCC2_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_FCC2_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetNewsgroups(const char *value) { - return SetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID, value); + return SetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetNewsgroups(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetNewshost(const char *value) { - return SetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID, value); + return SetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetNewshost(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetFollowupTo(const char *value) { - return SetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID, value); + return SetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetFollowupTo(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetSubject(const PRUnichar *value) { - return SetUnicodeHeader(MSG_SUBJECT_HEADER_ID, value); + return SetUnicodeHeader(MSG_SUBJECT_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetSubject(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_SUBJECT_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_SUBJECT_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetAttachments(const char *value) { - return SetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID, value); + NS_ASSERTION(0, "nsMsgCompFields::SetAttachments is not supported anymore, please use nsMsgCompFields::AddAttachment"); + return SetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::SetTemporaryFiles(const char *value) { - return SetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID, value); + NS_ASSERTION(0, "nsMsgCompFields::SetTemporaryFiles is not supported anymore, please use nsMsgCompFields::AddAttachment"); + return SetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetAttachments(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + NS_ASSERTION(0, "nsMsgCompFields::GetAttachments is not supported anymore, please use nsMsgCompFields::GetAttachmentsArray"); + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::GetTemporaryFiles(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetOrganization(const PRUnichar *value) { - return SetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, value); + return SetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetOrganization(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetReferences(const char *value) { - return SetAsciiHeader(MSG_REFERENCES_HEADER_ID, value); + return SetAsciiHeader(MSG_REFERENCES_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetReferences(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_REFERENCES_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_REFERENCES_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetOtherRandomHeaders(const PRUnichar *value) { - return SetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value); + return SetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetOtherRandomHeaders(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetNewspostUrl(const char *value) { - return SetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID, value); + return SetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetNewspostUrl(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetPriority(const char *value) { - return SetAsciiHeader(MSG_PRIORITY_HEADER_ID, value); + return SetAsciiHeader(MSG_PRIORITY_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetPriority(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_PRIORITY_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_PRIORITY_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetCharacterSet(const char *value) { - return SetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID, value); + return SetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetCharacterSet(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetMessageId(const char *value) { - return SetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID, value); + return SetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetMessageId(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetTemplateName(const PRUnichar *value) { - return SetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, value); + return SetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetTemplateName(PRUnichar **_retval) { - return GetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, _retval); + return GetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, _retval); } NS_IMETHODIMP nsMsgCompFields::SetDraftId(const char *value) { - return SetAsciiHeader(MSG_DRAFT_ID_HEADER_ID, value); + return SetAsciiHeader(MSG_DRAFT_ID_HEADER_ID, value); } NS_IMETHODIMP nsMsgCompFields::GetDraftId(char **_retval) { - *_retval = nsCRT::strdup(GetAsciiHeader(MSG_DRAFT_ID_HEADER_ID)); - return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + *_retval = nsCRT::strdup(GetAsciiHeader(MSG_DRAFT_ID_HEADER_ID)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsMsgCompFields::SetReturnReceipt(PRBool value) { m_returnReceipt = value; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetReturnReceipt(PRBool *_retval) { *_retval = m_returnReceipt; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetAttachVCard(PRBool value) { m_attachVCard = value; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetAttachVCard(PRBool *_retval) { *_retval = m_attachVCard; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetForcePlainText(PRBool value) { m_forcePlainText = value; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetForcePlainText(PRBool *_retval) { *_retval = m_forcePlainText; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetUseMultipartAlternative(PRBool value) { m_useMultipartAlternative = value; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetUseMultipartAlternative(PRBool *_retval) { *_retval = m_useMultipartAlternative; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetUuEncodeAttachments(PRBool value) { m_uuEncodeAttachments = value; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetUuEncodeAttachments(PRBool *_retval) { *_retval = m_uuEncodeAttachments; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgCompFields::SetBody(const PRUnichar *value) @@ -532,23 +449,23 @@ NS_IMETHODIMP nsMsgCompFields::SetBody(const PRUnichar *value) PR_FREEIF(m_body); if (value) { - char* cString; - ConvertFromUnicode(m_internalCharSet, nsAutoString(value), &cString); - m_body = cString; - if (!m_body) - return NS_ERROR_OUT_OF_MEMORY; + char* cString; + ConvertFromUnicode(m_internalCharSet, nsAutoString(value), &cString); + m_body = cString; + if (!m_body) + return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; } NS_IMETHODIMP nsMsgCompFields::GetBody(PRUnichar **_retval) { - nsString unicodeStr; - const char* cString = GetBody(); - ConvertToUnicode(m_internalCharSet, cString, unicodeStr); - *_retval = ToNewUnicode(unicodeStr); + nsString unicodeStr; + const char* cString = GetBody(); + ConvertToUnicode(m_internalCharSet, cString, unicodeStr); + *_retval = ToNewUnicode(unicodeStr); - return NS_OK; + return NS_OK; } nsresult nsMsgCompFields::SetBody(const char *value) @@ -556,9 +473,9 @@ nsresult nsMsgCompFields::SetBody(const char *value) PR_FREEIF(m_body); if (value) { - m_body = nsCRT::strdup(value); - if (!m_body) - return NS_ERROR_OUT_OF_MEMORY; + m_body = nsCRT::strdup(value); + if (!m_body) + return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; } @@ -568,12 +485,85 @@ const char* nsMsgCompFields::GetBody() return m_body ? m_body : ""; } +/* readonly attribute nsISupportsArray attachmentsArray; */ +NS_IMETHODIMP nsMsgCompFields::GetAttachmentsArray(nsISupportsArray * *aAttachmentsArray) +{ + NS_ENSURE_ARG_POINTER(aAttachmentsArray); + *aAttachmentsArray = m_attachments; + NS_IF_ADDREF(*aAttachmentsArray); + return NS_OK; +} + +/* void addAttachment (in nsIMsgAttachment attachment); */ +NS_IMETHODIMP nsMsgCompFields::AddAttachment(nsIMsgAttachment *attachment) +{ + PRUint32 i; + PRUint32 attachmentCount = 0; + m_attachments->Count(&attachmentCount); + + //Don't add twice the same attachment. + nsCOMPtr element; + PRBool sameUrl; + for (i = 0; i < attachmentCount; i ++) + { + m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + { + element->EqualsUrl(attachment, &sameUrl); + if (sameUrl) + return NS_OK; + } + } + + return m_attachments->InsertElementAt(attachment, attachmentCount); +} + +/* void removeAttachment (in nsIMsgAttachment attachment); */ +NS_IMETHODIMP nsMsgCompFields::RemoveAttachment(nsIMsgAttachment *attachment) +{ + PRUint32 i; + PRUint32 attachmentCount = 0; + m_attachments->Count(&attachmentCount); + + nsCOMPtr element; + PRBool sameUrl; + for (i = 0; i < attachmentCount; i ++) + { + m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + { + element->EqualsUrl(attachment, &sameUrl); + if (sameUrl) + { + m_attachments->DeleteElementAt(i); + break; + } + } + } + + return NS_OK; +} + +/* void removeAttachments (); */ +NS_IMETHODIMP nsMsgCompFields::RemoveAttachments() +{ + PRUint32 i; + PRUint32 attachmentCount = 0; + m_attachments->Count(&attachmentCount); + + for (i = 0; i < attachmentCount; i ++) + m_attachments->DeleteElementAt(0); + + return NS_OK; +} + + // This method is called during the creation of a new window. NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const PRUnichar *recipients, PRBool emailAddressOnly, nsIMsgRecipientArray **_retval) { NS_ASSERTION(recipients, "The recipient list is not supposed to be null -Fix the caller!"); - nsresult rv = NS_OK; + nsresult rv = NS_OK; if (! _retval) return NS_ERROR_NULL_POINTER; @@ -647,34 +637,35 @@ NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const PRUnichar *recipients, PRBo return rv; } + //This method is called during the sending of message from NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients nsresult nsMsgCompFields::SplitRecipientsEx(const PRUnichar *recipients, nsIMsgRecipientArray ** fullAddrsArray, nsIMsgRecipientArray ** emailsArray) { NS_ASSERTION(recipients, "The recipient list is not supposed to be null -Fix the caller!"); - nsresult rv = NS_OK; + nsresult rv = NS_OK; nsMsgRecipientArray* pAddrsArray = nsnull; - if (fullAddrsArray) + if (fullAddrsArray) { - *fullAddrsArray = nsnull; - pAddrsArray = new nsMsgRecipientArray; - if (! pAddrsArray) - return NS_ERROR_OUT_OF_MEMORY; - rv = pAddrsArray->QueryInterface(NS_GET_IID(nsIMsgRecipientArray), (void **)fullAddrsArray); + *fullAddrsArray = nsnull; + pAddrsArray = new nsMsgRecipientArray; + if (! pAddrsArray) + return NS_ERROR_OUT_OF_MEMORY; + rv = pAddrsArray->QueryInterface(NS_GET_IID(nsIMsgRecipientArray), (void **)fullAddrsArray); if (NS_FAILED(rv)) return rv; } - + nsMsgRecipientArray* pEmailsArray = nsnull; - if (emailsArray) + if (emailsArray) { - *emailsArray = nsnull; - pEmailsArray = new nsMsgRecipientArray; - if (! pEmailsArray) - return NS_ERROR_OUT_OF_MEMORY; - rv = pEmailsArray->QueryInterface(NS_GET_IID(nsIMsgRecipientArray), (void **)emailsArray); - if (NS_FAILED(rv)) + *emailsArray = nsnull; + pEmailsArray = new nsMsgRecipientArray; + if (! pEmailsArray) + return NS_ERROR_OUT_OF_MEMORY; + rv = pEmailsArray->QueryInterface(NS_GET_IID(nsIMsgRecipientArray), (void **)emailsArray); + if (NS_FAILED(rv)) return rv; } @@ -707,68 +698,68 @@ nsresult nsMsgCompFields::SplitRecipientsEx(const PRUnichar *recipients, nsIMsgR PRBool aBool; for (i = 0; i < numAddresses; i ++) - { + { if (pAddrsArray) { rv = parser->MakeFullAddress(msgCompHeaderInternalCharset(), pNames, pAddresses, &fullAddress); if (NS_SUCCEEDED(rv)) - { - rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress, aRecipient); - PR_FREEIF(fullAddress); + { + rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress, aRecipient); + PR_FREEIF(fullAddress); } - else - rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), pAddresses, aRecipient); + else + rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), pAddresses, aRecipient); if (NS_FAILED(rv)) return rv; - rv = pAddrsArray->AppendString(aRecipient.get(), &aBool); - if (NS_FAILED(rv)) - return rv; - } + rv = pAddrsArray->AppendString(aRecipient.get(), &aBool); + if (NS_FAILED(rv)) + return rv; + } if (pEmailsArray) { rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), pAddresses, aRecipient); if (NS_FAILED(rv)) return rv; - rv = pEmailsArray->AppendString(aRecipient.get(), &aBool); - if (NS_FAILED(rv)) - return rv; + rv = pEmailsArray->AppendString(aRecipient.get(), &aBool); + if (NS_FAILED(rv)) + return rv; } - pNames += PL_strlen(pNames) + 1; - pAddresses += PL_strlen(pAddresses) + 1; + pNames += PL_strlen(pNames) + 1; + pAddresses += PL_strlen(pAddresses) + 1; } - - PR_FREEIF(names); - PR_FREEIF(addresses); - } - - PR_Free(recipientsStr); - } - else - rv = NS_ERROR_FAILURE; + + PR_FREEIF(names); + PR_FREEIF(addresses); + } + + PR_Free(recipientsStr); + } + else + rv = NS_ERROR_FAILURE; } - - return rv; + + return rv; } NS_IMETHODIMP nsMsgCompFields::ConvertBodyToPlainText() { - nsresult rv = NS_OK; - - if (m_body && *m_body != 0) - { - PRUnichar * ubody; - rv = GetBody(&ubody); - if (NS_SUCCEEDED(rv)) - { - nsString body(ubody); - PR_Free(ubody); - rv = ConvertBufToPlainText(body, UseFormatFlowed(GetCharacterSet())); - if (NS_SUCCEEDED(rv)) - rv = SetBody(body.get()); - } - } - return rv; + nsresult rv = NS_OK; + + if (m_body && *m_body != 0) + { + PRUnichar * ubody; + rv = GetBody(&ubody); + if (NS_SUCCEEDED(rv)) + { + nsString body(ubody); + PR_Free(ubody); + rv = ConvertBufToPlainText(body, UseFormatFlowed(GetCharacterSet())); + if (NS_SUCCEEDED(rv)) + rv = SetBody(body.get()); + } + } + return rv; } diff --git a/mozilla/mailnews/compose/src/nsMsgCompFields.h b/mozilla/mailnews/compose/src/nsMsgCompFields.h index 530a0e3b3ff..5eab9759e8b 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompFields.h +++ b/mozilla/mailnews/compose/src/nsMsgCompFields.h @@ -38,8 +38,8 @@ #ifndef _MsgCompFields_H_ #define _MsgCompFields_H_ -#include "msgCore.h" #include "nsIMsgCompFields.h" +#include "msgCore.h" /* Note that all the "Get" methods never return NULL (except in case of serious @@ -48,12 +48,12 @@ class nsMsgCompFields : public nsIMsgCompFields { public: - nsMsgCompFields(); - virtual ~nsMsgCompFields(); + nsMsgCompFields(); + virtual ~nsMsgCompFields(); - /* this macro defines QueryInterface, AddRef and Release for this class */ - NS_DECL_ISUPPORTS - NS_DECL_NSIMSGCOMPFIELDS + /* this macro defines QueryInterface, AddRef and Release for this class */ + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGCOMPFIELDS typedef enum MsgHeaderID { @@ -77,111 +77,109 @@ public: MSG_MESSAGE_ID_HEADER_ID, MSG_X_TEMPLATE_HEADER_ID, MSG_DRAFT_ID_HEADER_ID, - MSG_TEMPORARY_FILES_HEADER_ID, + MSG_TEMPORARY_FILES_HEADER_ID, MSG_MAX_HEADERS //Must be the last one. } MsgHeaderID; - nsresult Copy(nsIMsgCompFields* pMsgCompFields); + nsresult SetAsciiHeader(MsgHeaderID header, const char *value); + const char* GetAsciiHeader(MsgHeaderID header); //just return the address of the internal header variable, don't dispose it - nsresult SetAsciiHeader(MsgHeaderID header, const char *value); - const char* GetAsciiHeader(MsgHeaderID header); //just return the address of the internal header variable, don't dispose it + nsresult SetUnicodeHeader(MsgHeaderID header, const PRUnichar *value); + nsresult GetUnicodeHeader(MsgHeaderID header, PRUnichar **_retval); //Will return a copy of the header, must be free using PR_Free() - nsresult SetUnicodeHeader(MsgHeaderID header, const PRUnichar *value); - nsresult GetUnicodeHeader(MsgHeaderID header, PRUnichar **_retval); //Will return a copy of the header, must be free using PR_Free() + /* Convenience routines to get and set header's value... + + IMPORTANT: + all routines const char* GetXxx(void) will return a pointer to the header, please don't free it. + */ - /* Convenience routines to get and set header's value... - - IMPORTANT: - all routines const char* GetXxx(void) will return a pointer to the header, please don't free it. - */ + nsresult SetFrom(const char *value) {return SetAsciiHeader(MSG_FROM_HEADER_ID, value);} + const char* GetFrom(void) {return GetAsciiHeader(MSG_FROM_HEADER_ID);} - nsresult SetFrom(const char *value) {return SetAsciiHeader(MSG_FROM_HEADER_ID, value);} - const char* GetFrom(void) {return GetAsciiHeader(MSG_FROM_HEADER_ID);} + nsresult SetReplyTo(const char *value) {return SetAsciiHeader(MSG_REPLY_TO_HEADER_ID, value);} + const char* GetReplyTo() {return GetAsciiHeader(MSG_REPLY_TO_HEADER_ID);} - nsresult SetReplyTo(const char *value) {return SetAsciiHeader(MSG_REPLY_TO_HEADER_ID, value);} - const char* GetReplyTo() {return GetAsciiHeader(MSG_REPLY_TO_HEADER_ID);} + nsresult SetTo(const char *value) {return SetAsciiHeader(MSG_TO_HEADER_ID, value);} + const char* GetTo() {return GetAsciiHeader(MSG_TO_HEADER_ID);} - nsresult SetTo(const char *value) {return SetAsciiHeader(MSG_TO_HEADER_ID, value);} - const char* GetTo() {return GetAsciiHeader(MSG_TO_HEADER_ID);} + nsresult SetCc(const char *value) {return SetAsciiHeader(MSG_CC_HEADER_ID, value);} + const char* GetCc() {return GetAsciiHeader(MSG_CC_HEADER_ID);} - nsresult SetCc(const char *value) {return SetAsciiHeader(MSG_CC_HEADER_ID, value);} - const char* GetCc() {return GetAsciiHeader(MSG_CC_HEADER_ID);} + nsresult SetBcc(const char *value) {return SetAsciiHeader(MSG_BCC_HEADER_ID, value);} + const char* GetBcc() {return GetAsciiHeader(MSG_BCC_HEADER_ID);} - nsresult SetBcc(const char *value) {return SetAsciiHeader(MSG_BCC_HEADER_ID, value);} - const char* GetBcc() {return GetAsciiHeader(MSG_BCC_HEADER_ID);} + nsresult SetFcc(const char *value) {return SetAsciiHeader(MSG_FCC_HEADER_ID, value);} + const char* GetFcc() {return GetAsciiHeader(MSG_FCC_HEADER_ID);} - nsresult SetFcc(const char *value) {return SetAsciiHeader(MSG_FCC_HEADER_ID, value);} - const char* GetFcc() {return GetAsciiHeader(MSG_FCC_HEADER_ID);} + nsresult SetFcc2(const char *value) {return SetAsciiHeader(MSG_FCC2_HEADER_ID, value);} + const char* GetFcc2() {return GetAsciiHeader(MSG_FCC2_HEADER_ID);} - nsresult SetFcc2(const char *value) {return SetAsciiHeader(MSG_FCC2_HEADER_ID, value);} - const char* GetFcc2() {return GetAsciiHeader(MSG_FCC2_HEADER_ID);} + const char* GetNewsgroups() {return GetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID);} - const char* GetNewsgroups() {return GetAsciiHeader(MSG_NEWSGROUPS_HEADER_ID);} + const char* GetNewshost() {return GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID);} - const char* GetNewshost() {return GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID);} + const char* GetFollowupTo() {return GetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID);} - const char* GetFollowupTo() {return GetAsciiHeader(MSG_FOLLOWUP_TO_HEADER_ID);} + nsresult SetSubject(const char *value) {return SetAsciiHeader(MSG_SUBJECT_HEADER_ID, value);} + const char* GetSubject() {return GetAsciiHeader(MSG_SUBJECT_HEADER_ID);} - nsresult SetSubject(const char *value) {return SetAsciiHeader(MSG_SUBJECT_HEADER_ID, value);} - const char* GetSubject() {return GetAsciiHeader(MSG_SUBJECT_HEADER_ID);} + const char* GetAttachments() { + NS_ASSERTION(0, "nsMsgCompFields::GetAttachments is not supported anymore, please use nsMsgCompFields::GetAttachmentsArray"); + return GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID); + } - const char* GetAttachments() {return GetAsciiHeader(MSG_ATTACHMENTS_HEADER_ID);} + const char* GetTemporaryFiles() { + NS_ASSERTION(0, "nsMsgCompFields::GetTemporaryFiles is not supported anymore, please use nsMsgCompFields::GetAttachmentsArray"); + return GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID); + } - const char* GetTemporaryFiles() {return GetAsciiHeader(MSG_TEMPORARY_FILES_HEADER_ID);} + nsresult SetOrganization(const char *value) {return SetAsciiHeader(MSG_ORGANIZATION_HEADER_ID, value);} + const char* GetOrganization() {return GetAsciiHeader(MSG_ORGANIZATION_HEADER_ID);} - nsresult SetOrganization(const char *value) {return SetAsciiHeader(MSG_ORGANIZATION_HEADER_ID, value);} - const char* GetOrganization() {return GetAsciiHeader(MSG_ORGANIZATION_HEADER_ID);} + const char* GetReferences() {return GetAsciiHeader(MSG_REFERENCES_HEADER_ID);} - const char* GetReferences() {return GetAsciiHeader(MSG_REFERENCES_HEADER_ID);} + nsresult SetOtherRandomHeaders(const char *value) {return SetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value);} + const char* GetOtherRandomHeaders() {return GetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID);} - nsresult SetOtherRandomHeaders(const char *value) {return SetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value);} - const char* GetOtherRandomHeaders() {return GetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID);} + const char* GetNewspostUrl() {return GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID);} - const char* GetNewspostUrl() {return GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID);} + const char* GetPriority() {return GetAsciiHeader(MSG_PRIORITY_HEADER_ID);} - const char* GetPriority() {return GetAsciiHeader(MSG_PRIORITY_HEADER_ID);} + const char* GetCharacterSet() {return GetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID);} - const char* GetCharacterSet() {return GetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID);} + const char* GetMessageId() {return GetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID);} - const char* GetMessageId() {return GetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID);} + nsresult SetTemplateName(const char *value) {return SetAsciiHeader(MSG_X_TEMPLATE_HEADER_ID, value);} + const char* GetTemplateName() {return GetAsciiHeader(MSG_X_TEMPLATE_HEADER_ID);} - nsresult SetTemplateName(const char *value) {return SetAsciiHeader(MSG_X_TEMPLATE_HEADER_ID, value);} - const char* GetTemplateName() {return GetAsciiHeader(MSG_X_TEMPLATE_HEADER_ID);} + const char* GetDraftId() {return GetAsciiHeader(MSG_DRAFT_ID_HEADER_ID);} - const char* GetDraftId() {return GetAsciiHeader(MSG_DRAFT_ID_HEADER_ID);} + PRBool GetReturnReceipt() {return m_returnReceipt;} + PRBool GetAttachVCard() {return m_attachVCard;} + PRBool GetForcePlainText() {return m_forcePlainText;} + PRBool GetUseMultipartAlternative() {return m_useMultipartAlternative;} + PRBool GetUuEncodeAttachments() {return m_uuEncodeAttachments;} - PRBool GetReturnReceipt() {return m_returnReceipt;} - PRBool GetAttachVCard() {return m_attachVCard;} - PRBool GetForcePlainText() {return m_forcePlainText;} - PRBool GetUseMultipartAlternative() {return m_useMultipartAlternative;} - PRBool GetUuEncodeAttachments() {return m_uuEncodeAttachments;} + nsresult SetBody(const char *value); + const char* GetBody(); - nsresult SetBody(const char *value); - const char* GetBody(); + nsresult SplitRecipientsEx(const PRUnichar *recipients, nsIMsgRecipientArray ** fullAddrsArray, nsIMsgRecipientArray ** emailsArray); - nsresult SplitRecipientsEx(const PRUnichar *recipients, nsIMsgRecipientArray ** fullAddrsArray, nsIMsgRecipientArray ** emailsArray); - - PRInt32 GetReturnReceiptType() { return m_receiptType; }; - void SetReturnReceiptType(PRInt32 type) {m_receiptType = type;}; - - nsresult CleanUpTempFiles(); + PRInt32 GetReturnReceiptType() { return m_receiptType; }; + void SetReturnReceiptType(PRInt32 type) {m_receiptType = type;}; protected: - char* m_headers[MSG_MAX_HEADERS]; - char* m_body; + char* m_headers[MSG_MAX_HEADERS]; + char* m_body; + nsCOMPtr m_attachments; PRBool m_attachVCard; PRBool m_forcePlainText; PRBool m_useMultipartAlternative; PRBool m_uuEncodeAttachments; PRBool m_returnReceipt; - PRInt32 m_receiptType; /* 0:None 1:DSN 2:MDN 3:BOTH */ - nsString m_internalCharSet; - - /* WARNING: - If you add any new member variable, you must update the function - nsMsgCompFields::Copy as well else they will not be copied automatically! - */ + PRInt32 m_receiptType; /* 0:None 1:DSN 2:MDN 3:BOTH */ + nsString m_internalCharSet; }; diff --git a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp index d2744766c8a..99e4ca6a0af 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp @@ -124,14 +124,14 @@ nsMsgMIMEGetConformToStandard (void) void nsMsgMIMESetConformToStandard (PRBool conform_p) { - /* - * If we are conforming to mime standard no matter what we set - * for the headers preference when generating mime headers we should - * also conform to the standard. Otherwise, depends the preference - * we set. For now, the headers preference is not accessible from UI. - */ - if (conform_p) - mime_headers_use_quoted_printable_p = PR_TRUE; + /* + * If we are conforming to mime standard no matter what we set + * for the headers preference when generating mime headers we should + * also conform to the standard. Otherwise, depends the preference + * we set. For now, the headers preference is not accessible from UI. + */ + if (conform_p) + mime_headers_use_quoted_printable_p = PR_TRUE; else { nsresult rv; nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); @@ -142,54 +142,54 @@ nsMsgMIMESetConformToStandard (PRBool conform_p) } nsresult mime_sanity_check_fields ( - const char *from, - const char *reply_to, - const char *to, - const char *cc, - const char *bcc, - const char *fcc, - const char *newsgroups, - const char *followup_to, - const char * /*subject*/, - const char * /*references*/, - const char * /*organization*/, - const char * /*other_random_headers*/) + const char *from, + const char *reply_to, + const char *to, + const char *cc, + const char *bcc, + const char *fcc, + const char *newsgroups, + const char *followup_to, + const char * /*subject*/, + const char * /*references*/, + const char * /*organization*/, + const char * /*other_random_headers*/) { - if (from) - while (IS_SPACE (*from)) - from++; - if (reply_to) - while (IS_SPACE (*reply_to)) - reply_to++; - if (to) - while (IS_SPACE (*to)) - to++; - if (cc) - while (IS_SPACE (*cc)) - cc++; - if (bcc) - while (IS_SPACE (*bcc)) - bcc++; - if (fcc) - while (IS_SPACE (*fcc)) - fcc++; - if (newsgroups) - while (IS_SPACE (*newsgroups)) - newsgroups++; - if (followup_to) - while (IS_SPACE (*followup_to)) - followup_to++; + if (from) + while (IS_SPACE (*from)) + from++; + if (reply_to) + while (IS_SPACE (*reply_to)) + reply_to++; + if (to) + while (IS_SPACE (*to)) + to++; + if (cc) + while (IS_SPACE (*cc)) + cc++; + if (bcc) + while (IS_SPACE (*bcc)) + bcc++; + if (fcc) + while (IS_SPACE (*fcc)) + fcc++; + if (newsgroups) + while (IS_SPACE (*newsgroups)) + newsgroups++; + if (followup_to) + while (IS_SPACE (*followup_to)) + followup_to++; - /* #### sanity check other_random_headers for newline conventions */ - if (!from || !*from || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_6)) - return NS_MSG_NO_SENDER; - else - if (((!to || !*to) && (!cc || !*cc) && - (!bcc || !*bcc) && (!newsgroups || !*newsgroups)) || - CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_7)) - return NS_MSG_NO_RECIPIENTS; - else - return NS_OK; + /* #### sanity check other_random_headers for newline conventions */ + if (!from || !*from || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_6)) + return NS_MSG_NO_SENDER; + else + if (((!to || !*to) && (!cc || !*cc) && + (!bcc || !*bcc) && (!newsgroups || !*newsgroups)) || + CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_7)) + return NS_MSG_NO_RECIPIENTS; + else + return NS_OK; } static char * @@ -223,44 +223,44 @@ nsMsgStripLine (char * string) char * mime_generate_headers (nsMsgCompFields *fields, - const char *charset, - nsMsgDeliverMode deliver_mode, nsIPrompt * aPrompt, PRInt32 *status) + const char *charset, + nsMsgDeliverMode deliver_mode, nsIPrompt * aPrompt, PRInt32 *status) { nsresult rv; *status = 0; nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); if (NS_FAILED(rv)) { - *status = rv; + *status = rv; return nsnull; } - int size = 0; - char *buffer = 0, *buffer_tail = 0; - PRBool isDraft = + int size = 0; + char *buffer = 0, *buffer_tail = 0; + PRBool isDraft = deliver_mode == nsIMsgSend::nsMsgSaveAsDraft || deliver_mode == nsIMsgSend::nsMsgSaveAsTemplate || deliver_mode == nsIMsgSend::nsMsgQueueForLater; - const char* pFrom; - const char* pTo; - const char* pCc; - const char* pMessageID; - const char* pReplyTo; - const char* pOrg; - const char* pNewsGrp; - const char* pFollow; - const char* pSubject; - const char* pPriority; - const char* pReference; - const char* pOtherHdr; + const char* pFrom; + const char* pTo; + const char* pCc; + const char* pMessageID; + const char* pReplyTo; + const char* pOrg; + const char* pNewsGrp; + const char* pFollow; + const char* pSubject; + const char* pPriority; + const char* pReference; + const char* pOtherHdr; nsCAutoString headerBuf; // accumulate header strings for charset conversion check headerBuf.Truncate(0); - NS_ASSERTION (fields, "null fields"); - if (!fields) - return nsnull; + NS_ASSERTION (fields, "null fields"); + if (!fields) + return nsnull; pFrom = fields->GetFrom(); if (pFrom) @@ -274,18 +274,18 @@ mime_generate_headers (nsMsgCompFields *fields, pCc = fields->GetCc(); if (pCc) headerBuf.Append(pCc); - pNewsGrp = fields->GetNewsgroups(); if (pNewsGrp) size += 3 * PL_strlen (pNewsGrp); - pFollow= fields->GetFollowupTo(); if (pFollow) size += 3 * PL_strlen (pFollow); + pNewsGrp = fields->GetNewsgroups(); if (pNewsGrp) size += 3 * PL_strlen (pNewsGrp); + pFollow= fields->GetFollowupTo(); if (pFollow) size += 3 * PL_strlen (pFollow); pSubject = fields->GetSubject(); if (pSubject) headerBuf.Append(pSubject); - pReference = fields->GetReferences(); if (pReference) size += 3 * PL_strlen (pReference); + pReference = fields->GetReferences(); if (pReference) size += 3 * PL_strlen (pReference); pOrg= fields->GetOrganization(); if (pOrg) headerBuf.Append(pOrg); - pOtherHdr= fields->GetOtherRandomHeaders(); if (pOtherHdr) size += 3 * PL_strlen (pOtherHdr); - pPriority = fields->GetPriority(); if (pPriority) size += 3 * PL_strlen (pPriority); - pMessageID = fields->GetMessageId(); if (pMessageID) size += PL_strlen (pMessageID); + pOtherHdr= fields->GetOtherRandomHeaders(); if (pOtherHdr) size += 3 * PL_strlen (pOtherHdr); + pPriority = fields->GetPriority(); if (pPriority) size += 3 * PL_strlen (pPriority); + pMessageID = fields->GetMessageId(); if (pMessageID) size += PL_strlen (pMessageID); /* Multiply by 3 here to make enough room for MimePartII conversion */ size += 3 * headerBuf.Length(); @@ -303,251 +303,251 @@ mime_generate_headers (nsMsgCompFields *fields, } } - /* Add a bunch of slop for the static parts of the headers. */ - /* size += 2048; */ - size += 2560; + /* Add a bunch of slop for the static parts of the headers. */ + /* size += 2048; */ + size += 2560; - buffer = (char *) PR_Malloc (size); - if (!buffer) - return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ - - buffer_tail = buffer; + buffer = (char *) PR_Malloc (size); + if (!buffer) + return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ + + buffer_tail = buffer; - if (pMessageID && *pMessageID) { - char *convbuf = NULL; - PUSH_STRING ("Message-ID: "); - PUSH_STRING (pMessageID); - PUSH_NEWLINE (); - /* MDN request header requires to have MessageID header presented - * in the message in order to - * coorelate the MDN reports to the original message. Here will be - * the right place - */ - if (fields->GetReturnReceipt() && - (fields->GetReturnReceiptType() == 2 || - fields->GetReturnReceiptType() == 3) && - (deliver_mode != nsIMsgSend::nsMsgSaveAsDraft && - deliver_mode != nsIMsgSend::nsMsgSaveAsTemplate)) - { - PRInt32 receipt_header_type = 0; + if (pMessageID && *pMessageID) { + char *convbuf = NULL; + PUSH_STRING ("Message-ID: "); + PUSH_STRING (pMessageID); + PUSH_NEWLINE (); + /* MDN request header requires to have MessageID header presented + * in the message in order to + * coorelate the MDN reports to the original message. Here will be + * the right place + */ + if (fields->GetReturnReceipt() && + (fields->GetReturnReceiptType() == 2 || + fields->GetReturnReceiptType() == 3) && + (deliver_mode != nsIMsgSend::nsMsgSaveAsDraft && + deliver_mode != nsIMsgSend::nsMsgSaveAsTemplate)) + { + PRInt32 receipt_header_type = 0; if (prefs) - prefs->GetIntPref("mail.receipt.request_header_type", &receipt_header_type); + prefs->GetIntPref("mail.receipt.request_header_type", &receipt_header_type); - // 0 = MDN Disposition-Notification-To: ; 1 = Return-Receipt-To: ; 2 = - // both MDN DNT & RRT headers - if (receipt_header_type == 1) { - RRT_HEADER: - PUSH_STRING ("Return-Receipt-To: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_FREEIF(convbuf); - } - else - PUSH_STRING (pFrom); - PUSH_NEWLINE (); - } - else { - PUSH_STRING ("Disposition-Notification-To: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_FREEIF(convbuf); - } - else - PUSH_STRING (pFrom); - PUSH_NEWLINE (); - if (receipt_header_type == 2) - goto RRT_HEADER; - } - } + // 0 = MDN Disposition-Notification-To: ; 1 = Return-Receipt-To: ; 2 = + // both MDN DNT & RRT headers + if (receipt_header_type == 1) { + RRT_HEADER: + PUSH_STRING ("Return-Receipt-To: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_FREEIF(convbuf); + } + else + PUSH_STRING (pFrom); + PUSH_NEWLINE (); + } + else { + PUSH_STRING ("Disposition-Notification-To: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_FREEIF(convbuf); + } + else + PUSH_STRING (pFrom); + PUSH_NEWLINE (); + if (receipt_header_type == 2) + goto RRT_HEADER; + } + } #ifdef SUPPORT_X_TEMPLATE_NAME - if (deliver_mode == MSG_SaveAsTemplate) { - PUSH_STRING ("X-Template: "); - char * pStr = fields->GetTemplateName(); - if (pStr) { - convbuf = nsMsgI18NEncodeMimePartIIStr((char *) - pStr, - charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { - PUSH_STRING (convbuf); - PR_FREEIF(convbuf); - } - else - PUSH_STRING(pStr); - } - PUSH_NEWLINE (); - } + if (deliver_mode == MSG_SaveAsTemplate) { + PUSH_STRING ("X-Template: "); + char * pStr = fields->GetTemplateName(); + if (pStr) { + convbuf = nsMsgI18NEncodeMimePartIIStr((char *) + pStr, + charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { + PUSH_STRING (convbuf); + PR_FREEIF(convbuf); + } + else + PUSH_STRING(pStr); + } + PUSH_NEWLINE (); + } #endif /* SUPPORT_X_TEMPLATE_NAME */ - } + } - PRExplodedTime now; + PRExplodedTime now; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now); int gmtoffset = (now.tm_params.tp_gmt_offset + now.tm_params.tp_dst_offset) / 60; - /* Use PR_FormatTimeUSEnglish() to format the date in US English format, - then figure out what our local GMT offset is, and append it (since - PR_FormatTimeUSEnglish() can't do that.) Generate four digit years as - per RFC 1123 (superceding RFC 822.) - */ - PR_FormatTimeUSEnglish(buffer_tail, 100, - "Date: %a, %d %b %Y %H:%M:%S ", - &now); + /* Use PR_FormatTimeUSEnglish() to format the date in US English format, + then figure out what our local GMT offset is, and append it (since + PR_FormatTimeUSEnglish() can't do that.) Generate four digit years as + per RFC 1123 (superceding RFC 822.) + */ + PR_FormatTimeUSEnglish(buffer_tail, 100, + "Date: %a, %d %b %Y %H:%M:%S ", + &now); - buffer_tail += PL_strlen (buffer_tail); - PR_snprintf(buffer_tail, buffer + size - buffer_tail, - "%c%02d%02d" CRLF, - (gmtoffset >= 0 ? '+' : '-'), - ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) / 60), - ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) % 60)); - buffer_tail += PL_strlen (buffer_tail); + buffer_tail += PL_strlen (buffer_tail); + PR_snprintf(buffer_tail, buffer + size - buffer_tail, + "%c%02d%02d" CRLF, + (gmtoffset >= 0 ? '+' : '-'), + ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) / 60), + ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) % 60)); + buffer_tail += PL_strlen (buffer_tail); - if (pFrom && *pFrom) { - char *convbuf; - PUSH_STRING ("From: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, - nsMsgMIMEGetConformToStandard()); + if (pFrom && *pFrom) { + char *convbuf; + PUSH_STRING ("From: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFrom, charset, + nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pFrom); - PUSH_NEWLINE (); - } + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pFrom); + PUSH_NEWLINE (); + } - if (pReplyTo && *pReplyTo) - { - char *convbuf; - PUSH_STRING ("Reply-To: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pReplyTo, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pReplyTo); - PUSH_NEWLINE (); - } - - if (pOrg && *pOrg) - { - char *convbuf; - PUSH_STRING ("Organization: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pOrg, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pOrg); - PUSH_NEWLINE (); - } - - // X-Mozilla-Draft-Info - if (isDraft) + if (pReplyTo && *pReplyTo) { - PUSH_STRING(HEADER_X_MOZILLA_DRAFT_INFO); - PUSH_STRING(": internal/draft; "); - if (fields->GetAttachVCard()) - PUSH_STRING("vcard=1"); - else - PUSH_STRING("vcard=0"); - PUSH_STRING("; "); - if (fields->GetReturnReceipt()) { - char *type = PR_smprintf("%d", (int) fields->GetReturnReceiptType()); - if (type) - { - PUSH_STRING("receipt="); - PUSH_STRING(type); - PR_FREEIF(type); - } - } - else - PUSH_STRING("receipt=0"); - PUSH_STRING("; "); - if (fields->GetUuEncodeAttachments()) - PUSH_STRING("uuencode=1"); - else - PUSH_STRING("uuencode=0"); + char *convbuf; + PUSH_STRING ("Reply-To: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pReplyTo, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pReplyTo); + PUSH_NEWLINE (); + } - PUSH_NEWLINE (); - } + if (pOrg && *pOrg) + { + char *convbuf; + PUSH_STRING ("Organization: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pOrg, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pOrg); + PUSH_NEWLINE (); + } + + // X-Mozilla-Draft-Info + if (isDraft) + { + PUSH_STRING(HEADER_X_MOZILLA_DRAFT_INFO); + PUSH_STRING(": internal/draft; "); + if (fields->GetAttachVCard()) + PUSH_STRING("vcard=1"); + else + PUSH_STRING("vcard=0"); + PUSH_STRING("; "); + if (fields->GetReturnReceipt()) { + char *type = PR_smprintf("%d", (int) fields->GetReturnReceiptType()); + if (type) + { + PUSH_STRING("receipt="); + PUSH_STRING(type); + PR_FREEIF(type); + } + } + else + PUSH_STRING("receipt=0"); + PUSH_STRING("; "); + if (fields->GetUuEncodeAttachments()) + PUSH_STRING("uuencode=1"); + else + PUSH_STRING("uuencode=0"); + + PUSH_NEWLINE (); + } - nsCOMPtr pHTTPHandler = - do_GetService(kHTTPHandlerCID, &rv); - if (NS_SUCCEEDED(rv) && pHTTPHandler) - { + nsCOMPtr pHTTPHandler = + do_GetService(kHTTPHandlerCID, &rv); + if (NS_SUCCEEDED(rv) && pHTTPHandler) + { nsXPIDLCString userAgentString; pHTTPHandler->GetUserAgent(getter_Copies(userAgentString)); - if (userAgentString) - { - // PUSH_STRING ("X-Mailer: "); // To be more standards compliant - PUSH_STRING ("User-Agent: "); - PUSH_STRING(userAgentString.get()); - PUSH_NEWLINE (); - } - } + if (userAgentString) + { + // PUSH_STRING ("X-Mailer: "); // To be more standards compliant + PUSH_STRING ("User-Agent: "); + PUSH_STRING(userAgentString.get()); + PUSH_NEWLINE (); + } + } - /* for Netscape Server, Accept-Language data sent in Mail header */ - char *acceptlang = nsMsgI18NGetAcceptLanguage(); - if( (acceptlang != NULL) && ( *acceptlang != '\0') ){ - PUSH_STRING( "X-Accept-Language: " ); - PUSH_STRING( acceptlang ); - PUSH_NEWLINE(); - } + /* for Netscape Server, Accept-Language data sent in Mail header */ + char *acceptlang = nsMsgI18NGetAcceptLanguage(); + if( (acceptlang != NULL) && ( *acceptlang != '\0') ){ + PUSH_STRING( "X-Accept-Language: " ); + PUSH_STRING( acceptlang ); + PUSH_NEWLINE(); + } - PUSH_STRING ("MIME-Version: 1.0" CRLF); + PUSH_STRING ("MIME-Version: 1.0" CRLF); - if (pNewsGrp && *pNewsGrp) { - /* turn whitespace into a comma list - */ - char *ptr, *ptr2; - char *n2; - char *convbuf; + if (pNewsGrp && *pNewsGrp) { + /* turn whitespace into a comma list + */ + char *ptr, *ptr2; + char *n2; + char *convbuf; - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pNewsGrp, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) - n2 = nsMsgStripLine (convbuf); - else { - ptr = PL_strdup(pNewsGrp); - if (!ptr) { - PR_FREEIF(buffer); - return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ - } - n2 = nsMsgStripLine(ptr); - NS_ASSERTION(n2 == ptr, "n2 != ptr"); /* Otherwise, the PR_Free below is - gonna choke badly. */ - } + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pNewsGrp, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) + n2 = nsMsgStripLine (convbuf); + else { + ptr = PL_strdup(pNewsGrp); + if (!ptr) { + PR_FREEIF(buffer); + return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ + } + n2 = nsMsgStripLine(ptr); + NS_ASSERTION(n2 == ptr, "n2 != ptr"); /* Otherwise, the PR_Free below is + gonna choke badly. */ + } - for(ptr=n2; *ptr != '\0'; ptr++) { - /* find first non white space */ - while(!IS_SPACE(*ptr) && *ptr != ',' && *ptr != '\0') - ptr++; + for(ptr=n2; *ptr != '\0'; ptr++) { + /* find first non white space */ + while(!IS_SPACE(*ptr) && *ptr != ',' && *ptr != '\0') + ptr++; - if(*ptr == '\0') - break; + if(*ptr == '\0') + break; - if(*ptr != ',') - *ptr = ','; + if(*ptr != ',') + *ptr = ','; - /* find next non white space */ - ptr2 = ptr+1; - while(IS_SPACE(*ptr2)) - ptr2++; + /* find next non white space */ + ptr2 = ptr+1; + while(IS_SPACE(*ptr2)) + ptr2++; - if(ptr2 != ptr+1) - PL_strcpy(ptr+1, ptr2); - } + if(ptr2 != ptr+1) + PL_strcpy(ptr+1, ptr2); + } // we need to decide the Newsgroup related headers // to write to the outgoing message. In ANY case, we need to write the @@ -591,163 +591,163 @@ mime_generate_headers (nsMsgCompFields *fields, PUSH_NEWLINE (); } - PR_FREEIF(n2); - } + PR_FREEIF(n2); + } - /* #### shamelessly duplicated from above */ - if (pFollow && *pFollow) { - /* turn whitespace into a comma list - */ - char *ptr, *ptr2; - char *n2; - char *convbuf; + /* #### shamelessly duplicated from above */ + if (pFollow && *pFollow) { + /* turn whitespace into a comma list + */ + char *ptr, *ptr2; + char *n2; + char *convbuf; - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFollow, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) - n2 = nsMsgStripLine (convbuf); - else { - ptr = PL_strdup(pFollow); - if (!ptr) { - PR_FREEIF(buffer); - return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ - } - n2 = nsMsgStripLine (ptr); - NS_ASSERTION(n2 == ptr, "n2 != ptr"); /* Otherwise, the PR_Free below is - gonna choke badly. */ - } + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pFollow, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) + n2 = nsMsgStripLine (convbuf); + else { + ptr = PL_strdup(pFollow); + if (!ptr) { + PR_FREEIF(buffer); + return nsnull; /* NS_ERROR_OUT_OF_MEMORY */ + } + n2 = nsMsgStripLine (ptr); + NS_ASSERTION(n2 == ptr, "n2 != ptr"); /* Otherwise, the PR_Free below is + gonna choke badly. */ + } - for (ptr=n2; *ptr != '\0'; ptr++) { - /* find first non white space */ - while(!IS_SPACE(*ptr) && *ptr != ',' && *ptr != '\0') - ptr++; + for (ptr=n2; *ptr != '\0'; ptr++) { + /* find first non white space */ + while(!IS_SPACE(*ptr) && *ptr != ',' && *ptr != '\0') + ptr++; - if(*ptr == '\0') - break; + if(*ptr == '\0') + break; - if(*ptr != ',') - *ptr = ','; + if(*ptr != ',') + *ptr = ','; - /* find next non white space */ - ptr2 = ptr+1; - while(IS_SPACE(*ptr2)) - ptr2++; + /* find next non white space */ + ptr2 = ptr+1; + while(IS_SPACE(*ptr2)) + ptr2++; - if(ptr2 != ptr+1) - PL_strcpy(ptr+1, ptr2); - } + if(ptr2 != ptr+1) + PL_strcpy(ptr+1, ptr2); + } - PUSH_STRING ("Followup-To: "); - PUSH_STRING (n2); - PR_Free (n2); - PUSH_NEWLINE (); - } + PUSH_STRING ("Followup-To: "); + PUSH_STRING (n2); + PR_Free (n2); + PUSH_NEWLINE (); + } - if (pTo && *pTo) { - char *convbuf; - PUSH_STRING ("To: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pTo, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pTo); + if (pTo && *pTo) { + char *convbuf; + PUSH_STRING ("To: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pTo, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pTo); - PUSH_NEWLINE (); - } + PUSH_NEWLINE (); + } - if (pCc && *pCc) { - char *convbuf; - PUSH_STRING ("CC: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pCc, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pCc); - PUSH_NEWLINE (); - } + if (pCc && *pCc) { + char *convbuf; + PUSH_STRING ("CC: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pCc, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pCc); + PUSH_NEWLINE (); + } - if (pSubject && *pSubject) { + if (pSubject && *pSubject) { - char *convbuf; - PUSH_STRING ("Subject: "); - convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pSubject, charset, - nsMsgMIMEGetConformToStandard()); - if (convbuf) { /* MIME-PartII conversion */ - PUSH_STRING (convbuf); - PR_Free(convbuf); - } - else - PUSH_STRING (pSubject); - PUSH_NEWLINE (); - } - - if (pPriority && *pPriority) - if (!PL_strcasestr(pPriority, "normal")) { - PUSH_STRING ("X-Priority: "); - /* Important: do not change the order of the - * following if statements - */ - if (PL_strcasestr (pPriority, "highest")) - PUSH_STRING("1 ("); - else if (PL_strcasestr(pPriority, "high")) - PUSH_STRING("2 ("); - else if (PL_strcasestr(pPriority, "lowest")) - PUSH_STRING("5 ("); - else if (PL_strcasestr(pPriority, "low")) - PUSH_STRING("4 ("); + char *convbuf; + PUSH_STRING ("Subject: "); + convbuf = nsMsgI18NEncodeMimePartIIStr((char *)pSubject, charset, + nsMsgMIMEGetConformToStandard()); + if (convbuf) { /* MIME-PartII conversion */ + PUSH_STRING (convbuf); + PR_Free(convbuf); + } + else + PUSH_STRING (pSubject); + PUSH_NEWLINE (); + } + + if (pPriority && *pPriority) + if (!PL_strcasestr(pPriority, "normal")) { + PUSH_STRING ("X-Priority: "); + /* Important: do not change the order of the + * following if statements + */ + if (PL_strcasestr (pPriority, "highest")) + PUSH_STRING("1 ("); + else if (PL_strcasestr(pPriority, "high")) + PUSH_STRING("2 ("); + else if (PL_strcasestr(pPriority, "lowest")) + PUSH_STRING("5 ("); + else if (PL_strcasestr(pPriority, "low")) + PUSH_STRING("4 ("); - PUSH_STRING (pPriority); - PUSH_STRING(")"); - PUSH_NEWLINE (); - } + PUSH_STRING (pPriority); + PUSH_STRING(")"); + PUSH_NEWLINE (); + } - if (pReference && *pReference) { - PUSH_STRING ("References: "); - if (PL_strlen(pReference) >= 986) { - char *references = PL_strdup(pReference); - char *trimAt = PL_strchr(references+1, '<'); - char *ptr; - // per sfraser, RFC 1036 - a message header line should not exceed - // 998 characters including the header identifier - // retiring the earliest reference one after the other - // but keep the first one for proper threading - while (references && PL_strlen(references) >= 986 && trimAt) { - ptr = PL_strchr(trimAt+1, '<'); - if (ptr) - nsCRT::memmove(trimAt, ptr, PL_strlen(ptr)+1); // including the - else - break; - } - NS_ASSERTION(references, "null references"); - if (references) { - PUSH_STRING (references); - PR_Free(references); - } - } - else - PUSH_STRING (pReference); - PUSH_NEWLINE (); - } + if (pReference && *pReference) { + PUSH_STRING ("References: "); + if (PL_strlen(pReference) >= 986) { + char *references = PL_strdup(pReference); + char *trimAt = PL_strchr(references+1, '<'); + char *ptr; + // per sfraser, RFC 1036 - a message header line should not exceed + // 998 characters including the header identifier + // retiring the earliest reference one after the other + // but keep the first one for proper threading + while (references && PL_strlen(references) >= 986 && trimAt) { + ptr = PL_strchr(trimAt+1, '<'); + if (ptr) + nsCRT::memmove(trimAt, ptr, PL_strlen(ptr)+1); // including the + else + break; + } + NS_ASSERTION(references, "null references"); + if (references) { + PUSH_STRING (references); + PR_Free(references); + } + } + else + PUSH_STRING (pReference); + PUSH_NEWLINE (); + } - if (pOtherHdr && *pOtherHdr) { - /* Assume they already have the right newlines and continuations - and so on. */ - PUSH_STRING (pOtherHdr); - } + if (pOtherHdr && *pOtherHdr) { + /* Assume they already have the right newlines and continuations + and so on. */ + PUSH_STRING (pOtherHdr); + } - if (buffer_tail > buffer + size - 1) + if (buffer_tail > buffer + size - 1) return nsnull; - /* realloc it smaller... */ - buffer = (char*)PR_REALLOC (buffer, buffer_tail - buffer + 1); + /* realloc it smaller... */ + buffer = (char*)PR_REALLOC (buffer, buffer_tail - buffer + 1); - return buffer; + return buffer; } static void @@ -772,46 +772,76 @@ GenerateGlobalRandomBytes(unsigned char *buf, PRInt32 len) char *mime_make_separator(const char *prefix) { - unsigned char rand_buf[13]; - GenerateGlobalRandomBytes(rand_buf, 12); + unsigned char rand_buf[13]; + GenerateGlobalRandomBytes(rand_buf, 12); return PR_smprintf("------------%s" - "%02X%02X%02X%02X" - "%02X%02X%02X%02X" - "%02X%02X%02X%02X", - prefix, - rand_buf[0], rand_buf[1], rand_buf[2], rand_buf[3], - rand_buf[4], rand_buf[5], rand_buf[6], rand_buf[7], - rand_buf[8], rand_buf[9], rand_buf[10], rand_buf[11]); + "%02X%02X%02X%02X" + "%02X%02X%02X%02X" + "%02X%02X%02X%02X", + prefix, + rand_buf[0], rand_buf[1], rand_buf[2], rand_buf[3], + rand_buf[4], rand_buf[5], rand_buf[6], rand_buf[7], + rand_buf[8], rand_buf[9], rand_buf[10], rand_buf[11]); } char * mime_generate_attachment_headers (const char *type, const char *encoding, - const char *description, - const char *x_mac_type, - const char *x_mac_creator, - const char *real_name, - const char *base_url, - PRBool /*digest_p*/, - nsMsgAttachmentHandler * /*ma*/, - const char *charset, + const char *description, + const char *x_mac_type, + const char *x_mac_creator, + const char *real_name, + const char *base_url, + PRBool /*digest_p*/, + nsMsgAttachmentHandler * /*ma*/, + const char *charset, const char *content_id, PRBool aBodyDocument) { nsresult rv; nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); - PRInt32 buffer_size = 2048 + (base_url ? 2*PL_strlen(base_url) : 0); - char *buffer = (char *) PR_Malloc (buffer_size); - char *buffer_tail = buffer; + PRInt32 buffer_size = 2048 + (base_url ? 2*PL_strlen(base_url) : 0); + char *buffer = (char *) PR_Malloc (buffer_size); + char *buffer_tail = buffer; - if (! buffer) - return 0; /* NS_ERROR_OUT_OF_MEMORY */ + if (! buffer) + return 0; /* NS_ERROR_OUT_OF_MEMORY */ - NS_ASSERTION (encoding, "null encoding"); + NS_ASSERTION (encoding, "null encoding"); - PUSH_STRING ("Content-Type: "); - PUSH_STRING (type); + PRInt32 parmFolding = 0; + if (NS_SUCCEEDED(rv) && prefs) + prefs->GetIntPref("mail.strictly_mime.parm_folding", &parmFolding); + + /* Let's encode the real name */ + char *encodedRealName = nsnull; + if (real_name) + { + encodedRealName = nsMsgI18NEncodeMimePartIIStr(real_name, + NS_ConvertUCS2toUTF8(nsMsgI18NFileSystemCharset()).get(), nsMsgMIMEGetConformToStandard()); + if (!encodedRealName || !*encodedRealName) + { + /* Let's try one more time using UTF8 */ + encodedRealName = nsMsgI18NEncodeMimePartIIStr(real_name, "UTF-8", nsMsgMIMEGetConformToStandard()); + if (!encodedRealName || !*encodedRealName) + { + PR_FREEIF(encodedRealName); + encodedRealName = PL_strdup(real_name); + } + } + + /* ... and then put backslashes before special characters (RFC 822 tells us to). */ + char *qtextName = msg_make_filename_qtext(encodedRealName, (parmFolding == 0 ? PR_TRUE : PR_FALSE)); + if (qtextName) + { + PR_FREEIF(encodedRealName); + encodedRealName = qtextName; + } + } + + PUSH_STRING ("Content-Type: "); + PUSH_STRING (type); if (mime_type_needs_charset (type)) { @@ -855,68 +885,64 @@ mime_generate_attachment_headers (const char *type, const char *encoding, if(type && !PL_strcasecmp(type, "text/plain")) { if(UseFormatFlowed(charset)) - PUSH_STRING ("; format=flowed"); - // else + PUSH_STRING ("; format=flowed"); + // else // { // Don't add a markup. Could use - // PUSH_STRING ("; format=fixed"); + // PUSH_STRING ("; format=fixed"); // but it is equivalent to nothing at all and we do want // to save bandwidth. Don't we? // } } } - if (x_mac_type && *x_mac_type) { - PUSH_STRING ("; x-mac-type=\""); - PUSH_STRING (x_mac_type); - PUSH_STRING ("\""); - } + if (x_mac_type && *x_mac_type) { + PUSH_STRING ("; x-mac-type=\""); + PUSH_STRING (x_mac_type); + PUSH_STRING ("\""); + } - if (x_mac_creator && *x_mac_creator) { - PUSH_STRING ("; x-mac-creator=\""); - PUSH_STRING (x_mac_creator); - PUSH_STRING ("\""); - } - - PRInt32 parmFolding = 0; - if (NS_SUCCEEDED(rv) && prefs) - prefs->GetIntPref("mail.strictly_mime.parm_folding", &parmFolding); + if (x_mac_creator && *x_mac_creator) { + PUSH_STRING ("; x-mac-creator=\""); + PUSH_STRING (x_mac_creator); + PUSH_STRING ("\""); + } #ifdef EMIT_NAME_IN_CONTENT_TYPE - if (real_name && *real_name) { - if (parmFolding == 0 || parmFolding == 1) { - PUSH_STRING (";\r\n name=\""); - PUSH_STRING (real_name); - PUSH_STRING ("\""); - } - else // if (parmFolding == 2) - { - char *rfc2231Parm = RFC2231ParmFolding("name", charset, - nsMsgI18NGetAcceptLanguage(), real_name); - if (rfc2231Parm) { - PUSH_STRING(";\r\n "); - PUSH_STRING(rfc2231Parm); - PR_Free(rfc2231Parm); - } - } - } + if (encodedRealName && *encodedRealName) { + if (parmFolding == 0 || parmFolding == 1) { + PUSH_STRING (";\r\n name=\""); + PUSH_STRING (encodedRealName); + PUSH_STRING ("\""); + } + else // if (parmFolding == 2) + { + char *rfc2231Parm = RFC2231ParmFolding("name", charset, + nsMsgI18NGetAcceptLanguage(), encodedRealName); + if (rfc2231Parm) { + PUSH_STRING(";\r\n "); + PUSH_STRING(rfc2231Parm); + PR_Free(rfc2231Parm); + } + } + } #endif /* EMIT_NAME_IN_CONTENT_TYPE */ - PUSH_NEWLINE (); + PUSH_NEWLINE (); - PUSH_STRING ("Content-Transfer-Encoding: "); - PUSH_STRING (encoding); - PUSH_NEWLINE (); + PUSH_STRING ("Content-Transfer-Encoding: "); + PUSH_STRING (encoding); + PUSH_NEWLINE (); - if (description && *description) { - char *s = mime_fix_header (description); - if (s) { - PUSH_STRING ("Content-Description: "); - PUSH_STRING (s); - PUSH_NEWLINE (); - PR_Free(s); - } - } + if (description && *description) { + char *s = mime_fix_header (description); + if (s) { + PUSH_STRING ("Content-Description: "); + PUSH_STRING (s); + PUSH_NEWLINE (); + PR_Free(s); + } + } if ( (content_id) && (*content_id) ) { @@ -926,340 +952,341 @@ mime_generate_attachment_headers (const char *type, const char *encoding, PUSH_NEWLINE (); } - if (real_name && *real_name) { - char *period = PL_strrchr(real_name, '.'); - PRInt32 pref_content_disposition = 0; + if (encodedRealName && *encodedRealName) { + char *period = PL_strrchr(encodedRealName, '.'); + PRInt32 pref_content_disposition = 0; rv = prefs->GetIntPref("mail.content_disposition_type", &pref_content_disposition); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get mail.content_disposition_type"); - PUSH_STRING ("Content-Disposition: "); + PUSH_STRING ("Content-Disposition: "); - if (pref_content_disposition == 1) - PUSH_STRING ("attachment"); - else - if (pref_content_disposition == 2 && - (!PL_strcasecmp(type, TEXT_PLAIN) || - (period && !PL_strcasecmp(period, ".txt")))) - PUSH_STRING("attachment"); + if (pref_content_disposition == 1) + PUSH_STRING ("attachment"); + else + if (pref_content_disposition == 2 && + (!PL_strcasecmp(type, TEXT_PLAIN) || + (period && !PL_strcasecmp(period, ".txt")))) + PUSH_STRING("attachment"); - /* If this document is an anonymous binary file or a vcard, - then always show it as an attachment, never inline. */ - else - if (!PL_strcasecmp(type, APPLICATION_OCTET_STREAM) || - !PL_strcasecmp(type, TEXT_VCARD) || - !PL_strcasecmp(type, APPLICATION_DIRECTORY)) /* text/x-vcard synonym */ - PUSH_STRING ("attachment"); - else - PUSH_STRING ("inline"); + /* If this document is an anonymous binary file or a vcard, + then always show it as an attachment, never inline. */ + else + if (!PL_strcasecmp(type, APPLICATION_OCTET_STREAM) || + !PL_strcasecmp(type, TEXT_VCARD) || + !PL_strcasecmp(type, APPLICATION_DIRECTORY)) /* text/x-vcard synonym */ + PUSH_STRING ("attachment"); + else + PUSH_STRING ("inline"); - if (parmFolding == 0 || parmFolding == 1) { - PUSH_STRING (";\r\n filename=\""); - PUSH_STRING (real_name); - PUSH_STRING ("\"" CRLF); - } - else // if (parmFolding == 2) - { - char *rfc2231Parm = RFC2231ParmFolding("filename", charset, - nsMsgI18NGetAcceptLanguage(), real_name); - if (rfc2231Parm) { - PUSH_STRING(";\r\n "); - PUSH_STRING(rfc2231Parm); - PUSH_NEWLINE (); - PR_Free(rfc2231Parm); - } - } - } - else - if (type && - (!PL_strcasecmp (type, MESSAGE_RFC822) || - !PL_strcasecmp (type, MESSAGE_NEWS))) - PUSH_STRING ("Content-Disposition: inline" CRLF); + if (parmFolding == 0 || parmFolding == 1) { + PUSH_STRING (";\r\n filename=\""); + PUSH_STRING (encodedRealName); + PUSH_STRING ("\"" CRLF); + } + else // if (parmFolding == 2) + { + char *rfc2231Parm = RFC2231ParmFolding("filename", charset, + nsMsgI18NGetAcceptLanguage(), encodedRealName); + if (rfc2231Parm) { + PUSH_STRING(";\r\n "); + PUSH_STRING(rfc2231Parm); + PUSH_NEWLINE (); + PR_Free(rfc2231Parm); + } + } + } + else + if (type && + (!PL_strcasecmp (type, MESSAGE_RFC822) || + !PL_strcasecmp (type, MESSAGE_NEWS))) + PUSH_STRING ("Content-Disposition: inline" CRLF); #ifdef GENERATE_CONTENT_BASE - /* If this is an HTML document, and we know the URL it originally - came from, write out a Content-Base header. */ - if (type && - (!PL_strcasecmp (type, TEXT_HTML) || - !PL_strcasecmp (type, TEXT_MDL)) && - base_url && *base_url) - { - PRInt32 col = 0; - const char *s = base_url; - const char *colon = PL_strchr (s, ':'); - PRBool useContentLocation = PR_FALSE; /* rhp - add this */ + /* If this is an HTML document, and we know the URL it originally + came from, write out a Content-Base header. */ + if (type && + (!PL_strcasecmp (type, TEXT_HTML) || + !PL_strcasecmp (type, TEXT_MDL)) && + base_url && *base_url) + { + PRInt32 col = 0; + const char *s = base_url; + const char *colon = PL_strchr (s, ':'); + PRBool useContentLocation = PR_FALSE; /* rhp - add this */ - if (!colon) - goto GIVE_UP_ON_CONTENT_BASE; /* malformed URL? */ + if (!colon) + goto GIVE_UP_ON_CONTENT_BASE; /* malformed URL? */ - /* Don't emit a content-base that points to (or into) a news or - mail message. */ - if (!PL_strncasecmp (s, "news:", 5) || - !PL_strncasecmp (s, "snews:", 6) || - !PL_strncasecmp (s, "IMAP:", 5) || - !PL_strncasecmp (s, "file:", 5) || /* rhp: fix targets from included HTML files */ - !PL_strncasecmp (s, "mailbox:", 8)) - goto GIVE_UP_ON_CONTENT_BASE; + /* Don't emit a content-base that points to (or into) a news or + mail message. */ + if (!PL_strncasecmp (s, "news:", 5) || + !PL_strncasecmp (s, "snews:", 6) || + !PL_strncasecmp (s, "IMAP:", 5) || + !PL_strncasecmp (s, "file:", 5) || /* rhp: fix targets from included HTML files */ + !PL_strncasecmp (s, "mailbox:", 8)) + goto GIVE_UP_ON_CONTENT_BASE; - /* rhp - Put in a pref for using Content-Location instead of Content-Base. - This will get tweaked to default to true in 5.0 - */ + /* rhp - Put in a pref for using Content-Location instead of Content-Base. + This will get tweaked to default to true in 5.0 + */ if (NS_SUCCEEDED(rv) && prefs) prefs->GetBoolPref("mail.use_content_location_on_send", &useContentLocation); - if (useContentLocation) - PUSH_STRING ("Content-Location: \""); - else - PUSH_STRING ("Content-Base: \""); - /* rhp - Pref for Content-Location usage */ + if (useContentLocation) + PUSH_STRING ("Content-Location: \""); + else + PUSH_STRING ("Content-Base: \""); + /* rhp - Pref for Content-Location usage */ /* rhp: this is to work with the Content-Location stuff */ CONTENT_LOC_HACK: - while (*s != 0 && *s != '#') - { - const char *ot = buffer_tail; + while (*s != 0 && *s != '#') + { + const char *ot = buffer_tail; - /* URLs must be wrapped at 40 characters or less. */ - if (col >= 38) { - PUSH_STRING(CRLF "\t"); - col = 0; - } + /* URLs must be wrapped at 40 characters or less. */ + if (col >= 38) { + PUSH_STRING(CRLF "\t"); + col = 0; + } - if (*s == ' ') - PUSH_STRING("%20"); - else if (*s == '\t') - PUSH_STRING("%09"); - else if (*s == '\n') - PUSH_STRING("%0A"); - else if (*s == '\r') - PUSH_STRING("%0D"); - else { - *buffer_tail++ = *s; - *buffer_tail = '\0'; - } - s++; - col += (buffer_tail - ot); - } - PUSH_STRING ("\"" CRLF); + if (*s == ' ') + PUSH_STRING("%20"); + else if (*s == '\t') + PUSH_STRING("%09"); + else if (*s == '\n') + PUSH_STRING("%0A"); + else if (*s == '\r') + PUSH_STRING("%0D"); + else { + *buffer_tail++ = *s; + *buffer_tail = '\0'; + } + s++; + col += (buffer_tail - ot); + } + PUSH_STRING ("\"" CRLF); - /* rhp: this is to try to get around this fun problem with Content-Location */ - if (!useContentLocation) { - PUSH_STRING ("Content-Location: \""); - s = base_url; - col = 0; - useContentLocation = PR_TRUE; - goto CONTENT_LOC_HACK; - } - /* rhp: this is to try to get around this fun problem with Content-Location */ + /* rhp: this is to try to get around this fun problem with Content-Location */ + if (!useContentLocation) { + PUSH_STRING ("Content-Location: \""); + s = base_url; + col = 0; + useContentLocation = PR_TRUE; + goto CONTENT_LOC_HACK; + } + /* rhp: this is to try to get around this fun problem with Content-Location */ GIVE_UP_ON_CONTENT_BASE: - ; - } + ; + } #endif /* GENERATE_CONTENT_BASE */ - /* realloc it smaller... */ - buffer = (char*) PR_REALLOC (buffer, buffer_tail - buffer + 1); + /* realloc it smaller... */ + buffer = (char*) PR_REALLOC (buffer, buffer_tail - buffer + 1); - return buffer; + PR_FREEIF(encodedRealName); + return buffer; } char * msg_generate_message_id (nsIMsgIdentity *identity) { - PRUint32 now; - PRTime prNow = PR_Now(); - PRInt64 microSecondsPerSecond, intermediateResult; - - LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); - LL_DIV(intermediateResult, prNow, microSecondsPerSecond); + PRUint32 now; + PRTime prNow = PR_Now(); + PRInt64 microSecondsPerSecond, intermediateResult; + + LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); + LL_DIV(intermediateResult, prNow, microSecondsPerSecond); LL_L2UI(now, intermediateResult); - PRUint32 salt = 0; - const char *host = 0; + PRUint32 salt = 0; + const char *host = 0; - nsXPIDLCString from; + nsXPIDLCString from; nsresult rv = identity->GetEmail(getter_Copies(from)); if (NS_FAILED(rv)) return nsnull; - GenerateGlobalRandomBytes((unsigned char *) &salt, sizeof(salt)); - if (from) { - host = PL_strchr (from, '@'); - if (host) { - const char *s; - for (s = ++host; *s; s++) + GenerateGlobalRandomBytes((unsigned char *) &salt, sizeof(salt)); + if (from) { + host = PL_strchr (from, '@'); + if (host) { + const char *s; + for (s = ++host; *s; s++) if (!nsCRT::IsAsciiAlpha(*s) && !nsCRT::IsAsciiDigit(*s) && - *s != '-' && *s != '_' && *s != '.') { - host = 0; - break; - } - } - } + *s != '-' && *s != '_' && *s != '.') { + host = 0; + break; + } + } + } - if (! host) - /* If we couldn't find a valid host name to use, we can't generate a - valid message ID, so bail, and let NNTP and SMTP generate them. */ - return 0; + if (! host) + /* If we couldn't find a valid host name to use, we can't generate a + valid message ID, so bail, and let NNTP and SMTP generate them. */ + return 0; - return PR_smprintf("<%lX.%lX@%s>", - (unsigned long) now, (unsigned long) salt, host); + return PR_smprintf("<%lX.%lX@%s>", + (unsigned long) now, (unsigned long) salt, host); } char * RFC2231ParmFolding(const char *parmName, const char *charset, - const char *language, const char *parmValue) + const char *language, const char *parmValue) { -#define PR_MAX_FOLDING_LEN 75 // this is to gurantee the folded line will - // never be greater than 78 = 75 + CRLFLWSP - char *foldedParm = NULL; - char *dupParm = NULL; - PRInt32 parmNameLen = 0; - PRInt32 parmValueLen = 0; - PRInt32 charsetLen = 0; - PRInt32 languageLen = 0; - PRBool needEscape = PR_FALSE; +#define PR_MAX_FOLDING_LEN 75 // this is to gurantee the folded line will + // never be greater than 78 = 75 + CRLFLWSP + char *foldedParm = NULL; + char *dupParm = NULL; + PRInt32 parmNameLen = 0; + PRInt32 parmValueLen = 0; + PRInt32 charsetLen = 0; + PRInt32 languageLen = 0; + PRBool needEscape = PR_FALSE; - NS_ASSERTION(parmName && *parmName && parmValue && *parmValue, "null parameters"); - if (!parmName || !*parmName || !parmValue || !*parmValue) - return NULL; - if ((charset && *charset && PL_strcasecmp(charset, "us-ascii") != 0) || - (language && *language && PL_strcasecmp(language, "en") != 0 && - PL_strcasecmp(language, "en-us") != 0)) - needEscape = PR_TRUE; + NS_ASSERTION(parmName && *parmName && parmValue && *parmValue, "null parameters"); + if (!parmName || !*parmName || !parmValue || !*parmValue) + return NULL; + if ((charset && *charset && PL_strcasecmp(charset, "us-ascii") != 0) || + (language && *language && PL_strcasecmp(language, "en") != 0 && + PL_strcasecmp(language, "en-us") != 0)) + needEscape = PR_TRUE; - if (needEscape) - dupParm = nsEscape(parmValue, url_Path); - else - dupParm = nsCRT::strdup(parmValue); + if (needEscape) + dupParm = nsEscape(parmValue, url_Path); + else + dupParm = nsCRT::strdup(parmValue); - if (!dupParm) - return NULL; + if (!dupParm) + return NULL; - if (needEscape) - { - parmValueLen = PL_strlen(dupParm); - parmNameLen = PL_strlen(parmName); - } + if (needEscape) + { + parmValueLen = PL_strlen(dupParm); + parmNameLen = PL_strlen(parmName); + } - if (needEscape) - parmNameLen += 5; // *=__'__'___ or *[0]*=__'__'__ or *[1]*=___ - else - parmNameLen += 5; // *[0]="___"; - charsetLen = charset ? PL_strlen(charset) : 0; - languageLen = language ? PL_strlen(language) : 0; + if (needEscape) + parmNameLen += 5; // *=__'__'___ or *[0]*=__'__'__ or *[1]*=___ + else + parmNameLen += 5; // *[0]="___"; + charsetLen = charset ? PL_strlen(charset) : 0; + languageLen = language ? PL_strlen(language) : 0; - if ((parmValueLen + parmNameLen + charsetLen + languageLen) < - PR_MAX_FOLDING_LEN) - { - foldedParm = PL_strdup(parmName); - if (needEscape) - { - NS_MsgSACat(&foldedParm, "*="); - if (charsetLen) - NS_MsgSACat(&foldedParm, charset); - NS_MsgSACat(&foldedParm, "'"); - if (languageLen) - NS_MsgSACat(&foldedParm, language); - NS_MsgSACat(&foldedParm, "'"); - } - else - NS_MsgSACat(&foldedParm, "=\""); - NS_MsgSACat(&foldedParm, dupParm); - if (!needEscape) - NS_MsgSACat(&foldedParm, "\""); - goto done; - } - else - { - int curLineLen = 0; - int counter = 0; - char digits[32]; - char *start = dupParm; - char *end = NULL; - char tmp = 0; + if ((parmValueLen + parmNameLen + charsetLen + languageLen) < + PR_MAX_FOLDING_LEN) + { + foldedParm = PL_strdup(parmName); + if (needEscape) + { + NS_MsgSACat(&foldedParm, "*="); + if (charsetLen) + NS_MsgSACat(&foldedParm, charset); + NS_MsgSACat(&foldedParm, "'"); + if (languageLen) + NS_MsgSACat(&foldedParm, language); + NS_MsgSACat(&foldedParm, "'"); + } + else + NS_MsgSACat(&foldedParm, "=\""); + NS_MsgSACat(&foldedParm, dupParm); + if (!needEscape) + NS_MsgSACat(&foldedParm, "\""); + goto done; + } + else + { + int curLineLen = 0; + int counter = 0; + char digits[32]; + char *start = dupParm; + char *end = NULL; + char tmp = 0; - while (parmValueLen > 0) - { - curLineLen = 0; - if (counter == 0) { - PR_FREEIF(foldedParm) - foldedParm = PL_strdup(parmName); - } - else { - if (needEscape) - NS_MsgSACat(&foldedParm, "\r\n "); - else - NS_MsgSACat(&foldedParm, ";\r\n "); - NS_MsgSACat(&foldedParm, parmName); - } - PR_snprintf(digits, sizeof(digits), "*%d", counter); - NS_MsgSACat(&foldedParm, digits); - curLineLen += PL_strlen(digits); - if (needEscape) - { - NS_MsgSACat(&foldedParm, "*="); - if (counter == 0) - { - if (charsetLen) - NS_MsgSACat(&foldedParm, charset); - NS_MsgSACat(&foldedParm, "'"); - if (languageLen) - NS_MsgSACat(&foldedParm, language); - NS_MsgSACat(&foldedParm, "'"); - curLineLen += charsetLen; - curLineLen += languageLen; - } - } - else - { - NS_MsgSACat(&foldedParm, "=\""); - } - counter++; - curLineLen += parmNameLen; - if (parmValueLen <= PR_MAX_FOLDING_LEN - curLineLen) - end = start + parmValueLen; - else - end = start + (PR_MAX_FOLDING_LEN - curLineLen); + while (parmValueLen > 0) + { + curLineLen = 0; + if (counter == 0) { + PR_FREEIF(foldedParm) + foldedParm = PL_strdup(parmName); + } + else { + if (needEscape) + NS_MsgSACat(&foldedParm, "\r\n "); + else + NS_MsgSACat(&foldedParm, ";\r\n "); + NS_MsgSACat(&foldedParm, parmName); + } + PR_snprintf(digits, sizeof(digits), "*%d", counter); + NS_MsgSACat(&foldedParm, digits); + curLineLen += PL_strlen(digits); + if (needEscape) + { + NS_MsgSACat(&foldedParm, "*="); + if (counter == 0) + { + if (charsetLen) + NS_MsgSACat(&foldedParm, charset); + NS_MsgSACat(&foldedParm, "'"); + if (languageLen) + NS_MsgSACat(&foldedParm, language); + NS_MsgSACat(&foldedParm, "'"); + curLineLen += charsetLen; + curLineLen += languageLen; + } + } + else + { + NS_MsgSACat(&foldedParm, "=\""); + } + counter++; + curLineLen += parmNameLen; + if (parmValueLen <= PR_MAX_FOLDING_LEN - curLineLen) + end = start + parmValueLen; + else + end = start + (PR_MAX_FOLDING_LEN - curLineLen); - tmp = 0; - if (*end && needEscape) - { - // check to see if we are in the middle of escaped char - if (*end == '%') - { - tmp = '%'; *end = nsnull; - } - else if (end-1 > start && *(end-1) == '%') - { - end -= 1; tmp = '%'; *end = nsnull; - } - else if (end-2 > start && *(end-2) == '%') - { - end -= 2; tmp = '%'; *end = nsnull; - } - else - { - tmp = *end; *end = nsnull; - } - } - else - { - tmp = *end; *end = nsnull; - } - NS_MsgSACat(&foldedParm, start); - if (!needEscape) - NS_MsgSACat(&foldedParm, "\""); + tmp = 0; + if (*end && needEscape) + { + // check to see if we are in the middle of escaped char + if (*end == '%') + { + tmp = '%'; *end = nsnull; + } + else if (end-1 > start && *(end-1) == '%') + { + end -= 1; tmp = '%'; *end = nsnull; + } + else if (end-2 > start && *(end-2) == '%') + { + end -= 2; tmp = '%'; *end = nsnull; + } + else + { + tmp = *end; *end = nsnull; + } + } + else + { + tmp = *end; *end = nsnull; + } + NS_MsgSACat(&foldedParm, start); + if (!needEscape) + NS_MsgSACat(&foldedParm, "\""); - parmValueLen -= (end-start); - if (tmp) - *end = tmp; - start = end; - } - } + parmValueLen -= (end-start); + if (tmp) + *end = tmp; + start = end; + } + } done: - nsCRT::free(dupParm); - return foldedParm; + nsCRT::free(dupParm); + return foldedParm; } PRBool @@ -1274,7 +1301,7 @@ mime_7bit_data_p (const char *string, PRUint32 size) if ((unsigned char) ptr[i] > 0x7F) return PR_FALSE; } - return PR_TRUE; + return PR_TRUE; } /* Strips whitespace, and expands newlines into newline-tab for use in @@ -1285,74 +1312,74 @@ mime_7bit_data_p (const char *string, PRUint32 size) char * mime_fix_header_1 (const char *string, PRBool addr_p, PRBool news_p) { - char *new_string; - const char *in; - char *out; - PRInt32 i, old_size, new_size; + char *new_string; + const char *in; + char *out; + PRInt32 i, old_size, new_size; - if (!string || !*string) - return 0; + if (!string || !*string) + return 0; - if (addr_p) { + if (addr_p) { nsresult rv = NS_OK; - nsCOMPtr pHeader = do_GetService(kMsgHeaderParserCID, &rv); - if (NS_SUCCEEDED(rv)) { - char *n; - pHeader->ReformatHeaderAddresses(nsnull, string, &n); - if (n) return n; - } - } + nsCOMPtr pHeader = do_GetService(kMsgHeaderParserCID, &rv); + if (NS_SUCCEEDED(rv)) { + char *n; + pHeader->ReformatHeaderAddresses(nsnull, string, &n); + if (n) return n; + } + } - old_size = PL_strlen (string); - new_size = old_size; - for (i = 0; i < old_size; i++) - if (string[i] == nsCRT::CR || string[i] == nsCRT::LF) - new_size += 2; + old_size = PL_strlen (string); + new_size = old_size; + for (i = 0; i < old_size; i++) + if (string[i] == nsCRT::CR || string[i] == nsCRT::LF) + new_size += 2; - new_string = (char *) PR_Malloc (new_size + 1); - if (! new_string) - return 0; + new_string = (char *) PR_Malloc (new_size + 1); + if (! new_string) + return 0; - in = string; - out = new_string; + in = string; + out = new_string; - /* strip leading whitespace. */ - while (IS_SPACE (*in)) - in++; + /* strip leading whitespace. */ + while (IS_SPACE (*in)) + in++; - /* replace CR, LF, or CRLF with CRLF-TAB. */ - while (*in) { - if (*in == nsCRT::CR || *in == nsCRT::LF) { - if (*in == nsCRT::CR && in[1] == nsCRT::LF) - in++; - in++; - *out++ = nsCRT::CR; - *out++ = nsCRT::LF; - *out++ = '\t'; - } - else - if (news_p && *in == ',') { - *out++ = *in++; - /* skip over all whitespace after a comma. */ - while (IS_SPACE (*in)) - in++; - } - else - *out++ = *in++; - } - *out = 0; + /* replace CR, LF, or CRLF with CRLF-TAB. */ + while (*in) { + if (*in == nsCRT::CR || *in == nsCRT::LF) { + if (*in == nsCRT::CR && in[1] == nsCRT::LF) + in++; + in++; + *out++ = nsCRT::CR; + *out++ = nsCRT::LF; + *out++ = '\t'; + } + else + if (news_p && *in == ',') { + *out++ = *in++; + /* skip over all whitespace after a comma. */ + while (IS_SPACE (*in)) + in++; + } + else + *out++ = *in++; + } + *out = 0; - /* strip trailing whitespace. */ - while (out > in && IS_SPACE (out[-1])) - *out-- = 0; + /* strip trailing whitespace. */ + while (out > in && IS_SPACE (out[-1])) + *out-- = 0; - /* If we ended up throwing it all away, use 0 instead of "". */ - if (!*new_string) { - PR_Free (new_string); - new_string = 0; - } + /* If we ended up throwing it all away, use 0 instead of "". */ + if (!*new_string) { + PR_Free (new_string); + new_string = 0; + } - return new_string; + return new_string; } char * @@ -1377,85 +1404,85 @@ PRBool mime_type_requires_b64_p (const char *type) { if (!type || !PL_strcasecmp (type, UNKNOWN_CONTENT_TYPE)) - /* Unknown types don't necessarily require encoding. (Note that - "unknown" and "application/octet-stream" aren't the same.) */ - return PR_FALSE; + /* Unknown types don't necessarily require encoding. (Note that + "unknown" and "application/octet-stream" aren't the same.) */ + return PR_FALSE; else if (!PL_strncasecmp (type, "image/", 6) || - !PL_strncasecmp (type, "audio/", 6) || - !PL_strncasecmp (type, "video/", 6) || - !PL_strncasecmp (type, "application/", 12)) - { - /* The following types are application/ or image/ types that are actually - known to contain textual data (meaning line-based, not binary, where - CRLF conversion is desired rather than disasterous.) So, if the type - is any of these, it does not *require* base64, and if we do need to - encode it for other reasons, we'll probably use quoted-printable. - But, if it's not one of these types, then we assume that any subtypes - of the non-"text/" types are binary data, where CRLF conversion would - corrupt it, so we use base64 right off the bat. + !PL_strncasecmp (type, "audio/", 6) || + !PL_strncasecmp (type, "video/", 6) || + !PL_strncasecmp (type, "application/", 12)) + { + /* The following types are application/ or image/ types that are actually + known to contain textual data (meaning line-based, not binary, where + CRLF conversion is desired rather than disasterous.) So, if the type + is any of these, it does not *require* base64, and if we do need to + encode it for other reasons, we'll probably use quoted-printable. + But, if it's not one of these types, then we assume that any subtypes + of the non-"text/" types are binary data, where CRLF conversion would + corrupt it, so we use base64 right off the bat. - The reason it's desirable to ship these as text instead of just using - base64 all the time is mainly to preserve the readability of them for - non-MIME users: if I mail a /bin/sh script to someone, it might not - need to be encoded at all, so we should leave it readable if we can. + The reason it's desirable to ship these as text instead of just using + base64 all the time is mainly to preserve the readability of them for + non-MIME users: if I mail a /bin/sh script to someone, it might not + need to be encoded at all, so we should leave it readable if we can. - This list of types was derived from the comp.mail.mime FAQ, section - 10.2.2, "List of known unregistered MIME types" on 2-Feb-96. - */ - static const char *app_and_image_types_which_are_really_text[] = { - "application/mac-binhex40", /* APPLICATION_BINHEX */ - "application/pgp", /* APPLICATION_PGP */ - "application/x-pgp-message", /* APPLICATION_PGP2 */ - "application/postscript", /* APPLICATION_POSTSCRIPT */ - "application/x-uuencode", /* APPLICATION_UUENCODE */ - "application/x-uue", /* APPLICATION_UUENCODE2 */ - "application/uue", /* APPLICATION_UUENCODE4 */ - "application/uuencode", /* APPLICATION_UUENCODE3 */ - "application/sgml", - "application/x-csh", - "application/x-javascript", - "application/x-latex", - "application/x-macbinhex40", - "application/x-ns-proxy-autoconfig", - "application/x-www-form-urlencoded", - "application/x-perl", - "application/x-sh", - "application/x-shar", - "application/x-tcl", - "application/x-tex", - "application/x-texinfo", - "application/x-troff", - "application/x-troff-man", - "application/x-troff-me", - "application/x-troff-ms", - "application/x-troff-ms", - "application/x-wais-source", - "image/x-bitmap", - "image/x-pbm", - "image/x-pgm", - "image/x-portable-anymap", - "image/x-portable-bitmap", - "image/x-portable-graymap", - "image/x-portable-pixmap", /* IMAGE_PPM */ - "image/x-ppm", - "image/x-xbitmap", /* IMAGE_XBM */ - "image/x-xbm", /* IMAGE_XBM2 */ - "image/xbm", /* IMAGE_XBM3 */ - "image/x-xpixmap", - "image/x-xpm", - 0 }; - const char **s; - for (s = app_and_image_types_which_are_really_text; *s; s++) - if (!PL_strcasecmp (type, *s)) - return PR_FALSE; + This list of types was derived from the comp.mail.mime FAQ, section + 10.2.2, "List of known unregistered MIME types" on 2-Feb-96. + */ + static const char *app_and_image_types_which_are_really_text[] = { + "application/mac-binhex40", /* APPLICATION_BINHEX */ + "application/pgp", /* APPLICATION_PGP */ + "application/x-pgp-message", /* APPLICATION_PGP2 */ + "application/postscript", /* APPLICATION_POSTSCRIPT */ + "application/x-uuencode", /* APPLICATION_UUENCODE */ + "application/x-uue", /* APPLICATION_UUENCODE2 */ + "application/uue", /* APPLICATION_UUENCODE4 */ + "application/uuencode", /* APPLICATION_UUENCODE3 */ + "application/sgml", + "application/x-csh", + "application/x-javascript", + "application/x-latex", + "application/x-macbinhex40", + "application/x-ns-proxy-autoconfig", + "application/x-www-form-urlencoded", + "application/x-perl", + "application/x-sh", + "application/x-shar", + "application/x-tcl", + "application/x-tex", + "application/x-texinfo", + "application/x-troff", + "application/x-troff-man", + "application/x-troff-me", + "application/x-troff-ms", + "application/x-troff-ms", + "application/x-wais-source", + "image/x-bitmap", + "image/x-pbm", + "image/x-pgm", + "image/x-portable-anymap", + "image/x-portable-bitmap", + "image/x-portable-graymap", + "image/x-portable-pixmap", /* IMAGE_PPM */ + "image/x-ppm", + "image/x-xbitmap", /* IMAGE_XBM */ + "image/x-xbm", /* IMAGE_XBM2 */ + "image/xbm", /* IMAGE_XBM3 */ + "image/x-xpixmap", + "image/x-xpm", + 0 }; + const char **s; + for (s = app_and_image_types_which_are_really_text; *s; s++) + if (!PL_strcasecmp (type, *s)) + return PR_FALSE; - /* All others must be assumed to be binary formats, and need Base64. */ - return PR_TRUE; - } + /* All others must be assumed to be binary formats, and need Base64. */ + return PR_TRUE; + } else - return PR_FALSE; + return PR_FALSE; } // @@ -1465,86 +1492,91 @@ mime_type_requires_b64_p (const char *type) PRBool mime_type_needs_charset (const char *type) { - /* Only text types should have charset. */ - if (!type || !*type) - return PR_FALSE; - else - if (!PL_strncasecmp (type, "text", 4)) - return PR_TRUE; - else - return PR_FALSE; + /* Only text types should have charset. */ + if (!type || !*type) + return PR_FALSE; + else + if (!PL_strncasecmp (type, "text", 4)) + return PR_TRUE; + else + return PR_FALSE; } /* Given a string, convert it to 'qtext' (quoted text) for RFC822 header purposes. */ char * msg_make_filename_qtext(const char *srcText, PRBool stripCRLFs) { - /* newString can be at most twice the original string (every char quoted). */ - char *newString = (char *) PR_Malloc(PL_strlen(srcText)*2 + 1); - if (!newString) return NULL; + /* newString can be at most twice the original string (every char quoted). */ + char *newString = (char *) PR_Malloc(PL_strlen(srcText)*2 + 1); + if (!newString) return NULL; - const char *s = srcText; - const char *end = srcText + PL_strlen(srcText); - char *d = newString; + const char *s = srcText; + const char *end = srcText + PL_strlen(srcText); + char *d = newString; - while(*s) - { - /* Put backslashes in front of existing backslashes, or double quote - characters. - If stripCRLFs is true, don't write out CRs or LFs. Otherwise, - write out a backslash followed by the CR but not - linear-white-space. - We might already have quoted pair of "\ " or "\\t" skip it. - */ - if (*s == '\\' || *s == '"' || - (!stripCRLFs && - (*s == nsCRT::CR && (*(s+1) != nsCRT::LF || - (*(s+1) == nsCRT::LF && (s+2) < end && !IS_SPACE(*(s+2))))))) - *d++ = '\\'; + while(*s) + { + /* Put backslashes in front of existing backslashes, or double quote + characters. + If stripCRLFs is true, don't write out CRs or LFs. Otherwise, + write out a backslash followed by the CR but not + linear-white-space. + We might already have quoted pair of "\ " or "\\t" skip it. + */ + if (*s == '\\' || *s == '"' || + (!stripCRLFs && + (*s == nsCRT::CR && (*(s+1) != nsCRT::LF || + (*(s+1) == nsCRT::LF && (s+2) < end && !IS_SPACE(*(s+2))))))) + *d++ = '\\'; - if (*s == nsCRT::CR) - { - if (stripCRLFs && *(s+1) == nsCRT::LF && (s+2) < end && IS_SPACE(*(s+2))) - s += 2; // skip CRLFLWSP - } - else - { - *d++ = *s; - } - s++; - } - *d = 0; + if (*s == nsCRT::CR) + { + if (stripCRLFs && *(s+1) == nsCRT::LF && (s+2) < end && IS_SPACE(*(s+2))) + s += 2; // skip CRLFLWSP + } + else + { + *d++ = *s; + } + s++; + } + *d = 0; - return newString; + return newString; } /* Rip apart the URL and extract a reasonable value for the `real_name' slot. */ void -msg_pick_real_name (nsMsgAttachmentHandler *attachment, const char *charset) +msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *proposedName, const char *charset) { nsresult rv; nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); const char *s, *s2; char *s3; - nsXPIDLCString url; if ( (attachment->m_real_name) && (*attachment->m_real_name)) - return; + return; + if (proposedName && *proposedName) + { + attachment->m_real_name = ToNewUTF8String(nsAutoString(proposedName)); + } + else //Let's extract the name from the URL + { + nsXPIDLCString url; attachment->mURL->GetSpec(getter_Copies(url)); - // Otherwise, extract a name from the URL. s = url; s2 = PL_strchr (s, ':'); if (s2) s = s2 + 1; /* If we know the URL doesn't have a sensible file name in it, - don't bother emitting a content-disposition. */ + don't bother emitting a content-disposition. */ if (!PL_strncasecmp (url, "news:", 5) || - !PL_strncasecmp (url, "snews:", 6) || - !PL_strncasecmp (url, "IMAP:", 5) || - !PL_strncasecmp (url, "mailbox:", 8)) - return; + !PL_strncasecmp (url, "snews:", 6) || + !PL_strncasecmp (url, "IMAP:", 5) || + !PL_strncasecmp (url, "mailbox:", 8)) + return; /* Take the part of the file name after the last / or \ */ s2 = PL_strrchr (s, '/'); @@ -1563,12 +1595,14 @@ msg_pick_real_name (nsMsgAttachmentHandler *attachment, const char *charset) /* Now lose the %XX crap. */ nsUnescape (attachment->m_real_name); + } PRInt32 parmFolding = 0; if (NS_SUCCEEDED(rv) && prefs) prefs->GetIntPref("mail.strictly_mime.parm_folding", &parmFolding); if (parmFolding == 0 || parmFolding == 1) + if (!proposedName || !(*proposedName)) { /* Convert to unicode */ nsAutoString uStr; @@ -1576,92 +1610,63 @@ msg_pick_real_name (nsMsgAttachmentHandler *attachment, const char *charset) if (NS_FAILED(rv)) uStr.AssignWithConversion(attachment->m_real_name); - char *utf8Str = ToNewUTF8String(uStr); - - /* Try to MIME-2 encode the filename... */ - char *mime2Name = nsMsgI18NEncodeMimePartIIStr((NULL != utf8Str) ? utf8Str : attachment->m_real_name, - charset, - nsMsgMIMEGetConformToStandard()); - if (mime2Name && (mime2Name != attachment->m_real_name)) - { - PR_Free(attachment->m_real_name); - attachment->m_real_name = mime2Name; - } - if (NULL != utf8Str) - { - nsMemory::Free(utf8Str); - } - - /* ... and then put backslashes before special characters (RFC 822 tells us - to). */ - - char *qtextName = NULL; - - qtextName = msg_make_filename_qtext(attachment->m_real_name, - (parmFolding == 0 ? PR_TRUE : PR_FALSE)); - - if (qtextName) - { - PR_Free(attachment->m_real_name); - attachment->m_real_name = qtextName; - } } /* Now a special case for attaching uuencoded files... - If we attach a file "foo.txt.uu", we will send it out with - Content-Type: text/plain; Content-Transfer-Encoding: x-uuencode. - When saving such a file, a mail reader will generally decode it first - (thus removing the uuencoding.) So, let's make life a little easier by - removing the indication of uuencoding from the file name itself. (This - will presumably make the file name in the Content-Disposition header be - the same as the file name in the "begin" line of the uuencoded data.) + If we attach a file "foo.txt.uu", we will send it out with + Content-Type: text/plain; Content-Transfer-Encoding: x-uuencode. + When saving such a file, a mail reader will generally decode it first + (thus removing the uuencoding.) So, let's make life a little easier by + removing the indication of uuencoding from the file name itself. (This + will presumably make the file name in the Content-Disposition header be + the same as the file name in the "begin" line of the uuencoded data.) - However, since there are mailers out there (including earlier versions of - Mozilla) that will use "foo.txt.uu" as the file name, we still need to - cope with that; the code which copes with that is in the MIME parser, in - libmime/mimei.c. + However, since there are mailers out there (including earlier versions of + Mozilla) that will use "foo.txt.uu" as the file name, we still need to + cope with that; the code which copes with that is in the MIME parser, in + libmime/mimei.c. */ if (attachment->m_already_encoded_p && - attachment->m_encoding) - { - char *result = attachment->m_real_name; - PRInt32 L = PL_strlen(result); - const char **exts = 0; + attachment->m_encoding) + { + char *result = attachment->m_real_name; + PRInt32 L = PL_strlen(result); + const char **exts = 0; - /* #### TOTAL KLUDGE. - I'd like to ask the mime.types file, "what extensions correspond - to obj->encoding (which happens to be "x-uuencode") but doing that - in a non-sphagetti way would require brain surgery. So, since - currently uuencode is the only content-transfer-encoding which we - understand which traditionally has an extension, we just special- - case it here! + /* #### TOTAL KLUDGE. + I'd like to ask the mime.types file, "what extensions correspond + to obj->encoding (which happens to be "x-uuencode") but doing that + in a non-sphagetti way would require brain surgery. So, since + currently uuencode is the only content-transfer-encoding which we + understand which traditionally has an extension, we just special- + case it here! - Note that it's special-cased in a similar way in libmime/mimei.c. - */ - if (!PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE) || - !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE2) || - !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE3) || - !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE4)) - { - static const char *uue_exts[] = { "uu", "uue", 0 }; - exts = uue_exts; - } + Note that it's special-cased in a similar way in libmime/mimei.c. + */ + if (!PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE) || + !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE2) || + !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE3) || + !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE4)) + { + static const char *uue_exts[] = { "uu", "uue", 0 }; + exts = uue_exts; + } - while (exts && *exts) - { - const char *ext = *exts; - PRInt32 L2 = PL_strlen(ext); - if (L > L2 + 1 && /* long enough */ - result[L - L2 - 1] == '.' && /* '.' in right place*/ - !PL_strcasecmp(ext, result + (L - L2))) /* ext matches */ - { - result[L - L2 - 1] = 0; /* truncate at '.' and stop. */ - break; - } - exts++; - } - } + while (exts && *exts) + { + const char *ext = *exts; + PRInt32 L2 = PL_strlen(ext); + if (L > L2 + 1 && /* long enough */ + result[L - L2 - 1] == '.' && /* '.' in right place*/ + !PL_strcasecmp(ext, result + (L - L2))) /* ext matches */ + { + result[L - L2 - 1] = 0; /* truncate at '.' and stop. */ + break; + } + exts++; + } + } } // Utility to create a nsIURI object... @@ -1674,16 +1679,16 @@ nsMsgNewURL(nsIURI** aInstancePtrResult, const char * aSpec) nsCOMPtr pNetService(do_GetService(kIOServiceCID, &rv)); if (NS_SUCCEEDED(rv) && pNetService) { - if (PL_strstr(aSpec, "://") == nsnull) - { - nsAutoString newSpec; newSpec.AssignWithConversion("http://"); - newSpec.AppendWithConversion(aSpec); + if (PL_strstr(aSpec, "://") == nsnull) + { + nsAutoString newSpec; newSpec.AssignWithConversion("http://"); + newSpec.AppendWithConversion(aSpec); nsCAutoString newspecC; newspecC.AssignWithConversion(newSpec); - rv = pNetService->NewURI(newspecC.get(), nsnull, aInstancePtrResult); + rv = pNetService->NewURI(newspecC.get(), nsnull, aInstancePtrResult); } else - rv = pNetService->NewURI(aSpec, nsnull, aInstancePtrResult); + rv = pNetService->NewURI(aSpec, nsnull, aInstancePtrResult); } return rv; } @@ -1720,7 +1725,7 @@ char NS_ASSERTION(PL_strncasecmp(url, "file://", 7) == 0, "invalid url"); finalPath = (char*)PR_Malloc(strlen(url)); if (finalPath == NULL) - return NULL; + return NULL; strcpy(finalPath, url+6+1); return finalPath; #endif @@ -1871,9 +1876,9 @@ GenerateFileNameFromURI(nsIURI *aURL) char * mime_gen_content_id(PRUint32 aPartNum, const char *aEmailAddress) { - PRInt32 randLen = 5; + PRInt32 randLen = 5; unsigned char rand_buf1[5]; - unsigned char rand_buf2[5]; + unsigned char rand_buf2[5]; char *domain = nsnull; char *defaultDomain = "@netscape.com"; @@ -1920,8 +1925,8 @@ GetFolderURIFromUserPrefs(nsMsgDeliverMode aMode, rv = prefs->CopyCharPref("mail.default_sendlater_uri", &uri); if (NS_FAILED(rv) || !uri) { - uri = PR_smprintf("%s", ANY_SERVER); - rv = NS_OK; + uri = PR_smprintf("%s", ANY_SERVER); + rv = NS_OK; } else { @@ -1946,12 +1951,12 @@ GetFolderURIFromUserPrefs(nsMsgDeliverMode aMode, } else { - PRBool doFcc = PR_FALSE; + PRBool doFcc = PR_FALSE; rv = identity->GetDoFcc(&doFcc); if (doFcc) - rv = identity->GetFccFolder(&uri); + rv = identity->GetFccFolder(&uri); else - uri = PL_strdup(""); + uri = PL_strdup(""); } return uri; @@ -1996,7 +2001,7 @@ nsMsgGetExtensionFromFileURL(nsString aUrl) ERROR_OUT: if (url) - nsMemory::Free(url); + nsMemory::Free(url); return nsnull; } @@ -2079,7 +2084,7 @@ nsMsgParseSubjectFromFile(nsFileSpec* fileSpec) char *ptr = &buffer[0]; NS_NewFileSpecWithSpec(*fileSpec, &tmpFileSpec); - if (!tmpFileSpec) + if (!tmpFileSpec) return nsnull; if (NS_FAILED(tmpFileSpec->OpenStreamForReading())) diff --git a/mozilla/mailnews/compose/src/nsMsgCompUtils.h b/mozilla/mailnews/compose/src/nsMsgCompUtils.h index 2af6821c41a..c6b64033c07 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompUtils.h +++ b/mozilla/mailnews/compose/src/nsMsgCompUtils.h @@ -63,43 +63,43 @@ char *nsMsgCreateTempFileName(char *tFileName); // messages during message composition // nsresult mime_sanity_check_fields ( - const char *from, - const char *reply_to, - const char *to, - const char *cc, - const char *bcc, - const char *fcc, - const char *newsgroups, - const char *followup_to, - const char * /*subject*/, - const char * /*references*/, - const char * /*organization*/, - const char * /*other_random_headers*/); + const char *from, + const char *reply_to, + const char *to, + const char *cc, + const char *bcc, + const char *fcc, + const char *newsgroups, + const char *followup_to, + const char * /*subject*/, + const char * /*references*/, + const char * /*organization*/, + const char * /*other_random_headers*/); char *mime_generate_headers (nsMsgCompFields *fields, - const char *charset, - nsMsgDeliverMode deliver_mode, nsIPrompt * aPrompt, PRInt32 *status); + const char *charset, + nsMsgDeliverMode deliver_mode, nsIPrompt * aPrompt, PRInt32 *status); char *mime_make_separator(const char *prefix); char *mime_gen_content_id(PRUint32 aPartNum, const char *aEmailAddress); char *mime_generate_attachment_headers (const char *type, - const char *encoding, - const char *description, - const char *x_mac_type, - const char *x_mac_creator, - const char *real_name, - const char *base_url, - PRBool digest_p, - nsMsgAttachmentHandler *ma, - const char *charset, + const char *encoding, + const char *description, + const char *x_mac_type, + const char *x_mac_creator, + const char *real_name, + const char *base_url, + PRBool digest_p, + nsMsgAttachmentHandler *ma, + const char *charset, const char *content_id, PRBool aBodyDocument); char *msg_generate_message_id (nsIMsgIdentity*); char *RFC2231ParmFolding(const char *parmName, const char *charset, - const char *language, const char *parmValue); + const char *language, const char *parmValue); PRBool mime_7bit_data_p (const char *string, PRUint32 size); @@ -114,7 +114,7 @@ PRBool mime_type_needs_charset (const char *type); char *msg_make_filename_qtext(const char *srcText, PRBool stripCRLFs); // Rip apart the URL and extract a reasonable value for the `real_name' slot. -void msg_pick_real_name (nsMsgAttachmentHandler *attachment, const char *charset); +void msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *proposedName, const char *charset); // // Informational calls... diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index c1d41811669..63402603e3d 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -135,15 +135,15 @@ static PRInt32 GetReplyHeaderType() static nsresult RemoveDuplicateAddresses(const char * addresses, const char * anothersAddresses, PRBool removeAliasesToMe, char** newAddress) { - nsresult rv; + nsresult rv; - nsCOMPtr parser (do_GetService(kHeaderParserCID)); - if (parser) - rv= parser->RemoveDuplicateAddresses("UTF-8", addresses, anothersAddresses, removeAliasesToMe, newAddress); - else - rv = NS_ERROR_FAILURE; + nsCOMPtr parser (do_GetService(kHeaderParserCID)); + if (parser) + rv= parser->RemoveDuplicateAddresses("UTF-8", addresses, anothersAddresses, removeAliasesToMe, newAddress); + else + rv = NS_ERROR_FAILURE; - return rv; + return rv; } static void TranslateLineEnding(nsString& data) @@ -200,34 +200,25 @@ nsMsgCompose::nsMsgCompose() printf("CREATE nsMsgCompose: %x\n", this); #endif - NS_INIT_REFCNT(); + NS_INIT_REFCNT(); - mQuotingToFollow = PR_FALSE; - mWhatHolder = 1; - mDocumentListener = nsnull; - m_window = nsnull; - m_editor = nsnull; - mQuoteStreamListener=nsnull; - m_compFields = new nsMsgCompFields; - NS_IF_ADDREF(m_compFields); - mType = nsIMsgCompType::New; - - // Get the default charset from pref, use this as a mail charset. - char * default_mail_charset = nsMsgI18NGetDefaultMailCharset(); - if (default_mail_charset) - { - m_compFields->SetCharacterSet(default_mail_charset); - PR_Free(default_mail_charset); - } + mQuotingToFollow = PR_FALSE; + mWhatHolder = 1; + mDocumentListener = nsnull; + m_window = nsnull; + m_editor = nsnull; + mQuoteStreamListener=nsnull; + m_compFields = nsnull; //m_compFields will be set during nsMsgCompose::Initialize + mType = nsIMsgCompType::New; // For TagConvertible // Read and cache pref mConvertStructs = PR_FALSE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); if (prefs) prefs->GetBoolPref("converter.html2txt.structs", &mConvertStructs); - m_composeHTML = PR_FALSE; + m_composeHTML = PR_FALSE; } @@ -237,13 +228,13 @@ nsMsgCompose::~nsMsgCompose() printf("DISPOSE nsMsgCompose: %x\n", this); #endif - if (mDocumentListener) - { - mDocumentListener->SetComposeObj(nsnull); - NS_RELEASE(mDocumentListener); - } - NS_IF_RELEASE(m_compFields); - NS_IF_RELEASE(mQuoteStreamListener); + if (mDocumentListener) + { + mDocumentListener->SetComposeObj(nsnull); + NS_RELEASE(mDocumentListener); + } + NS_IF_RELEASE(m_compFields); + NS_IF_RELEASE(mQuoteStreamListener); } /* the following macro actually implement addref, release and query interface for our component. */ @@ -522,12 +513,12 @@ NS_IMETHODIMP nsMsgCompose::ConvertAndLoadComposeWindow(nsIEditorShell *aEditorS if (aBuf.IsEmpty()) editor->BeginningOfDocument(); else - switch (GetReplyOnTop()) - { + switch (GetReplyOnTop()) + { // This should set the cursor after the body but before the sig - case 0 : - { - nsCOMPtr textEditor = do_QueryInterface(editor); + case 0 : + { + nsCOMPtr textEditor = do_QueryInterface(editor); if (!textEditor) { editor->BeginningOfDocument(); @@ -565,18 +556,18 @@ NS_IMETHODIMP nsMsgCompose::ConvertAndLoadComposeWindow(nsIEditorShell *aEditorS // break. expirement. selection->Collapse(parent, offset+1); - break; - } - - case 2 : - { - editor->SelectAll(); - break; - } - + break; + } + + case 2 : + { + editor->SelectAll(); + break; + } + // This should set the cursor to the top! - default : editor->BeginningOfDocument(); break; - } + default : editor->BeginningOfDocument(); break; + } nsCOMPtr selCon; editor->GetSelectionController(getter_AddRefs(selCon)); @@ -614,21 +605,21 @@ nsMsgCompose::GetQuotingToFollow(PRBool* quotingToFollow) nsresult nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, nsIMsgComposeParams *params) { - nsresult rv; + nsresult rv; NS_ENSURE_ARG(params); params->GetIdentity(getter_AddRefs(m_identity)); - if (aWindow) - { - m_window = aWindow; + if (aWindow) + { + m_window = aWindow; nsCOMPtr docshell; - nsCOMPtr globalObj(do_QueryInterface(aWindow)); - if (!globalObj) - return NS_ERROR_FAILURE; - - globalObj->GetDocShell(getter_AddRefs(docshell)); + nsCOMPtr globalObj(do_QueryInterface(aWindow)); + if (!globalObj) + return NS_ERROR_FAILURE; + + globalObj->GetDocShell(getter_AddRefs(docshell)); nsCOMPtr treeItem(do_QueryInterface(docshell)); nsCOMPtr treeOwner; rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); @@ -636,10 +627,10 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, m_baseWindow = do_QueryInterface(treeOwner); } - - MSG_ComposeFormat format; - params->GetFormat(&format); - + + MSG_ComposeFormat format; + params->GetFormat(&format); + MSG_ComposeType type; params->GetType(&type); @@ -649,22 +640,22 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, nsCOMPtr composeFields; params->GetComposeFields(getter_AddRefs(composeFields)); - switch (format) - { - case nsIMsgCompFormat::HTML : m_composeHTML = PR_TRUE; break; - case nsIMsgCompFormat::PlainText : m_composeHTML = PR_FALSE; break; + switch (format) + { + case nsIMsgCompFormat::HTML : m_composeHTML = PR_TRUE; break; + case nsIMsgCompFormat::PlainText : m_composeHTML = PR_FALSE; break; case nsIMsgCompFormat::OppositeOfDefault: /* ask the identity which compose to use */ if (m_identity) m_identity->GetComposeHtml(&m_composeHTML); /* then use the opposite */ m_composeHTML = !m_composeHTML; break; - default : + default : /* ask the identity which compose format to use */ if (m_identity) m_identity->GetComposeHtml(&m_composeHTML); break; - } + } params->GetSendListener(getter_AddRefs(mExternalSendListener)); nsXPIDLCString smtpPassword; @@ -676,13 +667,13 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, nsresult nsMsgCompose::SetDocumentCharset(const char *charset) { - // Set charset, this will be used for the MIME charset labeling. - m_compFields->SetCharacterSet(charset); - + // Set charset, this will be used for the MIME charset labeling. + m_compFields->SetCharacterSet(charset); + // notify the change to editor m_editor->SetDocumentCharacterSet(NS_ConvertASCIItoUCS2(charset).get()); - return NS_OK; + return NS_OK; } nsresult nsMsgCompose::RegisterStateListener(nsIMsgComposeStateListener *stateListener) @@ -747,15 +738,16 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide parser->MakeFullAddress(nsnull, NS_ConvertUCS2toUTF8(fullName).get(), email, &sender); } - if (!sender) - m_compFields->SetFrom(email); - else - m_compFields->SetFrom(sender); - PR_FREEIF(sender); + if (!sender) + m_compFields->SetFrom(email); + else + m_compFields->SetFrom(sender); + PR_FREEIF(sender); m_compFields->SetOrganization(organization); #if defined(DEBUG_ducarroz) || defined(DEBUG_seth_) + { printf("----------------------------\n"); printf("-- Sending Mail Message --\n"); printf("----------------------------\n"); @@ -763,8 +755,32 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide printf("To: %s Cc: %s Bcc: %s\n", m_compFields->GetTo(), m_compFields->GetCc(), m_compFields->GetBcc()); printf("Newsgroups: %s\n", m_compFields->GetNewsgroups()); printf("Subject: %s \nMsg: %s\n", m_compFields->GetSubject(), m_compFields->GetBody()); - printf("Attachments: %s\n",m_compFields->GetAttachments()); + nsCOMPtr attachmentsArray; + m_compFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray)); + if (attachmentsArray) + { + PRUint32 i; + PRUint32 attachmentCount = 0; + attachmentsArray->Count(&attachmentCount); + + nsCOMPtr element; + for (i = 0; i < attachmentCount; i ++) + { + attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + { + nsXPIDLString name; + nsXPIDLCString url; + nsXPIDLCString nameCStr; + element->GetName(getter_Copies(name)); + nameCStr.Adopt(ToNewCString(name)); + element->GetUrl(getter_Copies(url)); + printf("Attachment %d: %s - %s\n",i + 1, nameCStr.get(), url.get()); + } + } + } printf("----------------------------\n"); + } #endif //DEBUG mMsgSend = do_CreateInstance(NS_MSGSEND_CONTRACTID); @@ -818,16 +834,16 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide m_composeHTML?m_editor:nsnull, identity, m_compFields, - PR_FALSE, // PRBool digest_p, - PR_FALSE, // PRBool dont_deliver_p, - (nsMsgDeliverMode)deliverMode, // nsMsgDeliverMode mode, - nsnull, // nsIMsgDBHdr *msgToReplace *msgToReplace, - m_composeHTML?TEXT_HTML:TEXT_PLAIN, // const char *attachment1_type, - bodyString, // const char *attachment1_body, - bodyLength, // PRUint32 attachment1_body_length, - nsnull, // const struct nsMsgAttachmentData *attachments, - nsnull, // const struct nsMsgAttachedFile *preloaded_attachments, - nsnull, // nsMsgSendPart *relatedPart, + PR_FALSE, // PRBool digest_p, + PR_FALSE, // PRBool dont_deliver_p, + (nsMsgDeliverMode)deliverMode, // nsMsgDeliverMode mode, + nsnull, // nsIMsgDBHdr *msgToReplace *msgToReplace, + m_composeHTML?TEXT_HTML:TEXT_PLAIN, // const char *attachment1_type, + bodyString, // const char *attachment1_body, + bodyLength, // PRUint32 attachment1_body_length, + nsnull, // const struct nsMsgAttachmentData *attachments, + nsnull, // const struct nsMsgAttachedFile *preloaded_attachments, + nsnull, // nsMsgSendPart *relatedPart, m_window, // nsIDOMWindowInternal *parentWindow; mProgress, // nsIMsgProgress *progress, sendListener, // listener @@ -838,33 +854,33 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide PR_FREEIF(bodyString); } else - rv = NS_ERROR_FAILURE; + rv = NS_ERROR_FAILURE; } else rv = NS_ERROR_NOT_INITIALIZED; if (NS_FAILED(rv)) NotifyStateListeners(eComposeProcessDone,rv); - + return rv; } nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity, nsIMsgProgress *progress) { - nsresult rv = NS_OK; - PRBool entityConversionDone = PR_FALSE; + nsresult rv = NS_OK; + PRBool entityConversionDone = PR_FALSE; nsCOMPtr prompt; // i'm assuming the compose window is still up at this point... if (!prompt && m_window) m_window->GetPrompter(getter_AddRefs(prompt)); - if (m_editor && m_compFields && !m_composeHTML) - { + if (m_editor && m_compFields && !m_composeHTML) + { // The plain text compose window was used const char contentType[] = "text/plain"; - nsAutoString msgBody; - PRUnichar *bodyText = nsnull; + nsAutoString msgBody; + PRUnichar *bodyText = nsnull; nsAutoString format; format.AssignWithConversion(contentType); PRUint32 flags = nsIDocumentEncoder::OutputFormatted; @@ -873,19 +889,19 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide flags |= nsIDocumentEncoder::OutputFormatFlowed; rv = m_editor->GetContentsAs(format.get(), flags, &bodyText); - + if (NS_SUCCEEDED(rv) && nsnull != bodyText) { - msgBody = bodyText; + msgBody = bodyText; nsMemory::Free(bodyText); - // Convert body to mail charset not to utf-8 (because we don't manipulate body text) - char *outCString = nsnull; + // Convert body to mail charset not to utf-8 (because we don't manipulate body text) + char *outCString = nsnull; rv = nsMsgI18NSaveAsCharset(contentType, m_compFields->GetCharacterSet(), msgBody.get(), &outCString); SET_SIMULATED_ERROR(SIMULATED_SEND_ERROR_14, rv, NS_ERROR_UENC_NOMAPPING); - if (NS_SUCCEEDED(rv) && nsnull != outCString) - { + if (NS_SUCCEEDED(rv) && nsnull != outCString) + { // body contains multilingual data, confirm send to the user if (NS_ERROR_UENC_NOMAPPING == rv) { PRBool proceedTheSend; @@ -895,15 +911,15 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide return NS_ERROR_ABORT; } } - m_compFields->SetBody(outCString); + m_compFields->SetBody(outCString); entityConversionDone = PR_TRUE; - PR_Free(outCString); - } - else + PR_Free(outCString); + } + else { nsCAutoString msgbodyC; msgbodyC.AssignWithConversion(msgBody); - m_compFields->SetBody(msgbodyC.get()); + m_compFields->SetBody(msgbodyC.get()); } } } @@ -916,10 +932,10 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide m_compFields->GetSubject(getter_Copies(msgSubject)); PRBool showProgress = PR_FALSE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); if (prefs) { - prefs->GetBoolPref("mailnews.show_send_progress", &showProgress); + prefs->GetBoolPref("mailnews.show_send_progress", &showProgress); if (showProgress) { nsCOMPtr params = do_CreateInstance(NS_MSGCOMPOSEPROGRESSPARAMS_CONTRACTID, &rv); @@ -938,8 +954,8 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide } rv = _SendMsg(deliverMode, identity, entityConversionDone); - if (NS_FAILED(rv)) - { + if (NS_FAILED(rv)) + { nsCOMPtr sendReport; if (mMsgSend) mMsgSend->GetSendReport(getter_AddRefs(sendReport)); @@ -973,9 +989,9 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide if (progress) progress->CloseProgressDialog(PR_TRUE); - } - - return rv; + } + + return rv; } @@ -984,15 +1000,15 @@ nsresult nsMsgCompose::CloseWindow() nsresult rv = NS_OK; if (m_baseWindow) { - m_editor = nsnull; /* m_editor will be destroyed during the Close Window. Set it to null to */ - /* be sure we wont use it anymore. */ + m_editor = nsnull; /* m_editor will be destroyed during the Close Window. Set it to null to */ + /* be sure we wont use it anymore. */ nsIBaseWindow * aWindow = m_baseWindow; m_baseWindow = nsnull; rv = aWindow->Destroy(); } - return rv; + return rv; } nsresult nsMsgCompose::Abort() @@ -1046,89 +1062,89 @@ nsresult nsMsgCompose::SetEditor(nsIEditorShell * aEditor) nsresult nsMsgCompose::GetBodyModified(PRBool * modified) { - nsresult rv; + nsresult rv; - if (! modified) - return NS_ERROR_NULL_POINTER; + if (! modified) + return NS_ERROR_NULL_POINTER; - *modified = PR_TRUE; - - if (m_editor) - { - nsCOMPtr editor; - rv = m_editor->GetEditor(getter_AddRefs(editor)); - if (NS_SUCCEEDED(rv) && editor) - { - rv = editor->GetDocumentModified(modified); - if (NS_FAILED(rv)) - *modified = PR_TRUE; - } - } + *modified = PR_TRUE; + + if (m_editor) + { + nsCOMPtr editor; + rv = m_editor->GetEditor(getter_AddRefs(editor)); + if (NS_SUCCEEDED(rv) && editor) + { + rv = editor->GetDocumentModified(modified); + if (NS_FAILED(rv)) + *modified = PR_TRUE; + } + } - return NS_OK; + return NS_OK; } nsresult nsMsgCompose::SetBodyModified(PRBool modified) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; - if (m_editor) - { - nsCOMPtr editor; - rv = m_editor->GetEditor(getter_AddRefs(editor)); - if (NS_SUCCEEDED(rv) && editor) - { - nsCOMPtr theDoc; - rv = editor->GetDocument(getter_AddRefs(theDoc)); - if (NS_FAILED(rv)) - return rv; + if (m_editor) + { + nsCOMPtr editor; + rv = m_editor->GetEditor(getter_AddRefs(editor)); + if (NS_SUCCEEDED(rv) && editor) + { + nsCOMPtr theDoc; + rv = editor->GetDocument(getter_AddRefs(theDoc)); + if (NS_FAILED(rv)) + return rv; - nsCOMPtr diskDoc = do_QueryInterface(theDoc, &rv); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr diskDoc = do_QueryInterface(theDoc, &rv); + if (NS_FAILED(rv)) + return rv; - if (modified) - { - PRInt32 modCount = 0; - diskDoc->GetModificationCount(&modCount); - if (modCount == 0) - diskDoc->IncrementModificationCount(1); - } - else - diskDoc->ResetModificationCount(); - } - } + if (modified) + { + PRInt32 modCount = 0; + diskDoc->GetModificationCount(&modCount); + if (modCount == 0) + diskDoc->IncrementModificationCount(1); + } + else + diskDoc->ResetModificationCount(); + } + } - return rv; + return rv; } nsresult nsMsgCompose::GetDomWindow(nsIDOMWindowInternal * *aDomWindow) { - *aDomWindow = m_window; - NS_IF_ADDREF(*aDomWindow); - return NS_OK; + *aDomWindow = m_window; + NS_IF_ADDREF(*aDomWindow); + return NS_OK; } nsresult nsMsgCompose::GetCompFields(nsIMsgCompFields * *aCompFields) { - *aCompFields = (nsIMsgCompFields*)m_compFields; - NS_IF_ADDREF(*aCompFields); - return NS_OK; + *aCompFields = (nsIMsgCompFields*)m_compFields; + NS_IF_ADDREF(*aCompFields); + return NS_OK; } nsresult nsMsgCompose::GetComposeHTML(PRBool *aComposeHTML) { - *aComposeHTML = m_composeHTML; - return NS_OK; + *aComposeHTML = m_composeHTML; + return NS_OK; } nsresult nsMsgCompose::GetWrapLength(PRInt32 *aWrapLength) { nsresult rv; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; return prefs->GetIntPref("mailnews.wraplength", aWrapLength); @@ -1142,20 +1158,30 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, nsresult rv = NS_OK; mType = type; - if (compFields) - { - if (m_compFields) - rv = m_compFields->Copy(compFields); //TODO: we should not doing a copy, it's a waste of time!!! - } - - if (m_identity) - { - /* Setup reply-to field */ + + if (compFields) + { + NS_IF_RELEASE(m_compFields); + m_compFields = NS_REINTERPRET_CAST(nsMsgCompFields*, compFields); + NS_ADDREF(m_compFields); + } + else + { + NS_NEWXPCOM(m_compFields, nsMsgCompFields); + if (m_compFields) + NS_ADDREF(m_compFields); + else + return NS_ERROR_OUT_OF_MEMORY; + } + + if (m_identity) + { + /* Setup reply-to field */ nsString replyToStr; - nsXPIDLCString replyTo; + nsXPIDLCString replyTo; replyToStr.AssignWithConversion(m_compFields->GetReplyTo()); - m_identity->GetReplyTo(getter_Copies(replyTo)); + m_identity->GetReplyTo(getter_Copies(replyTo)); if (replyTo && *(const char *)replyTo) { if (replyToStr.Length() > 0) @@ -1163,34 +1189,34 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, replyToStr.AppendWithConversion(replyTo); } - m_compFields->SetReplyTo(replyToStr.get()); - - /* Setup bcc field */ - PRBool aBool; - nsString bccStr; + m_compFields->SetReplyTo(replyToStr.get()); + + /* Setup bcc field */ + PRBool aBool; + nsString bccStr; bccStr.AssignWithConversion(m_compFields->GetBcc()); - - m_identity->GetBccSelf(&aBool); - if (aBool) - { - nsXPIDLCString email; - m_identity->GetEmail(getter_Copies(email)); - if (bccStr.Length() > 0) + + m_identity->GetBccSelf(&aBool); + if (aBool) + { + nsXPIDLCString email; + m_identity->GetEmail(getter_Copies(email)); + if (bccStr.Length() > 0) bccStr.Append(PRUnichar(',')); bccStr.AppendWithConversion(email); - } - - m_identity->GetBccOthers(&aBool); - if (aBool) - { - nsXPIDLCString bccList; - m_identity->GetBccList(getter_Copies(bccList)); - if (bccStr.Length() > 0) - bccStr.Append(PRUnichar(',')); - bccStr.AppendWithConversion(bccList); - } - m_compFields->SetBcc(bccStr.get()); - } + } + + m_identity->GetBccOthers(&aBool); + if (aBool) + { + nsXPIDLCString bccList; + m_identity->GetBccList(getter_Copies(bccList)); + if (bccStr.Length() > 0) + bccStr.Append(PRUnichar(',')); + bccStr.AppendWithConversion(bccList); + } + m_compFields->SetBcc(bccStr.get()); + } // If we don't have an original message URI, nothing else to do... if (!originalMsgURI || *originalMsgURI == 0) @@ -1201,7 +1227,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, nsCAutoString firstURI(originalMsgURI); PRInt32 offset = firstURI.FindChar(','); if (offset >= 0) - firstURI.Truncate(offset); + firstURI.Truncate(offset); // store the original message URI so we can extract it after we send the message to properly // mark any disposition flags like replied or forwarded on the message. @@ -1265,7 +1291,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, } nsXPIDLCString author; - rv = msgHdr->GetAuthor(getter_Copies(author)); + rv = msgHdr->GetAuthor(getter_Copies(author)); if (NS_FAILED(rv)) return rv; m_compFields->SetTo(author); @@ -1286,14 +1312,13 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, } case nsIMsgCompType::ForwardAsAttachment: { + nsAutoString decodedSubject; PRUint32 flags; msgHdr->GetFlags(&flags); - subjectStr.Append("[Fwd: "); if (flags & MSG_FLAG_HAS_RE) subjectStr.Append("Re: "); subjectStr.Append(subject); - subjectStr.Append("]"); // use a charset of the original message nsXPIDLString mailCharset; @@ -1307,16 +1332,25 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, rv = mimeConverter->DecodeMimeHeader(subjectStr.get(), getter_Copies(decodedString), charset, charsetOverride); - if (NS_SUCCEEDED(rv)) { - m_compFields->SetSubject(decodedString); - } else { - m_compFields->SetSubject(subjectStr.get()); - } + if (NS_SUCCEEDED(rv)) + decodedSubject.Assign(decodedString); + else + decodedSubject.AssignWithConversion(subjectStr.get()); // Setup quoting callbacks for later... - mQuotingToFollow = PR_FALSE; //We don't need to quote the original message. - m_compFields->SetAttachments(originalMsgURI); + mQuotingToFollow = PR_FALSE; //We don't need to quote the original message. + nsCOMPtr attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && attachment) + { + attachment->SetName(decodedSubject.get()); + attachment->SetUrl(originalMsgURI); + m_compFields->AddAttachment(attachment); + } + decodedSubject.Insert(NS_LITERAL_STRING("Fwd: ").get(), 0); + decodedSubject.Append(NS_LITERAL_STRING("]").get()); + + m_compFields->SetSubject(decodedSubject.get()); break; } } @@ -1538,7 +1572,7 @@ QuotingOutputStreamListener::ConvertToPlainText(PRBool formatflowed /* = PR_FALS NS_IMETHODIMP QuotingOutputStreamListener::OnStartRequest(nsIRequest *request, nsISupports * /* ctxt */) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, nsISupports * /* ctxt */, nsresult status) @@ -1678,8 +1712,8 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns } else // Process "followup-to: newsgroup-content" here { - if (type != nsIMsgCompType::ReplyToSender) - compFields->SetNewsgroups(NS_LossyConvertUCS2toASCII(followUpTo).get()); + if (type != nsIMsgCompType::ReplyToSender) + compFields->SetNewsgroups(NS_LossyConvertUCS2toASCII(followUpTo).get()); if (type == nsIMsgCompType::Reply) compFields->SetTo(&emptyUnichar); } @@ -1699,15 +1733,15 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns { nsCString addressToBeRemoved(_compFields->GetTo()); if (mIdentity) - { - nsXPIDLCString email; - mIdentity->GetEmail(getter_Copies(email)); - addressToBeRemoved += ", "; - addressToBeRemoved += NS_CONST_CAST(char*, (const char *)email); - } + { + nsXPIDLCString email; + mIdentity->GetEmail(getter_Copies(email)); + addressToBeRemoved += ", "; + addressToBeRemoved += NS_CONST_CAST(char*, (const char *)email); + } rv= RemoveDuplicateAddresses(_compFields->GetCc(), addressToBeRemoved.get(), PR_TRUE, &resultStr); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) { _compFields->SetCc(resultStr); PR_Free(resultStr); @@ -1762,29 +1796,29 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns } NS_IMETHODIMP QuotingOutputStreamListener::OnDataAvailable(nsIRequest *request, - nsISupports *ctxt, nsIInputStream *inStr, + nsISupports *ctxt, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; NS_ENSURE_ARG(inStr); if (mHeadersOnly) return rv; - char *newBuf = (char *)PR_Malloc(count + 1); - if (!newBuf) - return NS_ERROR_FAILURE; + char *newBuf = (char *)PR_Malloc(count + 1); + if (!newBuf) + return NS_ERROR_FAILURE; - PRUint32 numWritten = 0; - rv = inStr->Read(newBuf, count, &numWritten); - if (rv == NS_BASE_STREAM_WOULD_BLOCK) - rv = NS_OK; - newBuf[numWritten] = '\0'; - if (NS_SUCCEEDED(rv) && numWritten > 0) + PRUint32 numWritten = 0; + rv = inStr->Read(newBuf, count, &numWritten); + if (rv == NS_BASE_STREAM_WOULD_BLOCK) + rv = NS_OK; + newBuf[numWritten] = '\0'; + if (NS_SUCCEEDED(rv) && numWritten > 0) mMsgBody.Append(NS_ConvertUTF8toUCS2(newBuf, numWritten)); - PR_FREEIF(newBuf); - return rv; + PR_FREEIF(newBuf); + return rv; } nsresult @@ -1836,7 +1870,7 @@ nsMsgCompose::QuoteOriginalMessage(const char *originalMsgURI, PRInt32 what) // return NS_ERROR_FAILURE; PRBool bAutoQuote = PR_TRUE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); if (prefs) prefs->GetBoolPref("mail.auto_quote", &bAutoQuote); @@ -1862,49 +1896,49 @@ nsMsgCompose::QuoteOriginalMessage(const char *originalMsgURI, PRInt32 what) // //CleanUpRecipient will remove un-necesary "<>" when a recipient as an address without name void nsMsgCompose::CleanUpRecipients(nsString& recipients) { - PRUint16 i; - PRBool startANewRecipient = PR_TRUE; - PRBool removeBracket = PR_FALSE; - nsAutoString newRecipient; - PRUnichar aChar; + PRUint16 i; + PRBool startANewRecipient = PR_TRUE; + PRBool removeBracket = PR_FALSE; + nsAutoString newRecipient; + PRUnichar aChar; - for (i = 0; i < recipients.Length(); i ++) - { - aChar = recipients[i]; - switch (aChar) - { - case '<' : - if (startANewRecipient) - removeBracket = PR_TRUE; - else - newRecipient += aChar; - startANewRecipient = PR_FALSE; - break; + for (i = 0; i < recipients.Length(); i ++) + { + aChar = recipients[i]; + switch (aChar) + { + case '<' : + if (startANewRecipient) + removeBracket = PR_TRUE; + else + newRecipient += aChar; + startANewRecipient = PR_FALSE; + break; - case '>' : - if (removeBracket) - removeBracket = PR_FALSE; - else - newRecipient += aChar; - break; + case '>' : + if (removeBracket) + removeBracket = PR_FALSE; + else + newRecipient += aChar; + break; - case ' ' : - newRecipient += aChar; - break; + case ' ' : + newRecipient += aChar; + break; - case ',' : - newRecipient += aChar; - startANewRecipient = PR_TRUE; - removeBracket = PR_FALSE; - break; + case ',' : + newRecipient += aChar; + startANewRecipient = PR_TRUE; + removeBracket = PR_FALSE; + break; - default : - newRecipient += aChar; - startANewRecipient = PR_FALSE; - break; - } - } - recipients = newRecipient; + default : + newRecipient += aChar; + startANewRecipient = PR_FALSE; + break; + } + } + recipients = newRecipient; } nsresult nsMsgCompose::ProcessReplyFlags() @@ -1918,7 +1952,7 @@ nsresult nsMsgCompose::ProcessReplyFlags() mType == nsIMsgCompType::ReplyToSender || mType == nsIMsgCompType::ReplyToSenderAndGroup || mType == nsIMsgCompType::ForwardAsAttachment || - mType == nsIMsgCompType::ForwardInline) + mType == nsIMsgCompType::ForwardInline) { if (!mOriginalMsgURI.IsEmpty()) { @@ -1934,7 +1968,7 @@ nsresult nsMsgCompose::ProcessReplyFlags() { nsMsgDispositionState dispositionSetting = nsIMsgFolder::nsMsgDispositionState_Replied; if (mType == nsIMsgCompType::ForwardAsAttachment || - mType == nsIMsgCompType::ForwardInline) + mType == nsIMsgCompType::ForwardInline) dispositionSetting = nsIMsgFolder::nsMsgDispositionState_Forwarded; msgFolder->AddMessageDispositionState(msgHdr, dispositionSetting); @@ -1976,7 +2010,7 @@ nsMsgComposeSendListener::nsMsgComposeSendListener(void) #if defined(DEBUG_ducarroz) printf("CREATE nsMsgComposeSendListener: %x\n", this); #endif - mDeliverMode = 0; + mDeliverMode = 0; NS_INIT_REFCNT(); } @@ -1991,13 +2025,13 @@ nsMsgComposeSendListener::~nsMsgComposeSendListener(void) NS_IMETHODIMP nsMsgComposeSendListener::SetMsgCompose(nsIMsgCompose *obj) { mWeakComposeObj = getter_AddRefs(NS_GetWeakReference(obj)); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMsgComposeSendListener::SetDeliverMode(MSG_DeliverMode deliverMode) { - mDeliverMode = deliverMode; - return NS_OK; + mDeliverMode = deliverMode; + return NS_OK; } nsresult @@ -2008,7 +2042,7 @@ nsMsgComposeSendListener::OnStartSending(const char *aMsgID, PRUint32 aMsgSize) #endif nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) + if (compose) { nsCOMPtr externalListener; compose->GetExternalSendListener(getter_AddRefs(externalListener)); @@ -2027,7 +2061,7 @@ nsMsgComposeSendListener::OnProgress(const char *aMsgID, PRUint32 aProgress, PRU #endif nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) + if (compose) { nsCOMPtr externalListener; compose->GetExternalSendListener(getter_AddRefs(externalListener)); @@ -2046,7 +2080,7 @@ nsMsgComposeSendListener::OnStatus(const char *aMsgID, const PRUnichar *aMsg) #endif nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) + if (compose) { nsCOMPtr externalListener; compose->GetExternalSendListener(getter_AddRefs(externalListener)); @@ -2060,22 +2094,22 @@ nsMsgComposeSendListener::OnStatus(const char *aMsgID, const PRUnichar *aMsg) nsresult nsMsgComposeSendListener::OnStopSending(const char *aMsgID, nsresult aStatus, const PRUnichar *aMsg, nsIFileSpec *returnFileSpec) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) - { - nsCOMPtr progress; - compose->GetProgress(getter_AddRefs(progress)); - + if (compose) + { + nsCOMPtr progress; + compose->GetProgress(getter_AddRefs(progress)); + //Unregister ourself from msg compose progress if (progress) progress->UnregisterListener(this); - if (NS_SUCCEEDED(aStatus)) - { + if (NS_SUCCEEDED(aStatus)) + { #ifdef NS_DEBUG - printf("nsMsgComposeSendListener: Success on the message send operation!\n"); + printf("nsMsgComposeSendListener: Success on the message send operation!\n"); #endif nsIMsgCompFields *compFields = nsnull; compose->GetCompFields(&compFields); //GetCompFields will addref, you need to release when your are done with it @@ -2083,17 +2117,17 @@ nsresult nsMsgComposeSendListener::OnStopSending(const char *aMsgID, nsresult aS // only process the reply flags if we successfully sent the message compose->ProcessReplyFlags(); - // Close the window ONLY if we are not going to do a save operation + // Close the window ONLY if we are not going to do a save operation PRUnichar *fieldsFCC = nsnull; if (NS_SUCCEEDED(compFields->GetFcc(&fieldsFCC))) { if (fieldsFCC && *fieldsFCC) { - if (Compare(nsDependentString(fieldsFCC), + if (Compare(nsDependentString(fieldsFCC), NS_LITERAL_STRING("nocopy://"), nsCaseInsensitiveStringComparator()) == 0) - { - compose->NotifyStateListeners(eComposeProcessDone, NS_OK); + { + compose->NotifyStateListeners(eComposeProcessDone, NS_OK); if (progress) progress->CloseProgressDialog(PR_FALSE); compose->CloseWindow(); @@ -2102,29 +2136,29 @@ nsresult nsMsgComposeSendListener::OnStopSending(const char *aMsgID, nsresult aS } else { - compose->NotifyStateListeners(eComposeProcessDone, NS_OK); + compose->NotifyStateListeners(eComposeProcessDone, NS_OK); if (progress) progress->CloseProgressDialog(PR_FALSE); compose->CloseWindow(); // if we fail on the simple GetFcc call, close the window to be safe and avoid // windows hanging around to prevent the app from exiting. } - // Remove the current draft msg when sending draft is done. - MSG_ComposeType compType = nsIMsgCompType::Draft; - compose->GetType(&compType); + // Remove the current draft msg when sending draft is done. + MSG_ComposeType compType = nsIMsgCompType::Draft; + compose->GetType(&compType); if (compType == nsIMsgCompType::Draft) RemoveCurrentDraftMessage(compose, PR_FALSE); NS_IF_RELEASE(compFields); - } - else - { + } + else + { #ifdef NS_DEBUG - printf("nsMsgComposeSendListener: the message send operation failed!\n"); + printf("nsMsgComposeSendListener: the message send operation failed!\n"); #endif - compose->NotifyStateListeners(eComposeProcessDone,aStatus); + compose->NotifyStateListeners(eComposeProcessDone,aStatus); if (progress) progress->CloseProgressDialog(PR_TRUE); - } + } nsCOMPtr externalListener; compose->GetExternalSendListener(getter_AddRefs(externalListener)); @@ -2139,7 +2173,7 @@ nsresult nsMsgComposeSendListener::OnGetDraftFolderURI(const char *aFolderURI) { nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) + if (compose) { compose->SetSavedFolderURI(aFolderURI); @@ -2175,20 +2209,20 @@ nsMsgComposeSendListener::OnProgress(PRUint32 aProgress, PRUint32 aProgressMax) nsresult nsMsgComposeSendListener::OnStopCopy(nsresult aStatus) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) - { + if (compose) + { // Ok, if we are here, we are done with the send/copy operation so // we have to do something with the window....SHOW if failed, Close // if succeeded - nsCOMPtr progress; - compose->GetProgress(getter_AddRefs(progress)); + nsCOMPtr progress; + compose->GetProgress(getter_AddRefs(progress)); if (progress) progress->CloseProgressDialog(NS_FAILED(aStatus)); - compose->NotifyStateListeners(eComposeProcessDone,aStatus); + compose->NotifyStateListeners(eComposeProcessDone,aStatus); if (NS_SUCCEEDED(aStatus)) { @@ -2214,10 +2248,10 @@ nsMsgComposeSendListener::OnStopCopy(nsresult aStatus) } } #ifdef NS_DEBUG - else - printf("nsMsgComposeSendListener: the message copy operation failed!\n"); + else + printf("nsMsgComposeSendListener: the message copy operation failed!\n"); #endif - } + } return rv; } @@ -2225,163 +2259,163 @@ nsMsgComposeSendListener::OnStopCopy(nsresult aStatus) nsresult nsMsgComposeSendListener::GetMsgFolder(nsIMsgCompose *compObj, nsIMsgFolder **msgFolder) { - nsresult rv; - nsCOMPtr aMsgFolder; - nsXPIDLCString folderUri; + nsresult rv; + nsCOMPtr aMsgFolder; + nsXPIDLCString folderUri; - rv = compObj->GetSavedFolderURI(getter_Copies(folderUri)); - NS_ENSURE_SUCCESS(rv, rv); + rv = compObj->GetSavedFolderURI(getter_Copies(folderUri)); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr resource; - rv = rdfService->GetResource(folderUri, getter_AddRefs(resource)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr resource; + rv = rdfService->GetResource(folderUri, getter_AddRefs(resource)); + NS_ENSURE_SUCCESS(rv, rv); - aMsgFolder = do_QueryInterface(resource, &rv); - NS_ENSURE_SUCCESS(rv, rv); - *msgFolder = aMsgFolder; - NS_IF_ADDREF(*msgFolder); - return rv; + aMsgFolder = do_QueryInterface(resource, &rv); + NS_ENSURE_SUCCESS(rv, rv); + *msgFolder = aMsgFolder; + NS_IF_ADDREF(*msgFolder); + return rv; } nsresult nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, PRBool calledByCopy) { - nsresult rv; - nsCOMPtr compFields = nsnull; + nsresult rv; + nsCOMPtr compFields = nsnull; rv = compObj->GetCompFields(getter_AddRefs(compFields)); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get compose fields"); - if (NS_FAILED(rv) || !compFields) - return rv; + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get compose fields"); + if (NS_FAILED(rv) || !compFields) + return rv; - nsXPIDLCString curDraftIdURL; - nsMsgKey newUid = 0; - nsXPIDLCString newDraftIdURL; - nsCOMPtr msgFolder; + nsXPIDLCString curDraftIdURL; + nsMsgKey newUid = 0; + nsXPIDLCString newDraftIdURL; + nsCOMPtr msgFolder; - rv = compFields->GetDraftId(getter_Copies(curDraftIdURL)); - NS_ASSERTION((NS_SUCCEEDED(rv) && (curDraftIdURL)), "RemoveCurrentDraftMessage can't get draft id"); + rv = compFields->GetDraftId(getter_Copies(curDraftIdURL)); + NS_ASSERTION((NS_SUCCEEDED(rv) && (curDraftIdURL)), "RemoveCurrentDraftMessage can't get draft id"); - // Skip if no draft id (probably a new draft msg). - if (NS_SUCCEEDED(rv) && curDraftIdURL.get() && nsCRT::strlen(curDraftIdURL.get())) - { - nsCOMPtr msgDBHdr; - rv = GetMsgDBHdrFromURI(curDraftIdURL, getter_AddRefs(msgDBHdr)); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg header DB interface pointer."); - if (NS_SUCCEEDED(rv) && msgDBHdr) - { // get the folder for the message resource - msgDBHdr->GetFolder(getter_AddRefs(msgFolder)); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg folder interface pointer."); - if (NS_SUCCEEDED(rv) && msgFolder) - { // build the msg arrary - nsCOMPtr messageArray; - rv = NS_NewISupportsArray(getter_AddRefs(messageArray)); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't allocate support array."); + // Skip if no draft id (probably a new draft msg). + if (NS_SUCCEEDED(rv) && curDraftIdURL.get() && nsCRT::strlen(curDraftIdURL.get())) + { + nsCOMPtr msgDBHdr; + rv = GetMsgDBHdrFromURI(curDraftIdURL, getter_AddRefs(msgDBHdr)); + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg header DB interface pointer."); + if (NS_SUCCEEDED(rv) && msgDBHdr) + { // get the folder for the message resource + msgDBHdr->GetFolder(getter_AddRefs(msgFolder)); + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg folder interface pointer."); + if (NS_SUCCEEDED(rv) && msgFolder) + { // build the msg arrary + nsCOMPtr messageArray; + rv = NS_NewISupportsArray(getter_AddRefs(messageArray)); + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't allocate support array."); - //nsCOMPtr msgSupport = do_QueryInterface(msgDBHdr, &rv); - //NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg header interface pointer."); - if (NS_SUCCEEDED(rv) && messageArray) - { // ready to delete the msg - rv = messageArray->AppendElement(msgDBHdr); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't append msg header to array."); - if (NS_SUCCEEDED(rv)) - rv = msgFolder->DeleteMessages(messageArray, nsnull, PR_TRUE, PR_FALSE, nsnull, PR_FALSE /*allowUndo*/); - NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't delete message."); - } - } - } - else - { - // If we get here we have the case where the draft folder + //nsCOMPtr msgSupport = do_QueryInterface(msgDBHdr, &rv); + //NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get msg header interface pointer."); + if (NS_SUCCEEDED(rv) && messageArray) + { // ready to delete the msg + rv = messageArray->AppendElement(msgDBHdr); + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't append msg header to array."); + if (NS_SUCCEEDED(rv)) + rv = msgFolder->DeleteMessages(messageArray, nsnull, PR_TRUE, PR_FALSE, nsnull, PR_FALSE /*allowUndo*/); + NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't delete message."); + } + } + } + else + { + // If we get here we have the case where the draft folder // is on the server and - // it's not currently open (in thread pane), so draft + // it's not currently open (in thread pane), so draft // msgs are saved to the server - // but they're not in our local DB. In this case, - // GetMsgDBHdrFromURI() will never - // find the msg. If the draft folder is a local one - // then we'll not get here because - // the draft msgs are saved to the local folder and - // are in local DB. Make sure the - // msg folder is imap. Even if we get here due to - // DB errors (worst case), we should - // still try to delete msg on the server because - // that's where the master copy of the - // msgs are stored, if draft folder is on the server. - // For local case, since DB is bad - // we can't do anything with it anyway so it'll be - // noop in this case. - rv = GetMsgFolder(compObj, getter_AddRefs(msgFolder)); - if (NS_SUCCEEDED(rv) && msgFolder) - { - nsCOMPtr imapFolder = do_QueryInterface(msgFolder); - NS_ASSERTION(imapFolder, "The draft folder MUST be an imap folder in order to mark the msg delete!"); - if (NS_SUCCEEDED(rv) && imapFolder) - { - char * str = PL_strstr(curDraftIdURL.get(), "#"); - NS_ASSERTION(str, "Failed to get current draft id url"); - if (str) - { - nsMsgKeyArray messageID; - nsCAutoString srcStr(str+1); - PRInt32 num=0, err; - num = srcStr.ToInteger(&err); - if (num != nsMsgKey_None) - { + // but they're not in our local DB. In this case, + // GetMsgDBHdrFromURI() will never + // find the msg. If the draft folder is a local one + // then we'll not get here because + // the draft msgs are saved to the local folder and + // are in local DB. Make sure the + // msg folder is imap. Even if we get here due to + // DB errors (worst case), we should + // still try to delete msg on the server because + // that's where the master copy of the + // msgs are stored, if draft folder is on the server. + // For local case, since DB is bad + // we can't do anything with it anyway so it'll be + // noop in this case. + rv = GetMsgFolder(compObj, getter_AddRefs(msgFolder)); + if (NS_SUCCEEDED(rv) && msgFolder) + { + nsCOMPtr imapFolder = do_QueryInterface(msgFolder); + NS_ASSERTION(imapFolder, "The draft folder MUST be an imap folder in order to mark the msg delete!"); + if (NS_SUCCEEDED(rv) && imapFolder) + { + char * str = PL_strstr(curDraftIdURL.get(), "#"); + NS_ASSERTION(str, "Failed to get current draft id url"); + if (str) + { + nsMsgKeyArray messageID; + nsCAutoString srcStr(str+1); + PRInt32 num=0, err; + num = srcStr.ToInteger(&err); + if (num != nsMsgKey_None) + { messageID.Add(num); - rv = imapFolder->StoreImapFlags(kImapMsgDeletedFlag, PR_TRUE, messageID.GetArray(), messageID.GetSize()); - } - } - } - } - } + rv = imapFolder->StoreImapFlags(kImapMsgDeletedFlag, PR_TRUE, messageID.GetArray(), messageID.GetSize()); + } + } + } + } + } - } + } - // Now get the new uid so that next save will remove the right msg - // regardless whether or not the exiting msg can be deleted. - if (calledByCopy) - { - nsCOMPtr msgSend; - rv = compObj->GetMessageSend(getter_AddRefs(msgSend)); - NS_ASSERTION(msgSend, "RemoveCurrentDraftMessage msgSend is null."); - if (NS_FAILED(rv) || !msgSend) - return rv; + // Now get the new uid so that next save will remove the right msg + // regardless whether or not the exiting msg can be deleted. + if (calledByCopy) + { + nsCOMPtr msgSend; + rv = compObj->GetMessageSend(getter_AddRefs(msgSend)); + NS_ASSERTION(msgSend, "RemoveCurrentDraftMessage msgSend is null."); + if (NS_FAILED(rv) || !msgSend) + return rv; - rv = msgSend->GetMessageKey(&newUid); - NS_ENSURE_SUCCESS(rv, rv); + rv = msgSend->GetMessageKey(&newUid); + NS_ENSURE_SUCCESS(rv, rv); - // Make sure we have a folder interface pointer - if (!msgFolder) - { - rv = GetMsgFolder(compObj, getter_AddRefs(msgFolder)); - NS_ENSURE_SUCCESS(rv, rv); - } + // Make sure we have a folder interface pointer + if (!msgFolder) + { + rv = GetMsgFolder(compObj, getter_AddRefs(msgFolder)); + NS_ENSURE_SUCCESS(rv, rv); + } - // Reset draft (uid) url with the new uid. - if (msgFolder && newUid) - { - rv = msgFolder->GenerateMessageURI(newUid, getter_Copies(newDraftIdURL)); - NS_ENSURE_SUCCESS(rv, rv); + // Reset draft (uid) url with the new uid. + if (msgFolder && newUid) + { + rv = msgFolder->GenerateMessageURI(newUid, getter_Copies(newDraftIdURL)); + NS_ENSURE_SUCCESS(rv, rv); - compFields->SetDraftId(newDraftIdURL.get()); - } - } - return rv; + compFields->SetDraftId(newDraftIdURL.get()); + } + } + return rv; } nsresult nsMsgComposeSendListener::SetMessageKey(PRUint32 aMessageKey) { - return NS_OK; + return NS_OK; } nsresult nsMsgComposeSendListener::GetMessageId(nsCString* aMessageId) { - return NS_OK; + return NS_OK; } /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ @@ -2390,11 +2424,11 @@ NS_IMETHODIMP nsMsgComposeSendListener::OnStateChange(nsIWebProgress *aWebProgre if (aStateFlags == nsIWebProgressListener::STATE_STOP) { nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); - if (compose) - { - nsCOMPtr progress; - compose->GetProgress(getter_AddRefs(progress)); - + if (compose) + { + nsCOMPtr progress; + compose->GetProgress(getter_AddRefs(progress)); + //Time to stop any pending operation... if (progress) { @@ -2509,7 +2543,7 @@ nsMsgDocumentStateListener::NotifyDocumentWillBeDestroyed(void) nsCOMPtrcompose = do_QueryReferent(mWeakComposeObj); if (compose) compose->SetEditor(nsnull); /* m_editor will be destroyed. Set it to null to */ - /* be sure we wont use it anymore. */ + /* be sure we wont use it anymore. */ return NS_OK; } @@ -2814,7 +2848,7 @@ nsresult nsMsgCompose::BuildBodyMessageAndSignature() { PRUnichar *bod = nsnull; - nsresult rv = NS_OK; + nsresult rv = NS_OK; // // This should never happen...if it does, just bail out... @@ -2832,30 +2866,30 @@ nsMsgCompose::BuildBodyMessageAndSignature() PRBool addSignature; switch (mType) { - case nsIMsgCompType::New : - case nsIMsgCompType::Reply : /* should not append! but just in case */ - case nsIMsgCompType::ReplyAll : /* should not append! but just in case */ - case nsIMsgCompType::ForwardAsAttachment : /* should not append! but just in case */ - case nsIMsgCompType::ForwardInline : - case nsIMsgCompType::NewsPost : - case nsIMsgCompType::ReplyToGroup : - case nsIMsgCompType::ReplyToSender : - case nsIMsgCompType::ReplyToSenderAndGroup : - addSignature = PR_TRUE; - break; + case nsIMsgCompType::New : + case nsIMsgCompType::Reply : /* should not append! but just in case */ + case nsIMsgCompType::ReplyAll : /* should not append! but just in case */ + case nsIMsgCompType::ForwardAsAttachment : /* should not append! but just in case */ + case nsIMsgCompType::ForwardInline : + case nsIMsgCompType::NewsPost : + case nsIMsgCompType::ReplyToGroup : + case nsIMsgCompType::ReplyToSender : + case nsIMsgCompType::ReplyToSenderAndGroup : + addSignature = PR_TRUE; + break; - case nsIMsgCompType::Draft : - case nsIMsgCompType::Template : - addSignature = PR_FALSE; - break; - - case nsIMsgCompType::MailToUrl : - addSignature = !(bod && *bod != 0); - break; + case nsIMsgCompType::Draft : + case nsIMsgCompType::Template : + addSignature = PR_FALSE; + break; + + case nsIMsgCompType::MailToUrl : + addSignature = !(bod && *bod != 0); + break; - default : - addSignature = PR_FALSE; - break; + default : + addSignature = PR_FALSE; + break; } if (m_editor) @@ -2865,7 +2899,7 @@ nsMsgCompose::BuildBodyMessageAndSignature() nsAutoString tSignature; if (addSignature) - ProcessSignature(m_identity, &tSignature); + ProcessSignature(m_identity, &tSignature); rv = ConvertAndLoadComposeWindow(m_editor, empty, bodStr, tSignature, PR_FALSE, m_composeHTML); @@ -2917,63 +2951,63 @@ nsresult nsMsgCompose::NotifyStateListeners(TStateListenerNotification aNotifica nsresult nsMsgCompose::AttachmentPrettyName(const char* url, PRUnichar** _retval) { - nsCAutoString unescapeURL(url); - nsUnescape(NS_CONST_CAST(char*, unescapeURL.get())); - if (unescapeURL.IsEmpty()) - { - nsAutoString unicodeUrl; - unicodeUrl.AssignWithConversion(url); + nsCAutoString unescapeURL(url); + nsUnescape(NS_CONST_CAST(char*, unescapeURL.get())); + if (unescapeURL.IsEmpty()) + { + nsAutoString unicodeUrl; + unicodeUrl.AssignWithConversion(url); - *_retval = ToNewUnicode(unicodeUrl); - return NS_OK; - } - - if (PL_strncasestr(unescapeURL.get(), "file:", 5)) - { - nsFileURL fileUrl(url); - nsFileSpec fileSpec(fileUrl); - char * leafName = fileSpec.GetLeafName(); - if (leafName && *leafName) - { - nsAutoString tempStr; - nsresult rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), leafName, tempStr); - if (NS_FAILED(rv)) - tempStr.AssignWithConversion(leafName); - *_retval = ToNewUnicode(tempStr); - nsCRT::free(leafName); - return NS_OK; - } - } + *_retval = ToNewUnicode(unicodeUrl); + return NS_OK; + } + + if (PL_strncasestr(unescapeURL, "file:", 5)) + { + nsFileURL fileUrl(url); + nsFileSpec fileSpec(fileUrl); + char * leafName = fileSpec.GetLeafName(); + if (leafName && *leafName) + { + nsAutoString tempStr; + nsresult rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), leafName, tempStr); + if (NS_FAILED(rv)) + tempStr.AssignWithConversion(leafName); + *_retval = ToNewUnicode(tempStr); + nsCRT::free(leafName); + return NS_OK; + } + } - if (PL_strncasestr(unescapeURL.get(), "http:", 5)) - unescapeURL.Cut(0, 7); + if (PL_strncasestr(unescapeURL.get(), "http:", 5)) + unescapeURL.Cut(0, 7); - *_retval = ToNewUnicode(unescapeURL); - return NS_OK; + *_retval = ToNewUnicode(unescapeURL); + return NS_OK; } static nsresult OpenAddressBook(const char * dbUri, nsIAddrDatabase** aDatabase, nsIAbDirectory** aDirectory) { - if (!aDatabase || !aDirectory) - return NS_ERROR_NULL_POINTER; + if (!aDatabase || !aDirectory) + return NS_ERROR_NULL_POINTER; nsresult rv; nsCOMPtr addresBook (do_GetService(NS_ADDRESSBOOK_CONTRACTID)); if (addresBook) rv = addresBook->GetAbDatabaseFromURI(dbUri, aDatabase); - nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); + if (NS_FAILED(rv)) + return rv; - nsCOMPtr resource; - rv = rdfService->GetResource(dbUri, getter_AddRefs(resource)); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr resource; + rv = rdfService->GetResource(dbUri, getter_AddRefs(resource)); + if (NS_FAILED(rv)) + return rv; - // query interface - rv = resource->QueryInterface(nsIAbDirectory::GetIID(), (void **)aDirectory); - return rv; + // query interface + rv = resource->QueryInterface(nsIAbDirectory::GetIID(), (void **)aDirectory); + return rv; } nsresult nsMsgCompose::GetABDirectories(const char * dirUri, nsISupportsArray* directoriesArray, PRBool searchSubDirectory) @@ -2983,7 +3017,7 @@ nsresult nsMsgCompose::GetABDirectories(const char * dirUri, nsISupportsArray* d collectedAddressbookFound = PR_FALSE; nsresult rv = NS_OK; - nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); + nsCOMPtr rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); if (NS_FAILED(rv)) return rv; nsCOMPtr resource; @@ -2998,13 +3032,13 @@ nsresult nsMsgCompose::GetABDirectories(const char * dirUri, nsISupportsArray* d return rv; nsCOMPtr subDirectories; - if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) - { - nsCOMPtr item; - if (NS_SUCCEEDED(subDirectories->First())) - { - do - { + if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) + { + nsCOMPtr item; + if (NS_SUCCEEDED(subDirectories->First())) + { + do + { if (NS_SUCCEEDED(subDirectories->CurrentItem(getter_AddRefs(item)))) { directory = do_QueryInterface(item, &rv); @@ -3015,8 +3049,8 @@ nsresult nsMsgCompose::GetABDirectories(const char * dirUri, nsISupportsArray* d if (NS_SUCCEEDED(directory->GetIsMailList(&bIsMailList)) && bIsMailList) continue; - nsCOMPtr source(do_QueryInterface(directory)); - + nsCOMPtr source(do_QueryInterface(directory)); + nsXPIDLCString uri; // rv = directory->GetDirUri(getter_Copies(uri)); rv = source->GetValue(getter_Copies(uri)); @@ -3061,13 +3095,13 @@ nsresult nsMsgCompose::BuildMailListArray(nsIAddrDatabase* database, nsIAbDirect nsCOMPtr directory; nsCOMPtr subDirectories; - if (NS_SUCCEEDED(parentDir->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) - { - nsCOMPtr item; - if (NS_SUCCEEDED(subDirectories->First())) - { - do - { + if (NS_SUCCEEDED(parentDir->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) + { + nsCOMPtr item; + if (NS_SUCCEEDED(subDirectories->First())) + { + do + { if (NS_SUCCEEDED(subDirectories->CurrentItem(getter_AddRefs(item)))) { directory = do_QueryInterface(item, &rv); @@ -3136,7 +3170,7 @@ nsresult nsMsgCompose::GetMailListAddresses(nsString& name, nsISupportsArray* ma } -#define MAX_OF_RECIPIENT_ARRAY 3 +#define MAX_OF_RECIPIENT_ARRAY 3 NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBool returnNonHTMLRecipients, PRUnichar **nonHTMLRecipients, PRUint32 *_retval) { @@ -3156,24 +3190,24 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, /* First, build an array with original recipients */ nsCOMPtr recipientsList[MAX_OF_RECIPIENT_ARRAY]; - nsXPIDLString originalRecipients[MAX_OF_RECIPIENT_ARRAY]; - m_compFields->GetTo(getter_Copies(originalRecipients[0])); - m_compFields->GetCc(getter_Copies(originalRecipients[1])); - m_compFields->GetBcc(getter_Copies(originalRecipients[2])); + nsXPIDLString originalRecipients[MAX_OF_RECIPIENT_ARRAY]; + m_compFields->GetTo(getter_Copies(originalRecipients[0])); + m_compFields->GetCc(getter_Copies(originalRecipients[1])); + m_compFields->GetBcc(getter_Copies(originalRecipients[2])); nsCOMPtr addressArray; nsCOMPtr emailArray; - for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++) - { + for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++) + { if (originalRecipients[i].IsEmpty()) continue; rv = m_compFields->SplitRecipientsEx((const PRUnichar *)(originalRecipients[i]), getter_AddRefs(addressArray), getter_AddRefs(emailArray)); - if (NS_SUCCEEDED(rv)) - { + if (NS_SUCCEEDED(rv)) + { PRInt32 nbrRecipients; nsXPIDLString emailAddr; nsXPIDLString addr; - addressArray->GetCount(&nbrRecipients); + addressArray->GetCount(&nbrRecipients); recipientsList[i] = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); if (NS_FAILED(rv)) @@ -3199,10 +3233,10 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (NS_FAILED(rv)) return rv; } - } + } else return rv; - } + } /* Then look them up in the Addressbooks*/ @@ -3232,7 +3266,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, abDirectory = do_QueryInterface(item, &rv); if (NS_FAILED(rv)) return rv; - + nsCOMPtr source(do_QueryInterface(abDirectory)); nsXPIDLCString uri; @@ -3268,30 +3302,30 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRUint32 nbrAddresses = 0; for (mailListAddresses->Count(&nbrAddresses); nbrAddresses > 0; nbrAddresses --) { - item = getter_AddRefs(mailListAddresses->ElementAt(nbrAddresses - 1)); - existingCard = do_QueryInterface(item, &rv); - if (NS_FAILED(rv)) - return rv; + item = getter_AddRefs(mailListAddresses->ElementAt(nbrAddresses - 1)); + existingCard = do_QueryInterface(item, &rv); + if (NS_FAILED(rv)) + return rv; - nsXPIDLString pDisplayName; - nsXPIDLString pEmail; + nsXPIDLString pDisplayName; + nsXPIDLString pEmail; nsAutoString fullNameStr; PRBool bIsMailList; - rv = existingCard->GetIsMailList(&bIsMailList); - if (NS_FAILED(rv)) - return rv; + rv = existingCard->GetIsMailList(&bIsMailList); + if (NS_FAILED(rv)) + return rv; - rv = existingCard->GetDisplayName(getter_Copies(pDisplayName)); - if (NS_FAILED(rv)) - return rv; + rv = existingCard->GetDisplayName(getter_Copies(pDisplayName)); + if (NS_FAILED(rv)) + return rv; if (bIsMailList) rv = existingCard->GetNotes(getter_Copies(pEmail)); else rv = existingCard->GetPrimaryEmail(getter_Copies(pEmail)); - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) + return rv; if (parser) { @@ -3302,7 +3336,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (!fullAddress.IsEmpty()) { /* We need to convert back the result from UTF-8 to Unicode */ - (void)ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress.get(), fullNameStr); + (void)ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress.get(), fullNameStr); } } if (fullNameStr.IsEmpty()) @@ -3360,8 +3394,8 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, /* Then if we have a card for this email address */ nsCAutoString emailStr; emailStr.AssignWithConversion(recipient->mEmail); - rv = abDataBase->GetCardForEmailAddress(abDirectory, emailStr.get(), getter_AddRefs(existingCard)); - if (NS_SUCCEEDED(rv) && existingCard) + rv = abDataBase->GetCardForEmailAddress(abDirectory, emailStr.get(), getter_AddRefs(existingCard)); + if (NS_SUCCEEDED(rv) && existingCard) { recipient->mPreferFormat = nsIAbPreferMailFormat::unknown; rv = existingCard->GetPreferMailFormat(&recipient->mPreferFormat); @@ -3393,11 +3427,11 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (prefs) { nsXPIDLString str; - prefs->CopyUnicharPref("mailnews.plaintext_domains", getter_Copies(str)); - plaintextDomains = str; - prefs->CopyUnicharPref("mailnews.html_domains", getter_Copies(str)); - htmlDomains = str; - } + prefs->CopyUnicharPref("mailnews.plaintext_domains", getter_Copies(str)); + plaintextDomains = str; + prefs->CopyUnicharPref("mailnews.html_domains", getter_Copies(str)); + htmlDomains = str; + } *_retval = -1; for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++) @@ -3479,7 +3513,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (returnNonHTMLRecipients) *nonHTMLRecipients = ToNewUnicode(nonHtmlRecipientsStr); - return rv; + return rv; } nsresult nsMsgCompose::GetNoHtmlNewsgroups(const char *newsgroups, char **_retval) @@ -3898,9 +3932,9 @@ nsresult nsMsgCompose::SetSignature(nsIMsgIdentity *identity) nsresult nsMsgCompose::ResetNodeEventHandlers(nsIDOMNode *node) { - // Because event handler attributes set into a node before this node is inserted - // into the DOM are not recognised (in fact not compiled), we need to parsed again - // the whole node and reset event handlers. + // Because event handler attributes set into a node before this node is inserted + // into the DOM are not recognised (in fact not compiled), we need to parsed again + // the whole node and reset event handlers. nsresult rv; nsAutoString aStr; @@ -4026,7 +4060,7 @@ nsMsgMailList::nsMsgMailList(nsString listName, nsString listDescription, nsIAbD if (!fullAddress.IsEmpty()) { /* We need to convert back the result from UTF-8 to Unicode */ - (void)ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress, mFullName); + (void)ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), fullAddress, mFullName); } } diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp index bb6183a8938..99d2ac66038 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp @@ -108,7 +108,7 @@ nsMsgComposeService::nsMsgComposeService() mStartTime = PR_IntervalNow(); mPreviousTime = mStartTime; #endif - NS_INIT_REFCNT(); + NS_INIT_REFCNT(); } /* the following macro actually implement addref, release and query interface for our component. */ @@ -157,36 +157,36 @@ static nsresult openWindow( const char *chrome, nsIMsgComposeParams *params ) NS_IMETHODIMP nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, const char *originalMsgURI, - MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgIdentity * identity, nsIMsgWindow *aMsgWindow) + MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgIdentity * identity, nsIMsgWindow *aMsgWindow) { - nsresult rv; - - /* Actually, the only way to implement forward inline is to simulate a template message. - Maybe one day when we will have more time we can change that - */ + nsresult rv; + + /* Actually, the only way to implement forward inline is to simulate a template message. + Maybe one day when we will have more time we can change that + */ if (type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft || type == nsIMsgCompType::Template) - { + { nsCOMPtr pMsgDraft (do_CreateInstance(NS_MSGDRAFT_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && pMsgDraft) - { + { nsCAutoString uriToOpen(originalMsgURI); uriToOpen.Append("?fetchCompleteMessage=true"); - switch(type) - { - case nsIMsgCompType::ForwardInline: - rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_TRUE, aMsgWindow); - break; - case nsIMsgCompType::Draft: - rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_FALSE, aMsgWindow); - break; - case nsIMsgCompType::Template: - rv = pMsgDraft->OpenEditorTemplate(uriToOpen.get(), nsnull, identity, aMsgWindow); - break; - } - } - return rv; - } + switch(type) + { + case nsIMsgCompType::ForwardInline: + rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_TRUE, aMsgWindow); + break; + case nsIMsgCompType::Draft: + rv = pMsgDraft->OpenDraftMsg(uriToOpen.get(), nsnull, identity, PR_FALSE, aMsgWindow); + break; + case nsIMsgCompType::Template: + rv = pMsgDraft->OpenEditorTemplate(uriToOpen.get(), nsnull, identity, aMsgWindow); + break; + } + } + return rv; + } nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && pMsgComposeParams) @@ -198,8 +198,8 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, const ch pMsgComposeParams->SetFormat(format); pMsgComposeParams->SetIdentity(identity); - if (originalMsgURI && *originalMsgURI) - if (type == nsIMsgCompType::NewsPost) + if (originalMsgURI && *originalMsgURI) + if (type == nsIMsgCompType::NewsPost) { nsCAutoString newsURI(originalMsgURI); nsCAutoString group; @@ -217,8 +217,8 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, const ch pMsgCompFields->SetNewsgroups(group.get()); pMsgCompFields->SetNewshost(host.get()); - } - else + } + else pMsgComposeParams->SetOriginalMsgURI(originalMsgURI); pMsgComposeParams->SetComposeFields(pMsgCompFields); @@ -237,7 +237,7 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, const ch rv = openWindow(msgComposeWindowURL, pMsgComposeParams); } } - return rv; + return rv; } NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgComposeWindowURL, nsIURI * aURI) @@ -255,7 +255,6 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom nsXPIDLCString aBccPart; nsXPIDLCString aSubjectPart; nsXPIDLCString aBodyPart; - nsXPIDLCString aAttachmentPart; nsXPIDLCString aNewsgroup; aMailtoUrl->GetMessageContents(getter_Copies(aToPart), getter_Copies(aCcPart), @@ -263,7 +262,7 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom nsnull /* follow */, nsnull /* organization */, nsnull /* reply to part */, getter_Copies(aSubjectPart), getter_Copies(aBodyPart), nsnull /* html part */, - nsnull /* a ref part */, getter_Copies(aAttachmentPart), + nsnull /* a ref part */, nsnull /* attachment part */, nsnull /* priority */, getter_Copies(aNewsgroup), nsnull /* host */, &aPlainText); @@ -271,18 +270,29 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom if (aPlainText) format = nsIMsgCompFormat::PlainText; + nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && pMsgComposeParams) + { + pMsgComposeParams->SetType(nsIMsgCompType::MailToUrl); + pMsgComposeParams->SetFormat(format); + + + nsCOMPtr pMsgCompFields (do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv)); + if (pMsgCompFields) + { //ugghh more conversion work!!!! - rv = OpenComposeWindowWithValues(aMsgComposeWindowURL, - nsIMsgCompType::MailToUrl, - format, - NS_ConvertUTF8toUCS2(aToPart).get(), - NS_ConvertUTF8toUCS2(aCcPart).get(), - NS_ConvertUTF8toUCS2(aBccPart).get(), - aNewsgroup, - NS_ConvertUTF8toUCS2(aSubjectPart).get(), - NS_ConvertUTF8toUCS2(aBodyPart).get(), - aAttachmentPart, - nsnull); + pMsgCompFields->SetTo(NS_ConvertUTF8toUCS2(aToPart).get()); + pMsgCompFields->SetCc(NS_ConvertUTF8toUCS2(aCcPart).get()); + pMsgCompFields->SetBcc(NS_ConvertUTF8toUCS2(aBccPart).get()); + pMsgCompFields->SetNewsgroups(aNewsgroup); + pMsgCompFields->SetSubject(NS_ConvertUTF8toUCS2(aSubjectPart).get()); + pMsgCompFields->SetBody(NS_ConvertUTF8toUCS2(aBodyPart).get()); + + pMsgComposeParams->SetComposeFields(pMsgCompFields); + + rv = OpenComposeWindowWithParams(aMsgComposeWindowURL, pMsgComposeParams); + } + } } } @@ -290,42 +300,46 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom } nsresult nsMsgComposeService::OpenComposeWindowWithValues(const char *msgComposeWindowURL, - MSG_ComposeType type, - MSG_ComposeFormat format, - const PRUnichar *to, - const PRUnichar *cc, - const PRUnichar *bcc, - const char *newsgroups, - const PRUnichar *subject, - const PRUnichar *body, - const char *attachment, - nsIMsgIdentity *identity) + MSG_ComposeType type, + MSG_ComposeFormat format, + const PRUnichar *to, + const PRUnichar *cc, + const PRUnichar *bcc, + const char *newsgroups, + const PRUnichar *subject, + const PRUnichar *body, + const char *attachment, + nsIMsgIdentity *identity) { - nsresult rv; + NS_ASSERTION(0, "nsMsgComposeService::OpenComposeWindowWithValues is not supported anymore, use OpenComposeWindowWithParams instead\n"); + + nsresult rv; nsCOMPtr pCompFields (do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && pCompFields) { - if (to) {pCompFields->SetTo(to);} - if (cc) {pCompFields->SetCc(cc);} - if (bcc) {pCompFields->SetBcc(bcc);} - if (newsgroups) {pCompFields->SetNewsgroups(newsgroups);} - if (subject) {pCompFields->SetSubject(subject);} - if (attachment) {pCompFields->SetAttachments(attachment);} - if (body) {pCompFields->SetBody(body);} - - rv = OpenComposeWindowWithCompFields(msgComposeWindowURL, type, format, pCompFields, identity); + if (to) {pCompFields->SetTo(to);} + if (cc) {pCompFields->SetCc(cc);} + if (bcc) {pCompFields->SetBcc(bcc);} + if (newsgroups) {pCompFields->SetNewsgroups(newsgroups);} + if (subject) {pCompFields->SetSubject(subject);} +// if (attachment) {pCompFields->SetAttachments(attachment);} + if (body) {pCompFields->SetBody(body);} + + rv = OpenComposeWindowWithCompFields(msgComposeWindowURL, type, format, pCompFields, identity); } return rv; } nsresult nsMsgComposeService::OpenComposeWindowWithCompFields(const char *msgComposeWindowURL, - MSG_ComposeType type, - MSG_ComposeFormat format, - nsIMsgCompFields *compFields, - nsIMsgIdentity *identity) + MSG_ComposeType type, + MSG_ComposeFormat format, + nsIMsgCompFields *compFields, + nsIMsgIdentity *identity) { - nsresult rv; + NS_ASSERTION(0, "nsMsgComposeService::OpenComposeWindowWithCompFields is not supported anymore, use OpenComposeWindowWithParams instead\n"); + + nsresult rv; nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && pMsgComposeParams) @@ -344,11 +358,11 @@ nsresult nsMsgComposeService::OpenComposeWindowWithCompFields(const char *msgCom rv = openWindow(msgComposeWindowURL, pMsgComposeParams); } - return rv; + return rv; } nsresult nsMsgComposeService::OpenComposeWindowWithParams(const char *msgComposeWindowURL, - nsIMsgComposeParams *params) + nsIMsgComposeParams *params) { NS_ENSURE_ARG_POINTER(params); if(mLogComposePerformance) @@ -364,19 +378,19 @@ nsresult nsMsgComposeService::InitCompose(nsIDOMWindowInternal *aWindow, nsIMsgComposeParams *params, nsIMsgCompose **_retval) { - nsresult rv; - nsIMsgCompose * msgCompose = nsnull; - - rv = nsComponentManager::CreateInstance(kMsgComposeCID, nsnull, - NS_GET_IID(nsIMsgCompose), - (void **) &msgCompose); - if (NS_SUCCEEDED(rv) && msgCompose) - { - msgCompose->Initialize(aWindow, params); - *_retval = msgCompose; - } - - return rv; + nsresult rv; + nsIMsgCompose * msgCompose = nsnull; + + rv = nsComponentManager::CreateInstance(kMsgComposeCID, nsnull, + NS_GET_IID(nsIMsgCompose), + (void **) &msgCompose); + if (NS_SUCCEEDED(rv) && msgCompose) + { + msgCompose->Initialize(aWindow, params); + *_retval = msgCompose; + } + + return rv; } /* readonly attribute boolean logComposePerformance; */ diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index ef5c476a067..b68b2472693 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -118,25 +118,25 @@ enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) }; static char* NET_GetLocalFileFromURL(char *url) { - char * finalPath; - NS_ASSERTION(PL_strncasecmp(url, "file://", 7) == 0, "invalid url"); - finalPath = (char*)PR_Malloc(strlen(url)); - if (finalPath == nsnull) - return nsnull; - strcpy(finalPath, url+6+1); - return finalPath; + char * finalPath; + NS_ASSERTION(PL_strncasecmp(url, "file://", 7) == 0, "invalid url"); + finalPath = (char*)PR_Malloc(strlen(url)); + if (finalPath == nsnull) + return nsnull; + strcpy(finalPath, url+6+1); + return finalPath; } static char* NET_GetURLFromLocalFile(char *filename) { /* file:///0 */ - char * finalPath = (char*)PR_Malloc(strlen(filename) + 8 + 1); - if (finalPath == nsnull) - return nsnull; - finalPath[0] = 0; - strcat(finalPath, "file://"); - strcat(finalPath, filename); - return finalPath; + char * finalPath = (char*)PR_Malloc(strlen(filename) + 8 + 1); + if (finalPath == nsnull) + return nsnull; + finalPath[0] = 0; + strcat(finalPath, "file://"); + strcat(finalPath, filename); + return finalPath; } #endif /* XP_MAC */ @@ -163,41 +163,41 @@ nsMsgComposeAndSend::nsMsgComposeAndSend() : printf("CREATE nsMsgComposeAndSend: %x\n", this); #endif mGUINotificationEnabled = PR_TRUE; - mAbortInProcess = PR_FALSE; + mAbortInProcess = PR_FALSE; mLastErrorReported = NS_OK; mEditor = nsnull; mMultipartRelatedAttachmentCount = 0; - mCompFields = nsnull; /* Where to send the message once it's done */ + mCompFields = nsnull; /* Where to send the message once it's done */ mSendMailAlso = PR_FALSE; - mOutputFile = nsnull; + mOutputFile = nsnull; - m_dont_deliver_p = PR_FALSE; - m_deliver_mode = nsMsgDeliverNow; + m_dont_deliver_p = PR_FALSE; + m_deliver_mode = nsMsgDeliverNow; - m_attachments_only_p = PR_FALSE; - m_pre_snarfed_attachments_p = PR_FALSE; - m_digest_p = PR_FALSE; - m_be_synchronous_p = PR_FALSE; - m_crypto_closure = nsnull; - m_attachment1_type = 0; - m_attachment1_encoding = 0; - m_attachment1_encoder_data = nsnull; - m_attachment1_body = 0; - m_attachment1_body_length = 0; - m_attachment_count = 0; - m_attachment_pending_count = 0; - m_attachments = nsnull; - m_status = 0; - m_attachments_done_callback = nsnull; - m_plaintext = nsnull; - m_related_part = nsnull; + m_attachments_only_p = PR_FALSE; + m_pre_snarfed_attachments_p = PR_FALSE; + m_digest_p = PR_FALSE; + m_be_synchronous_p = PR_FALSE; + m_crypto_closure = nsnull; + m_attachment1_type = 0; + m_attachment1_encoding = 0; + m_attachment1_encoder_data = nsnull; + m_attachment1_body = 0; + m_attachment1_body_length = 0; + m_attachment_count = 0; + m_attachment_pending_count = 0; + m_attachments = nsnull; + m_status = 0; + m_attachments_done_callback = nsnull; + m_plaintext = nsnull; + m_related_part = nsnull; m_related_body_part = nsnull; mOriginalHTMLBody = nsnull; // These are for temp file creation and return mReturnFileSpec = nsnull; mTempFileSpec = nsnull; - mHTMLFileSpec = nsnull; + mHTMLFileSpec = nsnull; mCopyFileSpec = nsnull; mCopyFileSpec2 = nsnull; mCopyObj = nsnull; @@ -220,7 +220,7 @@ nsMsgComposeAndSend::~nsMsgComposeAndSend() printf("DISPOSE nsMsgComposeAndSend: %x\n", this); #endif mSendReport = nsnull; - Clear(); + Clear(); } NS_IMETHODIMP nsMsgComposeAndSend::GetDefaultPrompt(nsIPrompt ** aPrompt) @@ -282,43 +282,44 @@ nsMsgComposeAndSend::Clear() #ifdef NS_DEBUG printf("\nTHE CLEANUP ROUTINE FOR nsMsgComposeAndSend() WAS CALLED\n"); #endif - PR_FREEIF (m_attachment1_type); - PR_FREEIF (m_attachment1_encoding); - PR_FREEIF (m_attachment1_body); + PR_FREEIF (m_attachment1_type); + PR_FREEIF (m_attachment1_encoding); + PR_FREEIF (m_attachment1_body); PR_FREEIF (mOriginalHTMLBody); - if (m_attachment1_encoder_data) + if (m_attachment1_encoder_data) { - MIME_EncoderDestroy(m_attachment1_encoder_data, PR_TRUE); - m_attachment1_encoder_data = 0; - } + MIME_EncoderDestroy(m_attachment1_encoder_data, PR_TRUE); + m_attachment1_encoder_data = 0; + } - if (m_plaintext) + if (m_plaintext) { - if (m_plaintext->mOutFile) - m_plaintext->mOutFile->Close(); + if (m_plaintext->mOutFile) + m_plaintext->mOutFile->Close(); - if (m_plaintext->mFileSpec) + if (m_plaintext->mFileSpec) { - m_plaintext->mFileSpec->Delete(PR_TRUE); - delete m_plaintext->mFileSpec; + m_plaintext->mFileSpec->Delete(PR_FALSE); + delete m_plaintext->mFileSpec; + m_plaintext->mFileSpec = nsnull; } - delete m_plaintext; - m_plaintext = nsnull; - } + delete m_plaintext; + m_plaintext = nsnull; + } - if (mHTMLFileSpec) + if (mHTMLFileSpec) { - mHTMLFileSpec->Delete(PR_FALSE); - delete mHTMLFileSpec; - mHTMLFileSpec= nsnull; - } + mHTMLFileSpec->Delete(PR_FALSE); + delete mHTMLFileSpec; + mHTMLFileSpec= nsnull; + } - if (mOutputFile) + if (mOutputFile) { - delete mOutputFile; - mOutputFile = 0; - } + delete mOutputFile; + mOutputFile = 0; + } if (mCopyFileSpec) { @@ -350,67 +351,66 @@ nsMsgComposeAndSend::Clear() { mTempFileSpec->Delete(PR_FALSE); delete mTempFileSpec; - mTempFileSpec = nsnull; + mTempFileSpec = nsnull; } - } + } - if (m_attachments) - { - PRUint32 i; - for (i = 0; i < m_attachment_count; i++) + if (m_attachments) + { + PRUint32 i; + for (i = 0; i < m_attachment_count; i++) { - if (m_attachments [i].m_encoder_data) + if (m_attachments [i].m_encoder_data) { - MIME_EncoderDestroy(m_attachments[i].m_encoder_data, PR_TRUE); - m_attachments [i].m_encoder_data = 0; - } + MIME_EncoderDestroy(m_attachments[i].m_encoder_data, PR_TRUE); + m_attachments [i].m_encoder_data = 0; + } - if (m_attachments[i].mURL) + if (m_attachments[i].mURL) { NS_RELEASE(m_attachments[i].mURL); m_attachments[i].mURL = nsnull; } - PR_FREEIF (m_attachments [i].m_type); - PR_FREEIF (m_attachments [i].m_charset); - PR_FREEIF (m_attachments [i].m_override_type); - PR_FREEIF (m_attachments [i].m_override_encoding); - PR_FREEIF (m_attachments [i].m_desired_type); - PR_FREEIF (m_attachments [i].m_description); - PR_FREEIF (m_attachments [i].m_x_mac_type); - PR_FREEIF (m_attachments [i].m_x_mac_creator); - PR_FREEIF (m_attachments [i].m_real_name); - PR_FREEIF (m_attachments [i].m_encoding); - PR_FREEIF (m_attachments [i].m_content_id); - if (m_attachments[i].mOutFile) + PR_FREEIF (m_attachments [i].m_type); + PR_FREEIF (m_attachments [i].m_charset); + PR_FREEIF (m_attachments [i].m_override_type); + PR_FREEIF (m_attachments [i].m_override_encoding); + PR_FREEIF (m_attachments [i].m_desired_type); + PR_FREEIF (m_attachments [i].m_description); + PR_FREEIF (m_attachments [i].m_x_mac_type); + PR_FREEIF (m_attachments [i].m_x_mac_creator); + PR_FREEIF (m_attachments [i].m_real_name); + PR_FREEIF (m_attachments [i].m_encoding); + PR_FREEIF (m_attachments [i].m_content_id); + if (m_attachments[i].mOutFile) m_attachments[i].mOutFile->Close(); - if (m_attachments[i].mFileSpec) + if (m_attachments[i].mFileSpec) { // Only Delete the file if this variable is set! if (m_attachments[i].mDeleteFile) - m_attachments[i].mFileSpec->Delete(PR_FALSE); - - delete m_attachments[i].mFileSpec; + m_attachments[i].mFileSpec->Delete(PR_FALSE); + delete m_attachments[i].mFileSpec; m_attachments[i].mFileSpec = nsnull; - } + } #ifdef XP_MAC - // + // // remove the appledoubled intermediate file after we done all. - // - if (m_attachments[i].mAppleFileSpec) + // + if (m_attachments[i].mAppleFileSpec) { - m_attachments[i].mAppleFileSpec->Delete(PR_FALSE); - delete m_attachments[i].mAppleFileSpec; + m_attachments[i].mAppleFileSpec->Delete(PR_FALSE); + delete m_attachments[i].mAppleFileSpec; m_attachments[i].mAppleFileSpec = nsnull; - } + } #endif /* XP_MAC */ - } + } - delete[] m_attachments; - m_attachment_count = m_attachment_pending_count = 0; - m_attachments = 0; - } + delete[] m_attachments; + m_attachment_count = m_attachment_pending_count = 0; + m_attachments = 0; + } // Cleanup listener mListener = nsnull; @@ -422,9 +422,9 @@ static char *mime_mailto_stream_write_buffer = 0; char * mime_get_stream_write_buffer(void) { - if (!mime_mailto_stream_write_buffer) - mime_mailto_stream_write_buffer = (char *) PR_Malloc(MIME_BUFFER_SIZE); - return mime_mailto_stream_write_buffer; + if (!mime_mailto_stream_write_buffer) + mime_mailto_stream_write_buffer = (char *) PR_Malloc(MIME_BUFFER_SIZE); + return mime_mailto_stream_write_buffer; } // Don't I18N this line...this is per the spec! @@ -438,144 +438,144 @@ char * mime_get_stream_write_buffer(void) NS_IMETHODIMP nsMsgComposeAndSend::GatherMimeAttachments() { - PRBool shouldDeleteDeliveryState = PR_TRUE; - PRInt32 status; + PRBool shouldDeleteDeliveryState = PR_TRUE; + PRInt32 status; PRUint32 i; - char *headers = 0; - PRFileDesc *in_file = 0; - PRBool multipart_p = PR_FALSE; - PRBool plaintext_is_mainbody_p = PR_FALSE; // only using text converted from HTML? - char *buffer = 0; - char *buffer_tail = 0; + char *headers = 0; + PRFileDesc *in_file = 0; + PRBool multipart_p = PR_FALSE; + PRBool plaintext_is_mainbody_p = PR_FALSE; // only using text converted from HTML? + char *buffer = 0; + char *buffer_tail = 0; nsXPIDLString msg; PRBool tonews; nsMsgSendPart *mpartcontainer = nsnull; - nsMsgSendPart* toppart = nsnull; // The very top most container of the message - // that we are going to send. + nsMsgSendPart* toppart = nsnull; // The very top most container of the message + // that we are going to send. - nsMsgSendPart* mainbody = nsnull; // The leaf node that contains the text of the - // message we're going to contain. + nsMsgSendPart* mainbody = nsnull; // The leaf node that contains the text of the + // message we're going to contain. - nsMsgSendPart* maincontainer = nsnull; // The direct child of toppart that will - // contain the mainbody. If mainbody is - // the same as toppart, then this is - // also the same. But if mainbody is - // to end up somewhere inside of a - // multipart/alternative or a - // multipart/related, then this is that - // multipart object. + nsMsgSendPart* maincontainer = nsnull; // The direct child of toppart that will + // contain the mainbody. If mainbody is + // the same as toppart, then this is + // also the same. But if mainbody is + // to end up somewhere inside of a + // multipart/alternative or a + // multipart/related, then this is that + // multipart object. - nsMsgSendPart* plainpart = nsnull; // If we converted HTML into plaintext, - // the message or child containing the plaintext - // goes here. (Need to use this to determine - // what headers to append/set to the main - // message body.) + nsMsgSendPart* plainpart = nsnull; // If we converted HTML into plaintext, + // the message or child containing the plaintext + // goes here. (Need to use this to determine + // what headers to append/set to the main + // message body.) nsCOMPtr promptObject; // only used if we have to show an alert here.... GetDefaultPrompt(getter_AddRefs(promptObject)); - char *hdrs = 0; - PRBool maincontainerISrelatedpart = PR_FALSE; + char *hdrs = 0; + PRBool maincontainerISrelatedpart = PR_FALSE; // If we have any attachments, we generate multipart. - multipart_p = (m_attachment_count > 0); + multipart_p = (m_attachment_count > 0); // to news is true if we have a m_field and we have a Newsgroup and it is not empty - tonews = PR_FALSE; - if (mCompFields) + tonews = PR_FALSE; + if (mCompFields) { - const char* pstrzNewsgroup = mCompFields->GetNewsgroups(); - if (pstrzNewsgroup && *pstrzNewsgroup) - tonews = PR_TRUE; - } + const char* pstrzNewsgroup = mCompFields->GetNewsgroups(); + if (pstrzNewsgroup && *pstrzNewsgroup) + tonews = PR_TRUE; + } - status = m_status; - if (status < 0) - goto FAIL; + status = m_status; + if (status < 0) + goto FAIL; - if (m_attachments_only_p) - { - /* If we get here, we should be fetching attachments only! */ - if (m_attachments_done_callback) + if (m_attachments_only_p) + { + /* If we get here, we should be fetching attachments only! */ + if (m_attachments_done_callback) { - struct nsMsgAttachedFile *attachments; + struct nsMsgAttachedFile *attachments; - NS_ASSERTION(m_attachment_count > 0, "not more attachment"); - if (m_attachment_count <= 0) + NS_ASSERTION(m_attachment_count > 0, "not more attachment"); + if (m_attachment_count <= 0) { - m_attachments_done_callback (nsnull, nsnull, nsnull); - m_attachments_done_callback = nsnull; - goto FAIL; - } + m_attachments_done_callback (nsnull, nsnull, nsnull); + m_attachments_done_callback = nsnull; + goto FAIL; + } - attachments = (struct nsMsgAttachedFile *)PR_Malloc((m_attachment_count + 1) * sizeof(*attachments)); + attachments = (struct nsMsgAttachedFile *)PR_Malloc((m_attachment_count + 1) * sizeof(*attachments)); - if (!attachments) - goto FAILMEM; - memset(attachments, 0, ((m_attachment_count + 1) * sizeof(*attachments))); - for (i = 0; i < m_attachment_count; i++) - { - nsMsgAttachmentHandler *ma = &m_attachments[i]; + if (!attachments) + goto FAILMEM; + memset(attachments, 0, ((m_attachment_count + 1) * sizeof(*attachments))); + for (i = 0; i < m_attachment_count; i++) + { + nsMsgAttachmentHandler *ma = &m_attachments[i]; #undef SNARF #define SNARF(x,y) do { if((y) && *(y) && !(x)) { ((x) = (y)); ((y) = 0); }} \ - while(0) - // Rather than copying the strings and dealing with allocation - // failures, we'll just "move" them into the other struct (this - // should be ok since this file uses PR_FREEIF when discarding - // the mime_attachment objects.) + while(0) + // Rather than copying the strings and dealing with allocation + // failures, we'll just "move" them into the other struct (this + // should be ok since this file uses PR_FREEIF when discarding + // the mime_attachment objects.) // - attachments[i].orig_url = ma->mURL; - attachments[i].file_spec = ma->mFileSpec; + attachments[i].orig_url = ma->mURL; + attachments[i].file_spec = ma->mFileSpec; - SNARF(attachments[i].type, ma->m_type); - SNARF(attachments[i].encoding, ma->m_encoding); - SNARF(attachments[i].description, ma->m_description); - SNARF(attachments[i].x_mac_type, ma->m_x_mac_type); - SNARF(attachments[i].x_mac_creator, ma->m_x_mac_creator); + SNARF(attachments[i].type, ma->m_type); + SNARF(attachments[i].encoding, ma->m_encoding); + SNARF(attachments[i].description, ma->m_description); + SNARF(attachments[i].x_mac_type, ma->m_x_mac_type); + SNARF(attachments[i].x_mac_creator, ma->m_x_mac_creator); #undef SNARF - attachments[i].size = ma->m_size; - attachments[i].unprintable_count = ma->m_unprintable_count; - attachments[i].highbit_count = ma->m_highbit_count; - attachments[i].ctl_count = ma->m_ctl_count; - attachments[i].null_count = ma->m_null_count; - attachments[i].max_line_length = ma->m_max_column; + attachments[i].size = ma->m_size; + attachments[i].unprintable_count = ma->m_unprintable_count; + attachments[i].highbit_count = ma->m_highbit_count; + attachments[i].ctl_count = ma->m_ctl_count; + attachments[i].null_count = ma->m_null_count; + attachments[i].max_line_length = ma->m_max_column; - /* Doesn't really matter, but let's not lie about encoding - in case it does someday. */ - if (attachments[i].highbit_count > 0 && attachments[i].encoding && - !PL_strcasecmp(attachments[i].encoding, ENCODING_7BIT)) - attachments[i].encoding = ENCODING_8BIT; - } + /* Doesn't really matter, but let's not lie about encoding + in case it does someday. */ + if (attachments[i].highbit_count > 0 && attachments[i].encoding && + !PL_strcasecmp(attachments[i].encoding, ENCODING_7BIT)) + attachments[i].encoding = ENCODING_8BIT; + } - m_attachments_done_callback(nsnull, nsnull, attachments); - PR_FREEIF(attachments); - m_attachments_done_callback = nsnull; - } - goto FAIL; - } + m_attachments_done_callback(nsnull, nsnull, attachments); + PR_FREEIF(attachments); + m_attachments_done_callback = nsnull; + } + goto FAIL; + } - /* If we get here, we're generating a message, so there shouldn't be an - attachments callback. */ - NS_ASSERTION(!m_attachments_done_callback, "shouldn't have an attachement callback!"); + /* If we get here, we're generating a message, so there shouldn't be an + attachments callback. */ + NS_ASSERTION(!m_attachments_done_callback, "shouldn't have an attachement callback!"); - if (!m_attachment1_type) { - m_attachment1_type = PL_strdup(TEXT_PLAIN); - if (!m_attachment1_type) - goto FAILMEM; - } + if (!m_attachment1_type) { + m_attachment1_type = PL_strdup(TEXT_PLAIN); + if (!m_attachment1_type) + goto FAILMEM; + } - // If we have a text/html main part, and we need a plaintext attachment, then - // we'll do so now. This is an asynchronous thing, so we'll kick it off and - // count on getting back here when it finishes. + // If we have a text/html main part, and we need a plaintext attachment, then + // we'll do so now. This is an asynchronous thing, so we'll kick it off and + // count on getting back here when it finishes. - if (m_plaintext == nsnull && - (mCompFields->GetForcePlainText() || - mCompFields->GetUseMultipartAlternative()) && - m_attachment1_body && PL_strcmp(m_attachment1_type, TEXT_HTML) == 0) - { + if (m_plaintext == nsnull && + (mCompFields->GetForcePlainText() || + mCompFields->GetUseMultipartAlternative()) && + m_attachment1_body && PL_strcmp(m_attachment1_type, TEXT_HTML) == 0) + { // // If we get here, we have an HTML body, but we really need to send // a text/plain message, so we will write the HTML out to a disk file, @@ -583,11 +583,11 @@ nsMsgComposeAndSend::GatherMimeAttachments() // take care of the conversion... // mHTMLFileSpec = nsMsgCreateTempFileSpec("nsmail.html"); - if (!mHTMLFileSpec) - goto FAILMEM; + if (!mHTMLFileSpec) + goto FAILMEM; - nsOutputFileStream tempfile(*mHTMLFileSpec, kDefaultMode, 00600); - if (! tempfile.is_open()) + nsOutputFileStream tempfile(*mHTMLFileSpec, kDefaultMode, 00600); + if (! tempfile.is_open()) { if (mSendReport) { @@ -597,35 +597,35 @@ nsMsgComposeAndSend::GatherMimeAttachments() nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } - status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; - goto FAIL; - } + status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; + goto FAIL; + } if (mOriginalHTMLBody) { PRUint32 origLen = nsCRT::strlen(mOriginalHTMLBody); status = tempfile.write(mOriginalHTMLBody, origLen); - if (status < int(origLen)) + if (status < int(origLen)) { - if (status >= 0) - status = NS_MSG_ERROR_WRITING_FILE; - goto FAIL; - } + if (status >= 0) + status = NS_MSG_ERROR_WRITING_FILE; + goto FAIL; + } } if (NS_FAILED(tempfile.flush()) || tempfile.failed()) { - status = NS_MSG_ERROR_WRITING_FILE; + status = NS_MSG_ERROR_WRITING_FILE; goto FAIL; } tempfile.close(); - m_plaintext = new nsMsgAttachmentHandler; - if (!m_plaintext) - goto FAILMEM; - m_plaintext->SetMimeDeliveryState(this); - m_plaintext->m_bogus_attachment = PR_TRUE; + m_plaintext = new nsMsgAttachmentHandler; + if (!m_plaintext) + goto FAILMEM; + m_plaintext->SetMimeDeliveryState(this); + m_plaintext->m_bogus_attachment = PR_TRUE; char *tempURL = nsMsgPlatformFileToURL (*mHTMLFileSpec); if (!tempURL || NS_FAILED(nsMsgNewURL(&(m_plaintext->mURL), tempURL))) @@ -638,42 +638,42 @@ nsMsgComposeAndSend::GatherMimeAttachments() NS_IF_ADDREF(m_plaintext->mURL); PR_FREEIF(tempURL); - PR_FREEIF(m_plaintext->m_type); - m_plaintext->m_type = PL_strdup(TEXT_HTML); - PR_FREEIF(m_plaintext->m_charset); - m_plaintext->m_charset = PL_strdup(mCompFields->GetCharacterSet()); - PR_FREEIF(m_plaintext->m_desired_type); - m_plaintext->m_desired_type = PL_strdup(TEXT_PLAIN); - m_attachment_pending_count ++; - status = m_plaintext->SnarfAttachment(mCompFields); - if (status < 0) - goto FAIL; - if (m_attachment_pending_count > 0) - return NS_OK; - } - - /* Kludge to avoid having to allocate memory on the toy computers... */ - buffer = mime_get_stream_write_buffer(); - if (! buffer) - goto FAILMEM; + PR_FREEIF(m_plaintext->m_type); + m_plaintext->m_type = PL_strdup(TEXT_HTML); + PR_FREEIF(m_plaintext->m_charset); + m_plaintext->m_charset = PL_strdup(mCompFields->GetCharacterSet()); + PR_FREEIF(m_plaintext->m_desired_type); + m_plaintext->m_desired_type = PL_strdup(TEXT_PLAIN); + m_attachment_pending_count ++; + status = m_plaintext->SnarfAttachment(mCompFields); + if (status < 0) + goto FAIL; + if (m_attachment_pending_count > 0) + return NS_OK; + } + + /* Kludge to avoid having to allocate memory on the toy computers... */ + buffer = mime_get_stream_write_buffer(); + if (! buffer) + goto FAILMEM; - buffer_tail = buffer; + buffer_tail = buffer; - NS_ASSERTION (m_attachment_pending_count == 0, "m_attachment_pending_count != 0"); + NS_ASSERTION (m_attachment_pending_count == 0, "m_attachment_pending_count != 0"); mComposeBundle->GetStringByID(NS_MSG_ASSEMBLING_MSG, getter_Copies(msg)); SetStatusMessage( msg ); - /* First, open the message file. - */ - mTempFileSpec = nsMsgCreateTempFileSpec("nsmail.eml"); - if (! mTempFileSpec) - goto FAILMEM; + /* First, open the message file. + */ + mTempFileSpec = nsMsgCreateTempFileSpec("nsmail.eml"); + if (! mTempFileSpec) + goto FAILMEM; mOutputFile = new nsOutputFileStream(*mTempFileSpec, kDefaultMode, 00600); - if (! mOutputFile->is_open() || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_4)) + if (! mOutputFile->is_open() || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_4)) { - status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; + status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; if (mSendReport) { nsAutoString error_msg; @@ -682,34 +682,34 @@ nsMsgComposeAndSend::GatherMimeAttachments() nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } - goto FAIL; - } + goto FAIL; + } - if (mCompFields->GetMessageId() == nsnull || *mCompFields->GetMessageId() == 0) - { - char * msgID = msg_generate_message_id(mUserIdentity); - mCompFields->SetMessageId(msgID); - PR_FREEIF(msgID); - } + if (mCompFields->GetMessageId() == nsnull || *mCompFields->GetMessageId() == 0) + { + char * msgID = msg_generate_message_id(mUserIdentity); + mCompFields->SetMessageId(msgID); + PR_FREEIF(msgID); + } - mainbody = new nsMsgSendPart(this, mCompFields->GetCharacterSet()); - if (!mainbody) - goto FAILMEM; + mainbody = new nsMsgSendPart(this, mCompFields->GetCharacterSet()); + if (!mainbody) + goto FAILMEM; - mainbody->SetMainPart(PR_TRUE); - mainbody->SetType(m_attachment1_type ? m_attachment1_type : TEXT_PLAIN); + mainbody->SetMainPart(PR_TRUE); + mainbody->SetType(m_attachment1_type ? m_attachment1_type : TEXT_PLAIN); - NS_ASSERTION(mainbody->GetBuffer() == nsnull, "not-null buffer"); - status = mainbody->SetBuffer(m_attachment1_body ? m_attachment1_body : ""); - if (status < 0) - goto FAIL; + NS_ASSERTION(mainbody->GetBuffer() == nsnull, "not-null buffer"); + status = mainbody->SetBuffer(m_attachment1_body ? m_attachment1_body : ""); + if (status < 0) + goto FAIL; - /* - Determine the encoding of the main message body before we free it. - The proper way to do this should be to test whatever text is in mainbody - just before writing it out, but that will require a fix that is less safe - and takes more memory. */ - PR_FREEIF(m_attachment1_encoding); + /* + Determine the encoding of the main message body before we free it. + The proper way to do this should be to test whatever text is in mainbody + just before writing it out, but that will require a fix that is less safe + and takes more memory. */ + PR_FREEIF(m_attachment1_encoding); // Check if the part contains 7 bit only. Re-label charset if necessary. PRBool body_is_us_ascii; @@ -720,94 +720,94 @@ nsMsgComposeAndSend::GatherMimeAttachments() body_is_us_ascii = mime_7bit_data_p (m_attachment1_body, m_attachment1_body_length); } - if (nsMsgI18Nstateful_charset(mCompFields->GetCharacterSet()) || - body_is_us_ascii) - m_attachment1_encoding = PL_strdup (ENCODING_7BIT); - else if (mime_use_quoted_printable_p) - m_attachment1_encoding = PL_strdup (ENCODING_QUOTED_PRINTABLE); - else - m_attachment1_encoding = PL_strdup (ENCODING_8BIT); + if (nsMsgI18Nstateful_charset(mCompFields->GetCharacterSet()) || + body_is_us_ascii) + m_attachment1_encoding = PL_strdup (ENCODING_7BIT); + else if (mime_use_quoted_printable_p) + m_attachment1_encoding = PL_strdup (ENCODING_QUOTED_PRINTABLE); + else + m_attachment1_encoding = PL_strdup (ENCODING_8BIT); - PR_FREEIF (m_attachment1_body); + PR_FREEIF (m_attachment1_body); - maincontainer = mainbody; + maincontainer = mainbody; - // If we were given a pre-saved collection of HTML and contained images, - // then we want mainbody to point to the HTML lump therein. - if (m_related_part) - { - // If m_related_part is of type text/html, set both maincontainer - // and mainbody to point to it. If m_related_part is multipart/related, - // however, set mainbody to be the first child within m_related_part. - delete mainbody; + // If we were given a pre-saved collection of HTML and contained images, + // then we want mainbody to point to the HTML lump therein. + if (m_related_part) + { + // If m_related_part is of type text/html, set both maincontainer + // and mainbody to point to it. If m_related_part is multipart/related, + // however, set mainbody to be the first child within m_related_part. + delete mainbody; - // No matter what, maincontainer points to the outermost related part. - maincontainer = m_related_part; - maincontainerISrelatedpart = PR_TRUE; + // No matter what, maincontainer points to the outermost related part. + maincontainer = m_related_part; + maincontainerISrelatedpart = PR_TRUE; - const char *relPartType = m_related_part->GetType(); - if (relPartType && !strcmp(relPartType, MULTIPART_RELATED)) - // outer shell is m/related, - // mainbody wants to be the HTML lump within - mainbody = m_related_part->GetChild(0); - else - // outer shell is text/html, - // so mainbody wants to be the same lump - mainbody = maincontainer; + const char *relPartType = m_related_part->GetType(); + if (relPartType && !strcmp(relPartType, MULTIPART_RELATED)) + // outer shell is m/related, + // mainbody wants to be the HTML lump within + mainbody = m_related_part->GetChild(0); + else + // outer shell is text/html, + // so mainbody wants to be the same lump + mainbody = maincontainer; - mainbody->SetMainPart(PR_TRUE); - } + mainbody->SetMainPart(PR_TRUE); + } - if (m_plaintext) + if (m_plaintext) { // - // OK. We have a plaintext version of the main body that we want to - // send instead of or with the text/html. Shove it in. + // OK. We have a plaintext version of the main body that we want to + // send instead of or with the text/html. Shove it in. // - plainpart = new nsMsgSendPart(this, mCompFields->GetCharacterSet()); - if (!plainpart) - goto FAILMEM; - status = plainpart->SetType(TEXT_PLAIN); - if (status < 0) - goto FAIL; - status = plainpart->SetFile(m_plaintext->mFileSpec); - if (status < 0) - goto FAIL; + plainpart = new nsMsgSendPart(this, mCompFields->GetCharacterSet()); + if (!plainpart) + goto FAILMEM; + status = plainpart->SetType(TEXT_PLAIN); + if (status < 0) + goto FAIL; + status = plainpart->SetFile(m_plaintext->mFileSpec); + if (status < 0) + goto FAIL; m_plaintext->mMainBody = PR_TRUE; m_plaintext->AnalyzeSnarfedFile(); // look for 8 bit text, long lines, etc. - m_plaintext->PickEncoding(mCompFields->GetCharacterSet(), this); - hdrs = mime_generate_attachment_headers(m_plaintext->m_type, - m_plaintext->m_encoding, - m_plaintext->m_description, - m_plaintext->m_x_mac_type, - m_plaintext->m_x_mac_creator, - nsnull, 0, - m_digest_p, - m_plaintext, - mCompFields->GetCharacterSet(), + m_plaintext->PickEncoding(mCompFields->GetCharacterSet(), this); + hdrs = mime_generate_attachment_headers(m_plaintext->m_type, + m_plaintext->m_encoding, + m_plaintext->m_description, + m_plaintext->m_x_mac_type, + m_plaintext->m_x_mac_creator, + nsnull, 0, + m_digest_p, + m_plaintext, + mCompFields->GetCharacterSet(), nsnull, PR_TRUE); - if (!hdrs) - goto FAILMEM; - status = plainpart->SetOtherHeaders(hdrs); - PR_Free(hdrs); - hdrs = nsnull; - if (status < 0) - goto FAIL; + if (!hdrs) + goto FAILMEM; + status = plainpart->SetOtherHeaders(hdrs); + PR_Free(hdrs); + hdrs = nsnull; + if (status < 0) + goto FAIL; - if (mCompFields->GetUseMultipartAlternative()) + if (mCompFields->GetUseMultipartAlternative()) { - nsMsgSendPart* htmlpart = maincontainer; - maincontainer = new nsMsgSendPart(this); - if (!maincontainer) - goto FAILMEM; + nsMsgSendPart* htmlpart = maincontainer; + maincontainer = new nsMsgSendPart(this); + if (!maincontainer) + goto FAILMEM; // Setup the maincontainer stuff... status = maincontainer->SetType(MULTIPART_ALTERNATIVE); if (status < 0) - goto FAIL; + goto FAIL; // Only create multipart related if its really necessary... if (mMultipartRelatedAttachmentCount > 0) @@ -816,92 +816,92 @@ nsMsgComposeAndSend::GatherMimeAttachments() if (!mpartcontainer) goto FAILMEM; - status = mpartcontainer->SetType(MULTIPART_RELATED); - if (status < 0) - goto FAIL; + status = mpartcontainer->SetType(MULTIPART_RELATED); + if (status < 0) + goto FAIL; - status = mpartcontainer->AddChild(htmlpart); - if (status < 0) - goto FAIL; + status = mpartcontainer->AddChild(htmlpart); + if (status < 0) + goto FAIL; // Hang stuff off of the maincontainer... status = maincontainer->AddChild(plainpart); - if (status < 0) - goto FAIL; + if (status < 0) + goto FAIL; status = maincontainer->AddChild(mpartcontainer); - if (status < 0) - goto FAIL; + if (status < 0) + goto FAIL; } else // Just a single HTML doc for the HTML mail { status = maincontainer->AddChild(plainpart); - if (status < 0) - goto FAIL; + if (status < 0) + goto FAIL; status = maincontainer->AddChild(htmlpart); - if (status < 0) - goto FAIL; + if (status < 0) + goto FAIL; } - // Create the encoder for the plaintext part here, - // because we aren't the main part (attachment1). - // (This, along with the rest of the routine, should really - // be restructured so that no special treatment is given to - // the main body text that came in. Best to put attachment1_text - // etc. into a nsMsgSendPart, then reshuffle the parts. Sigh.) - if (!PL_strcasecmp(m_plaintext->m_encoding, ENCODING_QUOTED_PRINTABLE)) - { - MimeEncoderData *plaintext_enc = MIME_QPEncoderInit(mime_encoder_output_fn, this); - if (!plaintext_enc) - { - status = NS_ERROR_OUT_OF_MEMORY; - goto FAIL; - } - plainpart->SetEncoderData(plaintext_enc); - } - } - else + // Create the encoder for the plaintext part here, + // because we aren't the main part (attachment1). + // (This, along with the rest of the routine, should really + // be restructured so that no special treatment is given to + // the main body text that came in. Best to put attachment1_text + // etc. into a nsMsgSendPart, then reshuffle the parts. Sigh.) + if (!PL_strcasecmp(m_plaintext->m_encoding, ENCODING_QUOTED_PRINTABLE)) + { + MimeEncoderData *plaintext_enc = MIME_QPEncoderInit(mime_encoder_output_fn, this); + if (!plaintext_enc) + { + status = NS_ERROR_OUT_OF_MEMORY; + goto FAIL; + } + plainpart->SetEncoderData(plaintext_enc); + } + } + else { - delete maincontainer; - if (maincontainerISrelatedpart) - m_related_part = nsnull; - maincontainer = plainpart; - mainbody = maincontainer; - PR_FREEIF(m_attachment1_type); - m_attachment1_type = PL_strdup(TEXT_PLAIN); - if (!m_attachment1_type) - goto FAILMEM; + delete maincontainer; + if (maincontainerISrelatedpart) + m_related_part = nsnull; + maincontainer = plainpart; + mainbody = maincontainer; + PR_FREEIF(m_attachment1_type); + m_attachment1_type = PL_strdup(TEXT_PLAIN); + if (!m_attachment1_type) + goto FAILMEM; - /* Override attachment1_encoding here. */ - PR_FREEIF(m_attachment1_encoding); - m_attachment1_encoding = PL_strdup(m_plaintext->m_encoding); + /* Override attachment1_encoding here. */ + PR_FREEIF(m_attachment1_encoding); + m_attachment1_encoding = PL_strdup(m_plaintext->m_encoding); - plaintext_is_mainbody_p = PR_TRUE; // converted plaintext is mainbody - } - } + plaintext_is_mainbody_p = PR_TRUE; // converted plaintext is mainbody + } + } - if ( (multipart_p && (!mCompFields->GetUseMultipartAlternative())) || + if ( (multipart_p && (!mCompFields->GetUseMultipartAlternative())) || mCompFields->GetUseMultipartAlternative() && (m_attachment_count > mMultipartRelatedAttachmentCount) ) { - toppart = new nsMsgSendPart(this); - if (!toppart) - goto FAILMEM; + toppart = new nsMsgSendPart(this); + if (!toppart) + goto FAILMEM; // This is JUST multpart related! if ( (mMultipartRelatedAttachmentCount > 0) && (m_attachment_count == mMultipartRelatedAttachmentCount) ) - status = toppart->SetType(MULTIPART_RELATED); + status = toppart->SetType(MULTIPART_RELATED); else - status = toppart->SetType(m_digest_p ? MULTIPART_DIGEST : MULTIPART_MIXED); + status = toppart->SetType(m_digest_p ? MULTIPART_DIGEST : MULTIPART_MIXED); - if (status < 0) - goto FAIL; + if (status < 0) + goto FAIL; - status = toppart->AddChild(maincontainer); - if (status < 0) - goto FAIL; + status = toppart->AddChild(maincontainer); + if (status < 0) + goto FAIL; if (m_attachment_count > mMultipartRelatedAttachmentCount) { @@ -909,115 +909,115 @@ nsMsgComposeAndSend::GatherMimeAttachments() } if (status < 0) goto FAIL; - } - else + } + else { - toppart = maincontainer; + toppart = maincontainer; } /* Write out the message headers. */ - headers = mime_generate_headers (mCompFields, mCompFields->GetCharacterSet(), - m_deliver_mode, promptObject, &status); - if (status < 0) - goto FAIL; + headers = mime_generate_headers (mCompFields, mCompFields->GetCharacterSet(), + m_deliver_mode, promptObject, &status); + if (status < 0) + goto FAIL; - if (!headers) - goto FAILMEM; + if (!headers) + goto FAILMEM; - // - // If we converted HTML into plaintext, the plaintext part (plainpart) - // already has its content-type and content-transfer-encoding - // ("other") headers set. - // - // In the specific case where such a plaintext part is the - // top level message part (iff an HTML message is being sent - // as text only and no other attachments exist) we want to - // preserve the original plainpart headers, since they - // contain accurate transfer encoding and Mac type/creator - // information. - // - // So, in the above case we append the main message headers, - // otherwise we overwrite whatever headers may have existed. - // - /* reordering of headers will happen in nsMsgSendPart::Write */ - if ((plainpart) && (plainpart == toppart)) - status = toppart->AppendOtherHeaders(headers); - else - status = toppart->SetOtherHeaders(headers); - PR_Free(headers); - headers = nsnull; - if (status < 0) - goto FAIL; + // + // If we converted HTML into plaintext, the plaintext part (plainpart) + // already has its content-type and content-transfer-encoding + // ("other") headers set. + // + // In the specific case where such a plaintext part is the + // top level message part (iff an HTML message is being sent + // as text only and no other attachments exist) we want to + // preserve the original plainpart headers, since they + // contain accurate transfer encoding and Mac type/creator + // information. + // + // So, in the above case we append the main message headers, + // otherwise we overwrite whatever headers may have existed. + // + /* reordering of headers will happen in nsMsgSendPart::Write */ + if ((plainpart) && (plainpart == toppart)) + status = toppart->AppendOtherHeaders(headers); + else + status = toppart->SetOtherHeaders(headers); + PR_Free(headers); + headers = nsnull; + if (status < 0) + goto FAIL; - // Set up the first part (user-typed.) For now, do it even if the first - // part is empty; we need to add things to skip it if this part is empty. + // Set up the first part (user-typed.) For now, do it even if the first + // part is empty; we need to add things to skip it if this part is empty. - // Set up encoder for the first part (message body.) - // - NS_ASSERTION(!m_attachment1_encoder_data, "not-null m_attachment1_encoder_data"); - if (!PL_strcasecmp(m_attachment1_encoding, ENCODING_BASE64)) - { - m_attachment1_encoder_data = MIME_B64EncoderInit(mime_encoder_output_fn, this); - if (!m_attachment1_encoder_data) goto FAILMEM; - } - else - if (!PL_strcasecmp(m_attachment1_encoding, ENCODING_QUOTED_PRINTABLE)) { - m_attachment1_encoder_data = - MIME_QPEncoderInit(mime_encoder_output_fn, this); - } + // Set up encoder for the first part (message body.) + // + NS_ASSERTION(!m_attachment1_encoder_data, "not-null m_attachment1_encoder_data"); + if (!PL_strcasecmp(m_attachment1_encoding, ENCODING_BASE64)) + { + m_attachment1_encoder_data = MIME_B64EncoderInit(mime_encoder_output_fn, this); + if (!m_attachment1_encoder_data) goto FAILMEM; + } + else + if (!PL_strcasecmp(m_attachment1_encoding, ENCODING_QUOTED_PRINTABLE)) { + m_attachment1_encoder_data = + MIME_QPEncoderInit(mime_encoder_output_fn, this); + } - // If we converted HTML into plaintext, the plaintext part - // already has its type/encoding headers set. So, in the specific - // case where such a plaintext part is the main message body - // (iff an HTML message is being sent as text only) - // we want to avoid generating type/encoding/digest headers; - // in all other cases, generate such headers here. - // - // We really want to set up headers as a dictionary of some sort - // so that we need not worry about duplicate header lines. - // - if ((!plainpart) || (plainpart != mainbody)) - { - hdrs = mime_generate_attachment_headers (m_attachment1_type, - m_attachment1_encoding, - 0, 0, 0, 0, 0, - m_digest_p, - nsnull, /* no "ma"! */ - mCompFields->GetCharacterSet(), + // If we converted HTML into plaintext, the plaintext part + // already has its type/encoding headers set. So, in the specific + // case where such a plaintext part is the main message body + // (iff an HTML message is being sent as text only) + // we want to avoid generating type/encoding/digest headers; + // in all other cases, generate such headers here. + // + // We really want to set up headers as a dictionary of some sort + // so that we need not worry about duplicate header lines. + // + if ((!plainpart) || (plainpart != mainbody)) + { + hdrs = mime_generate_attachment_headers (m_attachment1_type, + m_attachment1_encoding, + 0, 0, 0, 0, 0, + m_digest_p, + nsnull, /* no "ma"! */ + mCompFields->GetCharacterSet(), nsnull, PR_TRUE); - if (!hdrs) - goto FAILMEM; - status = mainbody->AppendOtherHeaders(hdrs); - if (status < 0) - goto FAIL; - } + if (!hdrs) + goto FAILMEM; + status = mainbody->AppendOtherHeaders(hdrs); + if (status < 0) + goto FAIL; + } - PR_FREEIF(hdrs); + PR_FREEIF(hdrs); - status = mainbody->SetEncoderData(m_attachment1_encoder_data); - m_attachment1_encoder_data = nsnull; - if (status < 0) - goto FAIL; + status = mainbody->SetEncoderData(m_attachment1_encoder_data); + m_attachment1_encoder_data = nsnull; + if (status < 0) + goto FAIL; // // Now we need to process attachments and slot them in the // correct heirarchy. // if (m_attachment_count > 0) - { - // 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); - buffer = mime_mailto_stream_read_buffer; - if (! buffer) - goto FAILMEM; - buffer_tail = buffer; + { + // 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); + buffer = mime_mailto_stream_read_buffer; + if (! buffer) + goto FAILMEM; + buffer_tail = buffer; // Gather all of the attachments for this message that are NOT // part of an enclosed MHTML message! - for (i = 0; i < m_attachment_count; i++) + for (i = 0; i < m_attachment_count; i++) { nsMsgAttachmentHandler *ma = &m_attachments[i]; if (!ma->mMHTMLPart) @@ -1058,90 +1058,90 @@ nsMsgComposeAndSend::GatherMimeAttachments() } } - } + } // Tell the user we are creating the message... mComposeBundle->GetStringByID(NS_MSG_CREATING_MESSAGE, getter_Copies(msg)); SetStatusMessage( msg ); - // OK, now actually write the structure we've carefully built up. - status = toppart->Write(); - if (status < 0) - goto FAIL; + // OK, now actually write the structure we've carefully built up. + status = toppart->Write(); + if (status < 0) + goto FAIL; if (mOutputFile) { - if (NS_FAILED(mOutputFile->flush()) || mOutputFile->failed()) + if (NS_FAILED(mOutputFile->flush()) || mOutputFile->failed()) { - status = NS_MSG_ERROR_WRITING_FILE; - goto FAIL; - } + status = NS_MSG_ERROR_WRITING_FILE; + goto FAIL; + } mOutputFile->close(); - delete mOutputFile; - mOutputFile = nsnull; + delete mOutputFile; + mOutputFile = nsnull; - /* If we don't do this check...ZERO length files can be sent */ - if (mTempFileSpec->GetFileSize() == 0) - { - status = NS_MSG_ERROR_WRITING_FILE; - goto FAIL; - } - } + /* If we don't do this check...ZERO length files can be sent */ + if (mTempFileSpec->GetFileSize() == 0) + { + status = NS_MSG_ERROR_WRITING_FILE; + goto FAIL; + } + } mComposeBundle->GetStringByID(NS_MSG_ASSEMB_DONE_MSG, getter_Copies(msg)); SetStatusMessage( msg ); if (m_dont_deliver_p && mListener) - { + { // - // Need to ditch the file spec here so that we don't delete the - // file, since in this case, the caller wants the file + // Need to ditch the file spec here so that we don't delete the + // file, since in this case, the caller wants the file // NS_NewFileSpecWithSpec(*mTempFileSpec, &mReturnFileSpec); delete mTempFileSpec; mTempFileSpec = nsnull; - if (!mReturnFileSpec) + if (!mReturnFileSpec) NotifyListenerOnStopSending(nsnull, NS_ERROR_OUT_OF_MEMORY, nsnull, nsnull); else NotifyListenerOnStopSending(nsnull, NS_OK, nsnull, mReturnFileSpec); - } - else + } + else { - status = DeliverMessage(); - if (NS_SUCCEEDED(status)) - shouldDeleteDeliveryState = PR_FALSE; - } - goto FAIL; + status = DeliverMessage(); + if (NS_SUCCEEDED(status)) + shouldDeleteDeliveryState = PR_FALSE; + } + goto FAIL; FAILMEM: - status = NS_ERROR_OUT_OF_MEMORY; + status = NS_ERROR_OUT_OF_MEMORY; FAIL: - if (toppart) - delete toppart; - toppart = nsnull; - mainbody = nsnull; - maincontainer = nsnull; + if (toppart) + delete toppart; + toppart = nsnull; + mainbody = nsnull; + maincontainer = nsnull; PR_FREEIF(headers); if (in_file) { - PR_Close (in_file); - in_file = nsnull; + PR_Close (in_file); + in_file = nsnull; } - if (shouldDeleteDeliveryState) - { - if (status < 0) - { - m_status = status; + if (shouldDeleteDeliveryState) + { + if (status < 0) + { + m_status = status; nsresult ignoreMe; - Fail (status, nsnull, &ignoreMe); - } - } + Fail (status, nsnull, &ignoreMe); + } + } - return status; + return status; } @@ -1150,8 +1150,8 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, nsMsgSendPart *toppart) // The very top most container of the message { nsresult status; - char *hdrs = 0; - nsMsgSendPart *part = nsnull; + char *hdrs = 0; + nsMsgSendPart *part = nsnull; // If this was one of those dead parts from a quoted web page, // then just return safely. @@ -1159,26 +1159,26 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, if (ma->m_bogus_attachment) return 0; - // If at this point we *still* don't have a content-type, then - // we're never going to get one. - if (ma->m_type == nsnull) + // If at this point we *still* don't have a content-type, then + // we're never going to get one. + if (ma->m_type == nsnull) { - ma->m_type = PL_strdup(UNKNOWN_CONTENT_TYPE); - if (ma->m_type == nsnull) - return 0; - } + ma->m_type = PL_strdup(UNKNOWN_CONTENT_TYPE); + if (ma->m_type == nsnull) + return 0; + } - ma->PickEncoding (mCompFields->GetCharacterSet(), this); + ma->PickEncoding (mCompFields->GetCharacterSet(), this); - part = new nsMsgSendPart(this); - if (!part) - return 0; - status = toppart->AddChild(part); - if (NS_FAILED(status)) - return 0; - status = part->SetType(ma->m_type); - if (NS_FAILED(status)) - return 0; + part = new nsMsgSendPart(this); + if (!part) + return 0; + status = toppart->AddChild(part); + if (NS_FAILED(status)) + return 0; + status = part->SetType(ma->m_type); + if (NS_FAILED(status)) + return 0; nsXPIDLCString turl; if (!ma->mURL) @@ -1203,33 +1203,33 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, // at all! ma->m_content_id, PR_FALSE); - if (!hdrs) - return 0; + if (!hdrs) + return 0; - status = part->SetOtherHeaders(hdrs); - PR_FREEIF(hdrs); - if (NS_FAILED(status)) - return 0; - status = part->SetFile(ma->mFileSpec); - if (NS_FAILED(status)) - return 0; - if (ma->m_encoder_data) + status = part->SetOtherHeaders(hdrs); + PR_FREEIF(hdrs); + if (NS_FAILED(status)) + return 0; + status = part->SetFile(ma->mFileSpec); + if (NS_FAILED(status)) + return 0; + if (ma->m_encoder_data) { - status = part->SetEncoderData(ma->m_encoder_data); + status = part->SetEncoderData(ma->m_encoder_data); if (NS_FAILED(status)) - return 0; - ma->m_encoder_data = nsnull; - } + return 0; + ma->m_encoder_data = nsnull; + } - ma->m_current_column = 0; + ma->m_current_column = 0; - if (ma->m_type && - (!PL_strcasecmp (ma->m_type, MESSAGE_RFC822) || - !PL_strcasecmp (ma->m_type, MESSAGE_NEWS))) { - status = part->SetStripSensitiveHeaders(PR_TRUE); - if (NS_FAILED(status)) - return 0; - } + if (ma->m_type && + (!PL_strcasecmp (ma->m_type, MESSAGE_RFC822) || + !PL_strcasecmp (ma->m_type, MESSAGE_NEWS))) { + status = part->SetStripSensitiveHeaders(PR_TRUE); + if (NS_FAILED(status)) + return 0; + } return 1; } @@ -1242,11 +1242,11 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, #endif // XP_MAC && DEBUG # define FROB(X) \ - if (X && *X) \ - { \ - if (*recipients) PL_strcat(recipients, ","); \ - PL_strcat(recipients, X); \ - } + if (X && *X) \ + { \ + if (*recipients) PL_strcat(recipients, ","); \ + PL_strcat(recipients, X); \ + } #if defined(XP_MAC) && defined(DEBUG) #pragma global_optimizer reset @@ -1256,7 +1256,7 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, nsresult mime_write_message_body(nsIMsgSend *state, char *buf, PRInt32 size) { - NS_ENSURE_ARG_POINTER(state); + NS_ENSURE_ARG_POINTER(state); nsOutputFileStream * output; state->GetOutputStream(&output); @@ -1367,9 +1367,9 @@ nsMsgComposeAndSend::GetBodyFromEditor() } } } - + // Convert body to mail charset - char *outCString = nsnull; + char *outCString = nsnull; const char *aCharset = mCompFields->GetCharacterSet(); if (aCharset && *aCharset) @@ -1523,7 +1523,7 @@ nsMsgComposeAndSend::EnsureLineBreaks(const char *body, PRUint32 bodyLen) // body will not have any null bytes, so we can use PL_strdup m_attachment1_body = PL_strdup(body); if (!m_attachment1_body) { - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; } m_attachment1_body_length = bodyLen; } @@ -1789,7 +1789,7 @@ nsMsgComposeAndSend::ProcessMultipartRelated(PRInt32 *aMailboxCount, PRInt32 *aN m_attachments[i].m_encoding = PL_strdup ("7bit"); if (m_attachments[i].mURL) - msg_pick_real_name(&m_attachments[i], mCompFields->GetCharacterSet()); + msg_pick_real_name(&m_attachments[i], nsnull, mCompFields->GetCharacterSet()); // // Next, generate a content id for use with this part @@ -1934,60 +1934,51 @@ nsMsgComposeAndSend::ProcessMultipartRelated(PRInt32 *aMailboxCount, PRInt32 *aN nsresult nsMsgComposeAndSend::CountCompFieldAttachments() { - char *attachmentList = (char *)mCompFields->GetAttachments(); + //Reset the counters mCompFieldLocalAttachments = 0; mCompFieldRemoteAttachments = 0; - if ((!attachmentList) || (!*attachmentList)) + //Get the attachments array + nsCOMPtr attachmentsArray; + mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray)); + if (!attachmentsArray) return NS_OK; - // Make our local copy... - attachmentList = PL_strdup(mCompFields->GetAttachments()); - - // parse the attachment list -#ifdef NS_DEBUG - printf("Comp fields attachment list = %s\n", (const char*)attachmentList); -#endif - - char *token = nsnull; - char *rest = NS_CONST_CAST(char*, (const char*)attachmentList); - nsCAutoString str; + PRUint32 i; + PRUint32 attachmentCount = 0; + attachmentsArray->Count(&attachmentCount); - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) + //Parse the attachments array + nsCOMPtr element; + nsXPIDLCString url; + for (i = 0; i < attachmentCount; i ++) { - str = token; - str.StripWhitespace(); - - if (!str.IsEmpty()) + attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + { + element->GetUrl(getter_Copies(url)); + if (!url.IsEmpty()) { // Check to see if this is a file URL, if so, don't retrieve // like a remote URL... - // - if (nsMsgIsLocalFile(str.get())) + if (nsMsgIsLocalFile(url.get())) { mCompFieldLocalAttachments++; -#ifdef NS_DEBUG - printf("Counting LOCAL attachment %d: %s\n", - mCompFieldLocalAttachments, str.get()); +#if defined(DEBUG_ducarroz) + printf("Counting LOCAL attachment %d: %s\n", mCompFieldLocalAttachments, url.get()); #endif } else // This is a remote URL... { mCompFieldRemoteAttachments++; -#ifdef NS_DEBUG - printf("Counting REMOTE attachment %d: %s\n", - mCompFieldRemoteAttachments, str.get()); +#if defined(DEBUG_ducarroz) + printf("Counting REMOTE attachment %d: %s\n", mCompFieldRemoteAttachments, url.get()); #endif } - - str = ""; } - - token = nsCRT::strtok(rest, ",", &rest); + } } - PR_FREEIF(attachmentList); return NS_OK; } @@ -2001,32 +1992,33 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments() if (mCompFieldLocalAttachments <= 0) return NS_OK; - char *attachmentList = (char *)mCompFields->GetAttachments(); - if ((!attachmentList) || (!*attachmentList)) - return NS_ERROR_FAILURE; + //Get the attachments array + nsCOMPtr attachmentsArray; + mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray)); + if (!attachmentsArray) + return NS_OK; - // Make our local copy... - attachmentList = PL_strdup(mCompFields->GetAttachments()); - - // parse the attachment list for local attachments + PRUint32 i; PRUint32 newLoc = 0; - char *token = nsnull; - char *rest = NS_CONST_CAST(char*, (const char*)attachmentList); - nsCAutoString str; + PRUint32 attachmentCount = 0; + attachmentsArray->Count(&attachmentCount); - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) + //Parse the attachments array + nsCOMPtr element; + nsXPIDLCString url; + for (i = 0; i < attachmentCount; i ++) { - str = token; - str.StripWhitespace(); - - if (!str.IsEmpty()) + attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) { - // Just look for local file:// attachments and do the right thing. - if (nsMsgIsLocalFile(str.get())) + element->GetUrl(getter_Copies(url)); + if (!url.IsEmpty()) { -#ifdef NS_DEBUG - printf("Adding LOCAL attachment %d: %s\n", newLoc, str.get()); + // Just look for local file:// attachments and do the right thing. + if (nsMsgIsLocalFile(url.get())) + { +#if defined(DEBUG_ducarroz) + printf("Adding LOCAL attachment %d: %s\n", newLoc, url.get()); #endif // // Now we have to setup the m_attachments entry for the file:// @@ -2036,46 +2028,59 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments() if (m_attachments[newLoc].mURL) NS_RELEASE(m_attachments[newLoc].mURL); - nsMsgNewURL(&(m_attachments[newLoc].mURL), str.get()); + nsMsgNewURL(&(m_attachments[newLoc].mURL), url.get()); if (m_attachments[newLoc].mFileSpec) + { + if (m_attachments[newLoc].mDeleteFile) + m_attachments[newLoc].mFileSpec->Delete(PR_FALSE); delete (m_attachments[newLoc].mFileSpec); - m_attachments[newLoc].mFileSpec = new nsFileSpec( nsFileURL(str.get()) ); - + } + m_attachments[newLoc].mFileSpec = new nsFileSpec( nsFileURL(url.get()) ); + m_attachments[newLoc].mDeleteFile = PR_FALSE; if (m_attachments[newLoc].mURL) - msg_pick_real_name(&m_attachments[newLoc], mCompFields->GetCharacterSet()); + { + nsXPIDLString proposedName; + element->GetName(getter_Copies(proposedName)); + msg_pick_real_name(&m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet()); + } // Now, most importantly, we need to figure out what the content type is for // this attachment...If we can't, then just make it application/octet-stream - nsresult rv = NS_OK; - nsCOMPtr mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && mimeFinder) + + PR_FREEIF(m_attachments[newLoc].m_type); + element->GetContentType(&m_attachments[newLoc].m_type); + if (!m_attachments[newLoc].m_type || !(*m_attachments[newLoc].m_type)) { - char *fileExt = nsMsgGetExtensionFromFileURL(NS_ConvertASCIItoUCS2(str)); - if (fileExt) + nsresult rv = NS_OK; + nsCOMPtr mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && mimeFinder) + { + char *fileExt = nsMsgGetExtensionFromFileURL(NS_ConvertASCIItoUCS2(url)); + if (fileExt) mimeFinder->GetTypeFromExtension(fileExt, &(m_attachments[newLoc].m_type)); - PR_FREEIF(fileExt); + PR_FREEIF(fileExt); + } } #ifdef XP_MAC //We always need to snarf the file to figure out how to send it, maybe we need to use apple double... m_attachments[newLoc].m_done = PR_FALSE; - m_attachments[newLoc].SetMimeDeliveryState(this); + m_attachments[newLoc].SetMimeDeliveryState(this); #else //We need to snarf the file to figure out how to send it only if we don't have a content type... if ((!m_attachments[newLoc].m_type) || (!*m_attachments[newLoc].m_type)) { m_attachments[newLoc].m_done = PR_FALSE; - m_attachments[newLoc].SetMimeDeliveryState(this); + m_attachments[newLoc].SetMimeDeliveryState(this); } else { - m_attachments[newLoc].m_done = PR_TRUE; - m_attachments[newLoc].SetMimeDeliveryState(nsnull); + m_attachments[newLoc].m_done = PR_TRUE; + m_attachments[newLoc].SetMimeDeliveryState(nsnull); } #endif - // For local files, if they are HTML docs and we don't have a charset, we should // sniff the file and see if we can figure it out. if ( (m_attachments[newLoc].m_type) && (*m_attachments[newLoc].m_type) ) @@ -2091,16 +2096,16 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments() } } + PR_FREEIF(m_attachments[newLoc].m_x_mac_type); + element->GetMacType(&m_attachments[newLoc].m_x_mac_type); + PR_FREEIF(m_attachments[newLoc].m_x_mac_creator); + element->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator); + ++newLoc; } - - str = ""; } - - token = nsCRT::strtok(rest, ",", &rest); } - - PR_FREEIF(attachmentList); + } return NS_OK; } @@ -2113,86 +2118,88 @@ nsMsgComposeAndSend::AddCompFieldRemoteAttachments(PRUint32 aStartLocation, if (mCompFieldRemoteAttachments <= 0) return NS_OK; - char *attachmentList = (char *)mCompFields->GetAttachments(); - if ((!attachmentList) || (!*attachmentList)) - return NS_ERROR_FAILURE; + //Get the attachments array + nsCOMPtr attachmentsArray; + mCompFields->GetAttachmentsArray(getter_AddRefs(attachmentsArray)); + if (!attachmentsArray) + return NS_OK; - // Make our local copy... - attachmentList = PL_strdup(mCompFields->GetAttachments()); - - // parse the attachment list for local attachments + PRUint32 i; PRUint32 newLoc = aStartLocation; - char *token = nsnull; - char *rest = NS_CONST_CAST(char*, (const char*)attachmentList); - nsCAutoString str; + PRUint32 attachmentCount = 0; + attachmentsArray->Count(&attachmentCount); - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) + //Parse the attachments array + nsCOMPtr element; + nsXPIDLCString url; + for (i = 0; i < attachmentCount; i ++) { - str = token; - str.Trim(" \t", PR_TRUE, PR_TRUE); // trim leading and trailing white spaces - - if (!str.IsEmpty()) + attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + { + element->GetUrl(getter_Copies(url)); + if (!url.IsEmpty()) { // Just look for files that are NOT local file attachments and do // the right thing. - // - if (! nsMsgIsLocalFile(str.get())) + if (! nsMsgIsLocalFile(url.get())) { -#ifdef NS_DEBUG - printf("Adding REMOTE attachment %d: %s\n", newLoc, str.get()); +#if defined(DEBUG_ducarroz) + printf("Adding REMOTE attachment %d: %s\n", newLoc, url.get()); #endif m_attachments[newLoc].mDeleteFile = PR_TRUE; m_attachments[newLoc].m_done = PR_FALSE; - m_attachments[newLoc].SetMimeDeliveryState(this); + m_attachments[newLoc].SetMimeDeliveryState(this); if (m_attachments[newLoc].mURL) NS_RELEASE(m_attachments[newLoc].mURL); - nsMsgNewURL(&(m_attachments[newLoc].mURL), str.get()); + nsMsgNewURL(&(m_attachments[newLoc].mURL), url.get()); PR_FREEIF(m_attachments[newLoc].m_charset); m_attachments[newLoc].m_charset = PL_strdup(mCompFields->GetCharacterSet()); PR_FREEIF(m_attachments[newLoc].m_encoding); m_attachments[newLoc].m_encoding = PL_strdup ("7bit"); + PR_FREEIF(m_attachments[newLoc].m_x_mac_type); + element->GetMacType(&m_attachments[newLoc].m_x_mac_type); + PR_FREEIF(m_attachments[newLoc].m_x_mac_creator); + element->GetMacCreator(&m_attachments[newLoc].m_x_mac_creator); + /* Count up attachments which are going to come from mail folders and from NNTP servers. */ - nsXPIDLCString turl; + nsCAutoString strUrl; + strUrl.Assign(url.get()); if (m_attachments[newLoc].mURL) { - msg_pick_real_name(&m_attachments[newLoc], - mCompFields->GetCharacterSet()); + nsXPIDLString proposedName; + element->GetName(getter_Copies(proposedName)); + msg_pick_real_name(&m_attachments[newLoc], proposedName, mCompFields->GetCharacterSet()); ++newLoc; } - else if (str.Find("_message:") != -1) + else if (strUrl.Find("_message:") != -1) { - if (str.Find("mailbox_message:") != -1 || - str.Find("imap_message:") != -1) + if (strUrl.Find("mailbox_message:") != -1 || + strUrl.Find("imap_message:") != -1) (*aMailboxCount)++; - else if (str.Find("news_message:") != -1 || - str.Find("snews_message:") != -1) + else if (strUrl.Find("news_message:") != -1 || + strUrl.Find("snews_message:") != -1) (*aNewsCount)++; - m_attachments[newLoc].m_uri = ToNewCString(str); + m_attachments[newLoc].m_uri = ToNewCString(strUrl); ++newLoc; - } - } - - str = ""; } - - token = nsCRT::strtok(rest, ",", &rest); + } + } + } } - - PR_FREEIF(attachmentList); return NS_OK; } int nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, - const nsMsgAttachedFile *preloaded_attachments) + const nsMsgAttachedFile *preloaded_attachments) { // // First, count the total number of attachments we are going to process @@ -2210,8 +2217,8 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, if (preloaded_attachments && preloaded_attachments[0].orig_url) { - while (preloaded_attachments[mPreloadedAttachmentCount].orig_url) - mPreloadedAttachmentCount++; + while (preloaded_attachments[mPreloadedAttachmentCount].orig_url) + mPreloadedAttachmentCount++; } // Count the attachments we have to go retrieve! Keep in mind, that these @@ -2228,9 +2235,9 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, PRInt32 tCount = 0; if (attachments && attachments[0].url) { - while (attachments[tCount].url) + while (attachments[tCount].url) { - mRemoteAttachmentCount++; + mRemoteAttachmentCount++; tCount++; } } @@ -2254,28 +2261,28 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, // Now handle the preloaded attachments... if (preloaded_attachments && preloaded_attachments[0].orig_url) { - // These are attachments which have already been downloaded to tmp files. - // We merely need to point the internal attachment data at those tmp - // files. - m_pre_snarfed_attachments_p = PR_TRUE; + // These are attachments which have already been downloaded to tmp files. + // We merely need to point the internal attachment data at those tmp + // files. + m_pre_snarfed_attachments_p = PR_TRUE; - for (i = mCompFieldLocalAttachments; i < mPreloadedAttachmentCount; i++) + for (i = mCompFieldLocalAttachments; i < mPreloadedAttachmentCount; i++) { - /* These attachments are already "snarfed". */ + /* These attachments are already "snarfed". */ m_attachments[i].mDeleteFile = PR_FALSE; - m_attachments[i].SetMimeDeliveryState(nsnull); - m_attachments[i].m_done = PR_TRUE; - NS_ASSERTION (preloaded_attachments[i].orig_url, "null url"); + m_attachments[i].SetMimeDeliveryState(nsnull); + m_attachments[i].m_done = PR_TRUE; + NS_ASSERTION (preloaded_attachments[i].orig_url, "null url"); if (m_attachments[i].mURL) NS_RELEASE(m_attachments[i].mURL); - m_attachments[i].mURL = preloaded_attachments[i].orig_url; + m_attachments[i].mURL = preloaded_attachments[i].orig_url; - PR_FREEIF(m_attachments[i].m_type); - m_attachments[i].m_type = PL_strdup (preloaded_attachments[i].type); + PR_FREEIF(m_attachments[i].m_type); + m_attachments[i].m_type = PL_strdup (preloaded_attachments[i].type); // Set it to the compose fields for a default... - PR_FREEIF(m_attachments[i].m_charset); + PR_FREEIF(m_attachments[i].m_charset); m_attachments[i].m_charset = PL_strdup (mCompFields->GetCharacterSet()); // If we still don't have a content type, we should really try sniff one out! @@ -2299,40 +2306,44 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, } } - PR_FREEIF(m_attachments[i].m_description); - m_attachments[i].m_description = PL_strdup (preloaded_attachments[i].description); - PR_FREEIF(m_attachments[i].m_real_name); - m_attachments[i].m_real_name = PL_strdup (preloaded_attachments[i].real_name); - PR_FREEIF(m_attachments[i].m_x_mac_type); - m_attachments[i].m_x_mac_type = PL_strdup (preloaded_attachments[i].x_mac_type); - PR_FREEIF(m_attachments[i].m_x_mac_creator); - m_attachments[i].m_x_mac_creator = PL_strdup (preloaded_attachments[i].x_mac_creator); - PR_FREEIF(m_attachments[i].m_encoding); - m_attachments[i].m_encoding = PL_strdup (preloaded_attachments[i].encoding); + PR_FREEIF(m_attachments[i].m_description); + m_attachments[i].m_description = PL_strdup (preloaded_attachments[i].description); + PR_FREEIF(m_attachments[i].m_real_name); + m_attachments[i].m_real_name = PL_strdup (preloaded_attachments[i].real_name); + PR_FREEIF(m_attachments[i].m_x_mac_type); + m_attachments[i].m_x_mac_type = PL_strdup (preloaded_attachments[i].x_mac_type); + PR_FREEIF(m_attachments[i].m_x_mac_creator); + m_attachments[i].m_x_mac_creator = PL_strdup (preloaded_attachments[i].x_mac_creator); + PR_FREEIF(m_attachments[i].m_encoding); + m_attachments[i].m_encoding = PL_strdup (preloaded_attachments[i].encoding); if (m_attachments[i].mFileSpec) + { + if (m_attachments[i].mDeleteFile) + m_attachments[i].mFileSpec->Delete(PR_FALSE); delete (m_attachments[i].mFileSpec); - m_attachments[i].mFileSpec = new nsFileSpec(*(preloaded_attachments[i].file_spec)); + } + m_attachments[i].mFileSpec = new nsFileSpec(*(preloaded_attachments[i].file_spec)); - m_attachments[i].m_size = preloaded_attachments[i].size; - m_attachments[i].m_unprintable_count = preloaded_attachments[i].unprintable_count; - m_attachments[i].m_highbit_count = preloaded_attachments[i].highbit_count; - m_attachments[i].m_ctl_count = preloaded_attachments[i].ctl_count; - m_attachments[i].m_null_count = preloaded_attachments[i].null_count; - m_attachments[i].m_max_column = preloaded_attachments[i].max_line_length; + m_attachments[i].m_size = preloaded_attachments[i].size; + m_attachments[i].m_unprintable_count = preloaded_attachments[i].unprintable_count; + m_attachments[i].m_highbit_count = preloaded_attachments[i].highbit_count; + m_attachments[i].m_ctl_count = preloaded_attachments[i].ctl_count; + m_attachments[i].m_null_count = preloaded_attachments[i].null_count; + m_attachments[i].m_max_column = preloaded_attachments[i].max_line_length; - /* If the attachment has an encoding, and it's not one of - the "null" encodings, then keep it. */ - if (m_attachments[i].m_encoding && - PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_7BIT) && - PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_8BIT) && - PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_BINARY)) - m_attachments[i].m_already_encoded_p = PR_TRUE; + /* If the attachment has an encoding, and it's not one of + the "null" encodings, then keep it. */ + if (m_attachments[i].m_encoding && + PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_7BIT) && + PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_8BIT) && + PL_strcasecmp (m_attachments[i].m_encoding, ENCODING_BINARY)) + m_attachments[i].m_already_encoded_p = PR_TRUE; if (m_attachments[i].mURL) - msg_pick_real_name(&m_attachments[i], mCompFields->GetCharacterSet()); - } - } + msg_pick_real_name(&m_attachments[i], nsnull, mCompFields->GetCharacterSet()); + } + } // First, handle the multipart related attachments if any... // @@ -2368,62 +2379,62 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, locCount++; m_attachments[i].mDeleteFile = PR_TRUE; m_attachments[i].m_done = PR_FALSE; - m_attachments[i].SetMimeDeliveryState(this); - NS_ASSERTION (attachments[locCount].url, "null url"); + m_attachments[i].SetMimeDeliveryState(this); + NS_ASSERTION (attachments[locCount].url, "null url"); if (m_attachments[i].mURL) NS_RELEASE(m_attachments[i].mURL); m_attachments[i].mURL = attachments[locCount].url; - PR_FREEIF(m_attachments[i].m_override_type); - m_attachments[i].m_override_type = PL_strdup (attachments[locCount].real_type); - PR_FREEIF(m_attachments[i].m_charset); - m_attachments[i].m_charset = PL_strdup (mCompFields->GetCharacterSet()); - PR_FREEIF(m_attachments[i].m_override_encoding); - m_attachments[i].m_override_encoding = PL_strdup (attachments[locCount].real_encoding); - PR_FREEIF(m_attachments[i].m_desired_type); - m_attachments[i].m_desired_type = PL_strdup (attachments[locCount].desired_type); - PR_FREEIF(m_attachments[i].m_description); - m_attachments[i].m_description = PL_strdup (attachments[locCount].description); - PR_FREEIF(m_attachments[i].m_real_name); - m_attachments[i].m_real_name = PL_strdup (attachments[locCount].real_name); - PR_FREEIF(m_attachments[i].m_x_mac_type); - m_attachments[i].m_x_mac_type = PL_strdup (attachments[locCount].x_mac_type); - PR_FREEIF(m_attachments[i].m_x_mac_creator); - m_attachments[i].m_x_mac_creator = PL_strdup (attachments[locCount].x_mac_creator); - PR_FREEIF(m_attachments[i].m_encoding); - m_attachments[i].m_encoding = PL_strdup ("7bit"); + PR_FREEIF(m_attachments[i].m_override_type); + m_attachments[i].m_override_type = PL_strdup (attachments[locCount].real_type); + PR_FREEIF(m_attachments[i].m_charset); + m_attachments[i].m_charset = PL_strdup (mCompFields->GetCharacterSet()); + PR_FREEIF(m_attachments[i].m_override_encoding); + m_attachments[i].m_override_encoding = PL_strdup (attachments[locCount].real_encoding); + PR_FREEIF(m_attachments[i].m_desired_type); + m_attachments[i].m_desired_type = PL_strdup (attachments[locCount].desired_type); + PR_FREEIF(m_attachments[i].m_description); + m_attachments[i].m_description = PL_strdup (attachments[locCount].description); + PR_FREEIF(m_attachments[i].m_real_name); + m_attachments[i].m_real_name = PL_strdup (attachments[locCount].real_name); + PR_FREEIF(m_attachments[i].m_x_mac_type); + m_attachments[i].m_x_mac_type = PL_strdup (attachments[locCount].x_mac_type); + PR_FREEIF(m_attachments[i].m_x_mac_creator); + m_attachments[i].m_x_mac_creator = PL_strdup (attachments[locCount].x_mac_creator); + PR_FREEIF(m_attachments[i].m_encoding); + m_attachments[i].m_encoding = PL_strdup ("7bit"); - // real name is set in the case of vcard so don't change it. - // m_attachments[i].m_real_name = 0; + // real name is set in the case of vcard so don't change it. + // m_attachments[i].m_real_name = 0; - /* Count up attachments which are going to come from mail folders - and from NNTP servers. */ - if (m_attachments[i].mURL) - { - nsXPIDLCString turl; - m_attachments[i].mURL->GetSpec(getter_Copies(turl)); - if (PL_strncasecmp(turl, "mailbox:",8) || - PL_strncasecmp(turl, "IMAP:",5)) - mailbox_count++; - else - if (PL_strncasecmp(turl, "news:",5) || - PL_strncasecmp(turl, "snews:",6)) - news_count++; + /* Count up attachments which are going to come from mail folders + and from NNTP servers. */ + if (m_attachments[i].mURL) + { + nsXPIDLCString turl; + m_attachments[i].mURL->GetSpec(getter_Copies(turl)); + if (PL_strncasecmp(turl, "mailbox:",8) || + PL_strncasecmp(turl, "IMAP:",5)) + mailbox_count++; + else + if (PL_strncasecmp(turl, "news:",5) || + PL_strncasecmp(turl, "snews:",6)) + news_count++; if (m_attachments[i].mURL) - msg_pick_real_name(&m_attachments[i], mCompFields->GetCharacterSet()); - } - } + msg_pick_real_name(&m_attachments[i], nsnull, mCompFields->GetCharacterSet()); + } + } } PRBool needToCallGatherMimeAttachments = PR_TRUE; if (m_attachment_count > 0) { - // If there is more than one mailbox URL, or more than one NNTP url, - // do the load in serial rather than parallel, for efficiency. - if (mailbox_count > 1 || news_count > 1) + // If there is more than one mailbox URL, or more than one NNTP url, + // do the load in serial rather than parallel, for efficiency. + if (mailbox_count > 1 || news_count > 1) m_be_synchronous_p = PR_TRUE; m_attachment_pending_count = m_attachment_count; @@ -2446,7 +2457,7 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, { m_attachments[i].m_bogus_attachment = PR_TRUE; m_attachments[i].m_done = PR_TRUE; - m_attachments[i].SetMimeDeliveryState(nsnull); + m_attachments[i].SetMimeDeliveryState(nsnull); m_attachment_pending_count--; continue; } @@ -2469,7 +2480,7 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, if (printfString) { - SetStatusMessage(printfString); + SetStatusMessage(printfString); PR_FREEIF(printfString); } @@ -2487,16 +2498,16 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments, } // If no attachments - finish now (this will call the done_callback). - if (needToCallGatherMimeAttachments) - return GatherMimeAttachments(); + if (needToCallGatherMimeAttachments) + return GatherMimeAttachments(); - return 0; + return 0; } int nsMsgComposeAndSend::SetMimeHeader(nsMsgCompFields::MsgHeaderID header, const char *value) { - char * dupHeader = nsnull; - PRInt32 ret = NS_ERROR_OUT_OF_MEMORY; + char * dupHeader = nsnull; + PRInt32 ret = NS_ERROR_OUT_OF_MEMORY; switch (header) { @@ -2505,13 +2516,13 @@ int nsMsgComposeAndSend::SetMimeHeader(nsMsgCompFields::MsgHeaderID header, cons case nsMsgCompFields::MSG_REPLY_TO_HEADER_ID : case nsMsgCompFields::MSG_CC_HEADER_ID : case nsMsgCompFields::MSG_BCC_HEADER_ID : - dupHeader = mime_fix_addr_header(value); + dupHeader = mime_fix_addr_header(value); break; case nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID : case nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID : - dupHeader = mime_fix_news_header(value); - break; + dupHeader = mime_fix_news_header(value); + break; case nsMsgCompFields::MSG_FCC_HEADER_ID : case nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID : @@ -2519,33 +2530,33 @@ int nsMsgComposeAndSend::SetMimeHeader(nsMsgCompFields::MsgHeaderID header, cons case nsMsgCompFields::MSG_REFERENCES_HEADER_ID : case nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID : case nsMsgCompFields::MSG_ATTACHMENTS_HEADER_ID : - dupHeader = mime_fix_header(value); - break; - - default : NS_ASSERTION(PR_FALSE, "invalid header"); // unhandled header - bad boy. + dupHeader = mime_fix_header(value); + break; + + default : NS_ASSERTION(PR_FALSE, "invalid header"); // unhandled header - bad boy. } - if (dupHeader) + if (dupHeader) { - ret = mCompFields->SetAsciiHeader(header, dupHeader); - PR_Free(dupHeader); - } - return ret; + ret = mCompFields->SetAsciiHeader(header, dupHeader); + PR_Free(dupHeader); + } + return ret; } nsresult nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields) { nsresult rv = NS_OK; - const char *pStr = nsnull; + const char *pStr = nsnull; nsMsgCompFields *tPtr = new nsMsgCompFields(); if (!tPtr) return NS_ERROR_OUT_OF_MEMORY; - mCompFields = do_QueryInterface( tPtr ); - if (!mCompFields) - return NS_ERROR_OUT_OF_MEMORY; + mCompFields = do_QueryInterface( tPtr ); + if (!mCompFields) + return NS_ERROR_OUT_OF_MEMORY; const char *cset = fields->GetCharacterSet(); // Make sure charset is sane... @@ -2558,20 +2569,20 @@ nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields) mCompFields->SetCharacterSet(fields->GetCharacterSet()); } - pStr = fields->GetMessageId(); - if (pStr) - { - mCompFields->SetMessageId((char *) pStr); - /* Don't bother checking for out of memory; if it fails, then we'll just - let the server generate the message-id, and suffer with the - possibility of duplicate messages.*/ - } - - pStr = fields->GetNewspostUrl(); - if (pStr && *pStr) + pStr = fields->GetMessageId(); + if (pStr) { - mCompFields->SetNewspostUrl((char *)pStr); - } + mCompFields->SetMessageId((char *) pStr); + /* Don't bother checking for out of memory; if it fails, then we'll just + let the server generate the message-id, and suffer with the + possibility of duplicate messages.*/ + } + + pStr = fields->GetNewspostUrl(); + if (pStr && *pStr) + { + mCompFields->SetNewspostUrl((char *)pStr); + } // Now, we will look for a URI defined as the default FCC pref. If this is set, // then SetFcc will use this value. The FCC field is a URI for the server that @@ -2635,58 +2646,74 @@ nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields) } } - mCompFields->SetNewspostUrl((char *) fields->GetNewspostUrl()); + mCompFields->SetNewspostUrl((char *) fields->GetNewspostUrl()); - /* strip whitespace from and duplicate header fields. */ - SetMimeHeader(nsMsgCompFields::MSG_FROM_HEADER_ID, fields->GetFrom()); - SetMimeHeader(nsMsgCompFields::MSG_REPLY_TO_HEADER_ID, fields->GetReplyTo()); - SetMimeHeader(nsMsgCompFields::MSG_TO_HEADER_ID, fields->GetTo()); - SetMimeHeader(nsMsgCompFields::MSG_CC_HEADER_ID, fields->GetCc()); - SetMimeHeader(nsMsgCompFields::MSG_BCC_HEADER_ID, fields->GetBcc()); - SetMimeHeader(nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID, fields->GetNewsgroups()); - SetMimeHeader(nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID, fields->GetFollowupTo()); - SetMimeHeader(nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID, fields->GetOrganization()); - SetMimeHeader(nsMsgCompFields::MSG_SUBJECT_HEADER_ID, fields->GetSubject()); - SetMimeHeader(nsMsgCompFields::MSG_REFERENCES_HEADER_ID, fields->GetReferences()); - SetMimeHeader(nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID, fields->GetTemplateName()); + /* strip whitespace from and duplicate header fields. */ + SetMimeHeader(nsMsgCompFields::MSG_FROM_HEADER_ID, fields->GetFrom()); + SetMimeHeader(nsMsgCompFields::MSG_REPLY_TO_HEADER_ID, fields->GetReplyTo()); + SetMimeHeader(nsMsgCompFields::MSG_TO_HEADER_ID, fields->GetTo()); + SetMimeHeader(nsMsgCompFields::MSG_CC_HEADER_ID, fields->GetCc()); + SetMimeHeader(nsMsgCompFields::MSG_BCC_HEADER_ID, fields->GetBcc()); + SetMimeHeader(nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID, fields->GetNewsgroups()); + SetMimeHeader(nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID, fields->GetFollowupTo()); + SetMimeHeader(nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID, fields->GetOrganization()); + SetMimeHeader(nsMsgCompFields::MSG_SUBJECT_HEADER_ID, fields->GetSubject()); + SetMimeHeader(nsMsgCompFields::MSG_REFERENCES_HEADER_ID, fields->GetReferences()); + SetMimeHeader(nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID, fields->GetTemplateName()); - // For the new way to deal with attachments from the FE... - SetMimeHeader(nsMsgCompFields::MSG_ATTACHMENTS_HEADER_ID, fields->GetAttachments()); + nsCOMPtr srcAttachmentArray; + fields->GetAttachmentsArray(getter_AddRefs(srcAttachmentArray)); + if (srcAttachmentArray) + { + PRUint32 i; + PRUint32 attachmentCount = 0; + srcAttachmentArray->Count(&attachmentCount); + if (attachmentCount > 0) + { + nsCOMPtr element; + for (i = 0; i < attachmentCount; i ++) + { + srcAttachmentArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element)); + if (element) + mCompFields->AddAttachment(element); + } + } + } - pStr = fields->GetOtherRandomHeaders(); - if (pStr) - mCompFields->SetOtherRandomHeaders((char *) pStr); + pStr = fields->GetOtherRandomHeaders(); + if (pStr) + mCompFields->SetOtherRandomHeaders((char *) pStr); - pStr = fields->GetPriority(); - if (pStr) - mCompFields->SetPriority((char *) pStr); + pStr = fields->GetPriority(); + if (pStr) + mCompFields->SetPriority((char *) pStr); - mCompFields->SetAttachVCard(fields->GetAttachVCard()); - mCompFields->SetForcePlainText(fields->GetForcePlainText()); - mCompFields->SetUseMultipartAlternative(fields->GetUseMultipartAlternative()); - mCompFields->SetReturnReceipt(fields->GetReturnReceipt()); - mCompFields->SetUuEncodeAttachments(fields->GetUuEncodeAttachments()); + mCompFields->SetAttachVCard(fields->GetAttachVCard()); + mCompFields->SetForcePlainText(fields->GetForcePlainText()); + mCompFields->SetUseMultipartAlternative(fields->GetUseMultipartAlternative()); + mCompFields->SetReturnReceipt(fields->GetReturnReceipt()); + mCompFields->SetUuEncodeAttachments(fields->GetUuEncodeAttachments()); - // + // // Check the fields for legitimacy... // - if ( m_deliver_mode != nsMsgSaveAsDraft && m_deliver_mode != nsMsgSaveAsTemplate ) + if ( m_deliver_mode != nsMsgSaveAsDraft && m_deliver_mode != nsMsgSaveAsTemplate ) { - rv = mime_sanity_check_fields (mCompFields->GetFrom(), mCompFields->GetReplyTo(), - mCompFields->GetTo(), mCompFields->GetCc(), - mCompFields->GetBcc(), mCompFields->GetFcc(), - mCompFields->GetNewsgroups(), mCompFields->GetFollowupTo(), - mCompFields->GetSubject(), mCompFields->GetReferences(), - mCompFields->GetOrganization(), - mCompFields->GetOtherRandomHeaders()); - } + rv = mime_sanity_check_fields (mCompFields->GetFrom(), mCompFields->GetReplyTo(), + mCompFields->GetTo(), mCompFields->GetCc(), + mCompFields->GetBcc(), mCompFields->GetFcc(), + mCompFields->GetNewsgroups(), mCompFields->GetFollowupTo(), + mCompFields->GetSubject(), mCompFields->GetReferences(), + mCompFields->GetOrganization(), + mCompFields->GetOtherRandomHeaders()); + } - return rv; + return rv; } nsresult nsMsgComposeAndSend::SnarfAndCopyBody(const char *attachment1_body, - PRUint32 attachment1_body_length, + PRUint32 attachment1_body_length, const char *attachment1_type) { // @@ -2696,8 +2723,8 @@ nsMsgComposeAndSend::SnarfAndCopyBody(const char *attachment1_body, // Strip whitespace from beginning and end of body. if (attachment1_body) { - // strip out whitespaces from the end of body ONLY. - while (attachment1_body_length > 0 && + // strip out whitespaces from the end of body ONLY. + while (attachment1_body_length > 0 && (attachment1_body[attachment1_body_length - 1] == ' ') ) { attachment1_body_length--; @@ -2721,24 +2748,24 @@ nsMsgComposeAndSend::SnarfAndCopyBody(const char *attachment1_body, nsresult nsMsgComposeAndSend::Init( nsIMsgIdentity *aUserIdentity, - nsMsgCompFields *fields, + nsMsgCompFields *fields, nsFileSpec *sendFileSpec, - PRBool digest_p, - PRBool dont_deliver_p, - nsMsgDeliverMode mode, + PRBool digest_p, + PRBool dont_deliver_p, + nsMsgDeliverMode mode, nsIMsgDBHdr *msgToReplace, - const char *attachment1_type, - const char *attachment1_body, - PRUint32 attachment1_body_length, - const nsMsgAttachmentData *attachments, - const nsMsgAttachedFile *preloaded_attachments, + const char *attachment1_type, + const char *attachment1_body, + PRUint32 attachment1_body_length, + const nsMsgAttachmentData *attachments, + const nsMsgAttachedFile *preloaded_attachments, const char *password) { - nsresult rv = NS_OK; - - //Reset last error - mLastErrorReported = NS_OK; - + nsresult rv = NS_OK; + + //Reset last error + mLastErrorReported = NS_OK; + nsXPIDLString msg; if (!mComposeBundle) mComposeBundle = do_GetService(NS_MSG_COMPOSESTRINGSERVICE_CONTRACTID); @@ -2756,8 +2783,8 @@ nsMsgComposeAndSend::Init( // blown create and send operations as well as just the "send a file" // operations. // - m_dont_deliver_p = dont_deliver_p; - m_deliver_mode = mode; + m_dont_deliver_p = dont_deliver_p; + m_deliver_mode = mode; mMsgToReplace = msgToReplace; mUserIdentity = aUserIdentity; @@ -2768,8 +2795,8 @@ nsMsgComposeAndSend::Init( // First sanity check the composition fields parameter and // see if we should continue // - if (!fields) - return NS_ERROR_OUT_OF_MEMORY; + if (!fields) + return NS_ERROR_OUT_OF_MEMORY; rv = InitCompositionFields(fields); if (NS_FAILED(rv)) @@ -2787,7 +2814,7 @@ nsMsgComposeAndSend::Init( // if (sendFileSpec) { - mTempFileSpec = sendFileSpec; + mTempFileSpec = sendFileSpec; return NS_OK; } @@ -2805,7 +2832,7 @@ nsMsgComposeAndSend::Init( } nsMsgMIMESetConformToStandard(strictly_mime); - mime_use_quoted_printable_p = strictly_mime; + mime_use_quoted_printable_p = strictly_mime; // Ok, now watch me pull a rabbit out of my hat....what we need // to do here is figure out what the body will be. If this is a @@ -2845,25 +2872,25 @@ SendDeliveryCallback(nsIURI *aUrl, nsresult aExitCode, nsMsgDeliveryType deliver if (deliveryType == nsMailDelivery) { - if (NS_FAILED(aExitCode)) - switch (aExitCode) - { - case NS_ERROR_UNKNOWN_HOST: - aExitCode = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER; - break; - default: - if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode)) - aExitCode = NS_ERROR_SEND_FAILED; - break; - } + if (NS_FAILED(aExitCode)) + switch (aExitCode) + { + case NS_ERROR_UNKNOWN_HOST: + aExitCode = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER; + break; + default: + if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode)) + aExitCode = NS_ERROR_SEND_FAILED; + break; + } msgSend->DeliverAsMailExit(aUrl, aExitCode); } else if (deliveryType == nsNewsDelivery) { - if (NS_FAILED(aExitCode)) - if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode)) - aExitCode = NS_ERROR_POST_FAILED; + if (NS_FAILED(aExitCode)) + if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode)) + aExitCode = NS_ERROR_POST_FAILED; msgSend->DeliverAsNewsExit(aUrl, aExitCode); } @@ -2885,28 +2912,28 @@ nsMsgComposeAndSend::DeliverMessage() return NS_ERROR_ABORT; } - PRBool mail_p = ((mCompFields->GetTo() && *mCompFields->GetTo()) || - (mCompFields->GetCc() && *mCompFields->GetCc()) || - (mCompFields->GetBcc() && *mCompFields->GetBcc())); - PRBool news_p = (mCompFields->GetNewsgroups() && - *(mCompFields->GetNewsgroups()) ? PR_TRUE : PR_FALSE); + PRBool mail_p = ((mCompFields->GetTo() && *mCompFields->GetTo()) || + (mCompFields->GetCc() && *mCompFields->GetCc()) || + (mCompFields->GetBcc() && *mCompFields->GetBcc())); + PRBool news_p = (mCompFields->GetNewsgroups() && + *(mCompFields->GetNewsgroups()) ? PR_TRUE : PR_FALSE); - if ( m_deliver_mode != nsMsgSaveAsDraft && - m_deliver_mode != nsMsgSaveAsTemplate ) - NS_ASSERTION(mail_p || news_p, "message without destination"); + if ( m_deliver_mode != nsMsgSaveAsDraft && + m_deliver_mode != nsMsgSaveAsTemplate ) + NS_ASSERTION(mail_p || news_p, "message without destination"); - if (m_deliver_mode == nsMsgQueueForLater) + if (m_deliver_mode == nsMsgQueueForLater) { - return QueueForLater(); - } - else if (m_deliver_mode == nsMsgSaveAsDraft) + return QueueForLater(); + } + else if (m_deliver_mode == nsMsgSaveAsDraft) { - return SaveAsDraft(); - } - else if (m_deliver_mode == nsMsgSaveAsTemplate) + return SaveAsDraft(); + } + else if (m_deliver_mode == nsMsgSaveAsTemplate) { - return SaveAsTemplate(); - } + return SaveAsTemplate(); + } // // Ok, we are about to send the file that we have built up...but what @@ -2945,16 +2972,16 @@ nsMsgComposeAndSend::DeliverMessage() } } - if (news_p) { + if (news_p) { if (mail_p) { mSendMailAlso = PR_TRUE; } return DeliverFileAsNews(); /* will call DeliverFileAsMail if it needs to */ } - else if (mail_p) { - return DeliverFileAsMail(); + else if (mail_p) { + return DeliverFileAsMail(); } - else { + else { return NS_ERROR_UNEXPECTED; } @@ -2988,11 +3015,11 @@ strip_nonprintable(char *string) nsresult nsMsgComposeAndSend::DeliverFileAsMail() { - char *buf, *buf2; - buf = (char *) PR_Malloc ((mCompFields->GetTo() ? PL_strlen (mCompFields->GetTo()) + 10 : 0) + - (mCompFields->GetCc() ? PL_strlen (mCompFields->GetCc()) + 10 : 0) + - (mCompFields->GetBcc() ? PL_strlen (mCompFields->GetBcc()) + 10 : 0) + - 10); + char *buf, *buf2; + buf = (char *) PR_Malloc ((mCompFields->GetTo() ? PL_strlen (mCompFields->GetTo()) + 10 : 0) + + (mCompFields->GetCc() ? PL_strlen (mCompFields->GetCc()) + 10 : 0) + + (mCompFields->GetBcc() ? PL_strlen (mCompFields->GetBcc()) + 10 : 0) + + 10); if (mSendReport) mSendReport->SetCurrentProcess(nsIMsgSendReport::process_SMTP); @@ -3000,7 +3027,7 @@ nsMsgComposeAndSend::DeliverFileAsMail() nsCOMPtr promptObject; GetDefaultPrompt(getter_AddRefs(promptObject)); - if (!buf) + if (!buf) { nsXPIDLString eMsg; mComposeBundle->GetStringByID(NS_ERROR_OUT_OF_MEMORY, getter_Copies(eMsg)); @@ -3009,50 +3036,50 @@ nsMsgComposeAndSend::DeliverFileAsMail() Fail(NS_ERROR_OUT_OF_MEMORY, eMsg, &ignoreMe); NotifyListenerOnStopSending(nsnull, NS_ERROR_OUT_OF_MEMORY, nsnull, nsnull); return NS_ERROR_OUT_OF_MEMORY; - } + } - nsresult rv; + nsresult rv; - PRBool collectOutgoingAddresses = PR_TRUE; - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); - if (NS_SUCCEEDED(rv) && prefs) - { - prefs->GetBoolPref(PREF_MAIL_COLLECT_EMAIL_ADDRESS_OUTGOING,&collectOutgoingAddresses); - } + PRBool collectOutgoingAddresses = PR_TRUE; + nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); + if (NS_SUCCEEDED(rv) && prefs) + { + prefs->GetBoolPref(PREF_MAIL_COLLECT_EMAIL_ADDRESS_OUTGOING,&collectOutgoingAddresses); + } - nsCOMPtr addressCollecter = - do_GetService(kCAddressCollecter, &rv); + nsCOMPtr addressCollecter = + do_GetService(kCAddressCollecter, &rv); - if (!NS_SUCCEEDED(rv)) - addressCollecter = nsnull; + if (!NS_SUCCEEDED(rv)) + addressCollecter = nsnull; - PRBool collectAddresses = (collectOutgoingAddresses && addressCollecter); + PRBool collectAddresses = (collectOutgoingAddresses && addressCollecter); - PL_strcpy (buf, ""); - buf2 = buf + PL_strlen (buf); - if (mCompFields->GetTo() && *mCompFields->GetTo()) - { - PL_strcat (buf2, mCompFields->GetTo()); - if (collectAddresses) - addressCollecter->CollectAddress(mCompFields->GetTo()); - } - if (mCompFields->GetCc() && *mCompFields->GetCc()) { - if (*buf2) PL_strcat (buf2, ","); - PL_strcat (buf2, mCompFields->GetCc()); - if (collectAddresses) - addressCollecter->CollectAddress(mCompFields->GetCc()); - } - if (mCompFields->GetBcc() && *mCompFields->GetBcc()) { - if (*buf2) PL_strcat (buf2, ","); - PL_strcat (buf2, mCompFields->GetBcc()); - if (collectAddresses) - addressCollecter->CollectAddress(mCompFields->GetBcc()); - } + PL_strcpy (buf, ""); + buf2 = buf + PL_strlen (buf); + if (mCompFields->GetTo() && *mCompFields->GetTo()) + { + PL_strcat (buf2, mCompFields->GetTo()); + if (collectAddresses) + addressCollecter->CollectAddress(mCompFields->GetTo()); + } + if (mCompFields->GetCc() && *mCompFields->GetCc()) { + if (*buf2) PL_strcat (buf2, ","); + PL_strcat (buf2, mCompFields->GetCc()); + if (collectAddresses) + addressCollecter->CollectAddress(mCompFields->GetCc()); + } + if (mCompFields->GetBcc() && *mCompFields->GetBcc()) { + if (*buf2) PL_strcat (buf2, ","); + PL_strcat (buf2, mCompFields->GetBcc()); + if (collectAddresses) + addressCollecter->CollectAddress(mCompFields->GetBcc()); + } // Ok, now MIME II encode this to prevent 8bit problems... char *convbuf = nsMsgI18NEncodeMimePartIIStr((char *)buf, mCompFields->GetCharacterSet(), - nsMsgMIMEGetConformToStandard()); + nsMsgMIMEGetConformToStandard()); if (convbuf) { // MIME-PartII conversion @@ -3080,8 +3107,8 @@ nsMsgComposeAndSend::DeliverFileAsMail() // Note: Don't do a SetMsgComposeAndSendObject since we are in the same thread, and // using callbacks for notification - nsCOMPtr aFileSpec; - NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec)); + nsCOMPtr aFileSpec; + NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec)); // we used to get the prompt from the compose window and we'd pass that in // to the smtp protocol as the prompt to use. But when you send a message, @@ -3133,31 +3160,31 @@ nsMsgComposeAndSend::DeliverFileAsNews() // Note: Don't do a SetMsgComposeAndSendObject since we are in the same thread, and // using callbacks for notification - nsCOMPtrfileToPost; - - rv = NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(fileToPost)); - if (NS_FAILED(rv)) return rv; + nsCOMPtrfileToPost; + + rv = NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(fileToPost)); + if (NS_FAILED(rv)) return rv; // Tell the user we are posting the message! nsXPIDLString msg; mComposeBundle->GetStringByID(NS_MSG_POSTING_MESSAGE, getter_Copies(msg)); SetStatusMessage( msg ); - nsCOMPtr mailSession = do_GetService(kMsgMailSessionCID, &rv); - if (NS_FAILED(rv)) return rv; + nsCOMPtr mailSession = do_GetService(kMsgMailSessionCID, &rv); + if (NS_FAILED(rv)) return rv; - if (!mailSession) return NS_ERROR_FAILURE; + if (!mailSession) return NS_ERROR_FAILURE; nsCOMPtr msgWindow; //JFD TODO: we should use GetDefaultPrompt instead - rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow)); - if(NS_FAILED(rv)) - return rv; + rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow)); + if(NS_FAILED(rv)) + return rv; rv = nntpService->PostMessage(fileToPost, mCompFields->GetNewsgroups(), mCompFields->GetNewspostUrl(), uriListener, msgWindow, nsnull); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) return rv; } return rv; @@ -3188,20 +3215,20 @@ nsMsgComposeAndSend::Fail(nsresult failure_code, const PRUnichar * error_msg, ns } if (m_attachments_done_callback) - { - /* mime_free_message_state will take care of cleaning up the - attachment files and attachment structures */ - m_attachments_done_callback (failure_code, error_msg, nsnull); + { + /* mime_free_message_state will take care of cleaning up the + attachment files and attachment structures */ + m_attachments_done_callback (failure_code, error_msg, nsnull); m_attachments_done_callback = nsnull; - } - + } + if (m_status == NS_OK) m_status = NS_ERROR_BUT_DONT_SHOW_ALERT; - //Stop any pending process... - Abort(); - - return NS_OK; + //Stop any pending process... + Abort(); + + return NS_OK; } void @@ -3230,7 +3257,7 @@ nsMsgComposeAndSend::DoDeliveryExitProcessing(nsIURI * aUri, nsresult aExitCode, if (aCheckForMail) { if ((mCompFields->GetTo() && *mCompFields->GetTo()) || - (mCompFields->GetCc() && *mCompFields->GetCc()) || + (mCompFields->GetCc() && *mCompFields->GetCc()) || (mCompFields->GetBcc() && *mCompFields->GetBcc())) { // If we're sending this news message to mail as well, start it now. @@ -3318,7 +3345,7 @@ nsMsgComposeAndSend::DoFcc() nsresult rv = MimeDoFCC(mTempFileSpec, nsMsgDeliverNow, mCompFields->GetBcc(), - mCompFields->GetFcc(), + mCompFields->GetFcc(), mCompFields->GetNewspostUrl()); if (NS_FAILED(rv)) { @@ -3538,19 +3565,19 @@ nsresult nsMsgComposeAndSend::CreateAndSendMessage( nsIEditorShell *aEditor, nsIMsgIdentity *aUserIdentity, - nsIMsgCompFields *fields, - PRBool digest_p, - PRBool dont_deliver_p, - nsMsgDeliverMode mode, + nsIMsgCompFields *fields, + PRBool digest_p, + PRBool dont_deliver_p, + nsMsgDeliverMode mode, nsIMsgDBHdr *msgToReplace, - const char *attachment1_type, - const char *attachment1_body, - PRUint32 attachment1_body_length, - const nsMsgAttachmentData *attachments, - const nsMsgAttachedFile *preloaded_attachments, - void *relatedPart, - nsIDOMWindowInternal *parentWindow, - nsIMsgProgress *progress, + const char *attachment1_type, + const char *attachment1_body, + PRUint32 attachment1_body_length, + const nsMsgAttachmentData *attachments, + const nsMsgAttachedFile *preloaded_attachments, + void *relatedPart, + nsIDOMWindowInternal *parentWindow, + nsIMsgProgress *progress, nsIMsgSendListener *aListener, const char *password ) @@ -3568,7 +3595,7 @@ nsMsgComposeAndSend::CreateAndSendMessage( if (!attachment1_body || !*attachment1_body) { - attachment1_body_length = 0; + attachment1_body_length = 0; attachment1_body = (char *) nsnull; } @@ -3577,13 +3604,13 @@ nsMsgComposeAndSend::CreateAndSendMessage( mEditor = aEditor; rv = Init(aUserIdentity, (nsMsgCompFields *)fields, nsnull, - digest_p, dont_deliver_p, mode, msgToReplace, - attachment1_type, attachment1_body, - attachment1_body_length, - attachments, preloaded_attachments, + digest_p, dont_deliver_p, mode, msgToReplace, + attachment1_type, attachment1_body, + attachment1_body_length, + attachments, preloaded_attachments, password); - if (NS_FAILED(rv) && mSendReport) + if (NS_FAILED(rv) && mSendReport) mSendReport->SetError(nsIMsgSendReport::process_Current, rv, PR_FALSE); return rv; @@ -3592,11 +3619,11 @@ nsMsgComposeAndSend::CreateAndSendMessage( nsresult nsMsgComposeAndSend::SendMessageFile( nsIMsgIdentity *aUserIndentity, - nsIMsgCompFields *fields, + nsIMsgCompFields *fields, nsIFileSpec *sendIFileSpec, PRBool deleteSendFileOnCompletion, - PRBool digest_p, - nsMsgDeliverMode mode, + PRBool digest_p, + nsMsgDeliverMode mode, nsIMsgDBHdr *msgToReplace, nsIMsgSendListener *aListener, const char *password @@ -3641,20 +3668,20 @@ nsMsgComposeAndSend::SendMessageFile( if (!deleteSendFileOnCompletion) { NS_NewFileSpecWithSpec(*sendFileSpec, &mReturnFileSpec); - if (!mReturnFileSpec) + if (!mReturnFileSpec) return NS_ERROR_OUT_OF_MEMORY; } rv = Init(aUserIndentity, (nsMsgCompFields *)fields, sendFileSpec, - digest_p, PR_FALSE, mode, msgToReplace, - nsnull, nsnull, nsnull, - nsnull, nsnull, + digest_p, PR_FALSE, mode, msgToReplace, + nsnull, nsnull, nsnull, + nsnull, nsnull, password); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) rv = DeliverMessage(); - if (NS_FAILED(rv) && mSendReport) + if (NS_FAILED(rv) && mSendReport) mSendReport->SetError(nsIMsgSendReport::process_Current, rv, PR_FALSE); return rv; @@ -3689,7 +3716,7 @@ BuildURLAttachmentData(nsIURI *url) nsCRT::memset(attachments, 0, sizeof(nsMsgAttachmentData) * attachCount); attachments[0].url = url; // The URL to attach. This should be 0 to signify "end of list". - attachments[0].real_name = (char *)PL_strdup(theName); // The original name of this document, which will eventually show up in the + attachments[0].real_name = (char *)PL_strdup(theName); // The original name of this document, which will eventually show up in the NS_IF_ADDREF(url); return attachments; @@ -3705,7 +3732,7 @@ nsMsgComposeAndSend::SendToMagicFolder(nsMsgDeliverMode mode) nsresult rv = MimeDoFCC(mTempFileSpec, mode, mCompFields->GetBcc(), - mCompFields->GetFcc(), + mCompFields->GetFcc(), mCompFields->GetNewspostUrl()); // // The caller of MimeDoFCC needs to deal with failure. @@ -3756,23 +3783,23 @@ char* nsMsgGetEnvelopeLine(void) { static char result[75] = ""; - PRExplodedTime now; + PRExplodedTime now; char buffer[128] = ""; // Generate envelope line in format of: From - Sat Apr 18 20:01:49 1998 // // Use PR_FormatTimeUSEnglish() to format the date in US English format, - // then figure out what our local GMT offset is, and append it (since - // PR_FormatTimeUSEnglish() can't do that.) Generate four digit years as - // per RFC 1123 (superceding RFC 822.) + // then figure out what our local GMT offset is, and append it (since + // PR_FormatTimeUSEnglish() can't do that.) Generate four digit years as + // per RFC 1123 (superceding RFC 822.) // PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now); - PR_FormatTimeUSEnglish(buffer, sizeof(buffer), - "%a %b %d %H:%M:%S %Y", - &now); + PR_FormatTimeUSEnglish(buffer, sizeof(buffer), + "%a %b %d %H:%M:%S %Y", + &now); // This value must be in ctime() format, with English abbreviations. - // PL_strftime("... %c ...") is no good, because it is localized. + // PL_strftime("... %c ...") is no good, because it is localized. // PL_strcpy(result, "From - "); PL_strcpy(result + 7, buffer); @@ -3782,10 +3809,10 @@ nsMsgGetEnvelopeLine(void) nsresult nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, - nsMsgDeliverMode mode, - const char *bcc_header, - const char *fcc_header, - const char *news_url) + nsMsgDeliverMode mode, + const char *bcc_header, + const char *fcc_header, + const char *news_url) { nsresult status = NS_OK; char *ibuffer = 0; @@ -3823,11 +3850,11 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, // Create the file that will be used for the copy service! // nsFileSpec *tFileSpec = nsMsgCreateTempFileSpec("nscopy.tmp"); - if (!tFileSpec) + if (!tFileSpec) return NS_ERROR_FAILURE; NS_NewFileSpecWithSpec(*tFileSpec, &mCopyFileSpec); - if (!mCopyFileSpec) + if (!mCopyFileSpec) { delete tFileSpec; return NS_ERROR_INVALID_ARG; @@ -3836,7 +3863,7 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, nsOutputFileStream tempOutfile(*tFileSpec, PR_WRONLY | PR_CREATE_FILE, 00600); delete tFileSpec; if (! tempOutfile.is_open()) - { + { if (mSendReport) { nsAutoString error_msg; @@ -3856,42 +3883,42 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, // nsInputFileStream inputFile(*input_file); if (!inputFile.is_open() || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_2)) - { - if (mSendReport) - { + { + if (mSendReport) + { nsAutoString error_msg; nsAutoString path; input_file->GetNativePathString(path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } - status = NS_MSG_UNABLE_TO_OPEN_FILE; - goto FAIL; - } + status = NS_MSG_UNABLE_TO_OPEN_FILE; + goto FAIL; + } // now the buffers... ibuffer = nsnull; while (!ibuffer && (ibuffer_size >= 1024)) { - ibuffer = (char *) PR_Malloc(ibuffer_size); - if (!ibuffer) - ibuffer_size /= 2; + ibuffer = (char *) PR_Malloc(ibuffer_size); + if (!ibuffer) + ibuffer_size /= 2; } if (!ibuffer) - { - status = NS_ERROR_OUT_OF_MEMORY; - goto FAIL; - } + { + status = NS_ERROR_OUT_OF_MEMORY; + goto FAIL; + } // // First, we we need to put a Berkeley "From - " delimiter at the head of // the file for parsing... // if (mode == nsMsgDeliverNow && fcc_header) - turi = PL_strdup(fcc_header); + turi = PL_strdup(fcc_header); else - turi = GetFolderURIFromUserPrefs(mode, mUserIdentity); + turi = GetFolderURIFromUserPrefs(mode, mUserIdentity); status = MessageFolderIsLocal(mUserIdentity, mode, turi, &folderIsLocal); if (NS_FAILED(status)) { goto FAIL; } @@ -3906,7 +3933,7 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, printfString = nsTextFormatter::smprintf(msg, "?"); if (printfString) { - SetStatusMessage(printfString); + SetStatusMessage(printfString); PR_FREEIF(printfString); } } @@ -3929,103 +3956,103 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, // Write out an X-Mozilla-Status header. // // This is required for the queue file, so that we can overwrite it once - // the messages have been delivered, and so that the MSG_FLAG_QUEUED bit - // is set. + // the messages have been delivered, and so that the MSG_FLAG_QUEUED bit + // is set. // - // 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. + // 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. // // // Need to add these lines for POP3 ONLY! IMAP servers will handle // this status information for summary file regeneration for us. if ( (mode == nsMsgQueueForLater || mode == nsMsgSaveAsDraft || - mode == nsMsgSaveAsTemplate || mode == nsMsgDeliverNow) && + mode == nsMsgSaveAsTemplate || mode == nsMsgDeliverNow) && folderIsLocal ) - { - char *buf = 0; - PRUint16 flags = 0; + { + char *buf = 0; + PRUint16 flags = 0; - flags |= MSG_FLAG_READ; - if (mode == nsMsgQueueForLater) - flags |= MSG_FLAG_QUEUED; - buf = PR_smprintf(X_MOZILLA_STATUS_FORMAT CRLF, flags); - if (buf) - { + flags |= MSG_FLAG_READ; + if (mode == nsMsgQueueForLater) + flags |= MSG_FLAG_QUEUED; + buf = PR_smprintf(X_MOZILLA_STATUS_FORMAT CRLF, flags); + if (buf) + { PRInt32 len = PL_strlen(buf); n = tempOutfile.write(buf, len); - PR_FREEIF(buf); - if (n != len) + PR_FREEIF(buf); + if (n != len) { status = NS_ERROR_FAILURE; - goto FAIL; + goto FAIL; } - } - - PRUint32 flags2 = 0; - if (mode == nsMsgSaveAsTemplate) - flags2 |= MSG_FLAG_TEMPLATE; - buf = PR_smprintf(X_MOZILLA_STATUS2_FORMAT CRLF, flags2); - if (buf) - { + } + + PRUint32 flags2 = 0; + if (mode == nsMsgSaveAsTemplate) + flags2 |= MSG_FLAG_TEMPLATE; + buf = PR_smprintf(X_MOZILLA_STATUS2_FORMAT CRLF, flags2); + if (buf) + { PRInt32 len = PL_strlen(buf); n = tempOutfile.write(buf, len); - PR_FREEIF(buf); - if (n != len) + PR_FREEIF(buf); + if (n != len) { status = NS_ERROR_FAILURE; - goto FAIL; + goto FAIL; } - } - } + } + } // Write out the FCC and BCC headers. - // When writing to the Queue file, we *must* write the FCC and BCC - // headers, or else that information would be lost. Because, when actually - // delivering the message (with "deliver now") we do FCC/BCC right away; - // but when queueing for later delivery, we do FCC/BCC at delivery-time. + // When writing to the Queue file, we *must* write the FCC and BCC + // headers, or else that information would be lost. Because, when actually + // delivering the message (with "deliver now") we do FCC/BCC right away; + // but when queueing for later delivery, we do FCC/BCC at delivery-time. // - // The question remains of whether FCC and BCC should be written into normal - // BCC folders (like the Sent Mail folder.) + // The question remains of whether FCC and BCC should be written into normal + // BCC folders (like the Sent Mail folder.) // - // For FCC, there seems no point to do that; it's not information that one - // would want to refer back to. + // For FCC, there seems no point to do that; it's not information that one + // would want to refer back to. // - // For BCC, the question isn't as clear. On the one hand, if I send someone - // a BCC'ed copy of the message, and save a copy of it for myself (with FCC) - // I might want to be able to look at that message later and see the list of - // people to whom I had BCC'ed it. + // For BCC, the question isn't as clear. On the one hand, if I send someone + // a BCC'ed copy of the message, and save a copy of it for myself (with FCC) + // I might want to be able to look at that message later and see the list of + // people to whom I had BCC'ed it. // - // On the other hand, the contents of the BCC header is sensitive - // information, and should perhaps not be stored at all. + // On the other hand, the contents of the BCC header is sensitive + // information, and should perhaps not be stored at all. // - // Thus the consultation of the #define SAVE_BCC_IN_FCC_FILE. + // Thus the consultation of the #define SAVE_BCC_IN_FCC_FILE. // - // (Note that, if there is a BCC header present in a message in some random - // folder, and that message is forwarded to someone, then the attachment - // code will strip out the BCC header before forwarding it.) + // (Note that, if there is a BCC header present in a message in some random + // folder, and that message is forwarded to someone, then the attachment + // code will strip out the BCC header before forwarding it.) // if ((mode == nsMsgQueueForLater || mode == nsMsgSaveAsDraft || - mode == nsMsgSaveAsTemplate) && fcc_header && *fcc_header) - { - PRInt32 L = PL_strlen(fcc_header) + 20; - char *buf = (char *) PR_Malloc (L); - if (!buf) - { - status = NS_ERROR_OUT_OF_MEMORY; - goto FAIL; - } + mode == nsMsgSaveAsTemplate) && fcc_header && *fcc_header) + { + PRInt32 L = PL_strlen(fcc_header) + 20; + char *buf = (char *) PR_Malloc (L); + if (!buf) + { + status = NS_ERROR_OUT_OF_MEMORY; + goto FAIL; + } - PR_snprintf(buf, L-1, "FCC: %s" CRLF, fcc_header); + PR_snprintf(buf, L-1, "FCC: %s" CRLF, fcc_header); PRInt32 len = PL_strlen(buf); n = tempOutfile.write(buf, len); - if (n != len) + if (n != len) { status = NS_ERROR_FAILURE; goto FAIL; } - } + } // // Ok, now I want to get the identity key and write it out if this is for a @@ -4053,96 +4080,96 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, if (bcc_header && *bcc_header #ifndef SAVE_BCC_IN_FCC_FILE - && (mode == MSG_QueueForLater || mode == MSG_SaveAsDraft || - mode == MSG_SaveAsTemplate) + && (mode == MSG_QueueForLater || mode == MSG_SaveAsDraft || + mode == MSG_SaveAsTemplate) #endif - ) - { - PRInt32 L = PL_strlen(bcc_header) + 20; - char *buf = (char *) PR_Malloc (L); - if (!buf) - { - status = NS_ERROR_OUT_OF_MEMORY; - goto FAIL; - } + ) + { + PRInt32 L = PL_strlen(bcc_header) + 20; + char *buf = (char *) PR_Malloc (L); + if (!buf) + { + status = NS_ERROR_OUT_OF_MEMORY; + goto FAIL; + } - PR_snprintf(buf, L-1, "BCC: %s" CRLF, bcc_header); + PR_snprintf(buf, L-1, "BCC: %s" CRLF, bcc_header); PRInt32 len = PL_strlen(buf); n = tempOutfile.write(buf, len); - if (n != len) + if (n != len) { status = NS_ERROR_FAILURE; goto FAIL; } - } + } // // Write out the X-Mozilla-News-Host header. - // This is done only when writing to the queue file, not the FCC file. - // We need this to complement the "Newsgroups" header for the case of - // queueing a message for a non-default news host. + // This is done only when writing to the queue file, not the FCC file. + // We need this to complement the "Newsgroups" header for the case of + // queueing a message for a non-default news host. // - // Convert a URL like "snews://host:123/" to the form "host:123/secure" - // or "news://user@host:222" to simply "host:222". + // Convert a URL like "snews://host:123/" to the form "host:123/secure" + // or "news://user@host:222" to simply "host:222". // 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 = nsMsgParseURLHost (news_url); - char *host_and_port = orig_hap; - if (host_and_port) - { - // There may be authinfo at the front of the host - it could be of - // the form "user:password@host:port", so take off everything before - // the first at-sign. We don't want to store authinfo in the queue - // folder, I guess, but would want it to be re-prompted-for at - // delivery-time. - // - char *at = PL_strchr (host_and_port, '@'); - if (at) - host_and_port = at + 1; - } + mode == nsMsgSaveAsTemplate) && news_url && *news_url) + { + PRBool secure_p = (news_url[0] == 's' || news_url[0] == 'S'); + char *orig_hap = nsMsgParseURLHost (news_url); + char *host_and_port = orig_hap; + if (host_and_port) + { + // There may be authinfo at the front of the host - it could be of + // the form "user:password@host:port", so take off everything before + // the first at-sign. We don't want to store authinfo in the queue + // folder, I guess, but would want it to be re-prompted-for at + // delivery-time. + // + char *at = PL_strchr (host_and_port, '@'); + if (at) + host_and_port = at + 1; + } - if ((host_and_port && *host_and_port) || !secure_p) - { - char *line = PR_smprintf(X_MOZILLA_NEWSHOST ": %s%s" CRLF, - host_and_port ? host_and_port : "", - secure_p ? "/secure" : ""); - PR_FREEIF(orig_hap); - orig_hap = 0; - if (!line) - { - status = NS_ERROR_OUT_OF_MEMORY; - goto FAIL; - } + if ((host_and_port && *host_and_port) || !secure_p) + { + char *line = PR_smprintf(X_MOZILLA_NEWSHOST ": %s%s" CRLF, + host_and_port ? host_and_port : "", + secure_p ? "/secure" : ""); + PR_FREEIF(orig_hap); + orig_hap = 0; + if (!line) + { + status = NS_ERROR_OUT_OF_MEMORY; + goto FAIL; + } PRInt32 len = PL_strlen(line); n = tempOutfile.write(line, len); - PR_FREEIF(line); - if (n != len) + PR_FREEIF(line); + if (n != len) { status = NS_ERROR_FAILURE; goto FAIL; } - } + } - PR_FREEIF(orig_hap); - orig_hap = 0; - } + PR_FREEIF(orig_hap); + orig_hap = 0; + } // // Read from the message file, and write to the FCC or Queue file. - // There are two tricky parts: the first is that the message file - // uses CRLF, and the FCC file should use LINEBREAK. The second - // is that the message file may have lines beginning with "From " - // but the FCC file must have those lines mangled. + // There are two tricky parts: the first is that the message file + // uses CRLF, and the FCC file should use LINEBREAK. The second + // is that the message file may have lines beginning with "From " + // but the FCC file must have those lines mangled. // - // It's unfortunate that we end up writing the FCC file a line - // at a time, but it's the easiest way... + // It's unfortunate that we end up writing the FCC file a line + // at a time, but it's the easiest way... // while (! inputFile.eof()) - { + { // check *ibuffer in case that ibuffer isn't big enough if (!inputFile.readline(ibuffer, ibuffer_size) && *ibuffer == 0) { @@ -4152,28 +4179,28 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, n = tempOutfile.write(ibuffer, PL_strlen(ibuffer)); n += tempOutfile.write(CRLF, 2); - if (n != (PRInt32) (PL_strlen(ibuffer) + 2)) // write failed - { - status = NS_MSG_ERROR_WRITING_FILE; - goto FAIL; - } - } + if (n != (PRInt32) (PL_strlen(ibuffer) + 2)) // write failed + { + status = NS_MSG_ERROR_WRITING_FILE; + goto FAIL; + } + } // // Terminate with a final newline. // n = tempOutfile.write(CRLF, 2); if (n != 2) // write failed - { - status = NS_MSG_ERROR_WRITING_FILE; + { + status = NS_MSG_ERROR_WRITING_FILE; goto FAIL; - } + } FAIL: if (ibuffer) - PR_FREEIF(ibuffer); + PR_FREEIF(ibuffer); if (obuffer && obuffer != ibuffer) - PR_FREEIF(obuffer); + PR_FREEIF(obuffer); if (tempOutfile.is_open()) @@ -4195,15 +4222,15 @@ FAIL: // If we weren't successful, then we should just return the error and // bail out. // - if (NS_SUCCEEDED(status)) - { - // - // If we are here, time to start the async copy service operation! - // - status = StartMessageCopyOperation(mCopyFileSpec, mode, turi); - } - PR_FREEIF(turi); - return status; + if (NS_SUCCEEDED(status)) + { + // + // If we are here, time to start the async copy service operation! + // + status = StartMessageCopyOperation(mCopyFileSpec, mode, turi); + } + PR_FREEIF(turi); + return status; } // @@ -4213,7 +4240,7 @@ FAIL: nsresult nsMsgComposeAndSend::StartMessageCopyOperation(nsIFileSpec *aFileSpec, nsMsgDeliverMode mode, - char *dest_uri) + char *dest_uri) { mCopyObj = new nsMsgCopy(); if (!mCopyObj) @@ -4226,9 +4253,9 @@ nsMsgComposeAndSend::StartMessageCopyOperation(nsIFileSpec *aFileSpec, nsresult rv; if (dest_uri && *dest_uri) - m_folderName = dest_uri; + m_folderName = dest_uri; else - m_folderName = GetFolderURIFromUserPrefs(mode, mUserIdentity); + m_folderName = GetFolderURIFromUserPrefs(mode, mUserIdentity); if (mListener) mListener->OnGetDraftFolderURI(m_folderName.get()); diff --git a/mozilla/mailnews/compose/src/nsMsgSendLater.cpp b/mozilla/mailnews/compose/src/nsMsgSendLater.cpp index 52314397dd0..b4f92716a3e 100644 --- a/mozilla/mailnews/compose/src/nsMsgSendLater.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSendLater.cpp @@ -398,7 +398,7 @@ SendOperationListener::OnStopSending(const char *aMsgID, nsresult aStatus, const // nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); if (NS_SUCCEEDED(rv) && prefs) - prefs->GetBoolPref("mail.really_delete_draft", &deleteMsgs); + prefs->GetBoolPref("mail.really_delete_draft", &deleteMsgs); if (deleteMsgs) { @@ -477,7 +477,7 @@ nsCOMPtr pMsgSend = nsnull; if (NS_FAILED(mMessage->GetRecipients(getter_Copies(recips)))) return NS_ERROR_UNEXPECTED; else - mMessage->GetCcList(getter_Copies(ccList)); + mMessage->GetCcList(getter_Copies(ccList)); // Get the composition fields interface nsresult res = nsComponentManager::CreateInstance(kMsgCompFieldsCID, NULL, NS_GET_IID(nsIMsgCompFields), @@ -506,13 +506,13 @@ nsCOMPtr pMsgSend = nsnull; fields->SetFrom(author.get()); if (m_to) - fields->SetTo(m_to); + fields->SetTo(m_to); if (m_bcc) - fields->SetBcc(m_bcc); + fields->SetBcc(m_bcc); if (m_fcc) - fields->SetFcc(m_fcc); + fields->SetFcc(m_fcc); if (m_newsgroups) fields->SetNewsgroups(m_newsgroups); @@ -593,15 +593,15 @@ nsMsgSendLater::StartNextMailFileSend() #endif mTempFileSpec = nsMsgCreateTempFileSpec("nsqmail.tmp"); - if (!mTempFileSpec) + if (!mTempFileSpec) return NS_ERROR_FAILURE; NS_NewFileSpecWithSpec(*mTempFileSpec, &mTempIFileSpec); - if (!mTempIFileSpec) + if (!mTempIFileSpec) return NS_ERROR_FAILURE; nsIMsgMessageService * messageService = nsnull; - rv = GetMessageServiceFromURI(aMessageURI, &messageService); + rv = GetMessageServiceFromURI(aMessageURI, &messageService); if (NS_FAILED(rv) && !messageService) return NS_ERROR_FACTORY_NOT_LOADED; @@ -635,7 +635,7 @@ nsMsgSendLater::StartNextMailFileSend() ReleaseMessageServiceFromURI(aMessageURI, messageService); Release(); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; return NS_OK; @@ -696,7 +696,7 @@ nsMsgSendLater::SendUnsentMessages(nsIMsgIdentity *identity) // ### fix me - if we need to reparse the folder, this will be asynchronous nsCOMPtr enumerator; nsresult ret = mMessageFolder->GetMessages(m_window, getter_AddRefs(enumerator)); - if (NS_FAILED(ret) || (!enumerator)) + if (NS_FAILED(ret) || (!enumerator)) { NS_IF_RELEASE(mIdentity); mIdentity = nsnull; @@ -717,7 +717,7 @@ nsMsgSendLater::SendUnsentMessages(nsIMsgIdentity *identity) // now get an enumerator for our array mMessagesToSend->Enumerate(getter_AddRefs(mEnumerator)); - return StartNextMailFileSend(); + return StartNextMailFileSend(); } nsresult @@ -759,72 +759,72 @@ nsMsgSendLater::DeleteCurrentMessage() nsresult nsMsgSendLater::BuildHeaders() { - char *buf = m_headers; - char *buf_end = buf + m_headersFP; + char *buf = m_headers; + char *buf_end = buf + m_headersFP; - PR_FREEIF(m_to); - PR_FREEIF(m_bcc); - PR_FREEIF(m_newsgroups); - PR_FREEIF(m_newshost); - m_flags = 0; + PR_FREEIF(m_to); + PR_FREEIF(m_bcc); + PR_FREEIF(m_newsgroups); + PR_FREEIF(m_newshost); + m_flags = 0; - while (buf < buf_end) - { - PRBool prune_p = PR_FALSE; - PRBool do_flags_p = PR_FALSE; - PRBool do_return_receipt_p = PR_FALSE; - char *colon = PL_strchr(buf, ':'); - char *end; - char *value = 0; - char **header = 0; - char *header_start = buf; + while (buf < buf_end) + { + PRBool prune_p = PR_FALSE; + PRBool do_flags_p = PR_FALSE; + PRBool do_return_receipt_p = PR_FALSE; + char *colon = PL_strchr(buf, ':'); + char *end; + char *value = 0; + char **header = 0; + char *header_start = buf; - if (! colon) - break; + if (! colon) + break; - end = colon; - while (end > buf && (*end == ' ' || *end == '\t')) - end--; + end = colon; + while (end > buf && (*end == ' ' || *end == '\t')) + end--; - switch (buf [0]) - { - case 'B': case 'b': - if (!PL_strncasecmp ("BCC", buf, end - buf)) - { - header = &m_bcc; - prune_p = PR_TRUE; - } - break; - case 'C': case 'c': - if (!PL_strncasecmp ("CC", buf, end - buf)) - header = &m_to; - else if (!PL_strncasecmp (HEADER_CONTENT_LENGTH, buf, end - buf)) - prune_p = PR_TRUE; - break; - case 'F': case 'f': - if (!PL_strncasecmp ("FCC", buf, end - buf)) - { - header = &m_fcc; - prune_p = PR_TRUE; - } - break; - case 'L': case 'l': - if (!PL_strncasecmp ("Lines", buf, end - buf)) - prune_p = PR_TRUE; - break; - case 'N': case 'n': - if (!PL_strncasecmp ("Newsgroups", buf, end - buf)) - header = &m_newsgroups; - break; - case 'S': case 's': - if (!PL_strncasecmp ("Sender", buf, end - buf)) - prune_p = PR_TRUE; - break; - case 'T': case 't': - if (!PL_strncasecmp ("To", buf, end - buf)) - header = &m_to; - break; - case 'X': case 'x': + switch (buf [0]) + { + case 'B': case 'b': + if (!PL_strncasecmp ("BCC", buf, end - buf)) + { + header = &m_bcc; + prune_p = PR_TRUE; + } + break; + case 'C': case 'c': + if (!PL_strncasecmp ("CC", buf, end - buf)) + header = &m_to; + else if (!PL_strncasecmp (HEADER_CONTENT_LENGTH, buf, end - buf)) + prune_p = PR_TRUE; + break; + case 'F': case 'f': + if (!PL_strncasecmp ("FCC", buf, end - buf)) + { + header = &m_fcc; + prune_p = PR_TRUE; + } + break; + case 'L': case 'l': + if (!PL_strncasecmp ("Lines", buf, end - buf)) + prune_p = PR_TRUE; + break; + case 'N': case 'n': + if (!PL_strncasecmp ("Newsgroups", buf, end - buf)) + header = &m_newsgroups; + break; + case 'S': case 's': + if (!PL_strncasecmp ("Sender", buf, end - buf)) + prune_p = PR_TRUE; + break; + case 'T': case 't': + if (!PL_strncasecmp ("To", buf, end - buf)) + header = &m_to; + break; + case 'X': case 'x': { PRInt32 headLen = PL_strlen(HEADER_X_MOZILLA_STATUS2); if (headLen == end - buf && @@ -847,110 +847,110 @@ nsMsgSendLater::BuildHeaders() } break; } - } + } - buf = colon + 1; - while (*buf == ' ' || *buf == '\t') - buf++; + buf = colon + 1; + while (*buf == ' ' || *buf == '\t') + buf++; - value = buf; + value = buf; SEARCH_NEWLINE: - while (*buf != 0 && *buf != nsCRT::CR && *buf != nsCRT::LF) - buf++; + while (*buf != 0 && *buf != nsCRT::CR && *buf != nsCRT::LF) + buf++; - if (buf+1 >= buf_end) - ; - // If "\r\n " or "\r\n\t" is next, that doesn't terminate the header. - else if (buf+2 < buf_end && - (buf[0] == nsCRT::CR && buf[1] == nsCRT::LF) && - (buf[2] == ' ' || buf[2] == '\t')) - { - buf += 3; - goto SEARCH_NEWLINE; - } - // If "\r " or "\r\t" or "\n " or "\n\t" is next, that doesn't terminate - // the header either. - else if ((buf[0] == nsCRT::CR || buf[0] == nsCRT::LF) && - (buf[1] == ' ' || buf[1] == '\t')) - { - buf += 2; - goto SEARCH_NEWLINE; - } + if (buf+1 >= buf_end) + ; + // If "\r\n " or "\r\n\t" is next, that doesn't terminate the header. + else if (buf+2 < buf_end && + (buf[0] == nsCRT::CR && buf[1] == nsCRT::LF) && + (buf[2] == ' ' || buf[2] == '\t')) + { + buf += 3; + goto SEARCH_NEWLINE; + } + // If "\r " or "\r\t" or "\n " or "\n\t" is next, that doesn't terminate + // the header either. + else if ((buf[0] == nsCRT::CR || buf[0] == nsCRT::LF) && + (buf[1] == ' ' || buf[1] == '\t')) + { + buf += 2; + goto SEARCH_NEWLINE; + } - if (header) - { - int L = buf - value; - if (*header) - { - char *newh = (char*) PR_Realloc ((*header), - PL_strlen(*header) + L + 10); - if (!newh) return NS_ERROR_OUT_OF_MEMORY; - *header = newh; - newh = (*header) + PL_strlen (*header); - *newh++ = ','; - *newh++ = ' '; + if (header) + { + int L = buf - value; + if (*header) + { + char *newh = (char*) PR_Realloc ((*header), + PL_strlen(*header) + L + 10); + if (!newh) return NS_ERROR_OUT_OF_MEMORY; + *header = newh; + newh = (*header) + PL_strlen (*header); + *newh++ = ','; + *newh++ = ' '; nsCRT::memcpy(newh, value, L); - newh [L] = 0; - } - else - { - *header = (char *) PR_Malloc(L+1); - if (!*header) return NS_ERROR_OUT_OF_MEMORY; + newh [L] = 0; + } + else + { + *header = (char *) PR_Malloc(L+1); + if (!*header) return NS_ERROR_OUT_OF_MEMORY; nsCRT::memcpy((*header), value, L); - (*header)[L] = 0; - } - } - else if (do_flags_p) - { - int i; - char *s = value; - PR_ASSERT(*s != ' ' && *s != '\t'); - m_flags = 0; - for (i=0 ; i<4 ; i++) { - m_flags = (m_flags << 4) | UNHEX(*s); - s++; - } - } - else if (do_return_receipt_p) - { - int L = buf - value; - char *draftInfo = (char*) PR_Malloc(L+1); - char *receipt = NULL; - if (!draftInfo) return NS_ERROR_OUT_OF_MEMORY; + (*header)[L] = 0; + } + } + else if (do_flags_p) + { + int i; + char *s = value; + PR_ASSERT(*s != ' ' && *s != '\t'); + m_flags = 0; + for (i=0 ; i<4 ; i++) { + m_flags = (m_flags << 4) | UNHEX(*s); + s++; + } + } + else if (do_return_receipt_p) + { + int L = buf - value; + char *draftInfo = (char*) PR_Malloc(L+1); + char *receipt = NULL; + if (!draftInfo) return NS_ERROR_OUT_OF_MEMORY; nsCRT::memcpy(draftInfo, value, L); - *(draftInfo+L)=0; - receipt = PL_strstr(draftInfo, "receipt="); - if (receipt) - { - char *s = receipt+8; - int requestForReturnReceipt = 0; - PR_sscanf(s, "%d", &requestForReturnReceipt); - + *(draftInfo+L)=0; + receipt = PL_strstr(draftInfo, "receipt="); + if (receipt) + { + char *s = receipt+8; + int requestForReturnReceipt = 0; + PR_sscanf(s, "%d", &requestForReturnReceipt); + if ((requestForReturnReceipt == 2 || requestForReturnReceipt == 3)) mRequestReturnReceipt = PR_TRUE; - } - PR_FREEIF(draftInfo); - } + } + PR_FREEIF(draftInfo); + } - if (*buf == nsCRT::CR || *buf == nsCRT::LF) - { - if (*buf == nsCRT::CR && buf[1] == nsCRT::LF) - buf++; - buf++; - } + if (*buf == nsCRT::CR || *buf == nsCRT::LF) + { + if (*buf == nsCRT::CR && buf[1] == nsCRT::LF) + buf++; + buf++; + } - if (prune_p) - { - char *to = header_start; - char *from = buf; - while (from < buf_end) - *to++ = *from++; - buf = header_start; - buf_end = to; - m_headersFP = buf_end - m_headers; - } - } + if (prune_p) + { + char *to = header_start; + char *from = buf; + while (from < buf_end) + *to++ = *from++; + buf = header_start; + buf_end = to; + m_headersFP = buf_end - m_headers; + } + } m_headers[m_headersFP++] = nsCRT::CR; m_headers[m_headersFP++] = nsCRT::LF; @@ -962,7 +962,7 @@ SEARCH_NEWLINE: int DoGrowBuffer(PRInt32 desired_size, PRInt32 element_size, PRInt32 quantum, - char **buffer, PRInt32 *size) + char **buffer, PRInt32 *size) { if (*size <= desired_size) { @@ -987,7 +987,7 @@ DoGrowBuffer(PRInt32 desired_size, PRInt32 element_size, PRInt32 quantum, #define do_grow_headers(desired_size) \ (((desired_size) >= m_headersSize) ? \ DoGrowBuffer ((desired_size), sizeof(char), 1024, \ - &m_headers, &m_headersSize) \ + &m_headers, &m_headersSize) \ : 0) nsresult @@ -1017,7 +1017,7 @@ nsMsgSendLater::DeliverQueuedLine(char *line, PRInt32 length) { if (m_headersPosition == 0) { - // This line is the first line in a header block. + // This line is the first line in a header block. // Remember its position. m_headersPosition = m_position; @@ -1041,11 +1041,11 @@ nsMsgSendLater::DeliverQueuedLine(char *line, PRInt32 length) if (line[0] == nsCRT::CR || line[0] == nsCRT::LF || line[0] == 0) { - // End of headers. Now parse them; open the temp file; + // End of headers. Now parse them; open the temp file; // and write the appropriate subset of the headers out. m_inhead = PR_FALSE; - mOutFile = new nsOutputFileStream(*mTempFileSpec, PR_WRONLY | PR_CREATE_FILE, 00600); + mOutFile = new nsOutputFileStream(*mTempFileSpec, PR_WRONLY | PR_CREATE_FILE, 00600); if ( (!mOutFile) || (!mOutFile->is_open()) ) return NS_MSG_ERROR_WRITING_FILE; @@ -1058,7 +1058,7 @@ nsMsgSendLater::DeliverQueuedLine(char *line, PRInt32 length) } else { - // Otherwise, this line belongs to a header. So append it to the + // Otherwise, this line belongs to a header. So append it to the // header data. if (!PL_strncasecmp (line, HEADER_X_MOZILLA_STATUS, PL_strlen(HEADER_X_MOZILLA_STATUS))) @@ -1225,7 +1225,7 @@ nsMsgSendLater::DealWithTheIdentityMojo(nsIMsgIdentity *identity, nsCOMPtr identities; if (NS_SUCCEEDED(defAcc->GetIdentities(getter_AddRefs(identities)))) { - nsIMsgIdentity *lookupIdentity = nsnull; + nsCOMPtr lookupIdentity; PRUint32 count = 0; char *tName = nsnull; @@ -1233,7 +1233,7 @@ nsMsgSendLater::DealWithTheIdentityMojo(nsIMsgIdentity *identity, for (PRUint32 i=0; i < count; i++) { rv = identities->QueryElementAt(0, NS_GET_IID(nsIMsgIdentity), - (void **)&lookupIdentity); + getter_AddRefs(lookupIdentity)); if (NS_FAILED(rv)) continue; @@ -1242,14 +1242,12 @@ nsMsgSendLater::DealWithTheIdentityMojo(nsIMsgIdentity *identity, { PR_FREEIF(tName); NS_IF_RELEASE(mIdentity); - mIdentity = lookupIdentity; + mIdentity = lookupIdentity.get(); NS_IF_ADDREF(mIdentity); return NS_OK; } else - { PR_FREEIF(tName); - } } } } diff --git a/mozilla/mailnews/compose/src/nsMsgSendPart.cpp b/mozilla/mailnews/compose/src/nsMsgSendPart.cpp index 00e55ae9730..6c4c6a86d3f 100644 --- a/mozilla/mailnews/compose/src/nsMsgSendPart.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSendPart.cpp @@ -49,6 +49,8 @@ #include "nsMsgMimeCID.h" #include "nsMimeTypes.h" #include "prmem.h" +#include "nsMsgPrompts.h" +#include "nsMsgComposeStringBundle.h" // defined in msgCompGlue.cpp static char *mime_mailto_stream_read_buffer = 0; @@ -73,7 +75,7 @@ nsresult MIME_EncoderWrite(MimeEncoderData *data, const char *buffer, PRInt32 si nsMsgSendPart::nsMsgSendPart(nsIMsgSend* state, const char *part_charset) { - m_state = nsnull; + m_state = nsnull; PL_strcpy(m_charset_name, part_charset ? part_charset : "us-ascii"); m_children = nsnull; @@ -99,19 +101,19 @@ nsMsgSendPart::nsMsgSendPart(nsIMsgSend* state, const char *part_charset) nsMsgSendPart::~nsMsgSendPart() { - if (m_encoder_data) { - MIME_EncoderDestroy(m_encoder_data, PR_FALSE); - m_encoder_data = nsnull; - } - for (int i=0 ; i < m_numchildren; i++) - delete m_children[i]; + if (m_encoder_data) { + MIME_EncoderDestroy(m_encoder_data, PR_FALSE); + m_encoder_data = nsnull; + } + for (int i=0 ; i < m_numchildren; i++) + delete m_children[i]; - delete [] m_children; + delete [] m_children; PR_FREEIF(m_buffer); - PR_FREEIF(m_other); - if (m_filespec) + PR_FREEIF(m_other); + if (m_filespec) delete m_filespec; - PR_FREEIF(m_type); + PR_FREEIF(m_type); } int nsMsgSendPart::CopyString(char** dest, const char* src) @@ -175,22 +177,22 @@ int nsMsgSendPart::SetMimeDeliveryState(nsIMsgSend *state) int nsMsgSendPart::AppendOtherHeaders(const char* more) { - if (!m_other) - return SetOtherHeaders(more); + if (!m_other) + return SetOtherHeaders(more); - if (!more || !*more) - return 0; + if (!more || !*more) + return 0; - char* tmp = (char *) PR_Malloc(sizeof(char) * (PL_strlen(m_other) + PL_strlen(more) + 2)); - if (!tmp) - return NS_ERROR_OUT_OF_MEMORY; + char* tmp = (char *) PR_Malloc(sizeof(char) * (PL_strlen(m_other) + PL_strlen(more) + 2)); + if (!tmp) + return NS_ERROR_OUT_OF_MEMORY; - PL_strcpy(tmp, m_other); - PL_strcat(tmp, more); - PR_FREEIF(m_other); - m_other = tmp; + PL_strcpy(tmp, m_other); + PL_strcat(tmp, more); + PR_FREEIF(m_other); + m_other = tmp; - return 0; + return 0; } @@ -323,7 +325,7 @@ int nsMsgSendPart::PushBody(char* buffer, PRInt32 length) out = buffer; } else { - /* Fix for bug #95985. We can't assume that all lines are shorter + /* 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. */ @@ -454,11 +456,11 @@ divide_content_headers(const char *headers, } #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. + // ### 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"); @@ -488,11 +490,11 @@ nsMsgSendPart::Write() int status = 0; char *separator = nsnull; -#define PUSHLEN(str, length) \ - do { \ - status = mime_write_message_body(m_state, str, length); \ - if (status < 0) goto FAIL; \ - } while (0) \ +#define PUSHLEN(str, length) \ + do { \ + status = mime_write_message_body(m_state, str, length); \ + if (status < 0) goto FAIL; \ + } while (0) \ #define PUSH(str) PUSHLEN(str, PL_strlen(str)) @@ -504,7 +506,7 @@ nsMsgSendPart::Write() return SKIP_EMPTY_PART; if (m_mainpart && m_type && PL_strcmp(m_type, TEXT_HTML) == 0) - { + { if (m_filespec) { // The "insert HTML links" code requires a memory buffer, @@ -532,7 +534,7 @@ nsMsgSendPart::Write() } if (m_parent && m_parent->m_type && - !PL_strcasecmp(m_parent->m_type, MULTIPART_DIGEST) && + !PL_strcasecmp(m_parent->m_type, MULTIPART_DIGEST) && m_type && (!PL_strcasecmp(m_type, MESSAGE_RFC822) || !PL_strcasecmp(m_type, MESSAGE_NEWS))) @@ -642,7 +644,7 @@ nsMsgSendPart::Write() } } - PUSH(CRLF); // A blank line, to mark the end of headers. + PUSH(CRLF); // A blank line, to mark the end of headers. m_firstBlock = PR_TRUE; /* only convert if we need to tag charset */ @@ -660,8 +662,18 @@ nsMsgSendPart::Write() if (!myStream.is_open()) { - status = -1; // ### Better error code for a temp file // mysteriously disappearing? + nsCOMPtr sendReport; + m_state->GetSendReport(getter_AddRefs(sendReport)); + if (sendReport) + { + nsAutoString error_msg; + nsAutoString path; + m_filespec->GetNativePathString(path); + nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); + sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); + } + status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; goto FAIL; } /* Kludge to avoid having to allocate memory on the toy computers... */ @@ -719,7 +731,7 @@ nsMsgSendPart::Write() if (!PL_strncasecmp(line, "BCC:", 4) || !PL_strncasecmp(line, "FCC:", 4) || !PL_strncasecmp(line, CONTENT_LENGTH ":", - CONTENT_LENGTH_LEN + 1) || + CONTENT_LENGTH_LEN + 1) || !PL_strncasecmp(line, "Lines:", 6) || !PL_strncasecmp(line, "Status:", 7) || !PL_strncasecmp(line, X_MOZILLA_STATUS ":", @@ -736,7 +748,7 @@ nsMsgSendPart::Write() PUSH(line); if (*line == nsCRT::CR || *line == nsCRT::LF) { - break; // Now can do normal reads for the body. + break; // Now can do normal reads for the body. } } } @@ -775,8 +787,8 @@ nsMsgSendPart::Write() PUSH(CRLF); PUSH("--"); - PUSH(separator); - PUSH(CRLF); + PUSH(separator); + PUSH(CRLF); } status = m_children[i]->Write(); @@ -794,7 +806,7 @@ nsMsgSendPart::Write() PUSH(separator); PUSH("--"); PUSH(CRLF); - } + } FAIL: PR_FREEIF(separator); diff --git a/mozilla/mailnews/mime/src/mimedrft.cpp b/mozilla/mailnews/mime/src/mimedrft.cpp index 1ad92fb1819..19e49803a27 100644 --- a/mozilla/mailnews/mime/src/mimedrft.cpp +++ b/mozilla/mailnews/mime/src/mimedrft.cpp @@ -159,13 +159,13 @@ nsMsgCreateTempFileSpec(char *tFileName) //////////////////////////////////////////////////////////////////////////////////// typedef enum { - nsMsg_RETURN_RECEIPT_BOOL_HEADER_MASK = 0, - nsMsg_ENCRYPTED_BOOL_HEADER_MASK, - nsMsg_SIGNED_BOOL_HEADER_MASK, - nsMsg_UUENCODE_BINARY_BOOL_HEADER_MASK, - nsMsg_ATTACH_VCARD_BOOL_HEADER_MASK, - nsMsg_LAST_BOOL_HEADER_MASK // last boolean header mask; must be the last one - // DON'T remove. + nsMsg_RETURN_RECEIPT_BOOL_HEADER_MASK = 0, + nsMsg_ENCRYPTED_BOOL_HEADER_MASK, + nsMsg_SIGNED_BOOL_HEADER_MASK, + nsMsg_UUENCODE_BINARY_BOOL_HEADER_MASK, + nsMsg_ATTACH_VCARD_BOOL_HEADER_MASK, + nsMsg_LAST_BOOL_HEADER_MASK // last boolean header mask; must be the last one + // DON'T remove. } nsMsgBoolHeaderSet; extern "C" void @@ -176,19 +176,19 @@ mime_dump_attachments ( nsMsgAttachmentData *attachData ) while ( (tmp) && (tmp->real_name) ) { - printf("Real Name : %s\n", tmp->real_name); + printf("Real Name : %s\n", tmp->real_name); if ( tmp->url ) { char *spec = nsnull; tmp->url->GetSpec(&spec); - printf("URL : %s\n", spec); + printf("URL : %s\n", spec); } - printf("Desired Type : %s\n", tmp->desired_type); + printf("Desired Type : %s\n", tmp->desired_type); printf("Real Type : %s\n", tmp->real_type); - printf("Real Encoding : %s\n", tmp->real_encoding); + printf("Real Encoding : %s\n", tmp->real_encoding); printf("Description : %s\n", tmp->description); printf("Mac Type : %s\n", tmp->x_mac_type); printf("Mac Creator : %s\n", tmp->x_mac_creator); @@ -200,43 +200,46 @@ mime_dump_attachments ( nsMsgAttachmentData *attachData ) nsresult CreateTheComposeWindow(nsIMsgCompFields *compFields, nsMsgAttachmentData *attachmentList, - MSG_ComposeType composeType, + MSG_ComposeType composeType, MSG_ComposeFormat composeFormat, - nsIMsgIdentity * identity) + nsIMsgIdentity * identity + ) { nsresult rv; MSG_ComposeFormat format = nsIMsgCompFormat::Default; #ifdef NS_DEBUG -printf("RICHIE: Need to do something with the attachment data!!!!\n"); mime_dump_attachments ( attachmentList ); #endif nsMsgAttachmentData *curAttachment = attachmentList; if (curAttachment) { - nsCAutoString attachments; - char* spec = nsnull; + nsXPIDLCString spec; - while (curAttachment && curAttachment->real_name) - { - rv = curAttachment->url->GetSpec(&spec); - if (NS_SUCCEEDED(rv) && spec) - { - if (attachments.Length()) - attachments.Append(','); - attachments.Append(spec); - nsCRT::free(spec); - spec = nsnull; - } - curAttachment++; - } - if (attachments.Length()) - { - compFields->SetAttachments(attachments.get()); - // remember the temp files to delete - compFields->SetTemporaryFiles(attachments.get()); - } + while (curAttachment && curAttachment->real_name) //JFD: Why do we check for real_name? + { + rv = curAttachment->url->GetSpec(getter_Copies(spec)); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && attachment) + { + nsAutoString nameStr; + rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), curAttachment->real_name, nameStr); + if (NS_FAILED(rv)) + nameStr.AssignWithConversion(curAttachment->real_name); + attachment->SetName(nameStr.get()); + attachment->SetUrl(spec.get()); + attachment->SetTemporary(PR_TRUE); + attachment->SetContentType(curAttachment->real_type); + attachment->SetMacType(curAttachment->x_mac_type); + attachment->SetMacCreator(curAttachment->x_mac_creator); + compFields->AddAttachment(attachment); + } + } + curAttachment++; + } } nsCOMPtr msgComposeService = @@ -246,56 +249,63 @@ mime_dump_attachments ( attachmentList ); if (identity && composeType == nsIMsgCompType::ForwardInline) { - PRBool composeHtml = PR_FALSE; - identity->GetComposeHtml(&composeHtml); - if (composeHtml) - format = nsIMsgCompFormat::HTML; - else - { - format = nsIMsgCompFormat::PlainText; - /* do we we need to convert the HTML body to plain text? */ - if (composeFormat == nsIMsgCompFormat::HTML) - compFields->ConvertBodyToPlainText(); - } + PRBool composeHtml = PR_FALSE; + identity->GetComposeHtml(&composeHtml); + if (composeHtml) + format = nsIMsgCompFormat::HTML; + else + { + format = nsIMsgCompFormat::PlainText; + /* do we we need to convert the HTML body to plain text? */ + if (composeFormat == nsIMsgCompFormat::HTML) + compFields->ConvertBodyToPlainText(); + } } else format = composeFormat; + + nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv) && pMsgComposeParams) + { + pMsgComposeParams->SetType(composeType); + pMsgComposeParams->SetFormat(format); + pMsgComposeParams->SetIdentity(identity); + pMsgComposeParams->SetComposeFields(compFields); - rv = msgComposeService->OpenComposeWindowWithCompFields(nsnull, /* default chrome */ - composeType, format, compFields, identity); + rv = msgComposeService->OpenComposeWindowWithParams(nsnull /* default chrome */, pMsgComposeParams); + } return rv; } -nsIMsgCompFields * +nsresult CreateCompositionFields(const char *from, - const char *reply_to, - const char *to, - const char *cc, - const char *bcc, - const char *fcc, - const char *newsgroups, - const char *followup_to, - const char *organization, - const char *subject, - const char *references, - const char *other_random_headers, - const char *priority, - const char *attachment, + const char *reply_to, + const char *to, + const char *cc, + const char *bcc, + const char *fcc, + const char *newsgroups, + const char *followup_to, + const char *organization, + const char *subject, + const char *references, + const char *other_random_headers, + const char *priority, const char *newspost_url, PRBool xlate_p, PRBool sign_p, - char *charset) + char *charset, + nsIMsgCompFields **_retval) { - nsIMsgCompFields *cFields = nsnull; - char *val; + NS_ENSURE_ARG_POINTER(_retval); - // Create the compose fields... - nsresult rv = nsComponentManager::CreateInstance(kMsgCompFieldsCID, NULL, - NS_GET_IID(nsIMsgCompFields), - (void **) &cFields); - if (NS_FAILED(rv) || !cFields) - return nsnull; - NS_ADDREF(cFields); + nsresult rv; + *_retval = nsnull; + + char *val; + nsCOMPtr cFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(cFields, NS_ERROR_OUT_OF_MEMORY); // Now set all of the passed in stuff... cFields->SetCharacterSet(charset); @@ -352,15 +362,14 @@ CreateCompositionFields(const char *from, cFields->SetPriority(val ? val : priority); PR_FREEIF(val); - val = MIME_DecodeMimeHeader(attachment, charset, PR_FALSE, PR_TRUE); - cFields->SetAttachments(val ? val : attachment); - PR_FREEIF(val); - val = MIME_DecodeMimeHeader(newspost_url, charset, PR_FALSE, PR_TRUE); cFields->SetNewspostUrl(val ? val : newspost_url); PR_FREEIF(val); - return cFields; + *_retval = cFields; + NS_IF_ADDREF(*_retval); + + return rv; } // RICHIE: @@ -423,13 +432,13 @@ mime_free_attach_data ( nsMsgAttachmentData *attachData, int cleanupCount) for ( i=0; i < cleanupCount; i++, tmp++ ) { - if ( tmp->url ) + if ( tmp->url ) delete tmp->url; PR_FREEIF(tmp->real_name); - PR_FREEIF(tmp->desired_type); + PR_FREEIF(tmp->desired_type); PR_FREEIF(tmp->real_type); - PR_FREEIF(tmp->real_encoding); + PR_FREEIF(tmp->real_encoding); PR_FREEIF(tmp->description); PR_FREEIF(tmp->x_mac_type); PR_FREEIF(tmp->x_mac_creator); @@ -448,19 +457,19 @@ mime_free_attachments ( nsMsgAttachedFile *attachments, int count ) for ( i = 0; i < count; i++, cur++ ) { - if ( cur->orig_url ) + if ( cur->orig_url ) NS_RELEASE(cur->orig_url); - PR_FREEIF ( cur->type ); - PR_FREEIF ( cur->encoding ); - PR_FREEIF ( cur->description ); - PR_FREEIF ( cur->x_mac_type ); - PR_FREEIF ( cur->x_mac_creator ); - if ( cur->file_spec ) + PR_FREEIF ( cur->type ); + PR_FREEIF ( cur->encoding ); + PR_FREEIF ( cur->description ); + PR_FREEIF ( cur->x_mac_type ); + PR_FREEIF ( cur->x_mac_creator ); + if ( cur->file_spec ) { cur->file_spec->Delete(PR_FALSE); - delete ( cur->file_spec ); - } + delete ( cur->file_spec ); + } } PR_FREEIF( attachments ); @@ -477,7 +486,7 @@ mime_draft_process_attachments(mime_draft_data *mdd) NS_ASSERTION ( mdd->attachments_count && mdd->attachments, "processing attachments but there aren't any" ); if ( !mdd->attachments || !mdd->attachments_count ) - return nsnull; + return nsnull; attachData = (nsMsgAttachmentData *) PR_MALLOC( ( (mdd->attachments_count+1) * sizeof (nsMsgAttachmentData) ) ); if ( !attachData ) @@ -490,13 +499,13 @@ mime_draft_process_attachments(mime_draft_data *mdd) for ( i=0; i < mdd->attachments_count; i++, tmp++, tmpFile++ ) { - if (tmpFile->type) + if (tmpFile->type) { - if (nsCRT::strcasecmp ( tmpFile->type, "text/x-vcard") == 0) - NS_MsgSACopy (&(tmp->real_name), tmpFile->description); - } + if (nsCRT::strcasecmp ( tmpFile->type, "text/x-vcard") == 0) + NS_MsgSACopy (&(tmp->real_name), tmpFile->description); + } - if ( tmpFile->orig_url ) + if ( tmpFile->orig_url ) { char *tmpSpec = nsnull; if (NS_FAILED(tmpFile->orig_url->GetSpec(&tmpSpec))) @@ -513,35 +522,40 @@ mime_draft_process_attachments(mime_draft_data *mdd) } NS_ADDREF(tmp->url); - if (!tmp->real_name) - NS_MsgSACopy ( &(tmp->real_name), tmpSpec ); - } + if (!tmp->real_name) + { + if (tmpFile->real_name) + NS_MsgSACopy ( &(tmp->real_name), tmpFile->real_name ); + else + NS_MsgSACopy ( &(tmp->real_name), tmpSpec ); + } + } - if ( tmpFile->type ) + if ( tmpFile->type ) { - NS_MsgSACopy ( &(tmp->desired_type), tmpFile->type ); - NS_MsgSACopy ( &(tmp->real_type), tmpFile->type ); - } + NS_MsgSACopy ( &(tmp->desired_type), tmpFile->type ); + NS_MsgSACopy ( &(tmp->real_type), tmpFile->type ); + } - if ( tmpFile->encoding ) + if ( tmpFile->encoding ) { - NS_MsgSACopy ( &(tmp->real_encoding), tmpFile->encoding ); - } + NS_MsgSACopy ( &(tmp->real_encoding), tmpFile->encoding ); + } - if ( tmpFile->description ) + if ( tmpFile->description ) { - NS_MsgSACopy ( &(tmp->description), tmpFile->description ); - } + NS_MsgSACopy ( &(tmp->description), tmpFile->description ); + } - if ( tmpFile->x_mac_type ) + if ( tmpFile->x_mac_type ) { - NS_MsgSACopy ( &(tmp->x_mac_type), tmpFile->x_mac_type ); - } + NS_MsgSACopy ( &(tmp->x_mac_type), tmpFile->x_mac_type ); + } - if ( tmpFile->x_mac_creator ) + if ( tmpFile->x_mac_creator ) { - NS_MsgSACopy ( &(tmp->x_mac_creator), tmpFile->x_mac_creator ); - } + NS_MsgSACopy ( &(tmp->x_mac_creator), tmpFile->x_mac_creator ); + } } return (attachData); @@ -555,27 +569,27 @@ FAIL: static void mime_fix_up_html_address( char **addr) { - // + // // We need to replace paired <> they are treated as HTML tag // - if (addr && *addr && PL_strchr(*addr, '<') && PL_strchr(*addr, '>')) - { - char *lt = NULL; - PRInt32 newLen = 0; - do - { - newLen = nsCRT::strlen(*addr) + 3 + 1; - *addr = (char *) PR_REALLOC(*addr, newLen); - NS_ASSERTION (*addr, "out of memory fixing up html address"); - lt = PL_strchr(*addr, '<'); - NS_ASSERTION(lt, "couldn't find < char in address"); + if (addr && *addr && PL_strchr(*addr, '<') && PL_strchr(*addr, '>')) + { + char *lt = NULL; + PRInt32 newLen = 0; + do + { + newLen = nsCRT::strlen(*addr) + 3 + 1; + *addr = (char *) PR_REALLOC(*addr, newLen); + NS_ASSERTION (*addr, "out of memory fixing up html address"); + lt = PL_strchr(*addr, '<'); + NS_ASSERTION(lt, "couldn't find < char in address"); nsCRT::memmove(lt+4, lt+1, newLen - 4 - (lt - *addr)); - *lt++ = '&'; - *lt++ = 'l'; - *lt++ = 't'; - *lt = ';'; - } while (PL_strchr(*addr, '<')); - } + *lt++ = '&'; + *lt++ = 'l'; + *lt++ = 't'; + *lt = ';'; + } while (PL_strchr(*addr, '<')); + } } static void @@ -585,53 +599,53 @@ mime_intl_mimepart_2_str(char **str, char *mcharset) // Converting these header values for UTF-8 for proper display // in the text input widgets. // - if (str && *str) - { + if (str && *str) + { // Now do conversion to UTF-8??? char *newStr = NULL; PRInt32 newStrLen; PRInt32 res = MIME_ConvertCharset(PR_TRUE, mcharset, "UTF-8", *str, nsCRT::strlen(*str), &newStr, &newStrLen, NULL); - if ( (NS_SUCCEEDED(res)) && (newStr && newStr != *str)) - { - PR_FREEIF(*str); - *str = newStr; - } - else - { - MIME_StripContinuations(*str); - } - } + if ( (NS_SUCCEEDED(res)) && (newStr && newStr != *str)) + { + PR_FREEIF(*str); + *str = newStr; + } + else + { + MIME_StripContinuations(*str); + } + } } static void mime_intl_insert_message_header_1(char **body, char **hdr_value, - char *hdr_str, - const char *html_hdr_str, - char *mailcharset, - PRBool htmlEdit) + char *hdr_str, + const char *html_hdr_str, + char *mailcharset, + PRBool htmlEdit) { - if (!body || !hdr_value || !hdr_str) - return; + if (!body || !hdr_value || !hdr_str) + return; - if (htmlEdit) - { - NS_MsgSACat(body, HEADER_START_JUNK); - } - else - { - NS_MsgSACat(body, MSG_LINEBREAK); - } - if (!html_hdr_str) - html_hdr_str = hdr_str; - NS_MsgSACat(body, html_hdr_str); - if (htmlEdit) - { - NS_MsgSACat(body, HEADER_MIDDLE_JUNK); - } - else - NS_MsgSACat(body, ": "); + if (htmlEdit) + { + NS_MsgSACat(body, HEADER_START_JUNK); + } + else + { + NS_MsgSACat(body, MSG_LINEBREAK); + } + if (!html_hdr_str) + html_hdr_str = hdr_str; + NS_MsgSACat(body, html_hdr_str); + if (htmlEdit) + { + NS_MsgSACat(body, HEADER_MIDDLE_JUNK); + } + else + NS_MsgSACat(body, ": "); // MIME decode header char* utf8 = MIME_DecodeMimeHeader(*hdr_value, mailcharset, PR_FALSE, @@ -643,8 +657,8 @@ mime_intl_insert_message_header_1(char **body, NS_MsgSACat(body, *hdr_value); // raw MIME encoded string } - if (htmlEdit) - NS_MsgSACat(body, HEADER_END_JUNK); + if (htmlEdit) + NS_MsgSACat(body, HEADER_END_JUNK); } char * @@ -663,442 +677,442 @@ MimeGetNamedString(PRInt32 id) static void mime_insert_all_headers(char **body, - MimeHeaders *headers, - MSG_ComposeFormat composeFormat, - char *mailcharset) + MimeHeaders *headers, + MSG_ComposeFormat composeFormat, + char *mailcharset) { - PRBool htmlEdit = (composeFormat == nsIMsgCompFormat::HTML); - char *newBody = NULL; - char *html_tag = PL_strcasestr(*body, ""); - int i; + PRBool htmlEdit = (composeFormat == nsIMsgCompFormat::HTML); + char *newBody = NULL; + char *html_tag = PL_strcasestr(*body, ""); + int i; - if (!headers->done_p) - { - MimeHeaders_build_heads_list(headers); - headers->done_p = PR_TRUE; - } + if (!headers->done_p) + { + MimeHeaders_build_heads_list(headers); + headers->done_p = PR_TRUE; + } - if (htmlEdit) - { - if (html_tag) - { - *html_tag = 0; - NS_MsgSACopy(&(newBody), *body); - *html_tag = '<'; - NS_MsgSACat(&newBody, "

"); - } - else - NS_MsgSACopy(&(newBody), "

"); + if (htmlEdit) + { + if (html_tag) + { + *html_tag = 0; + NS_MsgSACopy(&(newBody), *body); + *html_tag = '<'; + NS_MsgSACat(&newBody, "

"); + } + else + NS_MsgSACopy(&(newBody), "

"); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); - NS_MsgSACat(&newBody, MIME_HEADER_TABLE); - } - else + NS_MsgSACat(&newBody, MIME_HEADER_TABLE); + } + else { - NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); } - for (i = 0; i < headers->heads_size; i++) - { - char *head = headers->heads[i]; - char *end = (i == headers->heads_size-1 - ? headers->all_headers + headers->all_headers_fp - : headers->heads[i+1]); - char *colon, *ocolon; - char *contents; - char *name = 0; - char *c2 = 0; + for (i = 0; i < headers->heads_size; i++) + { + char *head = headers->heads[i]; + char *end = (i == headers->heads_size-1 + ? headers->all_headers + headers->all_headers_fp + : headers->heads[i+1]); + char *colon, *ocolon; + char *contents; + char *name = 0; + char *c2 = 0; - // Hack for BSD Mailbox delimiter. - if (i == 0 && head[0] == 'F' && !nsCRT::strncmp(head, "From ", 5)) - { - colon = head + 4; - contents = colon + 1; - } - else - { - /* Find the colon. */ - for (colon = head; colon < end; colon++) - if (*colon == ':') break; + // Hack for BSD Mailbox delimiter. + if (i == 0 && head[0] == 'F' && !nsCRT::strncmp(head, "From ", 5)) + { + colon = head + 4; + contents = colon + 1; + } + else + { + /* Find the colon. */ + for (colon = head; colon < end; colon++) + if (*colon == ':') break; - if (colon >= end) continue; /* junk */ + if (colon >= end) continue; /* junk */ - /* Back up over whitespace before the colon. */ - ocolon = colon; - for (; colon > head && nsCRT::IsAsciiSpace(colon[-1]); colon--) - ; + /* Back up over whitespace before the colon. */ + ocolon = colon; + for (; colon > head && nsCRT::IsAsciiSpace(colon[-1]); colon--) + ; - contents = ocolon + 1; - } + contents = ocolon + 1; + } - /* Skip over whitespace after colon. */ - while (contents <= end && nsCRT::IsAsciiSpace(*contents)) - contents++; + /* Skip over whitespace after colon. */ + while (contents <= end && nsCRT::IsAsciiSpace(*contents)) + contents++; - /* Take off trailing whitespace... */ - while (end > contents && nsCRT::IsAsciiSpace(end[-1])) - end--; + /* Take off trailing whitespace... */ + while (end > contents && nsCRT::IsAsciiSpace(end[-1])) + end--; - name = (char *)PR_MALLOC(colon - head + 1); - if (!name) + name = (char *)PR_MALLOC(colon - head + 1); + if (!name) return /* MIME_OUT_OF_MEMORY */; - nsCRT::memcpy(name, head, colon - head); - name[colon - head] = 0; + nsCRT::memcpy(name, head, colon - head); + name[colon - head] = 0; - c2 = (char *)PR_MALLOC(end - contents + 1); - if (!c2) - { - PR_Free(name); - return /* MIME_OUT_OF_MEMORY */; - } - nsCRT::memcpy(c2, contents, end - contents); - c2[end - contents] = 0; - + c2 = (char *)PR_MALLOC(end - contents + 1); + if (!c2) + { + PR_Free(name); + return /* MIME_OUT_OF_MEMORY */; + } + nsCRT::memcpy(c2, contents, end - contents); + c2[end - contents] = 0; + /* Do not reveal bcc recipients when forwarding a message! See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 */ if (nsCRT::strcasecmp(name, "bcc") != 0) { - if (htmlEdit) mime_fix_up_html_address(&c2); - - mime_intl_insert_message_header_1(&newBody, &c2, name, name, mailcharset, - htmlEdit); + if (htmlEdit) mime_fix_up_html_address(&c2); + + mime_intl_insert_message_header_1(&newBody, &c2, name, name, mailcharset, + htmlEdit); } - PR_Free(name); - PR_Free(c2); - } + PR_Free(name); + PR_Free(c2); + } - if (htmlEdit) - { - NS_MsgSACat(&newBody, ""); - NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); - if (html_tag) - NS_MsgSACat(&newBody, html_tag+6); - else - NS_MsgSACat(&newBody, *body); - } - else - { - NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); - NS_MsgSACat(&newBody, *body); - } + if (htmlEdit) + { + NS_MsgSACat(&newBody, ""); + NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); + if (html_tag) + NS_MsgSACat(&newBody, html_tag+6); + else + NS_MsgSACat(&newBody, *body); + } + else + { + NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACat(&newBody, *body); + } - if (newBody) - { - PR_FREEIF(*body); - *body = newBody; - } + if (newBody) + { + PR_FREEIF(*body); + *body = newBody; + } } static void mime_insert_normal_headers(char **body, - MimeHeaders *headers, - MSG_ComposeFormat composeFormat, - char *mailcharset) + MimeHeaders *headers, + MSG_ComposeFormat composeFormat, + char *mailcharset) { - char *newBody = NULL; - char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, PR_FALSE, PR_FALSE); - char *resent_comments = MimeHeaders_get(headers, HEADER_RESENT_COMMENTS, - PR_FALSE, PR_FALSE); - char *resent_date = MimeHeaders_get(headers, HEADER_RESENT_DATE, PR_FALSE, - PR_TRUE); - char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, PR_FALSE, - PR_TRUE); - char *resent_to = MimeHeaders_get(headers, HEADER_RESENT_TO, PR_FALSE, PR_TRUE); - char *resent_cc = MimeHeaders_get(headers, HEADER_RESENT_CC, PR_FALSE, PR_TRUE); - char *date = MimeHeaders_get(headers, HEADER_DATE, PR_FALSE, PR_TRUE); - char *from = MimeHeaders_get(headers, HEADER_FROM, PR_FALSE, PR_TRUE); - char *reply_to = MimeHeaders_get(headers, HEADER_REPLY_TO, PR_FALSE, PR_TRUE); - char *organization = MimeHeaders_get(headers, HEADER_ORGANIZATION, - PR_FALSE, PR_FALSE); - char *to = MimeHeaders_get(headers, HEADER_TO, PR_FALSE, PR_TRUE); - char *cc = MimeHeaders_get(headers, HEADER_CC, PR_FALSE, PR_TRUE); - char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, PR_FALSE, - PR_TRUE); - char *followup_to = MimeHeaders_get(headers, HEADER_FOLLOWUP_TO, PR_FALSE, - PR_TRUE); - char *references = MimeHeaders_get(headers, HEADER_REFERENCES, PR_FALSE, PR_TRUE); - const char *html_tag = PL_strcasestr(*body, ""); - PRBool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; - - if (!from) - from = MimeHeaders_get(headers, HEADER_SENDER, PR_FALSE, PR_TRUE); - if (!resent_from) - resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, PR_FALSE, - PR_TRUE); - - if (htmlEdit) - { - NS_MsgSACopy(&(newBody), "

"); + char *newBody = NULL; + char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, PR_FALSE, PR_FALSE); + char *resent_comments = MimeHeaders_get(headers, HEADER_RESENT_COMMENTS, + PR_FALSE, PR_FALSE); + char *resent_date = MimeHeaders_get(headers, HEADER_RESENT_DATE, PR_FALSE, + PR_TRUE); + char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, PR_FALSE, + PR_TRUE); + char *resent_to = MimeHeaders_get(headers, HEADER_RESENT_TO, PR_FALSE, PR_TRUE); + char *resent_cc = MimeHeaders_get(headers, HEADER_RESENT_CC, PR_FALSE, PR_TRUE); + char *date = MimeHeaders_get(headers, HEADER_DATE, PR_FALSE, PR_TRUE); + char *from = MimeHeaders_get(headers, HEADER_FROM, PR_FALSE, PR_TRUE); + char *reply_to = MimeHeaders_get(headers, HEADER_REPLY_TO, PR_FALSE, PR_TRUE); + char *organization = MimeHeaders_get(headers, HEADER_ORGANIZATION, + PR_FALSE, PR_FALSE); + char *to = MimeHeaders_get(headers, HEADER_TO, PR_FALSE, PR_TRUE); + char *cc = MimeHeaders_get(headers, HEADER_CC, PR_FALSE, PR_TRUE); + char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, PR_FALSE, + PR_TRUE); + char *followup_to = MimeHeaders_get(headers, HEADER_FOLLOWUP_TO, PR_FALSE, + PR_TRUE); + char *references = MimeHeaders_get(headers, HEADER_REFERENCES, PR_FALSE, PR_TRUE); + const char *html_tag = PL_strcasestr(*body, ""); + PRBool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; + + if (!from) + from = MimeHeaders_get(headers, HEADER_SENDER, PR_FALSE, PR_TRUE); + if (!resent_from) + resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, PR_FALSE, + PR_TRUE); + + if (htmlEdit) + { + NS_MsgSACopy(&(newBody), "

"); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); - NS_MsgSACat(&newBody, MIME_HEADER_TABLE); - } - else - { - NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACat(&newBody, MIME_HEADER_TABLE); + } + else + { + NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); - } - if (subject) - mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, - MimeGetNamedString(MIME_MHTML_SUBJECT), - mailcharset, htmlEdit); - if (resent_comments) - mime_intl_insert_message_header_1(&newBody, &resent_comments, - HEADER_RESENT_COMMENTS, - MimeGetNamedString(MIME_MHTML_RESENT_COMMENTS), - mailcharset, htmlEdit); - if (resent_date) - mime_intl_insert_message_header_1(&newBody, &resent_date, - HEADER_RESENT_DATE, - MimeGetNamedString(MIME_MHTML_RESENT_DATE), - mailcharset, htmlEdit); - if (resent_from) - { - if (htmlEdit) mime_fix_up_html_address(&resent_from); - mime_intl_insert_message_header_1(&newBody, &resent_from, - HEADER_RESENT_FROM, - MimeGetNamedString(MIME_MHTML_RESENT_FROM), - mailcharset, htmlEdit); - } - if (resent_to) - { - if (htmlEdit) mime_fix_up_html_address(&resent_to); - mime_intl_insert_message_header_1(&newBody, &resent_to, - HEADER_RESENT_TO, - MimeGetNamedString(MIME_MHTML_RESENT_TO), - mailcharset, htmlEdit); - } - if (resent_cc) - { - if (htmlEdit) mime_fix_up_html_address(&resent_cc); - mime_intl_insert_message_header_1(&newBody, &resent_cc, - HEADER_RESENT_CC, - MimeGetNamedString(MIME_MHTML_RESENT_CC), - mailcharset, htmlEdit); - } - if (date) - mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, - MimeGetNamedString(MIME_MHTML_DATE), - mailcharset, htmlEdit); - if (from) - { - if (htmlEdit) mime_fix_up_html_address(&from); - mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, - MimeGetNamedString(MIME_MHTML_FROM), - mailcharset, htmlEdit); - } - if (reply_to) - { - if (htmlEdit) mime_fix_up_html_address(&reply_to); - mime_intl_insert_message_header_1(&newBody, &reply_to, HEADER_REPLY_TO, - MimeGetNamedString(MIME_MHTML_REPLY_TO), - mailcharset, htmlEdit); - } - if (organization) - mime_intl_insert_message_header_1(&newBody, &organization, - HEADER_ORGANIZATION, - MimeGetNamedString(MIME_MHTML_ORGANIZATION), - mailcharset, htmlEdit); - if (to) - { - if (htmlEdit) mime_fix_up_html_address(&to); - mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, - MimeGetNamedString(MIME_MHTML_TO), - mailcharset, htmlEdit); - } - if (cc) - { - if (htmlEdit) mime_fix_up_html_address(&cc); - mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, - MimeGetNamedString(MIME_MHTML_CC), - mailcharset, htmlEdit); - } + } + if (subject) + mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, + MimeGetNamedString(MIME_MHTML_SUBJECT), + mailcharset, htmlEdit); + if (resent_comments) + mime_intl_insert_message_header_1(&newBody, &resent_comments, + HEADER_RESENT_COMMENTS, + MimeGetNamedString(MIME_MHTML_RESENT_COMMENTS), + mailcharset, htmlEdit); + if (resent_date) + mime_intl_insert_message_header_1(&newBody, &resent_date, + HEADER_RESENT_DATE, + MimeGetNamedString(MIME_MHTML_RESENT_DATE), + mailcharset, htmlEdit); + if (resent_from) + { + if (htmlEdit) mime_fix_up_html_address(&resent_from); + mime_intl_insert_message_header_1(&newBody, &resent_from, + HEADER_RESENT_FROM, + MimeGetNamedString(MIME_MHTML_RESENT_FROM), + mailcharset, htmlEdit); + } + if (resent_to) + { + if (htmlEdit) mime_fix_up_html_address(&resent_to); + mime_intl_insert_message_header_1(&newBody, &resent_to, + HEADER_RESENT_TO, + MimeGetNamedString(MIME_MHTML_RESENT_TO), + mailcharset, htmlEdit); + } + if (resent_cc) + { + if (htmlEdit) mime_fix_up_html_address(&resent_cc); + mime_intl_insert_message_header_1(&newBody, &resent_cc, + HEADER_RESENT_CC, + MimeGetNamedString(MIME_MHTML_RESENT_CC), + mailcharset, htmlEdit); + } + if (date) + mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, + MimeGetNamedString(MIME_MHTML_DATE), + mailcharset, htmlEdit); + if (from) + { + if (htmlEdit) mime_fix_up_html_address(&from); + mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, + MimeGetNamedString(MIME_MHTML_FROM), + mailcharset, htmlEdit); + } + if (reply_to) + { + if (htmlEdit) mime_fix_up_html_address(&reply_to); + mime_intl_insert_message_header_1(&newBody, &reply_to, HEADER_REPLY_TO, + MimeGetNamedString(MIME_MHTML_REPLY_TO), + mailcharset, htmlEdit); + } + if (organization) + mime_intl_insert_message_header_1(&newBody, &organization, + HEADER_ORGANIZATION, + MimeGetNamedString(MIME_MHTML_ORGANIZATION), + mailcharset, htmlEdit); + if (to) + { + if (htmlEdit) mime_fix_up_html_address(&to); + mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, + MimeGetNamedString(MIME_MHTML_TO), + mailcharset, htmlEdit); + } + if (cc) + { + if (htmlEdit) mime_fix_up_html_address(&cc); + mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, + MimeGetNamedString(MIME_MHTML_CC), + mailcharset, htmlEdit); + } /* Do not reveal bcc recipients when forwarding a message! See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 */ if (newsgroups) - mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, - MimeGetNamedString(MIME_MHTML_NEWSGROUPS), - mailcharset, htmlEdit); - if (followup_to) - { - if (htmlEdit) mime_fix_up_html_address(&followup_to); - mime_intl_insert_message_header_1(&newBody, &followup_to, - HEADER_FOLLOWUP_TO, - MimeGetNamedString(MIME_MHTML_FOLLOWUP_TO), - mailcharset, htmlEdit); - } - if (references) - { - if (htmlEdit) mime_fix_up_html_address(&references); - mime_intl_insert_message_header_1(&newBody, &references, - HEADER_REFERENCES, - MimeGetNamedString(MIME_MHTML_REFERENCES), - mailcharset, htmlEdit); - } - if (htmlEdit) - { - NS_MsgSACat(&newBody, ""); - NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); - if (html_tag) - NS_MsgSACat(&newBody, html_tag+6); - else - NS_MsgSACat(&newBody, *body); - } - else - { - NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); - NS_MsgSACat(&newBody, *body); - } - if (newBody) - { - PR_Free(*body); - *body = newBody; - } - PR_FREEIF(subject); - PR_FREEIF(resent_comments); - PR_FREEIF(resent_date); - PR_FREEIF(resent_from); - PR_FREEIF(resent_to); - PR_FREEIF(resent_cc); - PR_FREEIF(date); - PR_FREEIF(from); - PR_FREEIF(reply_to); - PR_FREEIF(organization); - PR_FREEIF(to); - PR_FREEIF(cc); - PR_FREEIF(newsgroups); - PR_FREEIF(followup_to); - PR_FREEIF(references); + mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, + MimeGetNamedString(MIME_MHTML_NEWSGROUPS), + mailcharset, htmlEdit); + if (followup_to) + { + if (htmlEdit) mime_fix_up_html_address(&followup_to); + mime_intl_insert_message_header_1(&newBody, &followup_to, + HEADER_FOLLOWUP_TO, + MimeGetNamedString(MIME_MHTML_FOLLOWUP_TO), + mailcharset, htmlEdit); + } + if (references) + { + if (htmlEdit) mime_fix_up_html_address(&references); + mime_intl_insert_message_header_1(&newBody, &references, + HEADER_REFERENCES, + MimeGetNamedString(MIME_MHTML_REFERENCES), + mailcharset, htmlEdit); + } + if (htmlEdit) + { + NS_MsgSACat(&newBody, ""); + NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); + if (html_tag) + NS_MsgSACat(&newBody, html_tag+6); + else + NS_MsgSACat(&newBody, *body); + } + else + { + NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACat(&newBody, *body); + } + if (newBody) + { + PR_Free(*body); + *body = newBody; + } + PR_FREEIF(subject); + PR_FREEIF(resent_comments); + PR_FREEIF(resent_date); + PR_FREEIF(resent_from); + PR_FREEIF(resent_to); + PR_FREEIF(resent_cc); + PR_FREEIF(date); + PR_FREEIF(from); + PR_FREEIF(reply_to); + PR_FREEIF(organization); + PR_FREEIF(to); + PR_FREEIF(cc); + PR_FREEIF(newsgroups); + PR_FREEIF(followup_to); + PR_FREEIF(references); } static void mime_insert_micro_headers(char **body, - MimeHeaders *headers, - MSG_ComposeFormat composeFormat, - char *mailcharset) + MimeHeaders *headers, + MSG_ComposeFormat composeFormat, + char *mailcharset) { - char *newBody = NULL; - char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, PR_FALSE, PR_FALSE); - char *from = MimeHeaders_get(headers, HEADER_FROM, PR_FALSE, PR_TRUE); - char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, PR_FALSE, - PR_TRUE); - char *date = MimeHeaders_get(headers, HEADER_DATE, PR_FALSE, PR_TRUE); - char *to = MimeHeaders_get(headers, HEADER_TO, PR_FALSE, PR_TRUE); - char *cc = MimeHeaders_get(headers, HEADER_CC, PR_FALSE, PR_TRUE); - char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, PR_FALSE, - PR_TRUE); - const char *html_tag = PL_strcasestr(*body, ""); - PRBool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; - - if (!from) - from = MimeHeaders_get(headers, HEADER_SENDER, PR_FALSE, PR_TRUE); - if (!resent_from) - resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, PR_FALSE, - PR_TRUE); - if (!date) - date = MimeHeaders_get(headers, HEADER_RESENT_DATE, PR_FALSE, PR_TRUE); - - if (htmlEdit) - { - NS_MsgSACopy(&(newBody), "

"); + char *newBody = NULL; + char *subject = MimeHeaders_get(headers, HEADER_SUBJECT, PR_FALSE, PR_FALSE); + char *from = MimeHeaders_get(headers, HEADER_FROM, PR_FALSE, PR_TRUE); + char *resent_from = MimeHeaders_get(headers, HEADER_RESENT_FROM, PR_FALSE, + PR_TRUE); + char *date = MimeHeaders_get(headers, HEADER_DATE, PR_FALSE, PR_TRUE); + char *to = MimeHeaders_get(headers, HEADER_TO, PR_FALSE, PR_TRUE); + char *cc = MimeHeaders_get(headers, HEADER_CC, PR_FALSE, PR_TRUE); + char *newsgroups = MimeHeaders_get(headers, HEADER_NEWSGROUPS, PR_FALSE, + PR_TRUE); + const char *html_tag = PL_strcasestr(*body, ""); + PRBool htmlEdit = composeFormat == nsIMsgCompFormat::HTML; + + if (!from) + from = MimeHeaders_get(headers, HEADER_SENDER, PR_FALSE, PR_TRUE); + if (!resent_from) + resent_from = MimeHeaders_get(headers, HEADER_RESENT_SENDER, PR_FALSE, + PR_TRUE); + if (!date) + date = MimeHeaders_get(headers, HEADER_RESENT_DATE, PR_FALSE, PR_TRUE); + + if (htmlEdit) + { + NS_MsgSACopy(&(newBody), "

"); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); NS_MsgSACat(&newBody, MIME_HEADER_TABLE); - } - else + } + else { - NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK); NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE)); } if (from) - { - if (htmlEdit) + { + if (htmlEdit) mime_fix_up_html_address(&from); - mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, - MimeGetNamedString(MIME_MHTML_FROM), - mailcharset, htmlEdit); - } - if (subject) - mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, - MimeGetNamedString(MIME_MHTML_SUBJECT), - mailcharset, htmlEdit); + mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM, + MimeGetNamedString(MIME_MHTML_FROM), + mailcharset, htmlEdit); + } + if (subject) + mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT, + MimeGetNamedString(MIME_MHTML_SUBJECT), + mailcharset, htmlEdit); /* - if (date) - mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, - MimeGetNamedString(MIME_MHTML_DATE), - mailcharset, htmlEdit); + if (date) + mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE, + MimeGetNamedString(MIME_MHTML_DATE), + mailcharset, htmlEdit); */ - if (resent_from) - { - if (htmlEdit) mime_fix_up_html_address(&resent_from); - mime_intl_insert_message_header_1(&newBody, &resent_from, - HEADER_RESENT_FROM, - MimeGetNamedString(MIME_MHTML_RESENT_FROM), - mailcharset, htmlEdit); - } - if (to) - { - if (htmlEdit) mime_fix_up_html_address(&to); - mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, - MimeGetNamedString(MIME_MHTML_TO), - mailcharset, htmlEdit); - } - if (cc) - { - if (htmlEdit) mime_fix_up_html_address(&cc); - mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, - MimeGetNamedString(MIME_MHTML_CC), - mailcharset, htmlEdit); - } + if (resent_from) + { + if (htmlEdit) mime_fix_up_html_address(&resent_from); + mime_intl_insert_message_header_1(&newBody, &resent_from, + HEADER_RESENT_FROM, + MimeGetNamedString(MIME_MHTML_RESENT_FROM), + mailcharset, htmlEdit); + } + if (to) + { + if (htmlEdit) mime_fix_up_html_address(&to); + mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO, + MimeGetNamedString(MIME_MHTML_TO), + mailcharset, htmlEdit); + } + if (cc) + { + if (htmlEdit) mime_fix_up_html_address(&cc); + mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC, + MimeGetNamedString(MIME_MHTML_CC), + mailcharset, htmlEdit); + } /* Do not reveal bcc recipients when forwarding a message! See http://bugzilla.mozilla.org/show_bug.cgi?id=41150 */ - if (newsgroups) - mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, - MimeGetNamedString(MIME_MHTML_NEWSGROUPS), - mailcharset, htmlEdit); - if (htmlEdit) - { - NS_MsgSACat(&newBody, ""); - NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); - if (html_tag) - NS_MsgSACat(&newBody, html_tag+6); - else - NS_MsgSACat(&newBody, *body); - } - else - { - NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); - NS_MsgSACat(&newBody, *body); - } - if (newBody) - { - PR_Free(*body); - *body = newBody; - } - PR_FREEIF(subject); - PR_FREEIF(from); - PR_FREEIF(resent_from); - PR_FREEIF(date); - PR_FREEIF(to); - PR_FREEIF(cc); - PR_FREEIF(newsgroups); + if (newsgroups) + mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS, + MimeGetNamedString(MIME_MHTML_NEWSGROUPS), + mailcharset, htmlEdit); + if (htmlEdit) + { + NS_MsgSACat(&newBody, ""); + NS_MsgSACat(&newBody, MSG_LINEBREAK "

"); + if (html_tag) + NS_MsgSACat(&newBody, html_tag+6); + else + NS_MsgSACat(&newBody, *body); + } + else + { + NS_MsgSACat(&newBody, MSG_LINEBREAK MSG_LINEBREAK); + NS_MsgSACat(&newBody, *body); + } + if (newBody) + { + PR_Free(*body); + *body = newBody; + } + PR_FREEIF(subject); + PR_FREEIF(from); + PR_FREEIF(resent_from); + PR_FREEIF(date); + PR_FREEIF(to); + PR_FREEIF(cc); + PR_FREEIF(newsgroups); } static void mime_insert_forwarded_message_headers(char **body, - MimeHeaders *headers, - MSG_ComposeFormat composeFormat, - char *mailcharset) + MimeHeaders *headers, + MSG_ComposeFormat composeFormat, + char *mailcharset) { - if (body && *body && headers) - { - PRInt32 show_headers = 0; + if (body && *body && headers) + { + PRInt32 show_headers = 0; nsresult res; // convert body from mail charset to UTF-8 @@ -1116,27 +1130,27 @@ mime_insert_forwarded_message_headers(char **body, if (NS_SUCCEEDED(res) && prefs) res = prefs->GetIntPref("mail.show_headers", &show_headers); - switch (show_headers) - { - case 0: - mime_insert_micro_headers(body, headers, composeFormat, mailcharset); - break; - default: - case 1: - mime_insert_normal_headers(body, headers, composeFormat, mailcharset); - break; - case 2: - mime_insert_all_headers(body, headers, composeFormat, mailcharset); - break; - } - } + switch (show_headers) + { + case 0: + mime_insert_micro_headers(body, headers, composeFormat, mailcharset); + break; + default: + case 1: + mime_insert_normal_headers(body, headers, composeFormat, mailcharset); + break; + case 2: + mime_insert_all_headers(body, headers, composeFormat, mailcharset); + break; + } + } } static void PR_CALLBACK mime_parse_stream_complete (nsMIMESession *stream) { struct mime_draft_data *mdd = (struct mime_draft_data *) stream->data_object; - nsIMsgCompFields *fields = NULL; + nsCOMPtr fields; int htmlAction = 0; int lineWidth = 0; @@ -1160,8 +1174,8 @@ mime_parse_stream_complete (nsMIMESession *stream) char *priority = 0; char *draftInfo = 0; - PRBool xlate_p = PR_FALSE; /* #### how do we determine this? */ - PRBool sign_p = PR_FALSE; /* #### how do we determine this? */ + PRBool xlate_p = PR_FALSE; /* #### how do we determine this? */ + PRBool sign_p = PR_FALSE; /* #### how do we determine this? */ PRBool forward_inline = PR_FALSE; NS_ASSERTION (mdd, "null mime draft data"); @@ -1233,7 +1247,7 @@ mime_parse_stream_complete (nsMIMESession *stream) subj = newSubj; } } - } + } else { repl = MimeHeaders_get(mdd->headers, HEADER_REPLY_TO, PR_FALSE, PR_FALSE); @@ -1272,9 +1286,10 @@ mime_parse_stream_complete (nsMIMESession *stream) } - fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll, - org, subj, refs, 0, priority, 0, news_host, - xlate_p, sign_p, mdd->mailcharset); + CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll, + org, subj, refs, 0, priority, news_host, + xlate_p, sign_p, mdd->mailcharset, + getter_AddRefs(fields)); draftInfo = MimeHeaders_get(mdd->headers, HEADER_X_MOZILLA_DRAFT_INFO, PR_FALSE, PR_FALSE); if (draftInfo && fields && !forward_inline) @@ -1469,11 +1484,12 @@ mime_parse_stream_complete (nsMIMESession *stream) } else { - fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll, - org, subj, refs, 0, priority, 0, news_host, + CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll, + org, subj, refs, 0, priority, news_host, GetMailXlateionPreference(), GetMailSigningPreference(), - mdd->mailcharset); + mdd->mailcharset, + getter_AddRefs(fields)); if (fields) CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::New, nsIMsgCompFormat::Default, mdd->identity); } @@ -1504,8 +1520,6 @@ mime_parse_stream_complete (nsMIMESession *stream) } PR_FREEIF(mdd); - if (fields) - NS_RELEASE(fields); // Release the prefs service MimeObject *obj = (mdd ? mdd->obj : 0); @@ -1665,7 +1679,7 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ) NS_ASSERTION (mdd->attachments, "no attachments"); attachments = (nsMsgAttachedFile *)PR_REALLOC(mdd->attachments, - sizeof (nsMsgAttachedFile) * + sizeof (nsMsgAttachedFile) * (nAttachments + 2)); if (!attachments) return MIME_OUT_OF_MEMORY; @@ -1739,21 +1753,21 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ) nsFileSpec *tmpSpec = nsnull; if (newAttachment->real_name && *newAttachment->real_name) { - //Need some convertion to native file system character set - nsAutoString outStr; - char * fileName = nsnull; - nsresult rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), newAttachment->real_name, outStr); - if (NS_SUCCEEDED(rv)) - { - rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), outStr, &fileName); - if (NS_FAILED(rv)) - fileName = PL_strdup(newAttachment->real_name); - } - else - fileName = PL_strdup(newAttachment->real_name); + //Need some convertion to native file system character set + nsAutoString outStr; + char * fileName = nsnull; + nsresult rv = ConvertToUnicode(NS_ConvertASCIItoUCS2(msgCompHeaderInternalCharset()), newAttachment->real_name, outStr); + if (NS_SUCCEEDED(rv)) + { + rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), outStr, &fileName); + if (NS_FAILED(rv)) + fileName = PL_strdup(newAttachment->real_name); + } + else + fileName = PL_strdup(newAttachment->real_name); tmpSpec = nsMsgCreateTempFileSpec(fileName); - PR_FREEIF(fileName); + PR_FREEIF(fileName); } else { @@ -1813,7 +1827,7 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ) return MIME_OUT_OF_MEMORY; NS_NewFileSpecWithSpec(*tmpSpec, &mdd->tmpFileSpec); - if (!mdd->tmpFileSpec) + if (!mdd->tmpFileSpec) return MIME_OUT_OF_MEMORY; newAttachment->file_spec = tmpSpec; @@ -1858,8 +1872,8 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ) nsresult mime_decompose_file_output_fn (char *buf, - PRInt32 size, - void *stream_closure ) + PRInt32 size, + void *stream_closure ) { struct mime_draft_data *mdd = (struct mime_draft_data *) stream_closure; int ret = 0; @@ -1973,7 +1987,7 @@ mime_bridge_create_draft_stream( mdd->options->url = nsCRT::strdup(mdd->url_name); mdd->options->format_out = format_out; // output format - mdd->options->decompose_file_p = PR_TRUE; /* new field in MimeDisplayOptions */ + mdd->options->decompose_file_p = PR_TRUE; /* new field in MimeDisplayOptions */ mdd->options->stream_closure = mdd; mdd->options->html_closure = mdd; mdd->options->decompose_headers_info_fn = make_mime_headers_copy; @@ -1983,16 +1997,16 @@ mime_bridge_create_draft_stream( rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**)&(mdd->options->prefs)); if (! (mdd->options->prefs && NS_SUCCEEDED(rv))) - { + { PR_FREEIF(mdd); return nsnull; } #ifdef FO_MAIL_MESSAGE_TO /* If we're attaching a message (for forwarding) then we must eradicate all - traces of xlateion from it, since forwarding someone else a message - that wasn't xlated for them doesn't work. We have to dexlate it - before sending it. + traces of xlateion from it, since forwarding someone else a message + that wasn't xlated for them doesn't work. We have to dexlate it + before sending it. */ // RICHIE mdd->options->dexlate_p = PR_TRUE; #endif /* FO_MAIL_MESSAGE_TO */ diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index ca067472dd0..4125e5f8a62 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -241,7 +241,7 @@ void nsStr::StrInsert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PR StrAppend(theTempStr,aDest,0,aDestOffset); //first copy leftmost data... } - StrAppend(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data + StrAppend(theTempStr,aSource,aSrcOffset,theLength); //next copy inserted (new) data PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index ca067472dd0..4125e5f8a62 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -241,7 +241,7 @@ void nsStr::StrInsert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PR StrAppend(theTempStr,aDest,0,aDestOffset); //first copy leftmost data... } - StrAppend(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data + StrAppend(theTempStr,aSource,aSrcOffset,theLength); //next copy inserted (new) data PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { diff --git a/mozilla/xpfe/components/remote/src/remoteControl.js b/mozilla/xpfe/components/remote/src/remoteControl.js index 194c8f222c4..7e5c63f9691 100644 --- a/mozilla/xpfe/components/remote/src/remoteControl.js +++ b/mozilla/xpfe/components/remote/src/remoteControl.js @@ -64,28 +64,18 @@ var browserRemoteControl = { msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService); if ( !msgComposeService ) return(false); - if ( mailToList ) + params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams); + if (params) { - msgComposeService.OpenComposeWindowWithValues(null, - Components.interfaces.nsIMsgCompType.New, - Components.interfaces.nsIMsgCompFormat.Default, - mailToList, - null, - null, - null, - null, - null, - null, - null); - } - else + params.type = Components.interfaces.nsIMsgCompType.New; + params.format = Components.interfaces.nsIMsgCompFormat.Default; + composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields); + if (composeFields) { - msgComposeService.OpenComposeWindow(null, - null, - Components.interfaces.nsIMsgCompType.New, - Components.interfaces.nsIMsgCompFormat.Default, - null, - null); + if (mailToList) + params.composeFields = composeFields; + msgComposeService.OpenComposeWindowWithParams(null, params); + } } return(true); },