Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1

This commit is contained in:
Matt A. Tobin 2019-11-03 00:17:46 -04:00 • committed by Roy Tam
commit e400f4130a
1564 changed files with 510348 additions and 0 deletions

View file

@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WMDebugLog_h___
#define WMDebugLog_h___
// Use PR_LOG for logging.
#include "mozilla/Logging.h"
extern PRLogModuleInfo *WMLOGMODULE; // Logging module
#define IMPORT_LOG0(x) MOZ_LOG(WMLOGMODULE, mozilla::LogLevel::Debug, (x))
#define IMPORT_LOG1(x, y) MOZ_LOG(WMLOGMODULE, mozilla::LogLevel::Debug, (x, y))
#define IMPORT_LOG2(x, y, z) MOZ_LOG(WMLOGMODULE, mozilla::LogLevel::Debug, (x, y, z))
#define IMPORT_LOG3(a, b, c, d) MOZ_LOG(WMLOGMODULE, mozilla::LogLevel::Debug, (a, b, c, d))
#endif /* WMDebugLog_h___ */

View file

@ -0,0 +1,14 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
SOURCES += [
'nsWMImport.cpp',
'nsWMSettings.cpp',
'nsWMStringBundle.cpp',
'nsWMUtils.cpp',
]
FINAL_LIBRARY = 'import'

View file

