message Save As ignores selected file type, plus some code cleanup.
r/sr=bienvenu
This commit is contained in:
sspitzer%netscape.com 2003-03-16 05:44:48 +00:00
Родитель 91b0ef2163
Коммит 127378455d
6 изменённых файлов: 244 добавлений и 288 удалений

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

@ -60,8 +60,6 @@ interface nsIMessenger : nsISupports {
readonly attribute nsITransactionManager transactionManager; readonly attribute nsITransactionManager transactionManager;
void SetWindow(in nsIDOMWindowInternal ptr, in nsIMsgWindow msgWindow); void SetWindow(in nsIDOMWindowInternal ptr, in nsIMsgWindow msgWindow);
void DoPrint();
void DoPrintPreview();
void DeleteMessages(in nsIRDFCompositeDataSource database, void DeleteMessages(in nsIRDFCompositeDataSource database,
in nsIRDFResource srcFolderResource, in nsIRDFResource srcFolderResource,
in nsISupportsArray messages, in nsISupportsArray messages,
@ -98,7 +96,7 @@ interface nsIMessenger : nsISupports {
void Redo(in nsIMsgWindow msgWindow); void Redo(in nsIMsgWindow msgWindow);
void sendUnsentMessages(in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow); void sendUnsentMessages(in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void SetDocumentCharset(in wstring characterSet); void SetDocumentCharset(in wstring characterSet);
void saveAs(in string url, in boolean asFile, in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow); void saveAs(in string aURI, in boolean aAsFile, in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void openAttachment(in string contentTpe, in string url, in string displayName, in string messageUri); void openAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);
void saveAttachment(in string contentTpe, in string url, in string displayName, in string messageUri); void saveAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);
void saveAllAttachments(in unsigned long count, [array, size_is(count)] in string contentTypeArray, void saveAllAttachments(in unsigned long count, [array, size_is(count)] in string contentTypeArray,

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

@ -44,23 +44,3 @@ function MessengerSetDefaultCharacterSet(aCharset)
// messenger.SetDocumentCharset. You'll just break things and reak havoc // messenger.SetDocumentCharset. You'll just break things and reak havoc
// if you call MsgReload() here... // if you call MsgReload() here...
} }
function PrintPreview() {
dump("PrintPreview()\n");
try {
messenger.DoPrintPreview();
}
catch (ex) {
dump("failed to print preview\n");
}
}
function Print() {
dump("Print()\n");
try {
messenger.DoPrint();
}
catch (ex) {
dump("failed to print\n");
}
}

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

@ -38,11 +38,7 @@ titleNewsPreHost=on
titleMailPreHost=for titleMailPreHost=for
replyToSender=Reply to Sender replyToSender=Reply to Sender
reply=Reply reply=Reply
# LOCALIZATION NOTES(HTMLFiles): Only translate "Files" in the line below # LOCALIZATION NOTES(EMLFiles): Do not translate "*.eml" in the line below
HTMLFiles=HTML Files (*.htm, *.html, *.shtml)
# LOCALIZATION NOTES(TextFiles): Do not translate "*.txt" in the line below
TextFiles=Text Files (*.txt)
# LOCALIZATION NOTES(TextFiles): Do not translate "*.eml" in the line below
EMLFiles=Mail Files (*.eml) EMLFiles=Mail Files (*.eml)
# LOCALIZATION NOTES(defaultSaveMessageAsFileName): Do not translate ".eml" # LOCALIZATION NOTES(defaultSaveMessageAsFileName): Do not translate ".eml"
# in the line below. Also, the complete file name should 8.3 # in the line below. Also, the complete file name should 8.3

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

@ -134,7 +134,6 @@
#include "nsCExternalHandlerService.h" #include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h" #include "nsIMIMEService.h"
static NS_DEFINE_CID(kIStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kMsgSendLaterCID, NS_MSGSENDLATER_CID); static NS_DEFINE_CID(kMsgSendLaterCID, NS_MSGSENDLATER_CID);
static NS_DEFINE_CID(kMsgPrintEngineCID, NS_MSG_PRINTENGINE_CID); static NS_DEFINE_CID(kMsgPrintEngineCID, NS_MSG_PRINTENGINE_CID);
@ -600,13 +599,10 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
{ {
nsIMsgMessageService * messageService = nsnull; nsIMsgMessageService * messageService = nsnull;
nsSaveAllAttachmentsState *saveState= (nsSaveAllAttachmentsState*) closure; nsSaveAllAttachmentsState *saveState= (nsSaveAllAttachmentsState*) closure;
nsCOMPtr<nsISupports> channelSupport;
nsCOMPtr<nsIMsgMessageFetchPartService> fetchService; nsCOMPtr<nsIMsgMessageFetchPartService> fetchService;
nsAutoString urlString; nsCAutoString urlString;
char *urlCString = nsnull; nsCOMPtr<nsIURI> URL;
nsCOMPtr<nsIURI> aURL;
nsCAutoString fullMessageUri(messageUri); nsCAutoString fullMessageUri(messageUri);
nsresult rv = NS_OK;
// XXX todo // XXX todo
// document the ownership model of saveListener // document the ownership model of saveListener
@ -622,13 +618,9 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
if (saveState) if (saveState)
saveListener->m_saveAllAttachmentsState = saveState; saveListener->m_saveAllAttachmentsState = saveState;
urlString.AssignWithConversion(unescapedUrl); urlString = unescapedUrl;
urlString.ReplaceSubstring(NS_LITERAL_CSTRING("/;section").get(), NS_LITERAL_CSTRING("?section").get());
urlString.ReplaceSubstring(NS_LITERAL_STRING("/;section").get(), NS_LITERAL_STRING("?section").get()); nsresult rv = CreateStartupUrl(urlString.get(), getter_AddRefs(URL));
urlCString = ToNewCString(urlString);
rv = CreateStartupUrl(urlCString, getter_AddRefs(aURL));
nsCRT::free(urlCString);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
{ {
@ -640,10 +632,9 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
if (fetchService) if (fetchService)
{ {
PRInt32 sectionPos = urlString.Find("?section"); PRInt32 sectionPos = urlString.Find("?section");
nsString mimePart; nsCString mimePart;
urlString.Right(mimePart, urlString.Length() - sectionPos); urlString.Right(mimePart, urlString.Length() - sectionPos);
fullMessageUri.AppendWithConversion(mimePart); fullMessageUri.Append(mimePart);
messageUri = fullMessageUri.get(); messageUri = fullMessageUri.get();
} }
@ -658,7 +649,7 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
if (contentType && !nsCRT::strcasecmp(APPLICATION_BINHEX, contentType)) if (contentType && !nsCRT::strcasecmp(APPLICATION_BINHEX, contentType))
{ {
nsCOMPtr<nsIStreamListener> listener (do_QueryInterface(convertedListener)); nsCOMPtr<nsIStreamListener> listener (do_QueryInterface(convertedListener));
nsCOMPtr<nsIStreamConverterService> streamConverterService = do_GetService(kIStreamConverterServiceCID, &rv); nsCOMPtr<nsIStreamConverterService> streamConverterService = do_GetService("@mozilla.org/streamConverters;1", &rv);
nsCOMPtr<nsISupports> channelSupport = do_QueryInterface(saveListener->m_channel); nsCOMPtr<nsISupports> channelSupport = do_QueryInterface(saveListener->m_channel);
rv = streamConverterService->AsyncConvertData(NS_ConvertASCIItoUCS2(APPLICATION_BINHEX).get(), rv = streamConverterService->AsyncConvertData(NS_ConvertASCIItoUCS2(APPLICATION_BINHEX).get(),
@ -669,9 +660,9 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
} }
#endif #endif
if (fetchService) if (fetchService)
rv = fetchService->FetchMimePart(aURL, messageUri, convertedListener, mMsgWindow, nsnull,nsnull); rv = fetchService->FetchMimePart(URL, messageUri, convertedListener, mMsgWindow, nsnull,nsnull);
else else
rv = messageService->DisplayMessage(messageUri, convertedListener, mMsgWindow,nsnull, nsnull, nsnull); rv = messageService->DisplayMessage(messageUri, convertedListener, mMsgWindow, nsnull, nsnull, nsnull);
} // if we got a message service } // if we got a message service
} // if we created a url } // if we created a url
@ -684,7 +675,7 @@ nsMessenger::SaveAttachment(nsIFileSpec * fileSpec,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsMessenger::OpenAttachment(const char * aContentType, const char * aUrl, const nsMessenger::OpenAttachment(const char * aContentType, const char * aURL, const
char * aDisplayName, const char * aMessageUri) char * aDisplayName, const char * aMessageUri)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -692,7 +683,7 @@ nsMessenger::OpenAttachment(const char * aContentType, const char * aUrl, const
rv = GetMessageServiceFromURI(aMessageUri, getter_AddRefs(messageService)); rv = GetMessageServiceFromURI(aMessageUri, getter_AddRefs(messageService));
if (messageService) if (messageService)
{ {
rv = messageService->OpenAttachment(aContentType, aDisplayName, aUrl, aMessageUri, mDocShell, mMsgWindow, nsnull); rv = messageService->OpenAttachment(aContentType, aDisplayName, aURL, aMessageUri, mDocShell, mMsgWindow, nsnull);
} }
return rv; return rv;
} }
@ -839,208 +830,244 @@ done:
return rv; return rv;
} }
enum MESSENGER_SAVEAS_FILE_TYPE
{
EML_FILE_TYPE = 0,
HTML_FILE_TYPE = 1,
TEXT_FILE_TYPE = 2,
ANY_FILE_TYPE = 3
};
NS_IMETHODIMP NS_IMETHODIMP
nsMessenger::SaveAs(const char* url, PRBool asFile, nsIMsgIdentity* identity, nsIMsgWindow *aMsgWindow) nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity, nsIMsgWindow *aMsgWindow)
{ {
nsresult rv = NS_ERROR_FAILURE; NS_ENSURE_ARG_POINTER(aURI);
nsCOMPtr<nsIMsgMessageService> messageService;
nsCOMPtr<nsIUrlListener> urlListener; nsCOMPtr<nsIMsgMessageService> messageService;
nsSaveMsgListener *saveListener = nsnull; nsCOMPtr<nsIUrlListener> urlListener;
nsCOMPtr<nsIURI> aURL; nsSaveMsgListener *saveListener = nsnull;
nsAutoString urlString; nsCOMPtr<nsIURI> url;
char *urlCString = nsnull; nsCOMPtr<nsIStreamListener> convertedListener;
nsCOMPtr<nsISupports> channelSupport; PRInt32 saveAsFileType = EML_FILE_TYPE;
nsCOMPtr<nsIStreamListener> convertedListener;
PRBool needDummyHeader = PR_TRUE; nsresult rv = GetMessageServiceFromURI(aURI, getter_AddRefs(messageService));
PRBool canonicalLineEnding = PR_FALSE; if (NS_FAILED(rv))
PRInt16 saveAsFileType = 0; // 0 - raw, 1 = html, 2 = text; goto done;
if (aAsFile)
{
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1", &rv);
if (NS_FAILED(rv))
goto done;
nsCOMPtr<nsIStreamConverterService> streamConverterService = do_GetService(kIStreamConverterServiceCID, &rv); filePicker->Init(nsnull, GetString(NS_LITERAL_STRING("SaveMailAs").get()), nsIFilePicker::modeSave);
if (NS_FAILED(rv)) goto done;
if (!url) { filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName").get()));
rv = NS_ERROR_NULL_POINTER;
goto done; // because we will be using GetFilterIndex()
// we must call AppendFilters() one at a time,
// in MESSENGER_SAVEAS_FILE_TYPE order
filePicker->AppendFilter(GetString(NS_LITERAL_STRING("EMLFiles").get()),
NS_LITERAL_STRING("*.eml").get());
filePicker->AppendFilters(nsIFilePicker::filterHTML);
filePicker->AppendFilters(nsIFilePicker::filterText);
filePicker->AppendFilters(nsIFilePicker::filterAll);
PRInt16 dialogResult;
nsCOMPtr <nsILocalFile> lastSaveDir;
rv = GetLastSaveDirectory(getter_AddRefs(lastSaveDir));
if (NS_SUCCEEDED(rv) && lastSaveDir)
{
filePicker->SetDisplayDirectory(lastSaveDir);
} }
rv = GetMessageServiceFromURI(url, getter_AddRefs(messageService)); rv = filePicker->Show(&dialogResult);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv) || dialogResult == nsIFilePicker::returnCancel)
goto done;
if (asFile) {
nsCOMPtr<nsILocalFile> localFile;
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1", &rv); rv = filePicker->GetFile(getter_AddRefs(localFile));
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv))
goto done;
filePicker->Init(nsnull, GetString(NS_LITERAL_STRING("SaveMailAs").get()), nsIFilePicker::modeSave);
rv = SetLastSaveDirectory(localFile);
filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName").get())); if (NS_FAILED(rv))
filePicker->AppendFilter(GetString(NS_LITERAL_STRING("EMLFiles").get()), goto done;
NS_LITERAL_STRING("*.eml").get());
filePicker->AppendFilters(nsIFilePicker::filterHTML | nsIFilePicker::filterText | nsIFilePicker::filterAll); PRInt32 filterIndex;
rv = filePicker->GetFilterIndex(&filterIndex);
PRInt16 dialogResult; if (NS_FAILED(rv))
goto done;
nsCOMPtr <nsILocalFile> lastSaveDir;
rv = GetLastSaveDirectory(getter_AddRefs(lastSaveDir)); // let filterIndex determine the saveAsFileType
if (NS_SUCCEEDED(rv) && lastSaveDir) { // unless the users chose "nsIFilePicker::filterAll", in which case
filePicker->SetDisplayDirectory(lastSaveDir); // try to determine the type from the filename extension
} // see bug #96134 for details
if (filterIndex == ANY_FILE_TYPE)
rv = filePicker->Show(&dialogResult); {
if (NS_FAILED(rv) || dialogResult == nsIFilePicker::returnCancel) nsAutoString fileName;
goto done; rv = localFile->GetLeafName(fileName);
if (NS_FAILED(rv))
nsCOMPtr<nsILocalFile> localFile; goto done;
rv = filePicker->GetFile(getter_AddRefs(localFile));
if (NS_FAILED(rv)) goto done; // First, check if they put ANY extension on the file, if not,
// then we should look at the type of file they have chosen and
rv = SetLastSaveDirectory(localFile); // tack on the file extension for them.
if (NS_FAILED(rv)) if (fileName.RFind(".", PR_TRUE) != kNotFound)
goto done; {
if (fileName.RFind(".htm", PR_TRUE) != kNotFound)
nsAutoString fileName; saveAsFileType = HTML_FILE_TYPE;
rv = localFile->GetLeafName(fileName); else if (fileName.RFind(".txt", PR_TRUE) != kNotFound)
if (NS_FAILED(rv)) goto done; saveAsFileType = TEXT_FILE_TYPE;
else
// First, check if they put ANY extension on the file, if not, saveAsFileType = EML_FILE_TYPE;
// then we should look at the type of file they have chosen and }
// tack on the file extension for them. else
// {
if (fileName.RFind(".", PR_TRUE) != -1) saveAsFileType = EML_FILE_TYPE;
{ }
if (fileName.RFind(".htm", PR_TRUE) != -1) }
saveAsFileType = 1; else
else if (fileName.RFind(".txt", PR_TRUE) != -1) {
saveAsFileType = 2; saveAsFileType = filterIndex;
else }
saveAsFileType = 0; // .eml type
} else { // XXX argh! converting from nsILocalFile to nsFileSpec ... oh baby, lets drop from unicode to ascii too
saveAsFileType = 0; // .eml type // nsXPIDLString path;
} // localFile->GetUnicodePath(getter_Copies(path));
nsCOMPtr<nsIFileSpec> fileSpec;
rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(fileSpec));
// XXX argh! converting from nsILocalFile to nsFileSpec ... oh baby, lets drop from unicode to ascii too if (NS_FAILED(rv))
// nsXPIDLString path; goto done;
// localFile->GetUnicodePath(getter_Copies(path));
nsCOMPtr<nsIFileSpec> fileSpec; // XXX todo
rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(fileSpec)); // document the ownership model of saveListener
if (NS_FAILED(rv)) goto done; saveListener = new nsSaveMsgListener(fileSpec, this);
if (!saveListener) {
// XXX todo rv = NS_ERROR_OUT_OF_MEMORY;
// document the ownership model of saveListener goto done;
saveListener = new nsSaveMsgListener(fileSpec, this); }
if (!saveListener) { NS_ADDREF(saveListener);
rv = NS_ERROR_OUT_OF_MEMORY;
goto done; rv = saveListener->QueryInterface(NS_GET_IID(nsIUrlListener), getter_AddRefs(urlListener));
} if (NS_FAILED(rv))
NS_ADDREF(saveListener); goto done;
rv = saveListener->QueryInterface(NS_GET_IID(nsIUrlListener), if (saveAsFileType == EML_FILE_TYPE)
getter_AddRefs(urlListener)); {
if (NS_FAILED(rv)) goto done; rv = messageService->SaveMessageToDisk(aURI, fileSpec, PR_FALSE,
urlListener, nsnull,
switch (saveAsFileType) { PR_FALSE, mMsgWindow);
case 0:
default:
rv = messageService->SaveMessageToDisk(url, fileSpec, PR_FALSE,
urlListener, nsnull,
PR_FALSE, mMsgWindow);
break;
case 1:
case 2:
urlString.AssignWithConversion(url);
// Setup the URL for a "Save As..." Operation...
// For now, if this is a save as TEXT operation, then do
// a "printing" operation
//
if (saveAsFileType == 1)
urlString.Append(NS_LITERAL_STRING("?header=saveas").get());
else
urlString.Append(NS_LITERAL_STRING("?header=print").get());
urlCString = ToNewCString(urlString);
rv = CreateStartupUrl(urlCString, getter_AddRefs(aURL));
nsCRT::free(urlCString);
if (NS_FAILED(rv)) goto done;
saveListener->m_channel = nsnull;
rv = NS_NewInputStreamChannel(getter_AddRefs(saveListener->m_channel),
aURL,
nsnull, // inputStream
NS_LITERAL_CSTRING(""), // contentType
NS_LITERAL_CSTRING("")); // contentCharset
if (NS_FAILED(rv)) goto done;
saveListener->m_outputFormat.AssignWithConversion(saveAsFileType == 1 ? TEXT_HTML : TEXT_PLAIN);
// Mark the fact that we need to do charset handling/text conversion!
if (saveListener->m_outputFormat.EqualsWithConversion(TEXT_PLAIN))
saveListener->m_doCharsetConversion = PR_TRUE;
channelSupport = do_QueryInterface(saveListener->m_channel);
rv = streamConverterService->AsyncConvertData(NS_ConvertASCIItoUCS2(MESSAGE_RFC822).get(),
// RICHIE - we should be able to go RFC822 to TXT, but not until
// Bug #1775 is fixed. saveListener->m_outputFormat.get()
NS_ConvertASCIItoUCS2(TEXT_HTML).get(),
saveListener,
channelSupport,
getter_AddRefs(convertedListener));
if (NS_FAILED(rv)) goto done;
rv = messageService->DisplayMessage(url, convertedListener,mMsgWindow,
nsnull, nsnull, nsnull);
break;
}
} }
else else
{ {
// ** save as Template nsCAutoString urlString(aURI);
nsCOMPtr<nsIFileSpec> fileSpec;
nsFileSpec tmpFileSpec("nsmail.tmp"); // we can't go RFC822 to TXT until bug #1775 is fixed
rv = NS_NewFileSpecWithSpec(tmpFileSpec, getter_AddRefs(fileSpec)); // so until then, do the HTML to TXT conversion in
if (NS_FAILED(rv)) goto done; // nsSaveMsgListener::OnStopRequest(), see ConvertBufToPlainText()
//
// XXX todo // Setup the URL for a "Save As..." Operation...
// document the ownership model of saveListener // For now, if this is a save as TEXT operation, then do
saveListener = new nsSaveMsgListener(fileSpec, this); // a "printing" operation
if (!saveListener) { if (saveAsFileType == TEXT_FILE_TYPE)
rv = NS_ERROR_OUT_OF_MEMORY; {
goto done; saveListener->m_outputFormat = NS_LITERAL_STRING(TEXT_PLAIN);
} saveListener->m_doCharsetConversion = PR_TRUE;
NS_ADDREF(saveListener); urlString += NS_LITERAL_CSTRING("?header=print");
}
if (identity) else
rv = identity->GetStationeryFolder(getter_Copies(saveListener->m_templateUri)); {
if (NS_FAILED(rv)) goto done; saveListener->m_outputFormat = NS_LITERAL_STRING(TEXT_HTML);
saveListener->m_doCharsetConversion = PR_FALSE;
needDummyHeader = urlString += NS_LITERAL_CSTRING("?header=saveas");
PL_strcasestr(saveListener->m_templateUri, "mailbox://") }
!= nsnull;
canonicalLineEnding = rv = CreateStartupUrl(urlString.get(), getter_AddRefs(url));
PL_strcasestr(saveListener->m_templateUri, "imap://") NS_ASSERTION(NS_SUCCEEDED(rv), "CreateStartupUrl failed");
!= nsnull; if (NS_FAILED(rv))
rv = saveListener->QueryInterface( goto done;
NS_GET_IID(nsIUrlListener),
getter_AddRefs(urlListener)); saveListener->m_channel = nsnull;
if (NS_FAILED(rv)) goto done; rv = NS_NewInputStreamChannel(getter_AddRefs(saveListener->m_channel),
url,
rv = messageService->SaveMessageToDisk(url, fileSpec, nsnull, // inputStream
needDummyHeader, NS_LITERAL_CSTRING(""), // contentType
urlListener, nsnull, NS_LITERAL_CSTRING("")); // contentCharset
canonicalLineEnding, mMsgWindow); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewInputStreamChannel failed");
if (NS_FAILED(rv))
goto done;
nsCOMPtr<nsIStreamConverterService> streamConverterService = do_GetService("@mozilla.org/streamConverters;1");
nsCOMPtr<nsISupports> channelSupport = do_QueryInterface(saveListener->m_channel);
// we can't go RFC822 to TXT until bug #1775 is fixed
// so until then, do the HTML to TXT conversion in
// nsSaveMsgListener::OnStopRequest(), see ConvertBufToPlainText()
rv = streamConverterService->AsyncConvertData(NS_LITERAL_STRING(MESSAGE_RFC822).get(),
NS_LITERAL_STRING(TEXT_HTML).get(),
saveListener,
channelSupport,
getter_AddRefs(convertedListener));
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncConvertData failed");
if (NS_FAILED(rv))
goto done;
rv = messageService->DisplayMessage(urlString.get(), convertedListener, mMsgWindow,
nsnull, nsnull, nsnull);
} }
}
else
{
// ** save as Template
nsCOMPtr<nsIFileSpec> fileSpec;
nsFileSpec tmpFileSpec("nsmail.tmp");
rv = NS_NewFileSpecWithSpec(tmpFileSpec, getter_AddRefs(fileSpec));
if (NS_FAILED(rv)) goto done;
// XXX todo
// document the ownership model of saveListener
saveListener = new nsSaveMsgListener(fileSpec, this);
if (!saveListener) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
NS_ADDREF(saveListener);
if (aIdentity)
rv = aIdentity->GetStationeryFolder(getter_Copies(saveListener->m_templateUri));
if (NS_FAILED(rv))
goto done;
PRBool needDummyHeader =
PL_strcasestr(saveListener->m_templateUri, "mailbox://")
!= nsnull;
PRBool canonicalLineEnding =
PL_strcasestr(saveListener->m_templateUri, "imap://")
!= nsnull;
rv = saveListener->QueryInterface(
NS_GET_IID(nsIUrlListener),
getter_AddRefs(urlListener));
if (NS_FAILED(rv))
goto done;
rv = messageService->SaveMessageToDisk(aURI, fileSpec,
needDummyHeader,
urlListener, nsnull,
canonicalLineEnding, mMsgWindow);
}
done: done:
if (NS_FAILED(rv)) { if (NS_FAILED(rv))
// XXX todo {
// document the ownership model of saveListener // XXX todo
NS_IF_RELEASE(saveListener); // document the ownership model of saveListener
Alert("saveMessageFailed"); NS_IF_RELEASE(saveListener);
} Alert("saveMessageFailed");
return rv; }
return rv;
} }
nsresult nsresult
@ -1533,51 +1560,6 @@ nsMessenger::SendUnsentMessages(nsIMsgIdentity *aIdentity, nsIMsgWindow *aMsgWin
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsMessenger::DoPrint()
{
#ifdef DEBUG_MESSENGER
printf("nsMessenger::DoPrint()\n");
#endif
nsresult rv = NS_ERROR_FAILURE;
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIContentViewer> viewer;
mDocShell->GetContentViewer(getter_AddRefs(viewer));
if (viewer)
{
nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint = do_QueryInterface(viewer);
if (webBrowserPrint) {
nsCOMPtr<nsIPrintSettings> printSettings;
webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings));
rv = webBrowserPrint->Print(printSettings, (nsIWebProgressListener*)nsnull);
}
#ifdef DEBUG_MESSENGER
else {
printf("the content viewer does not support printing\n");
}
#endif
}
#ifdef DEBUG_MESSENGER
else {
printf("failed to get the viewer for printing\n");
}
#endif
return rv;
}
NS_IMETHODIMP nsMessenger::DoPrintPreview()
{
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
#ifdef DEBUG_MESSENGER
printf("nsMessenger::DoPrintPreview() not implemented yet\n");
#endif
return rv;
}
nsSaveMsgListener::nsSaveMsgListener(nsIFileSpec* aSpec, nsMessenger *aMessenger) nsSaveMsgListener::nsSaveMsgListener(nsIFileSpec* aSpec, nsMessenger *aMessenger)
{ {
if (aSpec) if (aSpec)

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

@ -115,7 +115,7 @@ nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr)
return msgMessageService->MessageURIToMsgHdr(uri, msgHdr); return msgMessageService->MessageURIToMsgHdr(uri, msgHdr);
} }
nsresult CreateStartupUrl(char *uri, nsIURI** aUrl) nsresult CreateStartupUrl(const char *uri, nsIURI** aUrl)
{ {
nsresult rv = NS_ERROR_NULL_POINTER; nsresult rv = NS_ERROR_NULL_POINTER;
if (!uri || !*uri || !aUrl) return rv; if (!uri || !*uri || !aUrl) return rv;

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

@ -54,7 +54,7 @@ NS_MSG_BASE nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageServ
NS_MSG_BASE nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr); NS_MSG_BASE nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr);
NS_MSG_BASE nsresult CreateStartupUrl(char *uri, nsIURI** aUrl); NS_MSG_BASE nsresult CreateStartupUrl(const char *uri, nsIURI** aUrl);
NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriorityValue *outPriority); NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriorityValue *outPriority);