diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp
deleted file mode 100644
index d28fe25beffa..000000000000
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ /dev/null
@@ -1,4324 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.0 (the "NPL"); you may not use this file except in
- * compliance with the NPL. You may obtain a copy of the NPL at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the NPL is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
- * for the specific language governing rights and limitations under the
- * NPL.
- *
- * The Initial Developer of this code under the NPL is Netscape
- * Communications Corporation. Portions created by Netscape are
- * Copyright (C) 1998 Netscape Communications Corporation. All Rights
- * Reserved.
- */
-
-#include "rosetta_mailnews.h"
-#include "nsMsgSend.h"
-#include "nsMsgSendPart.h"
-#include "nsMsgComposeFact.h"
-#include "nsMsgCompPrefs.h"
-#include "nsMsgCompose.h"
-#include "nsEscape.h"
-#include "nsIMsgHeaderParser.h"
-#include "nsIMimeURLUtils.h"
-#include "nsQuickSort.h"
-#include "nsIPref.h"
-
-static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
-static NS_DEFINE_CID(kCMsgHeaderParserCID, NS_MSGHEADERPARSER_CID);
-static NS_DEFINE_CID(kCMimeURLUtilsCID, NS_IMIME_URLUTILS_CID);
-
-#ifdef UNREADY_CODE
-HJ04305
-#endif
-
-#define ALL_HEADERS (MSG_FROM_HEADER_MASK | \
- MSG_REPLY_TO_HEADER_MASK | \
- MSG_TO_HEADER_MASK | \
- MSG_CC_HEADER_MASK | \
- MSG_BCC_HEADER_MASK | \
- MSG_FCC_HEADER_MASK | \
- MSG_NEWSGROUPS_HEADER_MASK | \
- MSG_FOLLOWUP_TO_HEADER_MASK | \
- MSG_SUBJECT_HEADER_MASK | \
- MSG_ATTACHMENTS_HEADER_MASK)
-
-
-enum RecipientType {
- Address = 1, Domain = 2, Newsgroup = 3, GroupHierarchy = 4
-};
-
-/* this function will be used by the factory to generate an Message Compose Object....*/
-nsresult NS_NewMsgCompose(const nsIID &aIID, void ** aInstancePtrResult)
-{
- /* note this new macro for assertions...they can take a string describing the assertion */
- NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
- if (nsnull != aInstancePtrResult)
- {
- nsMsgCompose* pCompose = new nsMsgCompose();
- if (pCompose)
- return pCompose->QueryInterface(aIID, aInstancePtrResult);
- else
- return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
- }
- else
- return NS_ERROR_NULL_POINTER; /* aInstancePtrResult was NULL....*/
-}
-
-
-class RecipientEntry : public MSG_ZapIt {
-public:
- RecipientEntry(const char* name, const char* description,
- RecipientType type, PRBool htmlok);
- ~RecipientEntry();
-
- char* GetName() {return m_name;}
- char* GetDescription() {return m_description;}
- RecipientType GetType() {return m_type;}
- PRBool GetHTMLOk() {return m_htmlok;}
- PRBool GetNewHTMLOk() {return m_newhtmlok;}
- void SetNewOK(PRBool value);
- PRBool GetTouched() {return m_touched;}
-
-protected:
- char* m_name;
- char* m_description;
- RecipientType m_type;
- PRBool m_htmlok;
- PRBool m_newhtmlok;
- PRBool m_touched;
-};
-
-
-RecipientEntry::RecipientEntry(const char* name, const char* description,
- RecipientType type, PRBool htmlok)
-{
- m_name = PL_strdup(name);
- m_description = PL_strdup(description);
- if (!m_description) {
- PR_FREEIF(m_name); // Checking for name being NULL is the hack
- // used to see if we're out of memory.
- }
- m_type = type;
- m_htmlok = htmlok;
- m_newhtmlok = PR_FALSE;
- m_touched = PR_FALSE;
-}
-
-RecipientEntry::~RecipientEntry()
-{
- PR_FREEIF(m_name);
- PR_FREEIF(m_description);
-}
-
-void
-RecipientEntry::SetNewOK(PRBool value)
-{
- PR_ASSERT(!m_touched);
- m_touched = PR_TRUE;
- m_newhtmlok = value;
-}
-
-
-
-class MSG_HTMLRecipients : public MSG_ZapIt {
-public:
- MSG_HTMLRecipients();
- ~MSG_HTMLRecipients();
-
- int AddOne(const char* name, const char* description,
- RecipientType type, PRBool htmlok);
- MSG_RecipientList* GetList(PRBool htmlok);
-
- int SetNewList(PRInt32* notoklist, PRInt32* oklist);
-
- char** GetChangedList(RecipientType type, PRBool htmlok);
- void FreeChangedList(char** list);
- int GetNum() {return m_num;}
-
-protected:
- RecipientEntry** m_list;
- PRInt32 m_num;
- PRInt32 m_max;
- MSG_RecipientList* m_generatedList[2];
-};
-
-MSG_HTMLRecipients::MSG_HTMLRecipients() {
- m_list = NULL;
- m_num = 0;
- m_max = 0;
- m_generatedList[0] = NULL;
- m_generatedList[1] = NULL;
-}
-
-MSG_HTMLRecipients::~MSG_HTMLRecipients() {
- delete m_generatedList[0];
- delete m_generatedList[1];
- for (PRInt32 i=0 ; iGetType() == type &&
- PL_strcmp(m_list[i]->GetName(), name) == 0) return 0;
- }
- if (m_num >= m_max) {
- RecipientEntry** tmp = new RecipientEntry* [m_max + 10];
- if (!tmp) return MK_OUT_OF_MEMORY;
- m_max += 10;
- for (i=0 ; iGetName()) {
- delete m_list[m_num];
- return MK_OUT_OF_MEMORY;
- }
- m_num++;
- return 0;
-}
-
-
-MSG_RecipientList*
-MSG_HTMLRecipients::GetList(PRBool htmlok)
-{
- PRInt32 i, j;
- if (m_generatedList[0] == NULL) {
- // Sort the entries in the list. Within a given type, we want to
- // keep things in the order they were generated, but they need to
- // be grouped by type. So, it's bubble-sort time. Whee...
- for (i=1 ; i 0 && m_list[j]->GetType() < m_list[j-1]->GetType();
- j--) {
- RecipientEntry* tmp = m_list[j];
- m_list[j] = m_list[j-1];
- m_list[j-1] = tmp;
- }
- }
-
- m_generatedList[0] = new MSG_RecipientList [m_num + 1];
- if (!m_generatedList[0]) return NULL;
- m_generatedList[1] = new MSG_RecipientList [m_num + 1];
- if (!m_generatedList[1]) {
- delete [] m_generatedList[0];
- return NULL;
- }
- PRInt32 cur[2];
- cur[0] = cur[1] = 0;
- for (i=0 ; iGetHTMLOk());
- m_generatedList[w][cur[w]].name = m_list[i]->GetDescription();
- m_generatedList[w][cur[w]].value = i;
- (cur[w])++;
- }
- for (i=0 ; i<2 ; i++) {
- m_generatedList[i][cur[i]].name = NULL;
- m_generatedList[i][cur[i]].value = -1;
- }
- }
- return m_generatedList[int(htmlok)];
-}
-
-
-int
-MSG_HTMLRecipients::SetNewList(PRInt32* notoklist, PRInt32* oklist)
-{
- PRInt32 i;
-#ifdef DEBUG
- for (i=0 ; iGetTouched());
- }
-#endif
- for (int w=0 ; w<2 ; w++) {
- PRBool ok = (w == 1);
- PRInt32* list = ok ? oklist : notoklist;
- PR_ASSERT(list);
- if (!list) continue;
- for ( ; *list >= 0 ; list++) {
- PR_ASSERT(*list < m_num);
- if (*list >= m_num) break;
- m_list[*list]->SetNewOK(ok);
- }
- }
- int status = 0;
- for (i=0 ; iGetTouched());
- if (!m_list[i]->GetTouched()) {
- status = -1;
- }
- }
- return status;
-}
-
-
-char**
-MSG_HTMLRecipients::GetChangedList(RecipientType type, PRBool htmlok)
-{
- char** result = new char * [m_num + 1];
- if (!result) return NULL;
- char** tmp = result;
- for (PRInt32 i=0 ; iGetType() == type &&
- m_list[i]->GetNewHTMLOk() == htmlok &&
- m_list[i]->GetHTMLOk() != htmlok) {
- *tmp = m_list[i]->GetName();
- tmp++;
- }
- }
- *tmp = NULL;
- return result;
-}
-
-
-void
-MSG_HTMLRecipients::FreeChangedList(char** list)
-{
- delete [] list;
-}
-
-
-static void msg_free_attachment_list(struct nsMsgAttachmentData *list);
-
-/*JFD
-static void
-msg_delete_attached_files(struct nsMsgAttachedFile *attachments)
-{
- struct nsMsgAttachedFile *tmp;
- if (!attachments) return;
- for (tmp = attachments; tmp->orig_url; tmp++) {
- PR_FREEIF(tmp->orig_url);
- PR_FREEIF(tmp->type);
- PR_FREEIF(tmp->real_name);
- PR_FREEIF(tmp->encoding);
- PR_FREEIF(tmp->description);
- PR_FREEIF(tmp->x_mac_type);
- PR_FREEIF(tmp->x_mac_creator);
- if (tmp->file_name) {
- PR_Delete(tmp->file_name);
- PR_Free(tmp->file_name);
- }
- }
- PR_FREEIF(attachments);
-}
-*/
-
-nsMsgCompose::nsMsgCompose()
-{
- m_replyType = 0;
- m_markup = PR_FALSE;
- m_attachData = NULL;
- m_attachedFiles = NULL;
- m_defaultUrl = NULL;
- m_initfields = NULL;
- m_fields = NULL;
- m_messageId = NULL;
- m_attachmentString = NULL;
- m_quotedText = NULL;
- m_print = NULL;
- m_textContext = NULL;
- m_context = NULL;
- m_oldContext = NULL;
- m_quoteUrl = NULL;
- m_dummyUrl = NULL;
- m_exitQuoting = NULL;
- m_quotefunc = NULL;
- m_quoteclosure = NULL;
- m_deliveryInProgress = PR_FALSE;
- m_attachmentInProgress = PR_FALSE;
- m_pendingAttachmentsCount = 0;
- m_deliver_mode = nsMsgDeliverNow;
- m_cited = PR_FALSE;
- m_duplicatePost = PR_FALSE;
- m_htmlaction = MSG_HTMLAskUser;
- m_htmlrecip = NULL;
- m_status = 0;
- m_visible_headers = 0;
- m_host = NULL;
- m_closeAfterSave = PR_FALSE;
- m_haveQuoted = PR_FALSE;
- m_haveAttachedVcard = PR_FALSE;
- m_callbacks.CreateAskHTMLDialog = NULL;
- m_callbacks.CreateRecipientsDialog = NULL;
- m_callbackclosure = NULL;
- m_lineWidth = 0;
-
-#ifdef UNREADY_CODE
- HJ58932
-#endif
-
- /* the following macro is used to initialize the ref counting data */
- NS_INIT_REFCNT();
-}
-
-nsMsgCompose::~nsMsgCompose()
-{
-//JFD Dispose();
-}
-
-/* the following macro actually implement addref, release and query interface for our component. */
-NS_IMPL_ISUPPORTS(nsMsgCompose, nsIMsgCompose::GetIID());
-
-nsresult nsMsgCompose::CreateAndInitialize(/*MWContext* */PRInt32 context,
- /*MWContext* */PRInt32 old_context,
- /*MSG_Prefs* */PRInt32 prefs,
- nsIMsgCompFields* fields,
- /*MSG_Master* */PRInt32 master)
-{
- MSG_PaneCreate((MWContext*)context, (MSG_Master*)master); /*JFD*/
- m_prefs = (MSG_Prefs*)prefs;
- SetHTMLAction(MSG_HTMLAskUser);
- Initialize(old_context, fields);
- // make sure we have a valid folder tree - via side effect of getfoldertree
- if (master)
- ((MSG_Master*)master)->GetFolderTree();
-
- return NS_OK;
-}
-
-nsresult nsMsgCompose::Create(/*MWContext**/PRInt32 context, /*MSG_Prefs**/PRInt32 prefs, /*MSG_Master**/PRInt32 master)
-{
- MSG_PaneCreate((MWContext*)context, (MSG_Master*)master); /*JFD*/
- m_prefs = (MSG_Prefs*)prefs;
- // make sure we have a valid folder tree - via side effect of getfoldertree
- if (master)
- ((MSG_Master*)master)->GetFolderTree();
-
- return NS_OK;
-}
-
-
-nsresult nsMsgCompose::Initialize(/*MWContext**/PRInt32 old_context, nsIMsgCompFields* fields)
-{
-/*JFD
- m_print = new PrintSetup;
-*/
-#ifdef UNREADY_CODE
- HJ22867
-#endif
-
- InitializeHeaders((MWContext*)old_context, fields);
- m_visible_headers = GetInterestingHeaders();
- m_deliver_mode = nsMsgDeliverNow;
- m_haveAttachedVcard = PR_FALSE;
-
- m_fields->SetForcePlainText(PR_FALSE); // Coming into us, this field meant
- // "bring up the editor in plaintext
- // mode". Well, that's already been
- // done at this point. Now, we want
- // it to mean "convert this message
- // to plaintext on send". Which we
- // do only if DetermineHTMLAction()
- // tells us to.
- return NS_OK;
-}
-
-
-
-nsresult nsMsgCompose::Dispose()
-{
- // Don't interrupt if there's nothing to interrupt because we might lose
- // mocha messages.
- if (NET_AreThereActiveConnectionsForWindow(m_context))
- msg_InterruptContext (m_context, PR_FALSE);
- if (m_textContext != NULL)
- msg_InterruptContext(m_textContext, PR_TRUE);
-
-/*JFD
- msg_delete_attached_files (m_attachedFiles);
-*/
-
- PR_FREEIF(m_defaultUrl);
- PR_FREEIF(m_attachmentString);
-
-/*JFD
- msg_free_attachment_list(m_attachData);
-
- if (m_print) {
- delete m_print;
- m_print = NULL;
- }
-*/
-
-#ifdef UNREADY_CODE
- HJ09384
-#endif
-
- if (m_context)
- FE_DestroyMailCompositionContext(m_context);
- m_context = NULL;
-
- if (m_fields) {
- m_fields->Release();
- m_fields = NULL;
- }
- if (m_initfields) {
- m_initfields->Release();
- m_initfields = NULL;
- }
- if (m_htmlrecip) {
- delete m_htmlrecip;
- m_htmlrecip = NULL;
- }
-
-/*JFD
- DIR_Server* pab = NULL;
- ABook * ab = NULL;
-*/
-
- PR_FREEIF(m_quotedText);
- PR_FREEIF(m_messageId);
-
- return NS_OK;
-}
-
-
-MSG_PaneType nsMsgCompose::GetPaneType()
-{
- return MSG_COMPOSITIONPANE;
-}
-
-
-void nsMsgCompose::NotifyPrefsChange(NotifyCode) {
- // ###tw Write me!
-}
-
-
-int nsMsgCompose::CreateVcardAttachment ()
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
-
- nsMsgCompPrefs pCompPrefs;
- char* name;
- int status = 0;
-
- if (!m_haveAttachedVcard && AB_UserHasVCard() ) // don't attach a vcard if the user does not have a vcard
- {
-
- char * vCard = NULL;
- char * filename = NULL;
- AB_LoadIdentityVCard(&vCard);
- if (vCard)
- {
- AB_ExportVCardToTempFile (vCard, &filename);
- if (vCard)
- PR_Free(vCard); // free our allocated VCardString...
- char buf [ 2 * kMaxFullNameLength ];
- if (pCompPrefs.GetUserFullName())
- name = PL_strdup (pCompPrefs.GetUserFullName());
- // write out a content description string
-#ifdef UNREADY_CODE
- XP_SPRINTF (buf, XP_GetString (MK_ADDR_BOOK_CARD), name);
-#endif
- PR_FREEIF(name);
-
-
- char* temp = WH_FileName(filename, xpFileToPost);
- char * fileurl = NULL;
- if (temp)
- {
- fileurl = XP_PlatformFileToURL (temp);
- PR_Free(temp);
- }
- else
- return -1;
-
- // Send the vCard out with a filename which distinguishes this user. e.g. jsmith.vcf
- // The main reason to do this is for interop with Eudora, which saves off
- // the attachments separately from the message body
- char *vCardFileName = NULL;
- char *mailIdentityUserEmail = NULL;
- char *atSign = NULL;
- if (NS_SUCCEEDED(rv) && prefs)
- prefs->CopyCharPref("mail.identity.useremail", &mailIdentityUserEmail);
- if (mailIdentityUserEmail)
- {
- atSign = PL_strchr(mailIdentityUserEmail, '@');
- if (atSign) *atSign = 0;
- vCardFileName = PR_smprintf ("%s.vcf", mailIdentityUserEmail);
- PR_Free(mailIdentityUserEmail);
- }
- if (!vCardFileName)
- {
- vCardFileName = PL_strdup("vcard.vcf");
- if (!vCardFileName)
- return MK_OUT_OF_MEMORY;
- }
-
- char * origurl = XP_PlatformFileToURL (vCardFileName);
- int datacount = 0, filecount = 0;
- for (nsMsgAttachmentData *tmp1 = m_attachData; tmp1 && tmp1->url; tmp1++) datacount++;
- for (nsMsgAttachedFile *tmp = m_attachedFiles; tmp && tmp->orig_url; tmp++) filecount++;
-
- nsMsgAttachmentData *alist;
- if (datacount) {
- alist = (nsMsgAttachmentData *)
- PR_REALLOC(m_attachData, (datacount + 2) * sizeof(nsMsgAttachmentData));
- }
- else {
- alist = (nsMsgAttachmentData *)
- PR_Malloc((datacount + 2) * sizeof(nsMsgAttachmentData));
- }
- if (!alist)
- return MK_OUT_OF_MEMORY;
- m_attachData = alist;
- memset (m_attachData + datacount, 0, 2 * sizeof (nsMsgAttachmentData));
- m_attachData[datacount].url = fileurl;
- m_attachData[datacount].real_type = PL_strdup(vCardMimeFormat);
- m_attachData[datacount].description = PL_strdup (buf);
- m_attachData[datacount].real_name = PL_strdup (vCardFileName);
- m_attachData[datacount + 1].url = NULL;
-
- nsMsgAttachedFile *aflist;
- if (filecount) {
- aflist = (struct nsMsgAttachedFile *)
- PR_REALLOC(m_attachedFiles, (filecount + 2) * sizeof(nsMsgAttachedFile));
- }
- else {
- aflist = (struct nsMsgAttachedFile *)
- PR_Malloc((filecount + 2) * sizeof(nsMsgAttachedFile));
- }
-
- if (!aflist)
- return MK_OUT_OF_MEMORY;
-
- m_attachedFiles = aflist;
- memset (m_attachedFiles + filecount, 0, 2 * sizeof (nsMsgAttachedFile));
- m_attachedFiles[filecount].orig_url = origurl;
- m_attachedFiles[filecount].file_name = filename;
- m_attachedFiles[filecount].type = PL_strdup(vCardMimeFormat);
- m_attachedFiles[filecount].description = PL_strdup (buf);
- m_attachedFiles[filecount].real_name = PL_strdup (vCardFileName);
- m_attachedFiles[filecount + 1].orig_url = NULL;
-
- m_haveAttachedVcard = PR_TRUE;
-
- PR_Free(vCardFileName);
- }
- }
- return status;
-}
-
-
-char*
-nsMsgCompose::FigureBcc(PRBool newsBcc)
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
-
- nsMsgCompPrefs pCompPrefs;
- char* result = NULL;
- PRBool useBcc = PR_FALSE;
-
- if (newsBcc)
- if (NS_SUCCEEDED(rv) && prefs)
- {
- prefs->GetBoolPref("news.use_default_cc", &useBcc);
- }
- else
- if (NS_SUCCEEDED(rv) && prefs)
- {
- prefs->GetBoolPref("mail.use_default_cc", &useBcc);
- }
-
- if (useBcc || GetPrefs()->GetDefaultBccSelf(newsBcc) != 0)
- {
- const char* tmp = useBcc ?
- GetPrefs()->GetDefaultHeaderContents(
- newsBcc ? MSG_NEWS_BCC_HEADER_MASK : MSG_BCC_HEADER_MASK) : NULL;
- if (!GetPrefs()->GetDefaultBccSelf(newsBcc)) {
- result = PL_strdup(tmp ? tmp : "");
- } else if (!tmp || !*tmp) {
- result = PL_strdup(pCompPrefs.GetUserEmail());
- } else {
- result = PR_smprintf("%s, %s", pCompPrefs.GetUserEmail(), tmp);
- }
- }
- return result;
-}
-
-
-const char*
-nsMsgCompose::CheckForLosingFcc(const char* fcc)
-{
- if (fcc && *fcc) {
- char *q = GetPrefs()->MagicFolderName(MSG_FOLDER_FLAG_QUEUE);
- if (q && *q && !XP_FILENAMECMP (q, fcc)) {
- /* We cannot allow them to use the queued mail folder
- as their fcc folder, too. Tell them why. */
-
-#ifdef UNREADY_CODE
- const char *q = MSG_GetQueueFolderName();
- if (q) {
- if (!PL_strcasecmp(q,QUEUE_FOLDER_NAME_OLD))
- buf = PR_smprintf("%s%s", XP_GetString(MK_MSG_WHY_QUEUE_SPECIAL_OLD),
- XP_GetString(MK_MSG_NOT_AS_SENT_FOLDER));
- else buf = PR_smprintf("%s%s", XP_GetString(MK_MSG_WHY_QUEUE_SPECIAL),
- XP_GetString(MK_MSG_NOT_AS_SENT_FOLDER));
- }
- else buf = PR_smprintf("%s%s", XP_GetString(MK_MSG_WHY_QUEUE_SPECIAL),
- XP_GetString(MK_MSG_NOT_AS_SENT_FOLDER));
- if (buf) {
- FE_Alert(m_context, buf);
- PR_Free(buf);
- }
-#endif
-
- /* Now ignore the FCC file they passed in. */
- fcc = 0;
- }
- PR_FREEIF(q);
- }
- return fcc;
-}
-
-nsresult
-nsMsgCompose::GetCommandStatus(MSG_CommandType command,
- const nsMsgViewIndex* indices,
- PRInt32 numindices,
- PRBool *selectable_pP,
- MSG_COMMAND_CHECK_STATE *selected_pP,
- const char **display_stringP,
- PRBool *plural_pP)
-{
- const char *display_string = 0;
- PRBool plural_p = PR_FALSE;
- // N.B. default is PR_TRUE, so you don't need to set it in each case
- PRBool selectable_p = PR_TRUE;
- PRBool selected_p = PR_FALSE;
- PRBool selected_used_p = PR_FALSE;
-
- switch (command)
- {
- case MSG_AttachAsText:
- // the WinFE uses this for lots of update, so pretend we handle it.
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_ATTACH_AS_TEXT);
-#endif
- break;
- case MSG_SendMessage:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_SEND);
-#endif
- if (m_attachmentInProgress || m_deliveryInProgress)
- selectable_p = PR_FALSE;
- break;
- case MSG_SendMessageLater:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_SEND_LATER);
-#endif
- if (m_attachmentInProgress || m_deliveryInProgress)
- selectable_p = PR_FALSE;
- break;
- case nsMsgSave:
- case MSG_SaveDraft:
- case MSG_SaveDraftThenClose:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_SAVE_DRAFT);
-#endif
- if (m_attachmentInProgress || m_deliveryInProgress)
- selectable_p = PR_FALSE;
- break;
- case MSG_SaveTemplate:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_SAVE_TEMPLATE);
-#endif
- if (m_attachmentInProgress || m_deliveryInProgress)
- selectable_p = PR_FALSE;
- break;
- case MSG_Attach:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_ATTACH_ETC);
-#endif
- break;
-
- case MSG_ShowFrom:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_FROM);
-#endif
- selected_p = ShowingCompositionHeader(MSG_FROM_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowReplyTo:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_REPLY_TO);
-#endif
- selected_p = ShowingCompositionHeader(MSG_REPLY_TO_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowTo:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_MAIL_TO);
-#endif
- selected_p = ShowingCompositionHeader(MSG_TO_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowCC:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_MAIL_CC);
-#endif
- selected_p = ShowingCompositionHeader(MSG_CC_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowBCC:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_MAIL_BCC);
-#endif
- selected_p = ShowingCompositionHeader(MSG_BCC_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowFCC:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_FILE_CC);
-#endif
- selected_p = ShowingCompositionHeader(MSG_FCC_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowPostTo:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_POST_TO);
-#endif
- selected_p = ShowingCompositionHeader(MSG_NEWSGROUPS_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowFollowupTo:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_FOLLOWUPS_TO);
-#endif
- selected_p = ShowingCompositionHeader(MSG_FOLLOWUP_TO_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowSubject:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_SUBJECT);
-#endif
- selected_p = ShowingCompositionHeader(MSG_SUBJECT_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- case MSG_ShowAttachments:
-#ifdef UNREADY_CODE
- display_string = XP_GetString(MK_MSG_ATTACHMENT);
-#endif
- selected_p = ShowingCompositionHeader(MSG_ATTACHMENTS_HEADER_MASK);
- selected_used_p = PR_TRUE;
- break;
- default:
- selectable_p = PR_FALSE;
-/*JFD
- return MSG_Pane::GetCommandStatus(command, indices, numindices,
- selectable_pP, selected_pP, display_stringP, plural_pP);
-*/return 0;
- }
- if (selectable_pP)
- *selectable_pP = selectable_p;
- if (selected_pP)
- {
- if (selected_used_p)
- {
- if (selected_p)
- *selected_pP = MSG_Checked;
- else
- *selected_pP = MSG_Unchecked;
- }
- else
- {
- *selected_pP = MSG_NotUsed;
- }
- }
- if (display_stringP)
- *display_stringP = display_string;
- if (plural_pP)
- *plural_pP = plural_p;
-
- return 0;
-}
-
-
-nsresult
-nsMsgCompose::DoCommand(MSG_CommandType command, nsMsgViewIndex* indices,
- PRInt32 numindices)
-{
- nsresult status = 0;
- InterruptContext(PR_FALSE);
- switch (command) {
- case MSG_SendMessage:
- status = SendMessageNow(); /* ###tw Error-return-type mismatch! */
- break;
- case MSG_SendMessageLater:
- status = QueueMessageForLater();/* ###tw Error-return-type mismatch! */
- break;
- case nsMsgSave:
- status = SaveMessage();
- break;
- case MSG_SaveDraft:
- case MSG_SaveDraftThenClose:
- if (command == MSG_SaveDraftThenClose)
- m_closeAfterSave = PR_TRUE;
- status = SaveMessageAsDraft(); /* ### Error-return-type mismatch! */
- break;
- case MSG_SaveTemplate:
- status = SaveMessageAsTemplate();
- break;
- case MSG_ShowPostTo: // how to do this?
- ToggleCompositionHeader(MSG_NEWSGROUPS_HEADER_MASK);
- break;
- case MSG_ShowFrom:
- ToggleCompositionHeader(MSG_FROM_HEADER_MASK);
- break;
- case MSG_ShowReplyTo:
- ToggleCompositionHeader(MSG_REPLY_TO_HEADER_MASK);
- break;
- case MSG_ShowTo:
- ToggleCompositionHeader(MSG_TO_HEADER_MASK);
- break;
- case MSG_ShowCC:
- ToggleCompositionHeader(MSG_CC_HEADER_MASK);
- break;
- case MSG_ShowBCC:
- ToggleCompositionHeader(MSG_BCC_HEADER_MASK);
- break;
- case MSG_ShowFCC:
- ToggleCompositionHeader(MSG_FCC_HEADER_MASK);
- break;
- case MSG_ShowFollowupTo:
- ToggleCompositionHeader(MSG_FOLLOWUP_TO_HEADER_MASK);
- break;
- case MSG_ShowSubject:
- ToggleCompositionHeader(MSG_SUBJECT_HEADER_MASK);
- break;
- case MSG_ShowAttachments:
- ToggleCompositionHeader(MSG_ATTACHMENTS_HEADER_MASK);
- break;
- default:
-/*JFD
- status = MSG_Pane::DoCommand(command, indices, numindices);
-*/status=0;
- break;
- }
- return status;
-}
-
-extern "C" void FE_MsgShowHeaders(MSG_Pane *pPane, MSG_HEADER_SET mhsHeaders);
-
-void nsMsgCompose::ToggleCompositionHeader(PRUint32 header)
-{
- if (m_visible_headers & header) {
- m_visible_headers &= ~header;
- } else {
- m_visible_headers |= header;
- }
- FE_MsgShowHeaders(this, m_visible_headers);
-}
-
-PRBool
-nsMsgCompose::ShowingAllCompositionHeaders()
-{
- return m_visible_headers == ALL_HEADERS;
-}
-
-PRBool
-nsMsgCompose::ShowingCompositionHeader(PRUint32 mask)
-{
- return (m_visible_headers & mask) == mask;
-}
-
-
-int
-nsMsgCompose::SetCallbacks(MSG_CompositionPaneCallbacks* callbacks,
- void* closure)
-{
- m_callbacks = *callbacks;
- m_callbackclosure = closure;
- return 0;
-}
-
-#ifdef UNREADY_CODE
-HJ99161
-HJ73123
-#endif
-
-void
-nsMsgCompose::InitializeHeaders(MWContext* old_context, const nsIMsgCompFields* fields)
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
- nsMsgCompPrefs pCompPrefs;
-
- PR_ASSERT(m_fields == NULL);
- PR_ASSERT(m_initfields == NULL);
-
- const char *real_addr = pCompPrefs.GetUserEmail();
- char *real_return_address;
- const char* sig;
- PRBool forward_quoted;
- forward_quoted = PR_FALSE;
-
- m_fields = new nsMsgCompFields;
- if (!m_fields)
- return;
- m_fields->AddRef();
- if (fields)
- m_fields->Copy((nsIMsgCompFields*)fields);
- m_fields->SetOwner(this);
-
- m_oldContext = old_context;
- /* hack for forward quoted. Checks the attachment field for a cookie
- string indicating that this is a forward quoted operation. If a cookie
- is found, the attachment string is slid back down over the cookie. This
- will put the original string back in tact. */
-
- const char* attachment = m_fields->GetAttachments();
-
- if (attachment && *attachment) {
- if (!PL_strncmp(attachment, MSG_FORWARD_COOKIE,
- PL_strlen(MSG_FORWARD_COOKIE))) {
- attachment += PL_strlen(MSG_FORWARD_COOKIE);
- forward_quoted = PR_TRUE; /* set forward with quote flag */
- m_fields->SetAttachments((char *)attachment, NULL);
- attachment = m_fields->GetAttachments();
- }
- }
-
- m_status = -1;
-
- if (MISC_ValidateReturnAddress(old_context, real_addr) < 0) {
- return;
- }
-
-/*JFD
- real_return_address = MIME_MakeFromField(old_context->win_csid);
-*/ real_return_address = (char *)pCompPrefs.GetUserEmail();/*JFD*/
-
-/*JFD
- PR_ASSERT (m_context->type == MWContextMessageComposition);
- PR_ASSERT (XP_FindContextOfType(0, MWContextMessageComposition));
- PR_ASSERT (!m_context->msg_cframe);
-*/
-
- PRInt32 count = m_fields->GetNumForwardURL();
- if (count > 0) {
- // if forwarding one or more messages
- PR_ASSERT(*attachment == '\0');
- nsMsgAttachmentData *alist = (struct nsMsgAttachmentData *)
- PR_Malloc((count + 1) * sizeof(nsMsgAttachmentData));
- if (alist) {
- memset(alist, 0, (count + 1) * sizeof(*alist));
- for (count--; count >= 0; count--) {
- alist[count].url = (char*) m_fields->GetForwardURL(count);
- alist[count].real_name = (char*) m_fields->GetForwardURL(count);
- }
- SetAttachmentList(alist);
- // Don't call msg_free_attachment_list because we are not duplicating
- // url & real_name
- PR_Free(alist);;
- }
- } else if (*attachment) {
- // forwarding a single url
- // typically a web page
- nsMsgAttachmentData *alist;
- count = 1;
- alist = (struct nsMsgAttachmentData *)
- PR_Malloc((count + 1) * sizeof(nsMsgAttachmentData));
- if (alist) {
- memset(alist, 0, (count + 1) * sizeof(*alist));
- alist[0].url = (char *)attachment;
- alist[0].real_name = (char *)attachment;
- SetAttachmentList(alist);
- // Don't call msg_free_attachment_list because we are not duplicating
- // url & real_name
- PR_Free(alist);
- }
- } // else if (*attachment)
-
- if (*attachment) {
- if (*attachment != '(') {
- m_defaultUrl = PL_strdup(attachment);
- }
- }
- else if (old_context) {
- History_entry *h = SHIST_GetCurrent(&old_context->hist);
- if (h && h->address) {
- m_defaultUrl = PL_strdup(h->address);
- }
- if (m_defaultUrl)
- {
- MSG_Pane *msg_pane = MSG_FindPane(old_context,
- MSG_MESSAGEPANE);
- if (msg_pane)
- m_fields->SetHTMLPart((char *)msg_pane->GetHTMLPart(), NULL);
- }
- }
-
- if (!*m_fields->GetFrom()) {
- m_fields->SetFrom(real_return_address, NULL);
- }
-
- /* Guess what kind of reply this is based on the headers we passed in.
- */
-
- const char* newsgroups = m_fields->GetNewsgroups();
- const char* to = m_fields->GetTo();
- const char* cc = m_fields->GetCc();
- const char* references = m_fields->GetReferences();
-
- if (count > 0 || *attachment) {
- /* if an attachment exists and the forward_quoted flag is set, this
- is a forward quoted operation. */
- if (forward_quoted) {
- m_replyType = MSG_ForwardMessageQuoted;
- /* clear out the attachment list for forward quoted messages. */
- SetAttachmentList(NULL);
- m_pendingAttachmentsCount = 0;
- } else {
- m_replyType = MSG_ForwardMessageAttachment;
- }
- } else if (*references && *newsgroups && (*to || *cc)) {
- m_replyType = MSG_PostAndMailReply;
- } else if (*references && *newsgroups) {
- m_replyType = MSG_PostReply;
- } else if (*references && *cc) {
- m_replyType = MSG_ReplyToAll;
- } else if (*references && *to) {
- m_replyType = MSG_ReplyToSender;
- } else if (*newsgroups) {
- m_replyType = MSG_PostNew;
- } else {
- m_replyType = MSG_MailNew;
- }
-
-
-#ifdef UNREADY_CODE
- HJ77855
-#endif
-
- if (!*m_fields->GetOrganization()) {
- m_fields->SetOrganization((char *)pCompPrefs.GetOrganization(), NULL);
- }
-
- if (!*m_fields->GetReplyTo()) {
- m_fields->
- SetReplyTo((char *)GetPrefs()->
- GetDefaultHeaderContents(MSG_REPLY_TO_HEADER_MASK), NULL);
- }
- if (!*m_fields->GetFcc())
- {
- PRBool useDefaultFcc = PR_TRUE;
- /*int prefError =*/
- if (NS_SUCCEEDED(rv) && prefs)
- {
- prefs->GetBoolPref(*newsgroups ? "news.use_fcc" : "mail.use_fcc",
- &useDefaultFcc);
- }
-
- if (useDefaultFcc)
- {
- m_fields->SetFcc((char *)GetPrefs()->
- GetDefaultHeaderContents(*newsgroups ?
- MSG_NEWS_FCC_HEADER_MASK : MSG_FCC_HEADER_MASK), NULL);
- }
- }
- if (!*m_fields->GetBcc()) {
- char* bcc = FigureBcc(*newsgroups);
- m_fields->SetBcc(bcc, NULL);
- PR_FREEIF(bcc);
- }
-
- m_fields->SetFcc((char *)CheckForLosingFcc(m_fields->GetFcc()), NULL);
-
- {
- const char *body = m_fields->GetDefaultBody();
- if (body && *body)
- {
- m_fields->AppendBody((char *)body);
- m_fields->AppendBody(MSG_LINEBREAK);
- /* m_bodyEdited = PR_TRUE; */
- }
- }
-
- sig = FE_UsersSignature ();
- if (sig && *sig) {
- m_fields->AppendBody(MSG_LINEBREAK);
- /* If the sig doesn't begin with "--" followed by whitespace or a
- newline, insert "-- \n" (the pseudo-standard sig delimiter.) */
- if (sig[0] != '-' || sig[1] != '-' ||
- (sig[2] != ' ' && sig[2] != CR && sig[2] != LF)) {
- m_fields->AppendBody("-- " MSG_LINEBREAK);
- }
- m_fields->AppendBody((char *)sig);
- }
-
- PR_FREEIF (real_return_address);
-
-
- if (m_context)
- FE_SetDocTitle(m_context, (char*) GetWindowTitle());
-
-
- m_initfields = new nsMsgCompFields;
- if (m_initfields) {
- m_initfields->AddRef();
- m_fields->Copy((nsIMsgCompFields*)m_fields);
- m_initfields->SetOwner(this);
- }
-}
-
-
-PRBool nsMsgCompose::ShouldAutoQuote() {
- if (m_haveQuoted) return PR_FALSE;
- if (m_replyType == MSG_ForwardMessageQuoted ||
- GetPrefs()->GetAutoQuoteReply()) {
- switch (m_replyType) {
- case MSG_ForwardMessageQuoted:
- case MSG_PostAndMailReply:
- case MSG_PostReply:
- case MSG_ReplyToAll:
- case MSG_ReplyToSender:
- return PR_TRUE;
-
- default:
- break;
- }
- }
- return PR_FALSE;
-}
-
-
-
-
-const char* nsMsgCompose::GetDefaultURL() {
- return m_defaultUrl;
-}
-
-void nsMsgCompose::SetDefaultURL(const char *defaultURL,
- const char *htmlPart)
-{
- PR_FREEIF(m_defaultUrl);
- PR_FREEIF(m_quotedText);
- if (defaultURL)
- m_defaultUrl = PL_strdup(defaultURL);
- m_fields->SetHTMLPart((char *)htmlPart, NULL);
-}
-
-
-
-nsIMsgCompFields* nsMsgCompose::GetInitialFields()
-{
- return (nsIMsgCompFields*)m_initfields;
-}
-
-
-
-
-#define ALL_HEADERS (MSG_FROM_HEADER_MASK | \
- MSG_REPLY_TO_HEADER_MASK | \
- MSG_TO_HEADER_MASK | \
- MSG_CC_HEADER_MASK | \
- MSG_BCC_HEADER_MASK | \
- MSG_FCC_HEADER_MASK | \
- MSG_NEWSGROUPS_HEADER_MASK | \
- MSG_FOLLOWUP_TO_HEADER_MASK | \
- MSG_SUBJECT_HEADER_MASK | \
- MSG_ATTACHMENTS_HEADER_MASK)
-
-
-MSG_HEADER_SET nsMsgCompose::GetInterestingHeaders()
-{
- MSG_HEADER_SET desired_mask = 0;
- /* The FE has requested the list of "interesting" header fields.
- The logic here is a bit complicated, in the interest of DWIMity.
- */
-
- /* Cc, Subject, and Attachments are always interesting.
- */
- desired_mask |= (MSG_CC_HEADER_MASK |
- MSG_SUBJECT_HEADER_MASK /* |
- MSG_ATTACHMENTS_HEADER_MASK */);
-
- /* To is interesting if:
- - it is non-empty, or
- - this composition window was brought up with a "mail sending"
- command (Mail New, Reply-*, Forward, or Post and Mail).
- */
- if (*m_fields->GetTo() ||
- m_replyType == MSG_MailNew ||
- m_replyType == MSG_ReplyToSender ||
- m_replyType == MSG_ReplyToAll ||
- m_replyType == MSG_PostAndMailReply ||
- m_replyType == MSG_ForwardMessageAttachment ||
- m_replyType == MSG_ForwardMessageQuoted)
- desired_mask |= MSG_TO_HEADER_MASK;
-
- /* CC is interesting if:
- - it is non-empty, or
- - this composition window was brought up as a reply to another
- mail message. (Should mail-and-post do this too?)
- */
- if ((*m_fields->GetCc()) ||
- m_replyType == MSG_ReplyToSender ||
- m_replyType == MSG_ReplyToAll)
- desired_mask |= MSG_CC_HEADER_MASK;
-
- /* Reply-To and BCC are interesting if:
- - they are non-empty, AND
- - they are different from the default value
- (meaning the user has edited them this session.)
- */
- const char* reply_to = m_fields->GetReplyTo();
- const char* default_reply_to =
- GetPrefs()->GetDefaultHeaderContents(MSG_REPLY_TO_HEADER_MASK);
- if (reply_to && *reply_to &&
- ((default_reply_to && *default_reply_to)
- ? !!PL_strcmp (reply_to, default_reply_to) : PR_TRUE))
- desired_mask |= MSG_REPLY_TO_HEADER_MASK;
-
- /* (see above.) */
- const char* bcc = m_fields->GetBcc();
- const char* default_bcc =
- GetPrefs()->GetDefaultHeaderContents(MSG_BCC_HEADER_MASK);
- if (bcc && *bcc &&
- ((default_bcc && *default_bcc)
- ? !!PL_strcmp (bcc, default_bcc) : PR_TRUE))
- desired_mask |= MSG_BCC_HEADER_MASK;
-
- /* FCC is never interesting.
- */
-
- /* Newsgroups is interesting if:
- - it is non-empty, or
- - this composition window was brought up with a "news posting"
- command (Post New, Post Reply, or Post and Mail).
- */
-
- const char* newsgroups = m_fields->GetNewsgroups();
- if ((newsgroups && *newsgroups) ||
- m_replyType == MSG_PostNew ||
- m_replyType == MSG_PostReply ||
- m_replyType == MSG_PostAndMailReply)
- desired_mask |= MSG_NEWSGROUPS_HEADER_MASK;
-
- /* Followup-To is interesting if:
- - it is non-empty, AND
- - it differs from the Newsgroups field.
- */
- const char* followup_to = m_fields->GetFollowupTo();
- if (followup_to && *followup_to &&
- (newsgroups ? PL_strcmp (followup_to, newsgroups) : PR_TRUE))
- desired_mask |= MSG_FOLLOWUP_TO_HEADER_MASK;
-
- return desired_mask;
-}
-
-
-void
-nsMsgCompose::GetUrlDone_S(PrintSetup* pptr)
-{
-/*JFD
- ((nsMsgCompose*) (pptr->carg))->GetUrlDone(pptr);
-*/
-}
-
-
-#define QUOTE_BUFFER_SIZE 10240
-
-void
-nsMsgCompose::GetUrlDone(PrintSetup* /*pptr*/)
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
-
- PRFileDesc *file=(PRFileDesc *)nsnull;
- PR_FREEIF(m_quoteUrl);
- m_textContext = NULL; /* since this is called as a result of
- TXFE_AllConnectionsComplete, we know this context
- is going away by natural means */
- int bufSize = QUOTE_BUFFER_SIZE;
-
-/*JFD
- PR_Close(m_print->out);
-*/
- XP_StatStruct fileStat;
- char* curquote = NULL;
- PRInt32 replyOnTop = 0, replyWithExtraLines = 0;
-
- if (NS_SUCCEEDED(rv) && prefs)
- {
- prefs->GetIntPref("mailnews.reply_on_top", &replyOnTop);
- prefs->GetIntPref("mailnews.reply_with_extra_lines", &replyWithExtraLines);
- }
-
- PRInt32 extra = (m_markup ? 0 :
- (replyWithExtraLines ? MSG_LINEBREAK_LEN * replyWithExtraLines
- : 0));
-
-/*JFD
- if (XP_Stat(m_print->filename, &stat, xpTemporary) == 0) */ {
- m_quotedText = (char*) PR_Malloc(fileStat.st_size + 1 + extra);
-
- /* Insert two line break at the begining of the quoted text */
- if (!m_quotedText) return;
-
- curquote = m_quotedText;
-
- if (!m_markup && extra && replyOnTop == 1) {
- for (; replyWithExtraLines > 0; replyWithExtraLines--) {
- PL_strcpy(curquote, MSG_LINEBREAK);
- curquote += MSG_LINEBREAK_LEN;
- if (m_quotefunc)
- (*m_quotefunc)(m_quoteclosure, MSG_LINEBREAK);
- }
- }
- }
-
- /* Open hateful temporary file as input */
-/*JFD
- file = PR_Open (m_print->filename, PR_RDONLY, 493);
-*/
- if (file) {
- char* buf = NULL;
- while (!buf && (bufSize >= 512))
- {
- buf = (char*)PR_Malloc(bufSize + 1);
- if (!buf)
- bufSize /= 2;
- }
- if (buf) {
- PRInt32 bufferLen;
- CCCDataObject conv;
- int doConv;
- INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(m_context);
- PRInt16 win_csid = INTL_GetCSIWinCSID(c);
-
- /*
- * We aren't actually converting character encodings here.
- * (Note that both the "from" and "to" are the win_csid.)
- * This makes it call a special routine that makes sure we
- * deal with whole multibyte characters instead of partial
- * ones that happen to lie on the boundary of the buffer. -- erik
- */
- conv = INTL_CreateCharCodeConverter();
- if (conv) {
- doConv = INTL_GetCharCodeConverter(win_csid, win_csid, conv);
- } else {
- doConv = 0;
- }
-
- while (0 < (bufferLen = PR_Read(file, buf, bufSize))) {
- char *newBuf;
- buf[bufferLen] = '\0';
- if (doConv) {
- newBuf = (char *)
- INTL_CallCharCodeConverter(conv,
- (unsigned char *) buf,
- bufferLen);
- if (!newBuf) {
- newBuf = buf;
- }
- } else {
- newBuf = buf;
- }
- if (m_quotefunc) {
- (*m_quotefunc)(m_quoteclosure, newBuf);
- }
-
- if (m_quotedText && curquote) {
- PR_ASSERT(curquote + bufferLen <= m_quotedText + fileStat.st_size + extra);
- if (curquote + bufferLen <= m_quotedText + fileStat.st_size + extra) {
- PL_strcpy(curquote, newBuf);
- curquote += bufferLen;
- }
- }
-
- if (newBuf != buf) {
- PR_Free(newBuf);
- }
- }
-
- if (!m_markup && extra && replyOnTop == 0) {
- for (; replyWithExtraLines > 1; replyWithExtraLines--) {
- PL_strcpy(curquote, MSG_LINEBREAK);
- curquote += MSG_LINEBREAK_LEN;
- if (m_quotefunc)
- (*m_quotefunc)(m_quoteclosure, MSG_LINEBREAK);
- }
- }
-
- PR_Free(buf);
- if (conv) {
- INTL_DestroyCharCodeConverter(conv);
- }
- }
- PR_Close(file);
- }
- if (curquote) *curquote = '\0';
- m_cited = PR_TRUE;
-/*JFD
- PR_Delete(m_print->filename);
- PR_FREEIF(m_print->filename);
-*/
- if (m_exitQuoting) {
- (*m_exitQuoting)(m_dummyUrl, 0, m_context);
- m_exitQuoting = NULL;
- m_dummyUrl = NULL;
-
- /* hack that manages to get the cursor back to normal. */
- NET_SilentInterruptWindow(m_context);
- }
- if (m_quotefunc) {
- (*m_quotefunc)(m_quoteclosure, NULL);
- m_quotefunc = NULL;
- }
-
-
- /* Re-enable the UI. */
- FE_UpdateCompToolbar (this);
-}
-
-
-
-class QuotePlainIntoHTML : public MSG_ZapIt {
-public:
- QuotePlainIntoHTML(MWContext* context);
- ~QuotePlainIntoHTML();
-
- int DoQuote(const char* data);
- static PRInt32 QuoteLine_s(char* line, PRUint32 line_length, void* closure);
- PRInt32 QuoteLine(char* line, PRUint32 line_length);
-protected:
- MWContext* m_context;
- char* m_buffer;
- PRUint32 m_size;
- PRUint32 m_fp;
- PRBool m_insertedpre;
- char* m_outbuf;
- PRUint32 m_outbufsize;
- PRUint32 m_maxLineWidth;
- PRInt32 m_replyOnTop;
- PRInt32 m_replyWithExtraLines;
-};
-
-
-static int
-MyQuoteFunc(void* closure, const char* data)
-{
- return ((QuotePlainIntoHTML*) closure)->DoQuote(data);
-}
-
-
-
-
-
-QuotePlainIntoHTML::QuotePlainIntoHTML(MWContext* context)
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
-
- m_context = context;
- if (EDT_PasteQuoteBegin(m_context, PR_TRUE) != EDT_COP_OK) {
- m_context = NULL;
- }
- if (NS_SUCCEEDED(rv) && prefs)
- {
- prefs->GetIntPref("mailnews.reply_on_top", &m_replyOnTop);
- prefs->GetIntPref("mailnews.reply_with_extra_lines", &m_replyWithExtraLines);
- }
-
- m_buffer = NULL;
- m_size = 0;
- m_fp = 0;
- m_insertedpre = PR_FALSE;
- m_outbuf = NULL;
- m_outbufsize = 0;
- m_maxLineWidth = 0;
-}
-
-QuotePlainIntoHTML::~QuotePlainIntoHTML()
-{
- PR_FREEIF(m_buffer);
- delete [] m_outbuf;
-}
-
-
-
-int
-QuotePlainIntoHTML::DoQuote(const char* data)
-{
- if (data) {
- if (!m_context) return 0;
- return (int)msg_LineBuffer(data, PL_strlen(data), &m_buffer, &m_size, &m_fp, PR_FALSE,
-#ifdef XP_OS2
- (PRInt32 (_Optlink*) (char*,PRUint32,void*))
-#endif
- QuoteLine_s, this);
-
- } else {
- if (m_context) {
- if (m_fp > 0) {
- QuoteLine(m_buffer, m_fp);
- }
- if (m_insertedpre) {
- EDT_PasteQuote(m_context, "");
- }
- if ( 0 == m_replyOnTop && m_replyWithExtraLines)
- for (;m_replyWithExtraLines > 0; m_replyWithExtraLines--)
- EDT_PasteQuote(m_context, " ");
- EDT_PasteQuoteEnd(m_context);
-
- nsMsgCompose *cpane = (nsMsgCompose *)
- MSG_FindPane(m_context, MSG_COMPOSITIONPANE);
- if (cpane)
- cpane->SetLineWidth(m_maxLineWidth);
- }
- delete this;
- return 0;
- }
-}
-
-
-PRInt32
-QuotePlainIntoHTML::QuoteLine_s(char* line, PRUint32 length, void* closure)
-{
- return ((QuotePlainIntoHTML*)closure)->QuoteLine(line, length);
-}
-
-PRInt32
-QuotePlainIntoHTML::QuoteLine(char* line, PRUint32 length)
-{
- if (length > m_maxLineWidth)
- m_maxLineWidth = length;
-
- if (length >= 2 && line[0] == '>' && line[1] == ' ') {
- line += 2;
- length -= 2;
- if (!m_insertedpre) {
- EDT_PasteQuote(m_context, "
");
- m_insertedpre = PR_TRUE;
- }
- }
- else if (!m_insertedpre) {
- if (1 == m_replyOnTop && m_replyWithExtraLines)
- for (; m_replyWithExtraLines > 0; m_replyWithExtraLines--)
- EDT_PasteQuote(m_context, " ");
- }
-
- PRUint32 l = length * 2 + 50;
- if (l > m_outbufsize) {
- if (l < 512) l = 512;
- m_outbufsize = l;
- delete [] m_outbuf;
- m_outbuf = new char [m_outbufsize];
- }
- if (m_outbuf)
- {
- nsCOMPtr myURLUtil;
- int res = nsComponentManager::CreateInstance(kCMimeURLUtilsCID,
- NULL, nsIMimeURLUtils::GetIID(),
- (void **) getter_AddRefs(myURLUtil));
- if (!NS_SUCCEEDED(res))
- return 0;
-
- *m_outbuf = '\0';
- myURLUtil->ScanForURLs(line, length, m_outbuf, m_outbufsize, PR_TRUE);
- EDT_PasteQuote(m_context, m_outbuf);
- }
- return 0;
-}
-
-
-void
-nsMsgCompose::QuoteHTMLDone_S(URL_Struct* url, int /*status*/, MWContext* /*context*/)
-{
- nsMsgCompose *pane = (nsMsgCompose *) url->fe_data;
- if (pane) {
- PR_FREEIF(pane->m_quoteUrl);
- pane->m_quotefunc = NULL;
- if (pane->m_quoteclosure) {
- delete pane->m_quoteclosure;
- pane->m_quoteclosure = NULL;
- }
- }
- NET_FreeURLStruct(url);
-}
-
-
-
-nsresult nsMsgCompose::QuoteMessage(int (*func)(void* closure,
- const char* data),
- void* closure)
-{
- nsresult rv;
- NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
-
- nsresult status = 0;
- char* ptr;
- m_haveQuoted = PR_TRUE;
- if (!m_defaultUrl) return 0; /* Nothing to quote. */
- if (m_quoteUrl) return 0; /* Currently already quoting! */
-
- PR_ASSERT(m_quotefunc == NULL);
-
- if (m_markup) {
- func = MyQuoteFunc;
- closure = new QuotePlainIntoHTML(GetContext());
- if (!closure) return NS_ERROR_OUT_OF_MEMORY;
- }
-
- MSG_Pane *msgPane = FindPane(m_oldContext, MSG_MESSAGEPANE);
-
- char* htmlpart;
-
- if (msgPane && msgPane->GetQuoteUrl())
- {
- if (msgPane->GetQuoteHtmlPart())
- {
- htmlpart = PL_strdup(msgPane->GetQuoteHtmlPart());
- msgPane->SetQuoteHtmlPart(NULL);
- }
- else
- {
- htmlpart = NULL;
- }
- }
- else
- {
- htmlpart = m_fields->GetHTMLPart() ? PL_strdup(m_fields->GetHTMLPart()) : NULL;
- }
-
- PRBool quotehtml = (m_markup && htmlpart != NULL && *htmlpart != '\0');
-
- if (m_quotedText) {
- if (func) {
-#ifdef EXTRA_QUOTE_BEGIN
- if (m_markup) {
- if (EDT_PasteQuoteBegin(GetContext(),
- PR_TRUE) != EDT_COP_OK) {
- return eUNKNOWN;
- }
- }
-#endif
- (*func)(closure, m_quotedText);
- (*func)(closure, NULL);
- }
- return 0;
- }
-
-
- m_quotefunc = func;
- m_quoteclosure = closure;
-
-
- if (msgPane && msgPane->GetQuoteUrl())
- {
- m_quoteUrl = PL_strdup(msgPane->GetQuoteUrl());
- msgPane->SetQuoteUrl(NULL);
- }
- else
- m_quoteUrl = PL_strdup(m_defaultUrl);
- if (!m_quoteUrl) return eOUT_OF_MEMORY;
-
- /* remove any position information from the url
- */
- ptr = PL_strchr(m_quoteUrl, '#');
- if (ptr) *ptr = '\0';
-
- if (quotehtml) {
- URL_Struct* url = NET_CreateURLStruct(m_quoteUrl, NET_DONT_RELOAD);
- if (!url) return NS_ERROR_OUT_OF_MEMORY;
-
- // This is a hack, really should be url->msg_pane, but this prevents mail
- // quoting from working at all. We just need SOME sort of way to give
- // the msg_page to the completion function.
- url->fe_data = (void *)this;
-
- // Set this because when quoting messages that might have been
- // downloaded through IMAP MIME Parts on Demand (with some parts left out)
- // we think it is OK to only quote the inline parts that have been
- // downloaded.
- // (That is, we don't think it's necessary to re-download the entire message
- // from the server. We might be wrong about this, but so far haven't seen
- // any examples to the contrary.)
- url->allow_content_change = PR_TRUE;
-/*JFD
- MSG_UrlQueue::AddUrlToPane (url, QuoteHTMLDone_S, this, PR_TRUE, FO_QUOTE_HTML_MESSAGE);
-*/
- PR_FREEIF(htmlpart);
- return 0;
- }
-
-
- XL_InitializeTextSetup(m_print);
-/*JFD
- m_print->out = NULL;
- m_print->prefix = "> ";
-*/
- if (m_markup) {
- if (htmlpart && *htmlpart) {
- // Quoting html into html
- // We are kind of doomed on this case when force sending plain text
- // if there are hard line breaks.
-/*JFD
- m_print->width = 999;
-*/
- }
- else {
- // Quoting plain text into html; there are hard line breaks
- // We should not reformat the line when force sending plain text
- // message
- // This is done via recording the max line width when we quote each plain
- // text line and then use the max line width if it is greater than default
- // wraplinewidth. This prevent from reformatting the qutoed line in an
- // unwanted fashion.
-/*JFD
- m_print->width = 998;
-*/
- }
-
- // m_print->width = 999; // Cheap hack. The EDT_PasteQuote routine
- // generates HTML that is better at wrapping
- // than the TextFE is, so try and let it do the
- // wrapping instead.
- }
- else {
- if (htmlpart && *htmlpart) {
- // We are quoting html message into plain text message
- // Use wrapline width from preference
- PRInt32 width = 72;
-
- if (NS_SUCCEEDED(rv) && prefs)
- prefs->GetIntPref("mailnews.wraplength", &width);
-
- if (width == 0) width = 72;
- else if (width < 10) width = 10;
- else if (width > 30000) width = 30000;
-/*JFD
- m_print->width = width - 2;
-*/ }
- else {
- // We are quoting plain text message.to plain text
- // We shouldn't reformat the original message since everyline already
- // has hard line break we simply set the m_print->width to 999.
-/*JFD
- m_print->width = 997;
-*/
- }
- // m_print->width = 70; // The default window is 72 wide; subtract 2 for "> ".
- }
- PR_FREEIF(htmlpart);
-/*JFD
- m_print->carg = this;
- m_print->url = NET_CreateURLStruct(m_quoteUrl, NET_DONT_RELOAD);
- if (!m_print->url) {
- status = eOUT_OF_MEMORY;
- goto FAIL;
- }
- m_print->url->position_tag = 0;
- m_print->completion = nsMsgCompose::GetUrlDone_S;
- m_print->filename = WH_TempName("ns");
- if (!m_print->filename) {
- status = eOUT_OF_MEMORY;
- goto FAIL;
- }
- m_print->out = PR_Open(m_print->filename, PR_CREATE_FILE | PR_RDWR, 493);
- if (!m_print->out) {
- status = 9999; // ###tw Need the right error code!
- goto FAIL;
- }
- m_print->cx = m_context;
-*/
- m_exitQuoting = NULL;
- m_dummyUrl = NET_CreateURLStruct("about:", NET_DONT_RELOAD);
- m_dummyUrl->internal_url = PR_TRUE;
- if (m_dummyUrl) {
- FE_SetWindowLoading(m_context, m_dummyUrl, &m_exitQuoting);
- PR_ASSERT(m_exitQuoting != NULL);
- }
-
- /* Start the URL loading... (msg_get_url_done gets called later.) */
-
-
-/*JFD
- m_textContext = (MWContext*) XL_TranslateText(m_context, m_print->url,
- m_print);
-*/
- // ###tw I'm not at all sure this cast is the
- // right thing to do here...
-
- return 0;
-FAIL:
-/*JFD
- PR_FREEIF(m_print->filename);
-*/
- PR_FREEIF(m_quoteUrl);
-/*JFD
- if (m_print->out) {
- PR_Close(m_print->out);
- m_print->out = NULL;
- }
- if (m_print->url) {
- NET_FreeURLStruct(m_print->url);
- m_print->url = NULL;
- }
-*/
- return status;
-}
-
-
-int
-nsMsgCompose::PastePlaintextQuotation(const char* str)
-{
- if (str && *str) {
- if (EDT_PasteQuoteBegin(m_context, PR_TRUE) != EDT_COP_OK) {
- return -1;
- }
- EDT_PasteQuote(m_context, "