@ -0,0 +1,248 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
Windows Live Mail (Win32) import mail and addressbook interfaces
*/
#include "nscore.h"
#include "nsStringGlue.h"
#include "nsMsgUtils.h"
#include "nsIServiceManager.h"
#include "nsIImportService.h"
#include "nsWMImport.h"
#include "nsIMemory.h"
#include "nsIImportService.h"
#include "nsIImportMail.h"
#include "nsIImportMailboxDescriptor.h"
#include "nsIImportGeneric.h"
#include "nsIImportAddressBooks.h"
#include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIOutputStream.h"
#include "nsIAddrDatabase.h"
#include "nsWMSettings.h"
#include "nsTextFormatter.h"
#include "nsWMStringBundle.h"
#include "nsIStringBundle.h"
#include "nsUnicharUtils.h"
#include "WMDebugLog.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
PRLogModuleInfo *WMLOGMODULE = nullptr;
class ImportWMMailImpl : public nsIImportMail
{
public:
ImportWMMailImpl();
static nsresult Create(nsIImportMail** aImport);
// nsISupports interface
NS_DECL_THREADSAFE_ISUPPORTS
// nsIImportmail interface
/* void GetDefaultLocation (out nsIFile location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found, bool *userVerify);
/* nsIArray FindMailboxes (in nsIFile location); */
NS_IMETHOD FindMailboxes(nsIFile *location, nsIArray **_retval);
NS_IMETHOD ImportMailbox(nsIImportMailboxDescriptor *source,
nsIMsgFolder *dstFolder,
char16_t **pErrorLog, char16_t **pSuccessLog,
bool *fatalError);
/* unsigned long GetImportProgress (); */
NS_IMETHOD GetImportProgress(uint32_t *_retval);
NS_IMETHOD TranslateFolderName(const nsAString & aFolderName, nsAString & _retval);
public:
static void ReportSuccess(nsString& name, int32_t count, nsString *pStream);
static void ReportError(int32_t errorNum, nsString& name, nsString *pStream);
static void AddLinebreak(nsString *pStream);
static void SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess);
private:
virtual ~ImportWMMailImpl();
uint32_t m_bytesDone;
};
nsWMImport::nsWMImport()
{
// Init logging module.
if (!WMLOGMODULE)
WMLOGMODULE = PR_NewLogModule("IMPORT");
IMPORT_LOG0("nsWMImport Module Created\n");
nsWMStringBundle::GetStringBundle();
}
nsWMImport::~nsWMImport()
{
IMPORT_LOG0("nsWMImport Module Deleted\n");
}
NS_IMPL_ISUPPORTS(nsWMImport, nsIImportModule)
NS_IMETHODIMP nsWMImport::GetName(char16_t **name)
{
NS_ENSURE_ARG_POINTER(name);
// nsString title = "Windows Live Mail";
// *name = ToNewUnicode(title);
*name = nsWMStringBundle::GetStringByID(WMIMPORT_NAME);
return NS_OK;
}
NS_IMETHODIMP nsWMImport::GetDescription(char16_t **name)
{
NS_ENSURE_ARG_POINTER(name);
// nsString desc = "Windows Live Mail mail and address books";
// *name = ToNewUnicode(desc);
*name = nsWMStringBundle::GetStringByID(WMIMPORT_DESCRIPTION);
return NS_OK;
}
NS_IMETHODIMP nsWMImport::GetSupports(char **supports)
{
NS_PRECONDITION(supports != nullptr, "null ptr");
if (! supports)
return NS_ERROR_NULL_POINTER;
*supports = strdup(kWMSupportsString);
return NS_OK;
}
NS_IMETHODIMP nsWMImport::GetSupportsUpgrade(bool *pUpgrade)
{
NS_PRECONDITION(pUpgrade != nullptr, "null ptr");
if (! pUpgrade)
return NS_ERROR_NULL_POINTER;
*pUpgrade = true;
return NS_OK;
}
NS_IMETHODIMP nsWMImport::GetImportInterface(const char *pImportType,
nsISupports **ppInterface)
{
NS_ENSURE_ARG_POINTER(pImportType);
NS_ENSURE_ARG_POINTER(ppInterface);
*ppInterface = nullptr;
nsresult rv;
if (!strcmp(pImportType, "settings")) {
nsIImportSettings *pSettings = nullptr;
rv = nsWMSettings::Create(&pSettings);
if (NS_SUCCEEDED(rv)) {
pSettings->QueryInterface(kISupportsIID, (void **)ppInterface);
}
NS_IF_RELEASE(pSettings);
return rv;
}
return NS_ERROR_NOT_AVAILABLE;
}
/////////////////////////////////////////////////////////////////////////////////
nsresult ImportWMMailImpl::Create(nsIImportMail** aImport)
{
NS_ENSURE_ARG_POINTER(aImport);
*aImport = new ImportWMMailImpl();
NS_ENSURE_TRUE(*aImport, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aImport);
return NS_OK;
}
ImportWMMailImpl::ImportWMMailImpl()
{
}
ImportWMMailImpl::~ImportWMMailImpl()
{
}
NS_IMPL_ISUPPORTS(ImportWMMailImpl, nsIImportMail)
NS_IMETHODIMP ImportWMMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP ImportWMMailImpl::GetDefaultLocation(nsIFile **ppLoc, bool *found,
bool *userVerify)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP ImportWMMailImpl::FindMailboxes(nsIFile *pLoc,
nsIArray **ppArray)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void ImportWMMailImpl::AddLinebreak(nsString *pStream)
{
if (pStream)
pStream->Append(char16_t('\n'));
}
void ImportWMMailImpl::ReportSuccess(nsString& name, int32_t count, nsString *pStream)
{
if (!pStream)
return;
// load the success string
char16_t *pFmt = nsWMStringBundle::GetStringByID(WMIMPORT_MAILBOX_SUCCESS);
char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get(), count);
pStream->Append(pText);
nsTextFormatter::smprintf_free(pText);
nsWMStringBundle::FreeString(pFmt);
AddLinebreak(pStream);
}
void ImportWMMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *pStream)
{
if (!pStream)
return;
// load the error string
char16_t *pFmt = nsWMStringBundle::GetStringByID(errorNum);
char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
pStream->Append(pText);
nsTextFormatter::smprintf_free(pText);
nsWMStringBundle::FreeString(pFmt);
AddLinebreak(pStream);
}
void ImportWMMailImpl::SetLogs(nsString& success, nsString& error,
char16_t **pError, char16_t **pSuccess)
{
if (pError)
*pError = ToNewUnicode(error);
if (pSuccess)
*pSuccess = ToNewUnicode(success);
}
NS_IMETHODIMP ImportWMMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
nsIMsgFolder *pDstFolder,
char16_t **pErrorLog,
char16_t **pSuccessLog,
bool *fatalError)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP ImportWMMailImpl::GetImportProgress(uint32_t *pDoneSoFar)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View file

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsWMImport_h___
#define nsWMImport_h___
#include "nsIImportModule.h"
#include "nsCOMPtr.h"
#define NS_WMIMPORT_CID \
{ /* 42bc82bc-8e9f-4597-8b6e-e529daaf3af1 */ \
0x42bc82bc, 0x8e9f, 0x4597, \
{0x8b, 0x6e, 0xe5, 0x29, 0xda, 0xaf, 0x3a, 0xf1}}
// currently only support setting import
#define kWMSupportsString NS_IMPORT_SETTINGS_STR
class nsWMImport : public nsIImportModule
{
public:
nsWMImport();
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////////////////
// we suppport the nsIImportModule interface
////////////////////////////////////////////////////////////////////////////////////////
NS_DECL_NSIIMPORTMODULE
protected:
virtual ~nsWMImport();
};
#endif /* nsWMImport_h___ */

View file

@ -0,0 +1,758 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
Windows Live Mail (Win32) settings
*/
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsStringGlue.h"
#include "nsMsgUtils.h"
#include "nsWMImport.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgAccount.h"
#include "nsIImportSettings.h"
#include "nsWMSettings.h"
#include "nsMsgBaseCID.h"
#include "nsMsgCompCID.h"
#include "nsMsgI18N.h"
#include "nsISmtpService.h"
#include "nsISmtpServer.h"
#include "nsWMStringBundle.h"
#include "WMDebugLog.h"
#include "nsIPop3IncomingServer.h"
#include "nsIImapIncomingServer.h"
#include "nsINntpIncomingServer.h"
#include "stdlib.h"
#include "nsIFile.h"
#include "nsISimpleEnumerator.h"
#include "nsIMutableArray.h"
#include "nsIDOMDocument.h"
#include "nsNetUtil.h"
#include "nsIDOMNodeList.h"
#include "nsIFileStreams.h"
#include "nsIDOMParser.h"
#include "nsIDOMElement.h"
#include "nsTArray.h"
#include <windows.h>
#include "nsIWindowsRegKey.h"
#include "nsCOMArray.h"
#include "nsWMUtils.h"
class WMSettings {
public:
static bool DoImport(nsIMsgAccount **ppAccount);
static bool DoIMAPServer(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount);
static bool DoPOP3Server(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount);
static bool DoNNTPServer(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount);
static void SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
nsIDOMDocument *xmlDoc, nsAutoString &userName,
int32_t authMethodIncoming, bool isNNTP);
static void SetSmtpServer(nsIDOMDocument *xmlDoc, nsIMsgIdentity *id,
nsAutoString& inUserName, int32_t authMethodIncoming);
};
static int32_t checkNewMailTime;// WM global setting, let's default to 30
static bool checkNewMail; // WM global setting, let's default to false
// This won't cause unwanted autodownloads-
// user can set prefs after import
////////////////////////////////////////////////////////////////////////
nsresult nsWMSettings::Create(nsIImportSettings** aImport)
{
NS_PRECONDITION(aImport != nullptr, "null ptr");
if (! aImport)
return NS_ERROR_NULL_POINTER;
*aImport = new nsWMSettings();
if (! *aImport)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aImport);
return NS_OK;
}
nsWMSettings::nsWMSettings()
{
}
nsWMSettings::~nsWMSettings()
{
}
NS_IMPL_ISUPPORTS(nsWMSettings, nsIImportSettings)
NS_IMETHODIMP nsWMSettings::AutoLocate(char16_t **description,
nsIFile **location, bool *_retval)
{
NS_PRECONDITION(description != nullptr, "null ptr");
NS_PRECONDITION(_retval != nullptr, "null ptr");
if (!description || !_retval)
return NS_ERROR_NULL_POINTER;
*description = nsWMStringBundle::GetStringByID(WMIMPORT_NAME);
*_retval = false;
if (location)
*location = nullptr;
nsCOMPtr<nsIWindowsRegKey> key;
if (NS_SUCCEEDED(nsWMUtils::FindWMKey(getter_AddRefs(key))))
*_retval = true;
return NS_OK;
}
NS_IMETHODIMP nsWMSettings::SetLocation(nsIFile *location)
{
return NS_OK;
}
NS_IMETHODIMP nsWMSettings::Import(nsIMsgAccount **localMailAccount,
bool *_retval)
{
NS_PRECONDITION(_retval != nullptr, "null ptr");
if (WMSettings::DoImport(localMailAccount)) {
*_retval = true;
IMPORT_LOG0("Settings import appears successful\n");
}
else {
*_retval = false;
IMPORT_LOG0("Settings import returned FALSE\n");
}
return NS_OK;
}
bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
{
// do the windows registry stuff first
nsCOMPtr<nsIWindowsRegKey> key;
if (NS_FAILED(nsWMUtils::FindWMKey(getter_AddRefs(key)))) {
IMPORT_LOG0("*** Error finding Windows Live Mail registry account keys\n");
return false;
}
// 'poll for messages' setting in WM is a global setting-Like OE
// for all accounts dword ==0xffffffff for don't poll else 1/60000 = minutes
checkNewMailTime = 30;
checkNewMail = false;
nsresult rv;
nsCOMPtr<nsIWindowsRegKey> subKey;
if (NS_SUCCEEDED(key->OpenChild(NS_LITERAL_STRING("mail"),
nsIWindowsRegKey::ACCESS_QUERY_VALUE,
getter_AddRefs(subKey)))) {
uint32_t dwordResult = -1;
rv = subKey->ReadIntValue(NS_LITERAL_STRING("Poll For Mail"), &dwordResult); // reg_dword
subKey->Close();
if (NS_SUCCEEDED(rv) && dwordResult != -1){
checkNewMail = true;
checkNewMailTime = dwordResult / 60000;
}
}
// these are in main windowsmail key and if they don't exist-not to worry
// (less than 64 chars) e.g. account{4A18B81E-83CA-472A-8D7F-5301C0B97B8D}.oeaccount
nsAutoString defMailAcct, defNewsAcct;
key->ReadStringValue(NS_LITERAL_STRING("Default Mail Account"), defMailAcct); // ref_sz
key->ReadStringValue(NS_LITERAL_STRING("Default News Account"), defNewsAcct); // ref_sz
nsCOMPtr<nsIMsgAccountManager> accMgr =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Failed to create an account manager!\n");
return false;
}
nsCOMArray<nsIFile> fileArray;
if (NS_FAILED(nsWMUtils::GetOEAccountFiles(fileArray))) {
IMPORT_LOG0("*** Failed to get .oeaccount file!\n");
return false;
}
// Loop through *.oeaccounts files looking for POP3 & IMAP & NNTP accounts
// Ignore LDAP for now!
int accounts = 0;
nsCOMPtr<nsIDOMDocument> xmlDoc;
for (int32_t i = fileArray.Count() - 1 ; i >= 0; i--){
nsWMUtils::MakeXMLdoc(getter_AddRefs(xmlDoc), fileArray[i]);
nsAutoCString name;
fileArray[i]->GetNativeLeafName(name);
nsAutoString value;
nsCOMPtr<nsIMsgAccount> anAccount;
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_Server",
value)))
if (DoIMAPServer(accMgr, xmlDoc, value, getter_AddRefs(anAccount)))
accounts++;
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"NNTP_Server",
value)))
if (DoNNTPServer(accMgr, xmlDoc, value, getter_AddRefs(anAccount)))
accounts++;
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_Server",
value)))
if (DoPOP3Server(accMgr, xmlDoc, value, getter_AddRefs(anAccount)))
accounts++;
if (anAccount) {
nsString name;
// Is this the default account?
fileArray[i]->GetLeafName(name);
if (defMailAcct.Equals(name))
accMgr->SetDefaultAccount(anAccount);
}
}
// Now save the new acct info to pref file.
rv = accMgr->SaveAccountInfo();
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file");
return accounts != 0;
}
bool WMSettings::DoIMAPServer(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount)
{
int32_t authMethod; // Secure Password Authentication (SPA)
nsresult errorCode;
if (ppAccount)
*ppAccount = nullptr;
nsAutoString userName, value;
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_User_Name",
userName)))
return false;
bool result = false;
// I now have a user name/server name pair, find out if it already exists?
nsCOMPtr<nsIMsgIncomingServer> in;
nsresult rv = pMgr->FindServer(NS_ConvertUTF16toUTF8(userName),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("imap"),
getter_AddRefs(in));
if (NS_FAILED(rv) || (in == nullptr)) {
// Create the incoming server and an account for it?
rv = pMgr->CreateIncomingServer(NS_ConvertUTF16toUTF8(userName),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("imap"),
getter_AddRefs(in));
if (NS_SUCCEEDED(rv) && in) {
nsCOMPtr<nsIImapIncomingServer> imapServer = do_QueryInterface(in);
if (!imapServer){
IMPORT_LOG1("*** Failed to create nsIImapIncomingServer for %S!\n",
serverName.get());
return false;
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_Root_Folder",
value))) {
imapServer->SetServerDirectory(NS_ConvertUTF16toUTF8(value));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_Secure_Connection",
value))) {
if (value.ToInteger(&errorCode, 16))
in->SetSocketType(nsMsgSocketType::SSL);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_Use_Sicily",
value))) {
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
authMethod = secAuth ? nsMsgAuthMethod::secure :
nsMsgAuthMethod::passwordCleartext;
in->SetAuthMethod(authMethod);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"IMAP_Port",
value))) {
in->SetPort(value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Account_Name",
value))) {
rv = in->SetPrettyName(value);
}
in->SetDoBiff(checkNewMail);
in->SetBiffMinutes(checkNewMailTime);
IMPORT_LOG2("Created IMAP server named: %S, userName: %S\n",
serverName.get(), userName.get());
// We have a server, create an account.
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->CreateAccount(getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
rv = account->SetIncomingServer(in);
IMPORT_LOG0("Created an account and set the IMAP server "
"as the incoming server\n");
// Fiddle with the identities
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, false);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
}
else if (NS_SUCCEEDED(rv) && in) {
// for an existing server we create another identity,
// TB lists under 'manage identities'
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->FindAccountForServer(in, getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
IMPORT_LOG0("Created an identity and added to existing "
"IMAP incoming server\n");
// Fiddle with the identities
in->GetAuthMethod(&authMethod);
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, false);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
else
result = true;
return result;
}
bool WMSettings::DoPOP3Server(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount)
{
int32_t authMethod; // Secure Password Authentication (SPA)
nsresult errorCode;
if (ppAccount)
*ppAccount = nullptr;
nsAutoString userName, value;
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_User_Name",
userName)))
return false;
bool result = false;
// I now have a user name/server name pair, find out if it already exists?
nsCOMPtr<nsIMsgIncomingServer> in;
nsresult rv = pMgr->FindServer(NS_ConvertUTF16toUTF8(userName),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("pop3"),
getter_AddRefs(in));
if (NS_FAILED(rv) || (in == nullptr)) {
// Create the incoming server and an account for it?
rv = pMgr->CreateIncomingServer(NS_ConvertUTF16toUTF8(userName),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("pop3"),
getter_AddRefs(in));
if (NS_SUCCEEDED(rv) && in) {
nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in);
if (!pop3Server){
IMPORT_LOG1("*** Failed to create nsIPop3IncomingServer for %S!\n",
serverName.get());
return false;
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_Secure_Connection",
value)) &&
value.ToInteger(&errorCode, 16)) {
in->SetSocketType(nsMsgSocketType::SSL);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_Use_Sicily",
value))) {
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
authMethod = secAuth ? nsMsgAuthMethod::secure :
nsMsgAuthMethod::passwordCleartext;
in->SetAuthMethod(authMethod);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_Port",
value))) {
in->SetPort(value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"POP3_Skip_Account",
value))) {
if (!value.IsEmpty())
// OE:0=='Include this account when receiving mail or synchronizing'==
// TB:1==ActMgr:Server:advanced:Include this server when getting new mail
pop3Server->SetDeferGetNewMail(value.ToInteger(&errorCode, 16) == 0);
else
pop3Server->SetDeferGetNewMail(false);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Leave_Mail_On_Server",
value))) {
pop3Server->SetLeaveMessagesOnServer((bool)value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Remove_When_Deleted",
value))) {
pop3Server->SetDeleteMailLeftOnServer((bool)value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Remove_When_Expired",
value))) {
pop3Server->SetDeleteByAgeFromServer((bool)value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Expire_Days",
value))) {
pop3Server->SetNumDaysToLeaveOnServer(value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Account_Name",
value))) {
rv = in->SetPrettyName(value);
}
in->SetDoBiff(checkNewMail);
in->SetBiffMinutes(checkNewMailTime);
// set local folders as the Inbox to use for this POP3 server
nsCOMPtr<nsIMsgIncomingServer> localFoldersServer;
pMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));
if (!localFoldersServer) {
// XXX: We may need to move this local folder creation
// code to the generic nsImportSettings code
// if the other import modules end up needing to do this too.
// if Local Folders does not exist already, create it
rv = pMgr->CreateLocalMailAccount();
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Failed to create Local Folders!\n");
return false;
}
pMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));
}
// now get the account for this server
nsCOMPtr<nsIMsgAccount> localFoldersAccount;
pMgr->FindAccountForServer(localFoldersServer,
getter_AddRefs(localFoldersAccount));
if (localFoldersAccount) {
nsCString localFoldersAcctKey;
localFoldersAccount->GetKey(localFoldersAcctKey);
pop3Server->SetDeferredToAccount(localFoldersAcctKey);
}
IMPORT_LOG2("Created POP3 server named: %S, userName: %S\n",
serverName.get(), userName.get());
// We have a server, create an account.
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->CreateAccount(getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
rv = account->SetIncomingServer(in);
IMPORT_LOG0("Created a new account and set the incoming "
"server to the POP3 server.\n");
// Fiddle with the identities
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, false);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
}
else if (NS_SUCCEEDED(rv) && in) {
IMPORT_LOG2("Existing POP3 server named: %S, userName: %S\n",
serverName.get(), userName.get());
// for an existing server we create another identity,
// TB listed under 'manage identities'
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->FindAccountForServer(in, getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
IMPORT_LOG0("Created identity and added to existing POP3 incoming server.\n");
// Fiddle with the identities
in->GetAuthMethod(&authMethod);
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, false);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
else
result = true;
return result;
}
bool WMSettings::DoNNTPServer(nsIMsgAccountManager *pMgr,
nsIDOMDocument *xmlDoc,
const nsString& serverName,
nsIMsgAccount **ppAccount)
{
int32_t authMethod;
nsresult errorCode;
if (ppAccount)
*ppAccount = nullptr;
nsAutoString userName, value;
// this only exists if NNTP server requires it or not, anonymous login
nsWMUtils::GetValueForTag(xmlDoc, "NNTP_User_Name", userName);
bool result = false;
// I now have a user name/server name pair, find out if it already exists?
// NNTP can have empty user name. This is wild card in findserver
nsCOMPtr<nsIMsgIncomingServer> in;
nsresult rv = pMgr->FindServer(EmptyCString(),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("nntp"),
getter_AddRefs(in));
if (NS_FAILED(rv) || (in == nullptr)) {
// Create the incoming server and an account for it?
rv = pMgr->CreateIncomingServer(nsDependentCString(""),
NS_ConvertUTF16toUTF8(serverName),
NS_LITERAL_CSTRING("nntp"),
getter_AddRefs(in));
if (NS_SUCCEEDED(rv) && in) {
nsCOMPtr<nsINntpIncomingServer> nntpServer = do_QueryInterface(in);
if (!nntpServer) {
IMPORT_LOG1("*** Failed to create nsINnntpIncomingServer for %S!\n",
serverName.get());
return false;
}
if (!userName.IsEmpty()) { // if username req'd then auth req'd
nntpServer->SetPushAuth(true);
in->SetUsername(NS_ConvertUTF16toUTF8(userName));
}
nsAutoString value;
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"NNTP_Port",
value))) {
in->SetPort(value.ToInteger(&errorCode, 16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"Account_Name",
value))) {
in->SetPrettyName(value);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"NNTP_Use_Sicily",
value))) {
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
authMethod = secAuth ? nsMsgAuthMethod::secure :
nsMsgAuthMethod::passwordCleartext;
in->SetAuthMethod(authMethod);
}
IMPORT_LOG2("Created NNTP server named: %S, userName: %S\n",
serverName.get(), userName.get());
// We have a server, create an account.
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->CreateAccount(getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
rv = account->SetIncomingServer(in);
IMPORT_LOG0("Created an account and set the NNTP server "
"as the incoming server\n");
// Fiddle with the identities
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, true);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
}
else if (NS_SUCCEEDED(rv) && in) {
// for the existing server...
nsCOMPtr<nsIMsgAccount> account;
rv = pMgr->FindAccountForServer(in, getter_AddRefs(account));
if (NS_SUCCEEDED(rv) && account) {
IMPORT_LOG0("Using existing account and set the "
"NNTP server as the incoming server\n");
// Fiddle with the identities
in->GetAuthMethod(&authMethod);
SetIdentities(pMgr, account, xmlDoc, userName, authMethod, true);
result = true;
if (ppAccount)
account.forget(ppAccount);
}
}
else
result = true;
return result;
}
void WMSettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
nsIDOMDocument *xmlDoc, nsAutoString &inUserName,
int32_t authMethodIncoming, bool isNNTP)
{
// Get the relevant information for an identity
nsresult rv;
nsAutoString value;
nsCOMPtr<nsIMsgIdentity> id;
rv = pMgr->CreateIdentity(getter_AddRefs(id));
if (id) {
IMPORT_LOG0("Created identity and added to the account\n");
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
isNNTP ?
"NNTP_Display_Name" :
"SMTP_Display_Name",
value))) {
id->SetFullName(value);
IMPORT_LOG1("\tname: %S\n", value.get());
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
isNNTP ?
"NNTP_Organization_Name" :
"SMTP_Organization_Name",
value))) {
id->SetOrganization(value);
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
isNNTP ?
"NNTP_Email_Address" :
"SMTP_Email_Address",
value))) {
id->SetEmail(NS_ConvertUTF16toUTF8(value));
IMPORT_LOG1("\temail: %S\n", value.get());
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
isNNTP ?
"NNTP_Reply_To_Email_Address" :
"SMTP_Reply_To_Email_Address",
value))) {
id->SetReplyTo(NS_ConvertUTF16toUTF8(value));
}
// Windows users are used to top style quoting.
id->SetReplyOnTop(isNNTP ? 0 : 1);
pAcc->AddIdentity(id);
}
if (!isNNTP) // NNTP does not use SMTP in OE or TB
SetSmtpServer(xmlDoc, id, inUserName, authMethodIncoming);
}
void WMSettings::SetSmtpServer(nsIDOMDocument *xmlDoc, nsIMsgIdentity *id,
nsAutoString& inUserName, int32_t authMethodIncoming)
{
nsresult errorCode;
// set the id.smtpserver accordingly
if (!id)
return;
nsCString smtpServerKey, userName;
nsAutoString value, smtpName;
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc, "SMTP_Server", smtpName)))
return;
// first we have to calculate the smtp user name which is based on sicily
// smtp user name depends on sicily which may or not exist
int32_t useSicily = 0;
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"SMTP_Use_Sicily",
value))) {
useSicily = (int32_t)value.ToInteger(&errorCode,16);
}
switch (useSicily) {
case 1 : case 3 :
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"SMTP_User_Name",
value))) {
CopyUTF16toUTF8(value, userName);
}
else {
CopyUTF16toUTF8(inUserName, userName);
}
break;
case 2 :
CopyUTF16toUTF8(inUserName, userName);
break;
default :
break; // initial userName == ""
}
nsresult rv;
nsCOMPtr<nsISmtpService>
smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && smtpService) {
nsCOMPtr<nsISmtpServer> extgServer;
// don't try to make another server
// regardless if username doesn't match
rv = smtpService->FindServer(userName.get(),
NS_ConvertUTF16toUTF8(smtpName).get(),
getter_AddRefs(extgServer));
if (NS_SUCCEEDED(rv) && extgServer) {
// set our account keyed to this smptserver key
extgServer->GetKey(getter_Copies(smtpServerKey));
id->SetSmtpServerKey(smtpServerKey);
IMPORT_LOG1("SMTP server already exists: %S\n", smtpName);
}
else {
nsCOMPtr<nsISmtpServer> smtpServer;
rv = smtpService->CreateServer(getter_AddRefs(smtpServer));
if (NS_SUCCEEDED(rv) && smtpServer) {
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"SMTP_Port",
value))) {
smtpServer->SetPort(value.ToInteger(&errorCode,16));
}
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
"SMTP_Secure_Connection",
value))) {
if (value.ToInteger(&errorCode, 16) == 1)
smtpServer->SetSocketType(nsMsgSocketType::SSL);
else
smtpServer->SetSocketType(nsMsgSocketType::plain);
}
smtpServer->SetUsername(userName);
switch (useSicily) {
case 1 :
smtpServer->SetAuthMethod(nsMsgAuthMethod::secure);
break;
case 2 : // requires SMTP authentication to use the incoming server settings
smtpServer->SetAuthMethod(authMethodIncoming);
break;
case 3 :
smtpServer->SetAuthMethod(nsMsgAuthMethod::passwordCleartext);
break;
default:
smtpServer->SetAuthMethod(nsMsgAuthMethod::none);
}
smtpServer->SetHostname(NS_ConvertUTF16toUTF8(smtpName));
smtpServer->GetKey(getter_Copies(smtpServerKey));
id->SetSmtpServerKey(smtpServerKey);
IMPORT_LOG1("Created new SMTP server: %S\n", smtpName);
}
}
}
}

View file

@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsWMSettings_h___
#define nsWMSettings_h___
#include "nsIImportSettings.h"
class nsWMSettings : public nsIImportSettings {
public:
nsWMSettings();
static nsresult Create(nsIImportSettings** aImport);
NS_DECL_ISUPPORTS
NS_DECL_NSIIMPORTSETTINGS
private:
virtual ~nsWMSettings();
};
#endif /* nsWMSettings_h___ */

View file

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "prprf.h"
#include "prmem.h"
#include "nsCOMPtr.h"
#include "nsMsgUtils.h"
#include "nsIStringBundle.h"
#include "nsWMStringBundle.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
#include "mozilla/Services.h"
#define WM_MSGS_URL "chrome://messenger/locale/wmImportMsgs.properties"
nsIStringBundle * nsWMStringBundle::m_pBundle = nullptr;
nsIStringBundle *nsWMStringBundle::GetStringBundle(void)
{
if (m_pBundle)
return m_pBundle;
char* propertyURL = WM_MSGS_URL;
nsIStringBundle* sBundle = nullptr;
nsCOMPtr<nsIStringBundleService> sBundleService =
mozilla::services::GetStringBundleService();
if (sBundleService) {
sBundleService->CreateBundle(propertyURL, &sBundle);
}
m_pBundle = sBundle;
return sBundle;
}
void nsWMStringBundle::GetStringByID(int32_t stringID, nsString& result)
{
char16_t *ptrv = GetStringByID(stringID);
result = ptrv;
FreeString(ptrv);
}
char16_t *nsWMStringBundle::GetStringByID(int32_t stringID)
{
if (!m_pBundle)
m_pBundle = GetStringBundle();
if (m_pBundle) {
char16_t *ptrv = nullptr;
nsresult rv = m_pBundle->GetStringFromID(stringID, &ptrv);
if (NS_SUCCEEDED(rv) && ptrv)
return ptrv;
}
nsString resultString;
resultString.AppendLiteral("[StringID ");
resultString.AppendInt(stringID);
resultString.AppendLiteral("?]");
return ToNewUnicode(resultString);
}
void nsWMStringBundle::Cleanup(void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nullptr;
}

View file

@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsWMStringBundle_H__
#define _nsWMStringBundle_H__
#include "nsStringGlue.h"
class nsIStringBundle;
class nsWMStringBundle {
public:
static char16_t * GetStringByID(int32_t stringID);
static void GetStringByID(int32_t stringID, nsString& result);
static nsIStringBundle * GetStringBundle(void); // don't release
static void FreeString(char16_t *pStr) { NS_Free(pStr);}
static void Cleanup(void);
private:
static nsIStringBundle * m_pBundle;
};
#define WMIMPORT_NAME 2000
#define WMIMPORT_DESCRIPTION 2001
#define WMIMPORT_MAILBOX_SUCCESS 2002
#define WMIMPORT_MAILBOX_BADPARAM 2003
#define WMIMPORT_MAILBOX_BADSOURCEFILE 2004
#define WMIMPORT_MAILBOX_CONVERTERROR 2005
#define WMIMPORT_DEFAULT_NAME 2006
#define WMIMPORT_AUTOFIND 2007
#define WMIMPORT_ADDRESS_SUCCESS 2008
#define WMIMPORT_ADDRESS_CONVERTERROR 2009
#define WMIMPORT_ADDRESS_BADPARAM 2010
#endif /* _nsWMStringBundle_H__ */

View file

@ -0,0 +1,164 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h"
#include "nsNetCID.h"
#include "nsStringGlue.h"
#include "nsWMUtils.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMParser.h"
#include "nsIFileStreams.h"
#include "nsIFile.h"
#include "nsISimpleEnumerator.h"
#include "WMDebugLog.h"
#include "prio.h"
nsresult
nsWMUtils::FindWMKey(nsIWindowsRegKey **aKey)
{
nsresult rv;
nsCOMPtr<nsIWindowsRegKey> key =
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = key->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
NS_LITERAL_STRING("Software\\Microsoft\\Windows Live Mail"),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv)) {
NS_ADDREF(*aKey = key);
return rv;
}
rv = key->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
NS_LITERAL_STRING("Software\\Microsoft\\Windows Mail"),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
key.forget(aKey);
return rv;
}
nsresult
nsWMUtils::GetRootFolder(nsIFile **aRootFolder)
{
nsCOMPtr<nsIWindowsRegKey> key;
if (NS_FAILED(nsWMUtils::FindWMKey(getter_AddRefs(key)))) {
IMPORT_LOG0("*** Error finding Windows Live Mail registry account keys\n");
return NS_ERROR_NOT_AVAILABLE;
}
// This is essential to proceed; it is the location on disk of xml-type account files;
// it is in reg_expand_sz so it will need expanding to absolute path.
nsString storeRoot;
nsresult rv = key->ReadStringValue(NS_LITERAL_STRING("Store Root"), storeRoot);
key->Close(); // Finished with windows registry key. We do not want to return before this closing
if (NS_FAILED(rv) || storeRoot.IsEmpty()) {
IMPORT_LOG0("*** Error finding Windows Live Mail Store Root\n");
return rv;
}
uint32_t size = ::ExpandEnvironmentStringsW((LPCWSTR)storeRoot.get(), nullptr, 0);
nsString expandedStoreRoot;
expandedStoreRoot.SetLength(size - 1);
if (expandedStoreRoot.Length() != size - 1)
return NS_ERROR_FAILURE;
::ExpandEnvironmentStringsW((LPCWSTR)storeRoot.get(),
(LPWSTR)expandedStoreRoot.BeginWriting(),
size);
storeRoot = expandedStoreRoot;
nsCOMPtr<nsIFile> rootFolder(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = rootFolder->InitWithPath(storeRoot);
NS_ENSURE_SUCCESS(rv, rv);
rootFolder.forget(aRootFolder);
return NS_OK;
}
nsresult
nsWMUtils::GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray)
{
nsCOMPtr<nsIFile> rootFolder;
nsresult rv = GetRootFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
return GetOEAccountFilesInFolder(rootFolder, aFileArray);
}
nsresult
nsWMUtils::GetOEAccountFilesInFolder(nsIFile *aFolder,
nsCOMArray<nsIFile> &aFileArray)
{
nsCOMPtr<nsISimpleEnumerator> entries;
nsresult rv = aFolder->GetDirectoryEntries(getter_AddRefs(entries));
if (NS_FAILED(rv) || !entries)
return NS_ERROR_FAILURE;
bool hasMore;
while (NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> supports;
rv = entries->GetNext(getter_AddRefs(supports));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> file = do_QueryInterface(supports);
NS_ENSURE_SUCCESS(rv, rv);
bool isDirectory;
rv = file->IsDirectory(&isDirectory);
NS_ENSURE_SUCCESS(rv, rv);
if (isDirectory) {
GetOEAccountFilesInFolder(file, aFileArray);
}
else {
nsString name;
rv = file->GetLeafName(name);
NS_ENSURE_SUCCESS(rv, rv);
if (StringEndsWith(name, NS_LITERAL_STRING(".oeaccount")))
aFileArray.AppendObject(file);
}
}
return NS_OK;
}
nsresult
nsWMUtils::MakeXMLdoc(nsIDOMDocument **aXmlDoc,
nsIFile *aFile)
{
nsresult rv;
nsCOMPtr<nsIFileInputStream> stream =
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->Init(aFile, PR_RDONLY, -1, 0);
nsCOMPtr<nsIDOMParser> parser = do_CreateInstance(NS_DOMPARSER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
int64_t filesize;
aFile->GetFileSize(&filesize);
return parser->ParseFromStream(stream, nullptr, int32_t(filesize),
"application/xml", aXmlDoc);
}
nsresult
nsWMUtils::GetValueForTag(nsIDOMDocument *aXmlDoc,
const char *aTagName,
nsAString &aValue)
{
nsAutoString tagName;
tagName.AssignASCII(aTagName);
nsCOMPtr<nsIDOMNodeList> list;
if (NS_FAILED(aXmlDoc->GetElementsByTagName(tagName, getter_AddRefs(list))))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMNode> domNode;
list->Item(0, getter_AddRefs(domNode));
if (!domNode)
return NS_ERROR_FAILURE;
return domNode->GetTextContent(aValue);
}

View file

@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsWMUtils_h___
#define nsWMUtils_h___
#include <windows.h>
#include "nsIWindowsRegKey.h"
class nsIDOMDocument;
class nsWMUtils {
public:
static nsresult FindWMKey(nsIWindowsRegKey **aKey);
static nsresult GetRootFolder(nsIFile **aRootFolder);
static nsresult GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray);
static nsresult GetOEAccountFilesInFolder(nsIFile *aFolder,
nsCOMArray<nsIFile> &aFileArray);
static nsresult MakeXMLdoc(nsIDOMDocument **aXmlDoc,
nsIFile *aFile);
static nsresult GetValueForTag(nsIDOMDocument *aXmlDoc,
const char *aTagName,
nsAString &aValue);
};
#endif /* nsWMUtils_h___ */