Bug 1546364 - Reformat to Google coding style in mailnews/import. rs=reformat
# ignore-this-changeset
This commit is contained in:
Родитель
e406706987
Коммит
6f937bff08
|
@ -30,33 +30,28 @@
|
|||
#define IMAP_MBOX_SUFFIX ".imapmbox"
|
||||
|
||||
// stringbundle URI
|
||||
#define APPLEMAIL_MSGS_URL "chrome://messenger/locale/appleMailImportMsgs.properties"
|
||||
#define APPLEMAIL_MSGS_URL \
|
||||
"chrome://messenger/locale/appleMailImportMsgs.properties"
|
||||
|
||||
// magic constants
|
||||
#define kAccountMailboxID 1234
|
||||
|
||||
nsAppleMailImportModule::nsAppleMailImportModule()
|
||||
{
|
||||
nsAppleMailImportModule::nsAppleMailImportModule() {
|
||||
IMPORT_LOG0("nsAppleMailImportModule Created");
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
mozilla::services::GetStringBundleService();
|
||||
if (bundleService)
|
||||
bundleService->CreateBundle(APPLEMAIL_MSGS_URL, getter_AddRefs(mBundle));
|
||||
}
|
||||
|
||||
|
||||
nsAppleMailImportModule::~nsAppleMailImportModule()
|
||||
{
|
||||
nsAppleMailImportModule::~nsAppleMailImportModule() {
|
||||
IMPORT_LOG0("nsAppleMailImportModule Deleted");
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAppleMailImportModule, nsIImportModule)
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetName(char16_t **aName)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetName(char16_t **aName) {
|
||||
if (!mBundle) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -67,8 +62,7 @@ NS_IMETHODIMP nsAppleMailImportModule::GetName(char16_t **aName)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetDescription(char16_t **aName)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetDescription(char16_t **aName) {
|
||||
if (!mBundle) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -79,31 +73,31 @@ NS_IMETHODIMP nsAppleMailImportModule::GetDescription(char16_t **aName)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetSupports(char **aSupports)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetSupports(char **aSupports) {
|
||||
NS_ENSURE_ARG_POINTER(aSupports);
|
||||
*aSupports = strdup(NS_IMPORT_MAIL_STR);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetSupportsUpgrade(bool *aUpgrade)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetSupportsUpgrade(bool *aUpgrade) {
|
||||
NS_ENSURE_ARG_POINTER(aUpgrade);
|
||||
*aUpgrade = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetImportInterface(const char *aImportType, nsISupports **aInterface)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportModule::GetImportInterface(
|
||||
const char *aImportType, nsISupports **aInterface) {
|
||||
NS_ENSURE_ARG_POINTER(aImportType);
|
||||
NS_ENSURE_ARG_POINTER(aInterface);
|
||||
*aInterface = nullptr;
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!strcmp(aImportType, "mail")) {
|
||||
nsCOMPtr<nsIImportMail> mail(do_CreateInstance(NS_APPLEMAILIMPL_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportMail> mail(
|
||||
do_CreateInstance(NS_APPLEMAILIMPL_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportGeneric> generic;
|
||||
rv = impSvc->CreateNewGenericMail(getter_AddRefs(generic));
|
||||
|
@ -112,7 +106,8 @@ NS_IMETHODIMP nsAppleMailImportModule::GetImportInterface(const char *aImportTyp
|
|||
rv = mBundle->GetStringFromName("ApplemailImportName", name);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISupportsString> nameString(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsISupportsString> nameString(
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nameString->SetData(name);
|
||||
|
||||
|
@ -130,29 +125,28 @@ NS_IMETHODIMP nsAppleMailImportModule::GetImportInterface(const char *aImportTyp
|
|||
|
||||
#pragma mark -
|
||||
|
||||
nsAppleMailImportMail::nsAppleMailImportMail() : mProgress(0), mCurDepth(0)
|
||||
{
|
||||
nsAppleMailImportMail::nsAppleMailImportMail() : mProgress(0), mCurDepth(0) {
|
||||
IMPORT_LOG0("nsAppleMailImportMail created");
|
||||
}
|
||||
|
||||
nsresult nsAppleMailImportMail::Initialize()
|
||||
{
|
||||
nsresult nsAppleMailImportMail::Initialize() {
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
mozilla::services::GetStringBundleService();
|
||||
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return bundleService->CreateBundle(APPLEMAIL_MSGS_URL, getter_AddRefs(mBundle));
|
||||
return bundleService->CreateBundle(APPLEMAIL_MSGS_URL,
|
||||
getter_AddRefs(mBundle));
|
||||
}
|
||||
|
||||
nsAppleMailImportMail::~nsAppleMailImportMail()
|
||||
{
|
||||
nsAppleMailImportMail::~nsAppleMailImportMail() {
|
||||
IMPORT_LOG0("nsAppleMailImportMail destroyed");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAppleMailImportMail, nsIImportMail)
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportMail::GetDefaultLocation(nsIFile **aLocation, bool *aFound, bool *aUserVerify)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportMail::GetDefaultLocation(nsIFile **aLocation,
|
||||
bool *aFound,
|
||||
bool *aUserVerify) {
|
||||
NS_ENSURE_ARG_POINTER(aFound);
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(aUserVerify);
|
||||
|
@ -164,7 +158,8 @@ NS_IMETHODIMP nsAppleMailImportMail::GetDefaultLocation(nsIFile **aLocation, boo
|
|||
// try to find current user's top-level Mail folder
|
||||
nsCOMPtr<nsIFile> mailFolder(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
if (mailFolder) {
|
||||
nsresult rv = mailFolder->InitWithNativePath(NS_LITERAL_CSTRING(DEFAULT_MAIL_FOLDER));
|
||||
nsresult rv =
|
||||
mailFolder->InitWithNativePath(NS_LITERAL_CSTRING(DEFAULT_MAIL_FOLDER));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aFound = true;
|
||||
*aUserVerify = false;
|
||||
|
@ -177,8 +172,8 @@ NS_IMETHODIMP nsAppleMailImportMail::GetDefaultLocation(nsIFile **aLocation, boo
|
|||
|
||||
// this is the method that initiates all searching for mailboxes.
|
||||
// it will assume that it has a directory like ~/Library/Mail/
|
||||
NS_IMETHODIMP nsAppleMailImportMail::FindMailboxes(nsIFile *aMailboxFile, nsIArray **aResult)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportMail::FindMailboxes(nsIFile *aMailboxFile,
|
||||
nsIArray **aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aMailboxFile);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
|
@ -186,15 +181,15 @@ NS_IMETHODIMP nsAppleMailImportMail::FindMailboxes(nsIFile *aMailboxFile, nsIArr
|
|||
|
||||
bool exists = false;
|
||||
nsresult rv = aMailboxFile->Exists(&exists);
|
||||
if (NS_FAILED(rv) || !exists)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !exists) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIImportService> importService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> importService(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMutableArray> resultsArray(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
|
||||
if (!resultsArray)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIMutableArray> resultsArray(
|
||||
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
|
||||
if (!resultsArray) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mCurDepth = 1;
|
||||
|
||||
|
@ -203,51 +198,53 @@ NS_IMETHODIMP nsAppleMailImportMail::FindMailboxes(nsIFile *aMailboxFile, nsIArr
|
|||
mCurDepth--;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// 2. look for "global" mailboxes, that don't belong to any specific account. they are inside the
|
||||
// 2. look for "global" mailboxes, that don't belong to any specific
|
||||
// account. they are inside the
|
||||
// root's Mailboxes/ folder
|
||||
nsCOMPtr<nsIFile> mailboxesDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIFile> mailboxesDir(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mailboxesDir->InitWithFile(aMailboxFile);
|
||||
rv = mailboxesDir->Append(NS_LITERAL_STRING("Mailboxes"));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
IMPORT_LOG0("Looking for global Apple mailboxes");
|
||||
mailboxesDir->InitWithFile(aMailboxFile);
|
||||
rv = mailboxesDir->Append(NS_LITERAL_STRING("Mailboxes"));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
IMPORT_LOG0("Looking for global Apple mailboxes");
|
||||
|
||||
mCurDepth++;
|
||||
rv = FindMboxDirs(mailboxesDir, resultsArray, importService);
|
||||
mCurDepth--;
|
||||
}
|
||||
mCurDepth++;
|
||||
rv = FindMboxDirs(mailboxesDir, resultsArray, importService);
|
||||
mCurDepth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && resultsArray)
|
||||
resultsArray.forget(aResult);
|
||||
if (NS_SUCCEEDED(rv) && resultsArray) resultsArray.forget(aResult);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// operates on the Mail/ directory root, trying to find accounts (which are folders named something like "POP-hwaara@gmail.com")
|
||||
// and add their .mbox dirs
|
||||
void nsAppleMailImportMail::FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService)
|
||||
{
|
||||
// operates on the Mail/ directory root, trying to find accounts (which are
|
||||
// folders named something like "POP-hwaara@gmail.com") and add their .mbox dirs
|
||||
void nsAppleMailImportMail::FindAccountMailDirs(
|
||||
nsIFile *aRoot, nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService) {
|
||||
nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
|
||||
nsresult rv = aRoot->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
bool hasMore = false;
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
// get the next file entry
|
||||
nsCOMPtr<nsIFile> currentEntry;
|
||||
directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
|
||||
if (!currentEntry)
|
||||
continue;
|
||||
if (!currentEntry) continue;
|
||||
|
||||
// make sure it's a directory
|
||||
bool isDirectory = false;
|
||||
currentEntry->IsDirectory(&isDirectory);
|
||||
|
||||
if (isDirectory) {
|
||||
// now let's see if it's an account folder. if so, we want to traverse it for .mbox children
|
||||
// now let's see if it's an account folder. if so, we want to traverse it
|
||||
// for .mbox children
|
||||
nsAutoString folderName;
|
||||
currentEntry->GetLeafName(folderName);
|
||||
bool isAccountFolder = false;
|
||||
|
@ -256,19 +253,21 @@ void nsAppleMailImportMail::FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray
|
|||
// cut off "POP-" prefix so we get a nice folder name
|
||||
folderName.Cut(0, 4);
|
||||
isAccountFolder = true;
|
||||
}
|
||||
else if (StringBeginsWith(folderName, NS_LITERAL_STRING("IMAP-"))) {
|
||||
} else if (StringBeginsWith(folderName, NS_LITERAL_STRING("IMAP-"))) {
|
||||
// cut off "IMAP-" prefix so we get a nice folder name
|
||||
folderName.Cut(0, 5);
|
||||
isAccountFolder = true;
|
||||
}
|
||||
|
||||
if (isAccountFolder) {
|
||||
IMPORT_LOG1("Found account: %s\n", NS_ConvertUTF16toUTF8(folderName).get());
|
||||
IMPORT_LOG1("Found account: %s\n",
|
||||
NS_ConvertUTF16toUTF8(folderName).get());
|
||||
|
||||
// create a mailbox for this account, so we get a parent for "Inbox", "Sent Messages", etc.
|
||||
// create a mailbox for this account, so we get a parent for "Inbox",
|
||||
// "Sent Messages", etc.
|
||||
nsCOMPtr<nsIImportMailboxDescriptor> desc;
|
||||
nsresult rv = aImportService->CreateNewMailboxDescriptor(getter_AddRefs(desc));
|
||||
nsresult rv =
|
||||
aImportService->CreateNewMailboxDescriptor(getter_AddRefs(desc));
|
||||
desc->SetSize(1);
|
||||
desc->SetDepth(mCurDepth);
|
||||
desc->SetDisplayName(folderName.get());
|
||||
|
@ -276,8 +275,7 @@ void nsAppleMailImportMail::FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray
|
|||
|
||||
nsCOMPtr<nsIFile> mailboxDescFile;
|
||||
rv = desc->GetFile(getter_AddRefs(mailboxDescFile));
|
||||
if (!mailboxDescFile)
|
||||
continue;
|
||||
if (!mailboxDescFile) continue;
|
||||
|
||||
mailboxDescFile->InitWithFile(currentEntry);
|
||||
|
||||
|
@ -294,23 +292,25 @@ void nsAppleMailImportMail::FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray
|
|||
}
|
||||
|
||||
// adds the specified file as a mailboxdescriptor to the array
|
||||
nsresult nsAppleMailImportMail::AddMboxDir(nsIFile *aFolder, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService)
|
||||
{
|
||||
nsresult nsAppleMailImportMail::AddMboxDir(nsIFile *aFolder,
|
||||
nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService) {
|
||||
nsAutoString folderName;
|
||||
aFolder->GetLeafName(folderName);
|
||||
|
||||
// cut off the suffix, if any, or prefix if this is an account folder.
|
||||
if (StringEndsWith(folderName, NS_LITERAL_STRING(POP_MBOX_SUFFIX)))
|
||||
folderName.SetLength(folderName.Length()-5);
|
||||
folderName.SetLength(folderName.Length() - 5);
|
||||
else if (StringEndsWith(folderName, NS_LITERAL_STRING(IMAP_MBOX_SUFFIX)))
|
||||
folderName.SetLength(folderName.Length()-9);
|
||||
folderName.SetLength(folderName.Length() - 9);
|
||||
else if (StringBeginsWith(folderName, NS_LITERAL_STRING("POP-")))
|
||||
folderName.Cut(4, folderName.Length());
|
||||
else if (StringBeginsWith(folderName, NS_LITERAL_STRING("IMAP-")))
|
||||
folderName.Cut(5, folderName.Length());
|
||||
|
||||
nsCOMPtr<nsIImportMailboxDescriptor> desc;
|
||||
nsresult rv = aImportService->CreateNewMailboxDescriptor(getter_AddRefs(desc));
|
||||
nsresult rv =
|
||||
aImportService->CreateNewMailboxDescriptor(getter_AddRefs(desc));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// find out number of messages in this .mbox
|
||||
uint32_t numMessages = 0;
|
||||
|
@ -321,20 +321,21 @@ nsresult nsAppleMailImportMail::AddMboxDir(nsIFile *aFolder, nsIMutableArray *aM
|
|||
nsresult rv = messagesFolder->Append(NS_LITERAL_STRING("Messages"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// count the number of messages in this folder. it sucks that we have to iterate through the folder
|
||||
// but XPCOM doesn't give us any way to just get the file count, unfortunately. :-(
|
||||
// count the number of messages in this folder. it sucks that we have to
|
||||
// iterate through the folder but XPCOM doesn't give us any way to just
|
||||
// get the file count, unfortunately. :-(
|
||||
nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator;
|
||||
messagesFolder->GetDirectoryEntries(getter_AddRefs(dirEnumerator));
|
||||
if (dirEnumerator) {
|
||||
bool hasMore = false;
|
||||
while (NS_SUCCEEDED(dirEnumerator->HasMoreElements(&hasMore)) && hasMore) {
|
||||
while (NS_SUCCEEDED(dirEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
dirEnumerator->GetNextFile(getter_AddRefs(file));
|
||||
if (file) {
|
||||
bool isFile = false;
|
||||
file->IsFile(&isFile);
|
||||
if (isFile)
|
||||
numMessages++;
|
||||
if (isFile) numMessages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,15 +345,17 @@ nsresult nsAppleMailImportMail::AddMboxDir(nsIFile *aFolder, nsIMutableArray *aM
|
|||
desc->SetDisplayName(folderName.get());
|
||||
desc->SetDepth(mCurDepth);
|
||||
|
||||
IMPORT_LOG3("Will import %s with approx %d messages, depth is %d", NS_ConvertUTF16toUTF8(folderName).get(), numMessages, mCurDepth);
|
||||
IMPORT_LOG3("Will import %s with approx %d messages, depth is %d",
|
||||
NS_ConvertUTF16toUTF8(folderName).get(), numMessages,
|
||||
mCurDepth);
|
||||
|
||||
// XXX: this is silly. there's no setter for the mailbox descriptor's file, so we need to get it, and then modify it.
|
||||
// XXX: this is silly. there's no setter for the mailbox descriptor's file,
|
||||
// so we need to get it, and then modify it.
|
||||
nsCOMPtr<nsIFile> mailboxDescFile;
|
||||
rv = desc->GetFile(getter_AddRefs(mailboxDescFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mailboxDescFile)
|
||||
mailboxDescFile->InitWithFile(aFolder);
|
||||
if (mailboxDescFile) mailboxDescFile->InitWithFile(aFolder);
|
||||
|
||||
// add this mailbox descriptor to the list
|
||||
aMailboxDescs->AppendElement(desc);
|
||||
|
@ -361,18 +364,20 @@ nsresult nsAppleMailImportMail::AddMboxDir(nsIFile *aFolder, nsIMutableArray *aM
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Starts looking for .mbox dirs in the specified dir. The .mbox dirs contain messages and can be considered leafs in a tree of
|
||||
// nested mailboxes (subfolders).
|
||||
// Starts looking for .mbox dirs in the specified dir. The .mbox dirs contain
|
||||
// messages and can be considered leafs in a tree of nested mailboxes
|
||||
// (subfolders).
|
||||
//
|
||||
// If a mailbox has sub-mailboxes, they are contained in a sibling folder with the same name without the ".mbox" part.
|
||||
// example:
|
||||
// If a mailbox has sub-mailboxes, they are contained in a sibling folder with
|
||||
// the same name without the ".mbox" part. example:
|
||||
// MyParentMailbox.mbox/
|
||||
// MyParentMailbox/
|
||||
// MyChildMailbox.mbox/
|
||||
// MyOtherChildMailbox.mbox/
|
||||
//
|
||||
nsresult nsAppleMailImportMail::FindMboxDirs(nsIFile *aFolder, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService)
|
||||
{
|
||||
nsresult nsAppleMailImportMail::FindMboxDirs(nsIFile *aFolder,
|
||||
nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService) {
|
||||
NS_ENSURE_ARG_POINTER(aFolder);
|
||||
NS_ENSURE_ARG_POINTER(aMailboxDescs);
|
||||
NS_ENSURE_ARG_POINTER(aImportService);
|
||||
|
@ -384,33 +389,36 @@ nsresult nsAppleMailImportMail::FindMboxDirs(nsIFile *aFolder, nsIMutableArray *
|
|||
|
||||
// iterate through the folder contents
|
||||
nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
|
||||
nsresult rv = aFolder->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
|
||||
if (NS_FAILED(rv) || !directoryEnumerator)
|
||||
return rv;
|
||||
nsresult rv =
|
||||
aFolder->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
|
||||
if (NS_FAILED(rv) || !directoryEnumerator) return rv;
|
||||
|
||||
bool hasMore = false;
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
// get the next file entry
|
||||
nsCOMPtr<nsIFile> currentEntry;
|
||||
directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
|
||||
if (!currentEntry)
|
||||
continue;
|
||||
if (!currentEntry) continue;
|
||||
|
||||
// we only care about directories...
|
||||
if (NS_FAILED(currentEntry->IsDirectory(&isDir)) || !isDir)
|
||||
continue;
|
||||
if (NS_FAILED(currentEntry->IsDirectory(&isDir)) || !isDir) continue;
|
||||
|
||||
// now find out if this is a .mbox dir
|
||||
nsAutoString currentFolderName;
|
||||
if (NS_SUCCEEDED(currentEntry->GetLeafName(currentFolderName)) &&
|
||||
(StringEndsWith(currentFolderName, NS_LITERAL_STRING(POP_MBOX_SUFFIX)) ||
|
||||
StringEndsWith(currentFolderName, NS_LITERAL_STRING(IMAP_MBOX_SUFFIX)))) {
|
||||
IMPORT_LOG1("Adding .mbox dir: %s", NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
(StringEndsWith(currentFolderName,
|
||||
NS_LITERAL_STRING(POP_MBOX_SUFFIX)) ||
|
||||
StringEndsWith(currentFolderName,
|
||||
NS_LITERAL_STRING(IMAP_MBOX_SUFFIX)))) {
|
||||
IMPORT_LOG1("Adding .mbox dir: %s",
|
||||
NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
|
||||
// add this .mbox
|
||||
rv = AddMboxDir(currentEntry, aMailboxDescs, aImportService);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG1("Couldn't add .mbox for import: %s ... continuing anyway", NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
IMPORT_LOG1("Couldn't add .mbox for import: %s ... continuing anyway",
|
||||
NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -419,22 +427,26 @@ nsresult nsAppleMailImportMail::FindMboxDirs(nsIFile *aFolder, nsIMutableArray *
|
|||
currentEntry->GetPath(siblingMailboxDirPath);
|
||||
|
||||
// cut off suffix
|
||||
if (StringEndsWith(siblingMailboxDirPath, NS_LITERAL_STRING(IMAP_MBOX_SUFFIX)))
|
||||
siblingMailboxDirPath.SetLength(siblingMailboxDirPath.Length()-9);
|
||||
else if (StringEndsWith(siblingMailboxDirPath, NS_LITERAL_STRING(POP_MBOX_SUFFIX)))
|
||||
siblingMailboxDirPath.SetLength(siblingMailboxDirPath.Length()-5);
|
||||
if (StringEndsWith(siblingMailboxDirPath,
|
||||
NS_LITERAL_STRING(IMAP_MBOX_SUFFIX)))
|
||||
siblingMailboxDirPath.SetLength(siblingMailboxDirPath.Length() - 9);
|
||||
else if (StringEndsWith(siblingMailboxDirPath,
|
||||
NS_LITERAL_STRING(POP_MBOX_SUFFIX)))
|
||||
siblingMailboxDirPath.SetLength(siblingMailboxDirPath.Length() - 5);
|
||||
|
||||
IMPORT_LOG1("trying to locate a '%s'", NS_ConvertUTF16toUTF8(siblingMailboxDirPath).get());
|
||||
nsCOMPtr<nsIFile> siblingMailboxDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
IMPORT_LOG1("trying to locate a '%s'",
|
||||
NS_ConvertUTF16toUTF8(siblingMailboxDirPath).get());
|
||||
nsCOMPtr<nsIFile> siblingMailboxDir(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
rv = siblingMailboxDir->InitWithPath(siblingMailboxDirPath);
|
||||
bool reallyExists = false;
|
||||
siblingMailboxDir->Exists(&reallyExists);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && reallyExists) {
|
||||
IMPORT_LOG1("Found what looks like an .mbox container: %s", NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
IMPORT_LOG1("Found what looks like an .mbox container: %s",
|
||||
NS_ConvertUTF16toUTF8(currentFolderName).get());
|
||||
|
||||
// traverse this folder for other .mboxes
|
||||
mCurDepth++;
|
||||
|
@ -451,8 +463,8 @@ NS_IMETHODIMP
|
|||
nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
||||
nsIMsgFolder *aDstFolder,
|
||||
char16_t **aErrorLog,
|
||||
char16_t **aSuccessLog, bool *aFatalError)
|
||||
{
|
||||
char16_t **aSuccessLog,
|
||||
bool *aFatalError) {
|
||||
nsAutoString errorLog, successLog;
|
||||
|
||||
// reset progress
|
||||
|
@ -480,11 +492,11 @@ nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
|||
mboxFolder->Clone(getter_AddRefs(messagesFolder));
|
||||
rv = messagesFolder->Append(NS_LITERAL_STRING("Messages"));
|
||||
if (NS_FAILED(rv)) {
|
||||
// even if there are no messages, it might still be a valid mailbox, or even
|
||||
// a parent for other mailboxes.
|
||||
// even if there are no messages, it might still be a valid mailbox, or
|
||||
// even a parent for other mailboxes.
|
||||
//
|
||||
// just indicate that we're done, using the same number that we used to estimate
|
||||
// number of messages earlier.
|
||||
// just indicate that we're done, using the same number that we used to
|
||||
// estimate number of messages earlier.
|
||||
uint32_t finalSize;
|
||||
aMailbox->GetSize(&finalSize);
|
||||
mProgress = finalSize;
|
||||
|
@ -497,9 +509,11 @@ nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
|||
|
||||
// let's import the messages!
|
||||
nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
|
||||
rv = messagesFolder->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
|
||||
rv = messagesFolder->GetDirectoryEntries(
|
||||
getter_AddRefs(directoryEnumerator));
|
||||
if (NS_FAILED(rv)) {
|
||||
ReportStatus(u"ApplemailImportMailboxConvertError", mailboxName, errorLog);
|
||||
ReportStatus(u"ApplemailImportMailboxConvertError", mailboxName,
|
||||
errorLog);
|
||||
SetLogs(successLog, errorLog, aSuccessLog, aErrorLog);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -508,7 +522,8 @@ nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
|||
nsCOMPtr<nsIMsgPluggableStore> msgStore;
|
||||
rv = aDstFolder->GetMsgStore(getter_AddRefs(msgStore));
|
||||
if (!msgStore || NS_FAILED(rv)) {
|
||||
ReportStatus(u"ApplemailImportMailboxConverterror", mailboxName, errorLog);
|
||||
ReportStatus(u"ApplemailImportMailboxConverterror", mailboxName,
|
||||
errorLog);
|
||||
SetLogs(successLog, errorLog, aSuccessLog, aErrorLog);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -516,49 +531,44 @@ nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
|||
bool hasMore = false;
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
|
||||
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
// get the next file entry
|
||||
nsCOMPtr<nsIFile> currentEntry;
|
||||
directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
|
||||
if (!currentEntry)
|
||||
continue;
|
||||
if (!currentEntry) continue;
|
||||
|
||||
// make sure it's an .emlx file
|
||||
bool isFile = false;
|
||||
currentEntry->IsFile(&isFile);
|
||||
if (!isFile)
|
||||
continue;
|
||||
if (!isFile) continue;
|
||||
|
||||
nsAutoString leafName;
|
||||
currentEntry->GetLeafName(leafName);
|
||||
if (!StringEndsWith(leafName, NS_LITERAL_STRING(".emlx")))
|
||||
continue;
|
||||
if (!StringEndsWith(leafName, NS_LITERAL_STRING(".emlx"))) continue;
|
||||
|
||||
nsCOMPtr<nsIMsgDBHdr> msgHdr;
|
||||
bool reusable;
|
||||
rv = msgStore->GetNewMsgOutputStream(aDstFolder, getter_AddRefs(msgHdr),
|
||||
&reusable,
|
||||
getter_AddRefs(outStream));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv =
|
||||
msgStore->GetNewMsgOutputStream(aDstFolder, getter_AddRefs(msgHdr),
|
||||
&reusable, getter_AddRefs(outStream));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
// add the data to the mbox stream
|
||||
if (NS_SUCCEEDED(nsEmlxHelperUtils::AddEmlxMessageToStream(currentEntry, outStream))) {
|
||||
if (NS_SUCCEEDED(nsEmlxHelperUtils::AddEmlxMessageToStream(currentEntry,
|
||||
outStream))) {
|
||||
mProgress++;
|
||||
msgStore->FinishNewMessage(outStream, msgHdr);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
msgStore->DiscardNewMessage(outStream, msgHdr);
|
||||
break;
|
||||
}
|
||||
if (!reusable)
|
||||
outStream->Close();
|
||||
if (!reusable) outStream->Close();
|
||||
}
|
||||
if (outStream)
|
||||
outStream->Close();
|
||||
if (outStream) outStream->Close();
|
||||
}
|
||||
// just indicate that we're done, using the same number that we used to estimate
|
||||
// number of messages earlier.
|
||||
// just indicate that we're done, using the same number that we used to
|
||||
// estimate number of messages earlier.
|
||||
uint32_t finalSize;
|
||||
aMailbox->GetSize(&finalSize);
|
||||
mProgress = finalSize;
|
||||
|
@ -570,13 +580,13 @@ nsAppleMailImportMail::ImportMailbox(nsIImportMailboxDescriptor *aMailbox,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsAppleMailImportMail::ReportStatus(const char16_t* aErrorName, nsString &aName,
|
||||
nsAString &aStream)
|
||||
{
|
||||
void nsAppleMailImportMail::ReportStatus(const char16_t *aErrorName,
|
||||
nsString &aName, nsAString &aStream) {
|
||||
// get (and format, if needed) the error string from the bundle
|
||||
nsAutoString outString;
|
||||
const char16_t *fmt = { aName.get() };
|
||||
nsresult rv = mBundle->FormatStringFromName(NS_ConvertUTF16toUTF8(aErrorName).get(), &fmt, 1, outString);
|
||||
const char16_t *fmt = {aName.get()};
|
||||
nsresult rv = mBundle->FormatStringFromName(
|
||||
NS_ConvertUTF16toUTF8(aErrorName).get(), &fmt, 1, outString);
|
||||
// write it out the stream
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aStream.Append(outString);
|
||||
|
@ -584,23 +594,22 @@ void nsAppleMailImportMail::ReportStatus(const char16_t* aErrorName, nsString &a
|
|||
}
|
||||
}
|
||||
|
||||
void nsAppleMailImportMail::SetLogs(const nsAString &aSuccess, const nsAString &aError, char16_t **aOutSuccess, char16_t **aOutError)
|
||||
{
|
||||
if (aOutError && !*aOutError)
|
||||
*aOutError = ToNewUnicode(aError);
|
||||
if (aOutSuccess && !*aOutSuccess)
|
||||
*aOutSuccess = ToNewUnicode(aSuccess);
|
||||
void nsAppleMailImportMail::SetLogs(const nsAString &aSuccess,
|
||||
const nsAString &aError,
|
||||
char16_t **aOutSuccess,
|
||||
char16_t **aOutError) {
|
||||
if (aOutError && !*aOutError) *aOutError = ToNewUnicode(aError);
|
||||
if (aOutSuccess && !*aOutSuccess) *aOutSuccess = ToNewUnicode(aSuccess);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportMail::GetImportProgress(uint32_t *aDoneSoFar)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportMail::GetImportProgress(uint32_t *aDoneSoFar) {
|
||||
NS_ENSURE_ARG_POINTER(aDoneSoFar);
|
||||
*aDoneSoFar = mProgress;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAppleMailImportMail::TranslateFolderName(const nsAString &aFolderName, nsAString &aResult)
|
||||
{
|
||||
NS_IMETHODIMP nsAppleMailImportMail::TranslateFolderName(
|
||||
const nsAString &aFolderName, nsAString &aResult) {
|
||||
aResult = aFolderName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,19 @@
|
|||
#include "nsIImportMail.h"
|
||||
#include "ImportDebug.h"
|
||||
|
||||
#define NS_APPLEMAILIMPL_CID \
|
||||
{ 0x9117a1ea, 0xe012, 0x43b5, { 0xa0, 0x20, 0xcb, 0x8a, 0x66, 0xcc, 0x09, 0xe1 } }
|
||||
#define NS_APPLEMAILIMPL_CID \
|
||||
{ \
|
||||
0x9117a1ea, 0xe012, 0x43b5, { \
|
||||
0xa0, 0x20, 0xcb, 0x8a, 0x66, 0xcc, 0x09, 0xe1 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_APPLEMAILIMPORT_CID \
|
||||
{ 0x6d3f101c, 0x70ec, 0x4e04, { 0xb6, 0x8d, 0x99, 0x08, 0xd1, 0xae, 0xdd, 0xf3 } }
|
||||
#define NS_APPLEMAILIMPORT_CID \
|
||||
{ \
|
||||
0x6d3f101c, 0x70ec, 0x4e04, { \
|
||||
0xb6, 0x8d, 0x99, 0x08, 0xd1, 0xae, 0xdd, 0xf3 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_APPLEMAILIMPL_CONTRACTID "@mozilla.org/import/import-appleMailImpl;1"
|
||||
|
||||
|
@ -26,25 +34,21 @@
|
|||
class nsIImportService;
|
||||
class nsIMutableArray;
|
||||
|
||||
class nsAppleMailImportModule : public nsIImportModule
|
||||
{
|
||||
public:
|
||||
|
||||
class nsAppleMailImportModule : public nsIImportModule {
|
||||
public:
|
||||
nsAppleMailImportModule();
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsAppleMailImportModule();
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
};
|
||||
|
||||
class nsAppleMailImportMail : public nsIImportMail
|
||||
{
|
||||
public:
|
||||
|
||||
class nsAppleMailImportMail : public nsIImportMail {
|
||||
public:
|
||||
nsAppleMailImportMail();
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
@ -52,20 +56,26 @@ class nsAppleMailImportMail : public nsIImportMail
|
|||
|
||||
nsresult Initialize();
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsAppleMailImportMail();
|
||||
|
||||
void FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService);
|
||||
nsresult FindMboxDirs(nsIFile *aFolder, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService);
|
||||
nsresult AddMboxDir(nsIFile *aFolder, nsIMutableArray *aMailboxDescs, nsIImportService *aImportService);
|
||||
void FindAccountMailDirs(nsIFile *aRoot, nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService);
|
||||
nsresult FindMboxDirs(nsIFile *aFolder, nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService);
|
||||
nsresult AddMboxDir(nsIFile *aFolder, nsIMutableArray *aMailboxDescs,
|
||||
nsIImportService *aImportService);
|
||||
|
||||
// aInfoString is the format to a "foo %s" string. It may be NULL if the error string needs no such format.
|
||||
void ReportStatus(const char16_t* aErrorName, nsString &aName, nsAString &aStream);
|
||||
static void SetLogs(const nsAString& success, const nsAString& error, char16_t **aOutErrorLog, char16_t **aSuccessLog);
|
||||
// aInfoString is the format to a "foo %s" string. It may be NULL if the error
|
||||
// string needs no such format.
|
||||
void ReportStatus(const char16_t *aErrorName, nsString &aName,
|
||||
nsAString &aStream);
|
||||
static void SetLogs(const nsAString &success, const nsAString &error,
|
||||
char16_t **aOutErrorLog, char16_t **aSuccessLog);
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
uint32_t mProgress;
|
||||
uint16_t mCurDepth;
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
uint32_t mProgress;
|
||||
uint16_t mCurDepth;
|
||||
};
|
||||
|
||||
#endif /* nsAppleMailImport_h___ */
|
||||
|
|
|
@ -14,17 +14,18 @@ class nsIFile;
|
|||
|
||||
class nsEmlxHelperUtils {
|
||||
/* All emlx messages have a "flags" number in the metadata.
|
||||
These are the masks to decode that, found via http://jwz.livejournal.com/505711.html */
|
||||
These are the masks to decode that, found via
|
||||
http://jwz.livejournal.com/505711.html */
|
||||
enum EmlxMetadataMask {
|
||||
kRead = 1 << 0, // read
|
||||
kRead = 1 << 0, // read
|
||||
// 1 << 1, // deleted
|
||||
kAnswered = 1 << 2, // answered
|
||||
kAnswered = 1 << 2, // answered
|
||||
// 1 << 3, // encrypted
|
||||
kFlagged = 1 << 4, // flagged
|
||||
kFlagged = 1 << 4, // flagged
|
||||
// 1 << 5, // recent
|
||||
// 1 << 6, // draft
|
||||
// 1 << 7, // initial (no longer used)
|
||||
kForwarded = 1 << 8, // forwarded
|
||||
kForwarded = 1 << 8, // forwarded
|
||||
// 1 << 9, // redirected
|
||||
// 3F << 10, // attachment count (6 bits)
|
||||
// 7F << 16, // priority level (7 bits)
|
||||
|
@ -37,19 +38,24 @@ class nsEmlxHelperUtils {
|
|||
// 1 << 31 // (unused)
|
||||
};
|
||||
|
||||
// This method will scan the raw EMLX message buffer for "dangerous" so-called "From-lines" that we need to escape.
|
||||
// If it needs to modify any lines, it will return a non-NULL aOutBuffer. If aOutBuffer is NULL, no modification needed
|
||||
// to be made.
|
||||
static nsresult ConvertToMboxRD(const char *aMessageBufferStart, const char *aMessageBufferEnd, nsCString &aOutBuffer);
|
||||
// This method will scan the raw EMLX message buffer for "dangerous" so-called
|
||||
// "From-lines" that we need to escape. If it needs to modify any lines, it
|
||||
// will return a non-NULL aOutBuffer. If aOutBuffer is NULL, no modification
|
||||
// needed to be made.
|
||||
static nsresult ConvertToMboxRD(const char *aMessageBufferStart,
|
||||
const char *aMessageBufferEnd,
|
||||
nsCString &aOutBuffer);
|
||||
|
||||
// returns an int representing the X-Mozilla-Status flags set (e.g. "read", "flagged") converted from EMLX flags.
|
||||
static nsresult ConvertToMozillaStatusFlags(const char *aXMLBufferStart, const char *aXMLBufferEnd, uint32_t *aMozillaStatusFlags);
|
||||
|
||||
public:
|
||||
// returns an int representing the X-Mozilla-Status flags set (e.g. "read",
|
||||
// "flagged") converted from EMLX flags.
|
||||
static nsresult ConvertToMozillaStatusFlags(const char *aXMLBufferStart,
|
||||
const char *aXMLBufferEnd,
|
||||
uint32_t *aMozillaStatusFlags);
|
||||
|
||||
public:
|
||||
// add an .emlx message to the mbox output
|
||||
static nsresult AddEmlxMessageToStream(nsIFile *aEmlxFile, nsIOutputStream *aOutoutStream);
|
||||
|
||||
static nsresult AddEmlxMessageToStream(nsIFile *aEmlxFile,
|
||||
nsIOutputStream *aOutoutStream);
|
||||
};
|
||||
|
||||
#endif // nsEmlxHelperUtils_h___
|
||||
#endif // nsEmlxHelperUtils_h___
|
||||
|
|
|
@ -18,33 +18,29 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
nsresult nsEmlxHelperUtils::ConvertToMozillaStatusFlags(const char *aXMLBufferStart,
|
||||
const char *aXMLBufferEnd,
|
||||
uint32_t *aMozillaStatusFlags)
|
||||
{
|
||||
uint32_t *aMozillaStatusFlags) {
|
||||
// create a NSData wrapper around the buffer, so we can use the Cocoa call below
|
||||
NSData *metadata =
|
||||
[[[NSData alloc] initWithBytesNoCopy:(void *)aXMLBufferStart length:(aXMLBufferEnd-aXMLBufferStart) freeWhenDone:NO] autorelease];
|
||||
NSData *metadata = [[[NSData alloc] initWithBytesNoCopy:(void *)aXMLBufferStart
|
||||
length:(aXMLBufferEnd - aXMLBufferStart)
|
||||
freeWhenDone:NO] autorelease];
|
||||
|
||||
// get the XML data as a dictionary
|
||||
NSPropertyListFormat format;
|
||||
id plist = [NSPropertyListSerialization propertyListWithData:metadata
|
||||
options:NSPropertyListImmutable
|
||||
options:NSPropertyListImmutable
|
||||
format:&format
|
||||
error:NULL];
|
||||
error:NULL];
|
||||
|
||||
if (!plist)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!plist) return NS_ERROR_FAILURE;
|
||||
|
||||
// find the <flags>...</flags> value and convert to int
|
||||
const uint32_t emlxMessageFlags = [[(NSDictionary *)plist objectForKey:@"flags"] intValue];
|
||||
|
||||
if (emlxMessageFlags == 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (emlxMessageFlags == 0) return NS_ERROR_FAILURE;
|
||||
|
||||
if (emlxMessageFlags & nsEmlxHelperUtils::kRead)
|
||||
*aMozillaStatusFlags |= nsMsgMessageFlags::Read;
|
||||
if (emlxMessageFlags & nsEmlxHelperUtils::kRead) *aMozillaStatusFlags |= nsMsgMessageFlags::Read;
|
||||
if (emlxMessageFlags & nsEmlxHelperUtils::kForwarded)
|
||||
*aMozillaStatusFlags |= nsMsgMessageFlags::Forwarded;
|
||||
if (emlxMessageFlags & nsEmlxHelperUtils::kAnswered)
|
||||
|
@ -55,26 +51,23 @@ nsresult nsEmlxHelperUtils::ConvertToMozillaStatusFlags(const char *aXMLBufferSt
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsEmlxHelperUtils::ConvertToMboxRD(const char *aMessageBufferStart, const char *aMessageBufferEnd, nsCString &aOutBuffer)
|
||||
{
|
||||
nsresult nsEmlxHelperUtils::ConvertToMboxRD(const char *aMessageBufferStart,
|
||||
const char *aMessageBufferEnd, nsCString &aOutBuffer) {
|
||||
nsTArray<const char *> foundFromLines;
|
||||
|
||||
const char *cur = aMessageBufferStart;
|
||||
while (cur < aMessageBufferEnd) {
|
||||
|
||||
const char *foundFromStr = strnstr(cur, "From ", aMessageBufferEnd-cur);
|
||||
const char *foundFromStr = strnstr(cur, "From ", aMessageBufferEnd - cur);
|
||||
|
||||
if (foundFromStr) {
|
||||
// skip all prepending '>' chars
|
||||
const char *fromLineStart = foundFromStr;
|
||||
while (fromLineStart-- >= aMessageBufferStart) {
|
||||
if (*fromLineStart == '\n' || fromLineStart == aMessageBufferStart) {
|
||||
if (fromLineStart > aMessageBufferStart)
|
||||
fromLineStart++;
|
||||
if (fromLineStart > aMessageBufferStart) fromLineStart++;
|
||||
foundFromLines.AppendElement(fromLineStart);
|
||||
break;
|
||||
}
|
||||
else if (*fromLineStart != '>')
|
||||
} else if (*fromLineStart != '>')
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -90,10 +83,9 @@ nsresult nsEmlxHelperUtils::ConvertToMboxRD(const char *aMessageBufferStart, con
|
|||
|
||||
// go through foundFromLines
|
||||
if (foundFromLines.Length()) {
|
||||
|
||||
const char *chunkStart = aMessageBufferStart;
|
||||
for (unsigned i=0; i<foundFromLines.Length(); ++i) {
|
||||
aOutBuffer.Append(chunkStart, (foundFromLines[i]-chunkStart));
|
||||
for (unsigned i = 0; i < foundFromLines.Length(); ++i) {
|
||||
aOutBuffer.Append(chunkStart, (foundFromLines[i] - chunkStart));
|
||||
aOutBuffer.Append(NS_LITERAL_CSTRING(">"));
|
||||
|
||||
chunkStart = foundFromLines[i];
|
||||
|
@ -104,8 +96,7 @@ nsresult nsEmlxHelperUtils::ConvertToMboxRD(const char *aMessageBufferStart, con
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputStream *aOut)
|
||||
{
|
||||
nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputStream *aOut) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
// needed to be sure autoreleased objects are released too, which they might not
|
||||
|
@ -143,9 +134,7 @@ nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputS
|
|||
}
|
||||
|
||||
// skip whitespace
|
||||
while (*startOfMessageData == ' ' ||
|
||||
*startOfMessageData == '\n' ||
|
||||
*startOfMessageData == '\r' ||
|
||||
while (*startOfMessageData == ' ' || *startOfMessageData == '\n' || *startOfMessageData == '\r' ||
|
||||
*startOfMessageData == '\t')
|
||||
++startOfMessageData;
|
||||
|
||||
|
@ -159,7 +148,8 @@ nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputS
|
|||
return rv;
|
||||
}
|
||||
|
||||
// now read the XML metadata, so we can extract info like which flags (read? replied? flagged? etc) this message has.
|
||||
// now read the XML metadata, so we can extract info like which flags (read? replied? flagged?
|
||||
// etc) this message has.
|
||||
const char *startOfXMLMetadata = startOfMessageData + numberOfBytesToRead;
|
||||
const char *endOfXMLMetadata = (char *)[data bytes] + [data length];
|
||||
|
||||
|
@ -205,7 +195,8 @@ nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputS
|
|||
|
||||
// do any conversion needed for the mbox data to be valid mboxrd.
|
||||
nsCString convertedData;
|
||||
rv = ConvertToMboxRD(startOfMessageData, (startOfMessageData + numberOfBytesToRead), convertedData);
|
||||
rv = ConvertToMboxRD(startOfMessageData, (startOfMessageData + numberOfBytesToRead),
|
||||
convertedData);
|
||||
if (NS_FAILED(rv)) {
|
||||
[pool release];
|
||||
return rv;
|
||||
|
@ -224,7 +215,8 @@ nsresult nsEmlxHelperUtils::AddEmlxMessageToStream(nsIFile *aMessage, nsIOutputS
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_ASSERTION(actualBytesWritten == (convertedData.IsEmpty() ? numberOfBytesToRead : convertedData.Length()),
|
||||
NS_ASSERTION(actualBytesWritten ==
|
||||
(convertedData.IsEmpty() ? numberOfBytesToRead : convertedData.Length()),
|
||||
"Didn't write as many bytes as expected for .emlx file?");
|
||||
|
||||
// add newlines to denote the end of this message in the mbox
|
||||
|
|
|
@ -22,57 +22,45 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsBeckyAddressBooks, nsIImportAddressBooks)
|
||||
|
||||
nsresult
|
||||
nsBeckyAddressBooks::Create(nsIImportAddressBooks **aImport)
|
||||
{
|
||||
nsresult nsBeckyAddressBooks::Create(nsIImportAddressBooks **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsBeckyAddressBooks());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsBeckyAddressBooks::nsBeckyAddressBooks()
|
||||
: mReadBytes(0)
|
||||
{
|
||||
}
|
||||
nsBeckyAddressBooks::nsBeckyAddressBooks() : mReadBytes(0) {}
|
||||
|
||||
nsBeckyAddressBooks::~nsBeckyAddressBooks()
|
||||
{
|
||||
}
|
||||
nsBeckyAddressBooks::~nsBeckyAddressBooks() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetSupportsMultiple(bool *_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::GetSupportsMultiple(bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetAutoFind(char16_t **aDescription,
|
||||
bool *_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::GetAutoFind(char16_t **aDescription, bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aDescription);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*aDescription =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
*_retval = false;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetNeedsFieldMap(nsIFile *aLocation, bool *_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::GetNeedsFieldMap(nsIFile *aLocation, bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyAddressBooks::FindAddressBookDirectory(nsIFile **aAddressBookDirectory)
|
||||
{
|
||||
nsresult nsBeckyAddressBooks::FindAddressBookDirectory(
|
||||
nsIFile **aAddressBookDirectory) {
|
||||
nsCOMPtr<nsIFile> userDirectory;
|
||||
nsresult rv = nsBeckyUtils::FindUserDirectory(getter_AddRefs(userDirectory));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -83,24 +71,20 @@ nsBeckyAddressBooks::FindAddressBookDirectory(nsIFile **aAddressBookDirectory)
|
|||
bool exists = false;
|
||||
rv = userDirectory->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
bool isDirectory = false;
|
||||
rv = userDirectory->IsDirectory(&isDirectory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!isDirectory)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!isDirectory) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
userDirectory.forget(aAddressBookDirectory);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetDefaultLocation(nsIFile **aLocation,
|
||||
bool *aFound,
|
||||
bool *aUserVerify)
|
||||
{
|
||||
nsBeckyAddressBooks::GetDefaultLocation(nsIFile **aLocation, bool *aFound,
|
||||
bool *aUserVerify) {
|
||||
NS_ENSURE_ARG_POINTER(aFound);
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(aUserVerify);
|
||||
|
@ -117,44 +101,36 @@ nsBeckyAddressBooks::GetDefaultLocation(nsIFile **aLocation,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyAddressBooks::CreateAddressBookDescriptor(nsIImportABDescriptor **aDescriptor)
|
||||
{
|
||||
nsresult nsBeckyAddressBooks::CreateAddressBookDescriptor(
|
||||
nsIImportABDescriptor **aDescriptor) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportService> importService = do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIImportService> importService =
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return importService->CreateNewABDescriptor(aDescriptor);
|
||||
}
|
||||
|
||||
bool
|
||||
nsBeckyAddressBooks::IsAddressBookFile(nsIFile *aFile)
|
||||
{
|
||||
if (!aFile)
|
||||
return false;
|
||||
bool nsBeckyAddressBooks::IsAddressBookFile(nsIFile *aFile) {
|
||||
if (!aFile) return false;
|
||||
|
||||
nsresult rv;
|
||||
bool isFile = false;
|
||||
rv = aFile->IsFile(&isFile);
|
||||
if (NS_FAILED(rv) && !isFile)
|
||||
return false;
|
||||
if (NS_FAILED(rv) && !isFile) return false;
|
||||
|
||||
nsAutoString name;
|
||||
rv = aFile->GetLeafName(name);
|
||||
return StringEndsWith(name, NS_LITERAL_STRING(".bab"));
|
||||
}
|
||||
|
||||
bool
|
||||
nsBeckyAddressBooks::HasAddressBookFile(nsIFile *aDirectory)
|
||||
{
|
||||
if (!aDirectory)
|
||||
return false;
|
||||
bool nsBeckyAddressBooks::HasAddressBookFile(nsIFile *aDirectory) {
|
||||
if (!aDirectory) return false;
|
||||
|
||||
nsresult rv;
|
||||
bool isDirectory = false;
|
||||
rv = aDirectory->IsDirectory(&isDirectory);
|
||||
if (NS_FAILED(rv) || !isDirectory)
|
||||
return false;
|
||||
if (NS_FAILED(rv) || !isDirectory) return false;
|
||||
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
|
@ -165,24 +141,19 @@ nsBeckyAddressBooks::HasAddressBookFile(nsIFile *aDirectory)
|
|||
nsCOMPtr<nsIFile> file;
|
||||
rv = entries->GetNextFile(getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (IsAddressBookFile(file))
|
||||
return true;
|
||||
if (IsAddressBookFile(file)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
nsBeckyAddressBooks::CountAddressBookSize(nsIFile *aDirectory)
|
||||
{
|
||||
if (!aDirectory)
|
||||
return 0;
|
||||
uint32_t nsBeckyAddressBooks::CountAddressBookSize(nsIFile *aDirectory) {
|
||||
if (!aDirectory) return 0;
|
||||
|
||||
nsresult rv;
|
||||
bool isDirectory = false;
|
||||
rv = aDirectory->IsDirectory(&isDirectory);
|
||||
if (NS_FAILED(rv) || !isDirectory)
|
||||
return 0;
|
||||
if (NS_FAILED(rv) || !isDirectory) return 0;
|
||||
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
|
@ -206,14 +177,11 @@ nsBeckyAddressBooks::CountAddressBookSize(nsIFile *aDirectory)
|
|||
return total;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyAddressBooks::AppendAddressBookDescriptor(nsIFile *aEntry,
|
||||
nsIMutableArray *aCollected)
|
||||
{
|
||||
nsresult nsBeckyAddressBooks::AppendAddressBookDescriptor(
|
||||
nsIFile *aEntry, nsIMutableArray *aCollected) {
|
||||
NS_ENSURE_ARG_POINTER(aCollected);
|
||||
|
||||
if (!HasAddressBookFile(aEntry))
|
||||
return NS_OK;
|
||||
if (!HasAddressBookFile(aEntry)) return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportABDescriptor> descriptor;
|
||||
|
@ -231,10 +199,8 @@ nsBeckyAddressBooks::AppendAddressBookDescriptor(nsIFile *aEntry,
|
|||
return aCollected->AppendElement(descriptor);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyAddressBooks::CollectAddressBooks(nsIFile *aTarget,
|
||||
nsIMutableArray *aCollected)
|
||||
{
|
||||
nsresult nsBeckyAddressBooks::CollectAddressBooks(nsIFile *aTarget,
|
||||
nsIMutableArray *aCollected) {
|
||||
nsresult rv = AppendAddressBookDescriptor(aTarget, aCollected);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -259,9 +225,7 @@ nsBeckyAddressBooks::CollectAddressBooks(nsIFile *aTarget,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::FindAddressBooks(nsIFile *aLocation,
|
||||
nsIArray **_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::FindAddressBooks(nsIFile *aLocation, nsIArray **_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -271,8 +235,7 @@ nsBeckyAddressBooks::FindAddressBooks(nsIFile *aLocation,
|
|||
|
||||
bool isDirectory = false;
|
||||
rv = aLocation->IsDirectory(&isDirectory);
|
||||
if (NS_FAILED(rv) || !isDirectory)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !isDirectory) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = CollectAddressBooks(aLocation, array);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -283,20 +246,15 @@ nsBeckyAddressBooks::FindAddressBooks(nsIFile *aLocation,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::InitFieldMap(nsIImportFieldMap *aFieldMap)
|
||||
{
|
||||
nsBeckyAddressBooks::InitFieldMap(nsIImportFieldMap *aFieldMap) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::ImportAddressBook(nsIImportABDescriptor *aSource,
|
||||
nsIAddrDatabase *aDestination,
|
||||
nsIImportFieldMap *aFieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t **aErrorLog,
|
||||
char16_t **aSuccessLog,
|
||||
bool *aFatalError)
|
||||
{
|
||||
nsBeckyAddressBooks::ImportAddressBook(
|
||||
nsIImportABDescriptor *aSource, nsIAddrDatabase *aDestination,
|
||||
nsIImportFieldMap *aFieldMap, nsISupports *aSupportService,
|
||||
char16_t **aErrorLog, char16_t **aSuccessLog, bool *aFatalError) {
|
||||
NS_ENSURE_ARG_POINTER(aSource);
|
||||
NS_ENSURE_ARG_POINTER(aDestination);
|
||||
NS_ENSURE_ARG_POINTER(aErrorLog);
|
||||
|
@ -320,14 +278,14 @@ nsBeckyAddressBooks::ImportAddressBook(nsIImportABDescriptor *aSource,
|
|||
rv = entries->GetNextFile(getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!IsAddressBookFile(file))
|
||||
continue;
|
||||
if (!IsAddressBookFile(file)) continue;
|
||||
|
||||
bool aborted = false;
|
||||
nsAutoString name;
|
||||
aSource->GetPreferredName(name);
|
||||
nsVCardAddress vcard;
|
||||
rv = vcard.ImportAddresses(&aborted, name.get(), file, aDestination, error, &mReadBytes);
|
||||
rv = vcard.ImportAddresses(&aborted, name.get(), file, aDestination, error,
|
||||
&mReadBytes);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
|
@ -336,30 +294,24 @@ nsBeckyAddressBooks::ImportAddressBook(nsIImportABDescriptor *aSource,
|
|||
if (!error.IsEmpty())
|
||||
*aErrorLog = ToNewUnicode(error);
|
||||
else
|
||||
*aSuccessLog = nsBeckyStringBundle::GetStringByName("BeckyImportAddressSuccess");
|
||||
*aSuccessLog =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportAddressSuccess");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetImportProgress(uint32_t *_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::GetImportProgress(uint32_t *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = mReadBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::SetSampleLocation(nsIFile *aLocation)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
nsBeckyAddressBooks::SetSampleLocation(nsIFile *aLocation) { return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyAddressBooks::GetSampleData(int32_t aRecordNumber,
|
||||
bool *aRecordExists,
|
||||
char16_t **_retval)
|
||||
{
|
||||
nsBeckyAddressBooks::GetSampleData(int32_t aRecordNumber, bool *aRecordExists,
|
||||
char16_t **_retval) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,16 +10,15 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsIMutableArray.h"
|
||||
|
||||
class nsBeckyAddressBooks final : public nsIImportAddressBooks
|
||||
{
|
||||
public:
|
||||
class nsBeckyAddressBooks final : public nsIImportAddressBooks {
|
||||
public:
|
||||
nsBeckyAddressBooks();
|
||||
static nsresult Create(nsIImportAddressBooks **aImport);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTADDRESSBOOKS
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsBeckyAddressBooks();
|
||||
|
||||
uint32_t mReadBytes;
|
||||
|
|
|
@ -25,28 +25,18 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsBeckyFilters, nsIImportFilters)
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::Create(nsIImportFilters **aImport)
|
||||
{
|
||||
nsresult nsBeckyFilters::Create(nsIImportFilters **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsBeckyFilters());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsBeckyFilters::nsBeckyFilters()
|
||||
: mLocation(nullptr),
|
||||
mServer(nullptr),
|
||||
mConvertedFile(nullptr)
|
||||
{
|
||||
}
|
||||
: mLocation(nullptr), mServer(nullptr), mConvertedFile(nullptr) {}
|
||||
|
||||
nsBeckyFilters::~nsBeckyFilters()
|
||||
{
|
||||
}
|
||||
nsBeckyFilters::~nsBeckyFilters() {}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetDefaultFilterLocation(nsIFile **aFile)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetDefaultFilterLocation(nsIFile **aFile) {
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
nsresult rv;
|
||||
|
@ -58,9 +48,8 @@ nsBeckyFilters::GetDefaultFilterLocation(nsIFile **aFile)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetFilterFile(bool aIncoming, nsIFile *aLocation, nsIFile **aFile)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetFilterFile(bool aIncoming, nsIFile *aLocation,
|
||||
nsIFile **aFile) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
|
@ -79,24 +68,21 @@ nsBeckyFilters::GetFilterFile(bool aIncoming, nsIFile *aLocation, nsIFile **aFil
|
|||
bool exists = false;
|
||||
rv = filter->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
filter.forget(aFile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyFilters::AutoLocate(char16_t **aDescription,
|
||||
nsIFile **aLocation,
|
||||
bool *_retval)
|
||||
{
|
||||
nsBeckyFilters::AutoLocate(char16_t **aDescription, nsIFile **aLocation,
|
||||
bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
if (aDescription) {
|
||||
*aDescription =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
}
|
||||
*aLocation = nullptr;
|
||||
*_retval = false;
|
||||
|
@ -114,25 +100,20 @@ nsBeckyFilters::AutoLocate(char16_t **aDescription,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyFilters::SetLocation(nsIFile *aLocation)
|
||||
{
|
||||
nsBeckyFilters::SetLocation(nsIFile *aLocation) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
|
||||
bool exists = false;
|
||||
nsresult rv = aLocation->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
mLocation = aLocation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsMsgSearchAttribValue
|
||||
ConvertSearchKeyToAttrib(const nsACString &aKey)
|
||||
{
|
||||
if (aKey.EqualsLiteral("From") ||
|
||||
aKey.EqualsLiteral("Sender") ||
|
||||
static nsMsgSearchAttribValue ConvertSearchKeyToAttrib(const nsACString &aKey) {
|
||||
if (aKey.EqualsLiteral("From") || aKey.EqualsLiteral("Sender") ||
|
||||
aKey.EqualsLiteral("From, Sender, X-Sender")) {
|
||||
return nsMsgSearchAttrib::Sender;
|
||||
} else if (aKey.EqualsLiteral("Subject")) {
|
||||
|
@ -151,9 +132,8 @@ ConvertSearchKeyToAttrib(const nsACString &aKey)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static nsMsgSearchOpValue
|
||||
ConvertSearchFlagsToOperator(const nsACString &aFlags)
|
||||
{
|
||||
static nsMsgSearchOpValue ConvertSearchFlagsToOperator(
|
||||
const nsACString &aFlags) {
|
||||
nsCString flags(aFlags);
|
||||
int32_t lastTabPosition = flags.RFindChar('\t');
|
||||
if ((lastTabPosition == -1) ||
|
||||
|
@ -173,12 +153,10 @@ ConvertSearchFlagsToOperator(const nsACString &aFlags)
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::ParseRuleLine(const nsCString &aLine,
|
||||
nsMsgSearchAttribValue *aSearchAttribute,
|
||||
nsMsgSearchOpValue *aSearchOperator,
|
||||
nsString &aSearchKeyword)
|
||||
{
|
||||
nsresult nsBeckyFilters::ParseRuleLine(const nsCString &aLine,
|
||||
nsMsgSearchAttribValue *aSearchAttribute,
|
||||
nsMsgSearchOpValue *aSearchOperator,
|
||||
nsString &aSearchKeyword) {
|
||||
int32_t firstColonPosition = aLine.FindChar(':');
|
||||
if (firstColonPosition == -1 ||
|
||||
(int32_t)aLine.Length() == firstColonPosition - 1) {
|
||||
|
@ -193,31 +171,30 @@ nsBeckyFilters::ParseRuleLine(const nsCString &aLine,
|
|||
|
||||
int32_t length = secondColonPosition - firstColonPosition - 1;
|
||||
nsMsgSearchAttribValue searchAttribute;
|
||||
searchAttribute = ConvertSearchKeyToAttrib(Substring(aLine, firstColonPosition + 1, length));
|
||||
if (searchAttribute < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
searchAttribute = ConvertSearchKeyToAttrib(
|
||||
Substring(aLine, firstColonPosition + 1, length));
|
||||
if (searchAttribute < 0) return NS_ERROR_FAILURE;
|
||||
|
||||
int32_t tabPosition = aLine.FindChar('\t');
|
||||
if (tabPosition == -1 ||
|
||||
(int32_t)aLine.Length() == tabPosition - 1) {
|
||||
if (tabPosition == -1 || (int32_t)aLine.Length() == tabPosition - 1) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsMsgSearchOpValue searchOperator;
|
||||
searchOperator = ConvertSearchFlagsToOperator(Substring(aLine, tabPosition + 1));
|
||||
if (searchOperator < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
searchOperator =
|
||||
ConvertSearchFlagsToOperator(Substring(aLine, tabPosition + 1));
|
||||
if (searchOperator < 0) return NS_ERROR_FAILURE;
|
||||
|
||||
*aSearchOperator = searchOperator;
|
||||
*aSearchAttribute = searchAttribute;
|
||||
length = tabPosition - secondColonPosition - 1;
|
||||
CopyUTF8toUTF16(Substring(aLine, secondColonPosition + 1, length), aSearchKeyword);
|
||||
CopyUTF8toUTF16(Substring(aLine, secondColonPosition + 1, length),
|
||||
aSearchKeyword);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::SetSearchTerm(const nsCString &aLine, nsIMsgFilter *aFilter)
|
||||
{
|
||||
nsresult nsBeckyFilters::SetSearchTerm(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter) {
|
||||
NS_ENSURE_ARG_POINTER(aFilter);
|
||||
|
||||
nsresult rv;
|
||||
|
@ -258,11 +235,9 @@ nsBeckyFilters::SetSearchTerm(const nsCString &aLine, nsIMsgFilter *aFilter)
|
|||
return aFilter->AppendTerm(term);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CreateRuleAction(nsIMsgFilter *aFilter,
|
||||
nsMsgRuleActionType actionType,
|
||||
nsIMsgRuleAction **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::CreateRuleAction(nsIMsgFilter *aFilter,
|
||||
nsMsgRuleActionType actionType,
|
||||
nsIMsgRuleAction **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgRuleAction> action;
|
||||
rv = aFilter->CreateAction(getter_AddRefs(action));
|
||||
|
@ -275,10 +250,8 @@ nsBeckyFilters::CreateRuleAction(nsIMsgFilter *aFilter,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetActionTarget(const nsCString &aLine,
|
||||
nsCString &aTarget)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetActionTarget(const nsCString &aLine,
|
||||
nsCString &aTarget) {
|
||||
int32_t firstColonPosition = aLine.FindChar(':');
|
||||
if (firstColonPosition < -1 ||
|
||||
aLine.Length() == static_cast<uint32_t>(firstColonPosition)) {
|
||||
|
@ -290,11 +263,9 @@ nsBeckyFilters::GetActionTarget(const nsCString &aLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetResendTarget(const nsCString &aLine,
|
||||
nsCString &aTemplate,
|
||||
nsCString &aTargetAddress)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetResendTarget(const nsCString &aLine,
|
||||
nsCString &aTemplate,
|
||||
nsCString &aTargetAddress) {
|
||||
nsresult rv;
|
||||
nsAutoCString target;
|
||||
rv = GetActionTarget(aLine, target);
|
||||
|
@ -315,12 +286,9 @@ nsBeckyFilters::GetResendTarget(const nsCString &aLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CreateResendAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType,
|
||||
nsIMsgRuleAction **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::CreateResendAction(
|
||||
const nsCString &aLine, nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType, nsIMsgRuleAction **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgRuleAction> action;
|
||||
rv = CreateRuleAction(aFilter, aActionType, getter_AddRefs(action));
|
||||
|
@ -342,22 +310,20 @@ nsBeckyFilters::CreateResendAction(const nsCString &aLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetFolderNameFromTarget(const nsCString &aTarget, nsAString &aName)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetFolderNameFromTarget(const nsCString &aTarget,
|
||||
nsAString &aName) {
|
||||
int32_t backslashPosition = aTarget.RFindChar('\\');
|
||||
if (backslashPosition > 0) {
|
||||
NS_ConvertUTF8toUTF16 utf16String(Substring(aTarget, backslashPosition + 1));
|
||||
NS_ConvertUTF8toUTF16 utf16String(
|
||||
Substring(aTarget, backslashPosition + 1));
|
||||
nsBeckyUtils::TranslateFolderName(utf16String, aName);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetDistributeTarget(const nsCString &aLine,
|
||||
nsCString &aTargetFolder)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetDistributeTarget(const nsCString &aLine,
|
||||
nsCString &aTargetFolder) {
|
||||
nsresult rv;
|
||||
nsAutoCString target;
|
||||
rv = GetActionTarget(aLine, target);
|
||||
|
@ -368,7 +334,7 @@ nsBeckyFilters::GetDistributeTarget(const nsCString &aLine,
|
|||
rv = GetFolderNameFromTarget(target, folderName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr <nsIMsgFolder> folder;
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
rv = GetMessageFolder(folderName, getter_AddRefs(folder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -379,12 +345,9 @@ nsBeckyFilters::GetDistributeTarget(const nsCString &aLine,
|
|||
return folder->GetURI(aTargetFolder);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CreateDistributeAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType,
|
||||
nsIMsgRuleAction **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::CreateDistributeAction(
|
||||
const nsCString &aLine, nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType, nsIMsgRuleAction **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgRuleAction> action;
|
||||
rv = CreateRuleAction(aFilter, aActionType, getter_AddRefs(action));
|
||||
|
@ -400,11 +363,9 @@ nsBeckyFilters::CreateDistributeAction(const nsCString &aLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CreateLeaveOrDeleteAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
nsIMsgRuleAction **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::CreateLeaveOrDeleteAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
nsIMsgRuleAction **_retval) {
|
||||
nsresult rv;
|
||||
nsMsgRuleActionType actionType;
|
||||
if (aLine.CharAt(3) == '0') {
|
||||
|
@ -426,45 +387,38 @@ nsBeckyFilters::CreateLeaveOrDeleteAction(const nsCString &aLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::SetRuleAction(const nsCString &aLine, nsIMsgFilter *aFilter)
|
||||
{
|
||||
if (!aFilter || aLine.Length() < 4)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsresult nsBeckyFilters::SetRuleAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter) {
|
||||
if (!aFilter || aLine.Length() < 4) return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMsgRuleAction> action;
|
||||
switch (aLine.CharAt(1)) {
|
||||
case 'R': // Reply
|
||||
rv = CreateResendAction(aLine,
|
||||
aFilter,
|
||||
nsMsgFilterAction::Reply,
|
||||
case 'R': // Reply
|
||||
rv = CreateResendAction(aLine, aFilter, nsMsgFilterAction::Reply,
|
||||
getter_AddRefs(action));
|
||||
break;
|
||||
case 'F': // Forward
|
||||
rv = CreateResendAction(aLine,
|
||||
aFilter,
|
||||
nsMsgFilterAction::Forward,
|
||||
case 'F': // Forward
|
||||
rv = CreateResendAction(aLine, aFilter, nsMsgFilterAction::Forward,
|
||||
getter_AddRefs(action));
|
||||
break;
|
||||
case 'L': // Leave or delete
|
||||
case 'L': // Leave or delete
|
||||
rv = CreateLeaveOrDeleteAction(aLine, aFilter, getter_AddRefs(action));
|
||||
break;
|
||||
case 'Y': // Copy
|
||||
rv = CreateDistributeAction(aLine,
|
||||
aFilter,
|
||||
case 'Y': // Copy
|
||||
rv = CreateDistributeAction(aLine, aFilter,
|
||||
nsMsgFilterAction::CopyToFolder,
|
||||
getter_AddRefs(action));
|
||||
break;
|
||||
case 'M': // Move
|
||||
rv = CreateDistributeAction(aLine,
|
||||
aFilter,
|
||||
case 'M': // Move
|
||||
rv = CreateDistributeAction(aLine, aFilter,
|
||||
nsMsgFilterAction::MoveToFolder,
|
||||
getter_AddRefs(action));
|
||||
break;
|
||||
case 'G': // Set flag
|
||||
if (aLine.CharAt(3) == 'R') // Read
|
||||
rv = CreateRuleAction(aFilter, nsMsgFilterAction::MarkRead, getter_AddRefs(action));
|
||||
case 'G': // Set flag
|
||||
if (aLine.CharAt(3) == 'R') // Read
|
||||
rv = CreateRuleAction(aFilter, nsMsgFilterAction::MarkRead,
|
||||
getter_AddRefs(action));
|
||||
break;
|
||||
default:
|
||||
return NS_OK;
|
||||
|
@ -479,12 +433,10 @@ nsBeckyFilters::SetRuleAction(const nsCString &aLine, nsIMsgFilter *aFilter)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CreateFilter(bool aIncoming, nsIMsgFilter **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::CreateFilter(bool aIncoming, nsIMsgFilter **_retval) {
|
||||
NS_ENSURE_STATE(mServer);
|
||||
|
||||
nsCOMPtr <nsIMsgFilterList> filterList;
|
||||
nsCOMPtr<nsIMsgFilterList> filterList;
|
||||
nsresult rv = mServer->GetFilterList(nullptr, getter_AddRefs(filterList));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -495,7 +447,8 @@ nsBeckyFilters::CreateFilter(bool aIncoming, nsIMsgFilter **_retval)
|
|||
if (aIncoming)
|
||||
filter->SetFilterType(nsMsgFilterType::InboxRule | nsMsgFilterType::Manual);
|
||||
else
|
||||
filter->SetFilterType(nsMsgFilterType::PostOutgoing | nsMsgFilterType::Manual);
|
||||
filter->SetFilterType(nsMsgFilterType::PostOutgoing |
|
||||
nsMsgFilterType::Manual);
|
||||
|
||||
filter->SetEnabled(true);
|
||||
filter.forget(_retval);
|
||||
|
@ -503,12 +456,10 @@ nsBeckyFilters::CreateFilter(bool aIncoming, nsIMsgFilter **_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::AppendFilter(nsIMsgFilter *aFilter)
|
||||
{
|
||||
nsresult nsBeckyFilters::AppendFilter(nsIMsgFilter *aFilter) {
|
||||
NS_ENSURE_STATE(mServer);
|
||||
|
||||
nsCOMPtr <nsIMsgFilterList> filterList;
|
||||
nsCOMPtr<nsIMsgFilterList> filterList;
|
||||
nsresult rv = mServer->GetFilterList(nullptr, getter_AddRefs(filterList));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -519,9 +470,7 @@ nsBeckyFilters::AppendFilter(nsIMsgFilter *aFilter)
|
|||
return filterList->InsertFilterAt(count, aFilter);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming)
|
||||
{
|
||||
nsresult nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILineInputStream> lineStream;
|
||||
rv = nsBeckyUtils::CreateLineInputStream(aFile, getter_AddRefs(lineStream));
|
||||
|
@ -539,8 +488,7 @@ nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming)
|
|||
if (line.EqualsLiteral(":Begin \"\"")) {
|
||||
CreateFilter(aIncoming, getter_AddRefs(filter));
|
||||
} else if (line.EqualsLiteral(":End \"\"")) {
|
||||
if (filter)
|
||||
AppendFilter(filter);
|
||||
if (filter) AppendFilter(filter);
|
||||
filter = nullptr;
|
||||
}
|
||||
break;
|
||||
|
@ -550,7 +498,7 @@ nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming)
|
|||
case '@':
|
||||
SetSearchTerm(line, filter);
|
||||
break;
|
||||
case '$': // $X: disabled
|
||||
case '$': // $X: disabled
|
||||
if (StringBeginsWith(line, NS_LITERAL_CSTRING("$X")) && filter) {
|
||||
filter->SetEnabled(false);
|
||||
}
|
||||
|
@ -564,9 +512,7 @@ nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyFilters::Import(char16_t **aError,
|
||||
bool *_retval)
|
||||
{
|
||||
nsBeckyFilters::Import(char16_t **aError, bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aError);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -585,8 +531,7 @@ nsBeckyFilters::Import(char16_t **aError,
|
|||
bool retval = false;
|
||||
rv = AutoLocate(nullptr, getter_AddRefs(mLocation), &retval);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!retval)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!retval) return NS_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// What type of location do we have?
|
||||
|
@ -615,40 +560,40 @@ nsBeckyFilters::Import(char16_t **aError,
|
|||
nsAutoString fileName;
|
||||
rv = mLocation->GetLeafName(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (fileName.EqualsLiteral("OFilter.def"))
|
||||
haveIncoming = false;
|
||||
if (fileName.EqualsLiteral("OFilter.def")) haveIncoming = false;
|
||||
}
|
||||
|
||||
// Try importing from the passed in file or the default incoming filters file.
|
||||
if ((haveFile && haveIncoming) || (!haveFile &&
|
||||
NS_SUCCEEDED(GetFilterFile(true, mLocation, getter_AddRefs(filterFile)))))
|
||||
{
|
||||
if ((haveFile && haveIncoming) ||
|
||||
(!haveFile && NS_SUCCEEDED(GetFilterFile(true, mLocation,
|
||||
getter_AddRefs(filterFile))))) {
|
||||
rv = CollectServers();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(filterFile, getter_AddRefs(mConvertedFile));
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(filterFile,
|
||||
getter_AddRefs(mConvertedFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = ParseFilterFile(mConvertedFile, true);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*_retval = true;
|
||||
if (NS_SUCCEEDED(rv)) *_retval = true;
|
||||
|
||||
(void)RemoveConvertedFile();
|
||||
}
|
||||
|
||||
// If we didn't have a file passed (but a directory), try finding also outgoing filters.
|
||||
if ((haveFile && !haveIncoming) || (!haveFile &&
|
||||
NS_SUCCEEDED(GetFilterFile(false, mLocation, getter_AddRefs(filterFile)))))
|
||||
{
|
||||
// If we didn't have a file passed (but a directory), try finding also
|
||||
// outgoing filters.
|
||||
if ((haveFile && !haveIncoming) ||
|
||||
(!haveFile && NS_SUCCEEDED(GetFilterFile(false, mLocation,
|
||||
getter_AddRefs(filterFile))))) {
|
||||
rv = CollectServers();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(filterFile, getter_AddRefs(mConvertedFile));
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(filterFile,
|
||||
getter_AddRefs(mConvertedFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = ParseFilterFile(mConvertedFile, false);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*_retval = true;
|
||||
if (NS_SUCCEEDED(rv)) *_retval = true;
|
||||
|
||||
(void)RemoveConvertedFile();
|
||||
}
|
||||
|
@ -656,11 +601,9 @@ nsBeckyFilters::Import(char16_t **aError,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::FindMessageFolder(const nsAString &aName,
|
||||
nsIMsgFolder *aParentFolder,
|
||||
nsIMsgFolder **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::FindMessageFolder(const nsAString &aName,
|
||||
nsIMsgFolder *aParentFolder,
|
||||
nsIMsgFolder **_retval) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> found;
|
||||
|
@ -693,23 +636,19 @@ nsBeckyFilters::FindMessageFolder(const nsAString &aName,
|
|||
return NS_MSG_ERROR_INVALID_FOLDER_NAME;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::FindMessageFolderInServer(const nsAString &aName,
|
||||
nsIMsgIncomingServer *aServer,
|
||||
nsIMsgFolder **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::FindMessageFolderInServer(
|
||||
const nsAString &aName, nsIMsgIncomingServer *aServer,
|
||||
nsIMsgFolder **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIMsgFolder> rootFolder;
|
||||
nsCOMPtr<nsIMsgFolder> rootFolder;
|
||||
rv = aServer->GetRootMsgFolder(getter_AddRefs(rootFolder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return FindMessageFolder(aName, rootFolder, _retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::GetMessageFolder(const nsAString &aName,
|
||||
nsIMsgFolder **_retval)
|
||||
{
|
||||
nsresult nsBeckyFilters::GetMessageFolder(const nsAString &aName,
|
||||
nsIMsgFolder **_retval) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
|
@ -727,16 +666,13 @@ nsBeckyFilters::GetMessageFolder(const nsAString &aName,
|
|||
nsCOMPtr<nsIMsgFolder> found;
|
||||
for (uint32_t i = 0; i < accountCount; i++) {
|
||||
nsCOMPtr<nsIMsgAccount> account(do_QueryElementAt(accounts, i));
|
||||
if (!account)
|
||||
continue;
|
||||
if (!account) continue;
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
account->GetIncomingServer(getter_AddRefs(server));
|
||||
if (!server)
|
||||
continue;
|
||||
if (!server) continue;
|
||||
FindMessageFolderInServer(aName, server, getter_AddRefs(found));
|
||||
if (found)
|
||||
break;
|
||||
if (found) break;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
|
@ -747,17 +683,14 @@ nsBeckyFilters::GetMessageFolder(const nsAString &aName,
|
|||
FindMessageFolderInServer(aName, server, getter_AddRefs(found));
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return NS_MSG_ERROR_INVALID_FOLDER_NAME;
|
||||
if (!found) return NS_MSG_ERROR_INVALID_FOLDER_NAME;
|
||||
|
||||
found.forget(_retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::CollectServers()
|
||||
{
|
||||
nsresult nsBeckyFilters::CollectServers() {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
|
@ -772,25 +705,20 @@ nsBeckyFilters::CollectServers()
|
|||
// We can also import filters into the Local Folders account.
|
||||
rv = accountManager->GetLocalFoldersServer(getter_AddRefs(mServer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!mServer)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (!mServer) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyFilters::RemoveConvertedFile()
|
||||
{
|
||||
nsresult nsBeckyFilters::RemoveConvertedFile() {
|
||||
nsresult rv = NS_OK;
|
||||
if (mConvertedFile) {
|
||||
bool exists = false;
|
||||
mConvertedFile->Exists(&exists);
|
||||
if (exists) {
|
||||
rv = mConvertedFile->Remove(false);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mConvertedFile = nullptr;
|
||||
if (NS_SUCCEEDED(rv)) mConvertedFile = nullptr;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,16 +15,15 @@
|
|||
class nsIMsgFilter;
|
||||
class nsIMsgRuleAction;
|
||||
|
||||
class nsBeckyFilters final : public nsIImportFilters
|
||||
{
|
||||
public:
|
||||
class nsBeckyFilters final : public nsIImportFilters {
|
||||
public:
|
||||
nsBeckyFilters();
|
||||
static nsresult Create(nsIImportFilters **aImport);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTFILTERS
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsBeckyFilters();
|
||||
|
||||
nsCOMPtr<nsIFile> mLocation;
|
||||
|
@ -39,32 +38,29 @@ private:
|
|||
nsMsgSearchOpValue *aSearchOperator,
|
||||
nsString &aSearchKeyword);
|
||||
nsresult CollectServers();
|
||||
nsresult FindMessageFolder(const nsAString& aName,
|
||||
nsresult FindMessageFolder(const nsAString &aName,
|
||||
nsIMsgFolder *aParantFolder,
|
||||
nsIMsgFolder **_retval);
|
||||
nsresult FindMessageFolderInServer(const nsAString& aName,
|
||||
nsresult FindMessageFolderInServer(const nsAString &aName,
|
||||
nsIMsgIncomingServer *aServer,
|
||||
nsIMsgFolder **_retval);
|
||||
nsresult GetMessageFolder(const nsAString& aName, nsIMsgFolder **_retval);
|
||||
nsresult GetMessageFolder(const nsAString &aName, nsIMsgFolder **_retval);
|
||||
nsresult GetActionTarget(const nsCString &aLine, nsCString &aTarget);
|
||||
nsresult GetFolderNameFromTarget(const nsCString &aTarget, nsAString &aName);
|
||||
nsresult GetDistributeTarget(const nsCString &aLine,
|
||||
nsCString &aTargetFolder);
|
||||
nsresult GetResendTarget(const nsCString &aLine,
|
||||
nsCString &aTemplate,
|
||||
nsresult GetResendTarget(const nsCString &aLine, nsCString &aTemplate,
|
||||
nsCString &aTargetAddress);
|
||||
nsresult CreateRuleAction(nsIMsgFilter *aFilter,
|
||||
nsMsgRuleActionType actionType,
|
||||
nsIMsgRuleAction **_retval);
|
||||
nsresult CreateDistributeAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
nsresult CreateDistributeAction(const nsCString &aLine, nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType,
|
||||
nsIMsgRuleAction **_retval);
|
||||
nsresult CreateLeaveOrDeleteAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
nsIMsgRuleAction **_retval);
|
||||
nsresult CreateResendAction(const nsCString &aLine,
|
||||
nsIMsgFilter *aFilter,
|
||||
nsresult CreateResendAction(const nsCString &aLine, nsIMsgFilter *aFilter,
|
||||
const nsMsgRuleActionType &aActionType,
|
||||
nsIMsgRuleAction **_retval);
|
||||
nsresult CreateFilter(bool aIncoming, nsIMsgFilter **_retval);
|
||||
|
|
|
@ -26,58 +26,48 @@
|
|||
#include "nsBeckyFilters.h"
|
||||
#include "nsBeckyStringBundle.h"
|
||||
|
||||
nsBeckyImport::nsBeckyImport()
|
||||
{
|
||||
}
|
||||
nsBeckyImport::nsBeckyImport() {}
|
||||
|
||||
nsBeckyImport::~nsBeckyImport()
|
||||
{
|
||||
}
|
||||
nsBeckyImport::~nsBeckyImport() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBeckyImport, nsIImportModule)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyImport::GetName(char16_t **aName)
|
||||
{
|
||||
nsBeckyImport::GetName(char16_t **aName) {
|
||||
NS_ENSURE_ARG_POINTER(aName);
|
||||
*aName =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportName");
|
||||
*aName = nsBeckyStringBundle::GetStringByName("BeckyImportName");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyImport::GetDescription(char16_t **aDescription)
|
||||
{
|
||||
nsBeckyImport::GetDescription(char16_t **aDescription) {
|
||||
NS_ENSURE_ARG_POINTER(aDescription);
|
||||
*aDescription =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportDescription");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyImport::GetSupports(char **aSupports)
|
||||
{
|
||||
nsBeckyImport::GetSupports(char **aSupports) {
|
||||
NS_ENSURE_ARG_POINTER(aSupports);
|
||||
*aSupports = strdup(kBeckySupportsString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyImport::GetSupportsUpgrade(bool *aUpgrade)
|
||||
{
|
||||
nsBeckyImport::GetSupportsUpgrade(bool *aUpgrade) {
|
||||
NS_ENSURE_ARG_POINTER(aUpgrade);
|
||||
*aUpgrade = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyImport::GetMailImportInterface(nsISupports **aInterface)
|
||||
{
|
||||
nsresult nsBeckyImport::GetMailImportInterface(nsISupports **aInterface) {
|
||||
nsCOMPtr<nsIImportMail> importer;
|
||||
nsresult rv = nsBeckyMail::Create(getter_AddRefs(importer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIImportService> importService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> importService(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIImportGeneric> generic;
|
||||
rv = importService->CreateNewGenericMail(getter_AddRefs(generic));
|
||||
|
@ -88,7 +78,8 @@ nsBeckyImport::GetMailImportInterface(nsISupports **aInterface)
|
|||
nsString name;
|
||||
name.Adopt(nsBeckyStringBundle::GetStringByName("BeckyImportName"));
|
||||
|
||||
nsCOMPtr<nsISupportsString> nameString(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsISupportsString> nameString(
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nameString->SetData(name);
|
||||
|
@ -97,15 +88,15 @@ nsBeckyImport::GetMailImportInterface(nsISupports **aInterface)
|
|||
return CallQueryInterface(generic, aInterface);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyImport::GetAddressBookImportInterface(nsISupports **aInterface)
|
||||
{
|
||||
nsresult nsBeckyImport::GetAddressBookImportInterface(
|
||||
nsISupports **aInterface) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportAddressBooks> importer;
|
||||
rv = nsBeckyAddressBooks::Create(getter_AddRefs(importer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIImportService> importService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> importService(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIImportGeneric> generic;
|
||||
|
@ -116,9 +107,7 @@ nsBeckyImport::GetAddressBookImportInterface(nsISupports **aInterface)
|
|||
return CallQueryInterface(generic, aInterface);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyImport::GetSettingsImportInterface(nsISupports **aInterface)
|
||||
{
|
||||
nsresult nsBeckyImport::GetSettingsImportInterface(nsISupports **aInterface) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportSettings> importer;
|
||||
rv = nsBeckySettings::Create(getter_AddRefs(importer));
|
||||
|
@ -127,9 +116,7 @@ nsBeckyImport::GetSettingsImportInterface(nsISupports **aInterface)
|
|||
return CallQueryInterface(importer, aInterface);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyImport::GetFiltersImportInterface(nsISupports **aInterface)
|
||||
{
|
||||
nsresult nsBeckyImport::GetFiltersImportInterface(nsISupports **aInterface) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportFilters> importer;
|
||||
rv = nsBeckyFilters::Create(getter_AddRefs(importer));
|
||||
|
@ -139,14 +126,13 @@ nsBeckyImport::GetFiltersImportInterface(nsISupports **aInterface)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyImport::GetImportInterface(const char *aImportType, nsISupports **aInterface)
|
||||
{
|
||||
nsBeckyImport::GetImportInterface(const char *aImportType,
|
||||
nsISupports **aInterface) {
|
||||
NS_ENSURE_ARG_POINTER(aImportType);
|
||||
NS_ENSURE_ARG_POINTER(aInterface);
|
||||
|
||||
*aInterface = nullptr;
|
||||
if (!strcmp(aImportType, "mail"))
|
||||
return GetMailImportInterface(aInterface);
|
||||
if (!strcmp(aImportType, "mail")) return GetMailImportInterface(aInterface);
|
||||
if (!strcmp(aImportType, "addressbook"))
|
||||
return GetAddressBookImportInterface(aInterface);
|
||||
if (!strcmp(aImportType, "settings"))
|
||||
|
|
|
@ -8,29 +8,31 @@
|
|||
|
||||
#include "nsIImportModule.h"
|
||||
|
||||
#define NS_BECKYIMPORT_CID \
|
||||
{ \
|
||||
0x7952a6cf, 0x2442,0x4c04, \
|
||||
{0x9f, 0x02, 0x15, 0x0b, 0x15, 0xa0, 0xa8, 0x41}}
|
||||
#define NS_BECKYIMPORT_CID \
|
||||
{ \
|
||||
0x7952a6cf, 0x2442, 0x4c04, { \
|
||||
0x9f, 0x02, 0x15, 0x0b, 0x15, 0xa0, 0xa8, 0x41 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define kBeckySupportsString NS_IMPORT_MAIL_STR "," NS_IMPORT_ADDRESS_STR "," NS_IMPORT_SETTINGS_STR "," NS_IMPORT_FILTERS_STR
|
||||
#define kBeckySupportsString \
|
||||
NS_IMPORT_MAIL_STR "," NS_IMPORT_ADDRESS_STR "," NS_IMPORT_SETTINGS_STR \
|
||||
"," NS_IMPORT_FILTERS_STR
|
||||
|
||||
class nsBeckyImport final : public nsIImportModule
|
||||
{
|
||||
public:
|
||||
class nsBeckyImport final : public nsIImportModule {
|
||||
public:
|
||||
nsBeckyImport();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsBeckyImport();
|
||||
|
||||
nsresult GetMailImportInterface(nsISupports **aInterface);
|
||||
nsresult GetAddressBookImportInterface(nsISupports **aInterface);
|
||||
nsresult GetSettingsImportInterface(nsISupports **aInterface);
|
||||
nsresult GetFiltersImportInterface(nsISupports **aInterface);
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsBeckyImport_h___ */
|
||||
|
|
|
@ -34,35 +34,26 @@
|
|||
#define X_BECKY_INCLUDE_HEADER "X-Becky-Include"
|
||||
|
||||
enum {
|
||||
BECKY_STATUS_READ = 1 << 0,
|
||||
BECKY_STATUS_READ = 1 << 0,
|
||||
BECKY_STATUS_FORWARDED = 1 << 1,
|
||||
BECKY_STATUS_REPLIED = 1 << 2
|
||||
BECKY_STATUS_REPLIED = 1 << 2
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBeckyMail, nsIImportMail)
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::Create(nsIImportMail **aImport)
|
||||
{
|
||||
nsresult nsBeckyMail::Create(nsIImportMail **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsBeckyMail());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsBeckyMail::nsBeckyMail()
|
||||
: mReadBytes(0)
|
||||
{
|
||||
}
|
||||
nsBeckyMail::nsBeckyMail() : mReadBytes(0) {}
|
||||
|
||||
nsBeckyMail::~nsBeckyMail()
|
||||
{
|
||||
}
|
||||
nsBeckyMail::~nsBeckyMail() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyMail::GetDefaultLocation(nsIFile **aLocation,
|
||||
bool *aFound,
|
||||
bool *aUserVerify)
|
||||
{
|
||||
nsBeckyMail::GetDefaultLocation(nsIFile **aLocation, bool *aFound,
|
||||
bool *aUserVerify) {
|
||||
NS_ENSURE_ARG_POINTER(aFound);
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(aUserVerify);
|
||||
|
@ -76,9 +67,8 @@ nsBeckyMail::GetDefaultLocation(nsIFile **aLocation,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::CreateMailboxDescriptor(nsIImportMailboxDescriptor **aDescriptor)
|
||||
{
|
||||
nsresult nsBeckyMail::CreateMailboxDescriptor(
|
||||
nsIImportMailboxDescriptor **aDescriptor) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportService> importService;
|
||||
importService = do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv);
|
||||
|
@ -87,9 +77,7 @@ nsBeckyMail::CreateMailboxDescriptor(nsIImportMailboxDescriptor **aDescriptor)
|
|||
return importService->CreateNewMailboxDescriptor(aDescriptor);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::GetMailboxName(nsIFile *aMailbox, nsAString &aName)
|
||||
{
|
||||
nsresult nsBeckyMail::GetMailboxName(nsIFile *aMailbox, nsAString &aName) {
|
||||
nsCOMPtr<nsIFile> iniFile;
|
||||
nsBeckyUtils::GetMailboxINIFile(aMailbox, getter_AddRefs(iniFile));
|
||||
if (iniFile) {
|
||||
|
@ -113,12 +101,10 @@ nsBeckyMail::GetMailboxName(nsIFile *aMailbox, nsAString &aName)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::AppendMailboxDescriptor(nsIFile *aEntry,
|
||||
const nsString &aName,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected)
|
||||
{
|
||||
nsresult nsBeckyMail::AppendMailboxDescriptor(nsIFile *aEntry,
|
||||
const nsString &aName,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportMailboxDescriptor> descriptor;
|
||||
rv = CreateMailboxDescriptor(getter_AddRefs(descriptor));
|
||||
|
@ -146,11 +132,8 @@ nsBeckyMail::AppendMailboxDescriptor(nsIFile *aEntry,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::CollectMailboxesInFolderListFile(nsIFile *aListFile,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected)
|
||||
{
|
||||
nsresult nsBeckyMail::CollectMailboxesInFolderListFile(
|
||||
nsIFile *aListFile, uint32_t aDepth, nsIMutableArray *aCollected) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILineInputStream> lineStream;
|
||||
rv = nsBeckyUtils::CreateLineInputStream(aListFile,
|
||||
|
@ -168,8 +151,7 @@ nsBeckyMail::CollectMailboxesInFolderListFile(nsIFile *aListFile,
|
|||
rv = lineStream->ReadLine(folderName, &more);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (folderName.IsEmpty())
|
||||
continue;
|
||||
if (folderName.IsEmpty()) continue;
|
||||
|
||||
nsCOMPtr<nsIFile> folder;
|
||||
rv = parent->Clone(getter_AddRefs(folder));
|
||||
|
@ -185,11 +167,9 @@ nsBeckyMail::CollectMailboxesInFolderListFile(nsIFile *aListFile,
|
|||
return isEmpty ? NS_ERROR_FILE_NOT_FOUND : NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::CollectMailboxesInDirectory(nsIFile *aDirectory,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected)
|
||||
{
|
||||
nsresult nsBeckyMail::CollectMailboxesInDirectory(nsIFile *aDirectory,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected) {
|
||||
nsAutoString mailboxName;
|
||||
nsresult rv = GetMailboxName(aDirectory, mailboxName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -198,7 +178,8 @@ nsBeckyMail::CollectMailboxesInDirectory(nsIFile *aDirectory,
|
|||
AppendMailboxDescriptor(aDirectory, mailboxName, aDepth, aCollected);
|
||||
|
||||
nsCOMPtr<nsIFile> folderListFile;
|
||||
rv = nsBeckyUtils::GetFolderListFile(aDirectory, getter_AddRefs(folderListFile));
|
||||
rv = nsBeckyUtils::GetFolderListFile(aDirectory,
|
||||
getter_AddRefs(folderListFile));
|
||||
bool folderListExists = false;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -245,8 +226,7 @@ nsBeckyMail::CollectMailboxesInDirectory(nsIFile *aDirectory,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyMail::FindMailboxes(nsIFile *aLocation, nsIArray **_retval)
|
||||
{
|
||||
nsBeckyMail::FindMailboxes(nsIFile *aLocation, nsIArray **_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -262,23 +242,19 @@ nsBeckyMail::FindMailboxes(nsIFile *aLocation, nsIArray **_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
GetBeckyStatusValue(const nsCString &aHeader, nsACString &aValue)
|
||||
{
|
||||
static nsresult GetBeckyStatusValue(const nsCString &aHeader,
|
||||
nsACString &aValue) {
|
||||
int32_t valueStartPosition;
|
||||
|
||||
valueStartPosition = aHeader.FindChar(':');
|
||||
if (valueStartPosition < 0)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (valueStartPosition < 0) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
valueStartPosition++;
|
||||
|
||||
int32_t commaPosition = aHeader.FindChar(',', valueStartPosition);
|
||||
if (commaPosition < 0)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (commaPosition < 0) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsAutoCString value(Substring(aHeader,
|
||||
valueStartPosition,
|
||||
nsAutoCString value(Substring(aHeader, valueStartPosition,
|
||||
commaPosition - valueStartPosition));
|
||||
value.Trim(" \t");
|
||||
|
||||
|
@ -287,14 +263,12 @@ GetBeckyStatusValue(const nsCString &aHeader, nsACString &aValue)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
GetBeckyIncludeValue(const nsCString &aHeader, nsACString &aValue)
|
||||
{
|
||||
static nsresult GetBeckyIncludeValue(const nsCString &aHeader,
|
||||
nsACString &aValue) {
|
||||
int32_t valueStartPosition;
|
||||
|
||||
valueStartPosition = aHeader.FindChar(':');
|
||||
if (valueStartPosition < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (valueStartPosition < 0) return NS_ERROR_FAILURE;
|
||||
|
||||
valueStartPosition++;
|
||||
nsAutoCString value(Substring(aHeader, valueStartPosition));
|
||||
|
@ -305,19 +279,17 @@ GetBeckyIncludeValue(const nsCString &aHeader, nsACString &aValue)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
ConvertBeckyStatusToMozillaStatus(const nsCString &aHeader,
|
||||
nsMsgMessageFlagType *aMozillaStatusFlag)
|
||||
{
|
||||
static bool ConvertBeckyStatusToMozillaStatus(
|
||||
const nsCString &aHeader, nsMsgMessageFlagType *aMozillaStatusFlag) {
|
||||
nsresult rv;
|
||||
nsAutoCString statusString;
|
||||
rv = GetBeckyStatusValue(aHeader, statusString);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
nsresult errorCode;
|
||||
uint32_t beckyStatusFlag = static_cast<uint32_t>(statusString.ToInteger(&errorCode, 16));
|
||||
if (NS_FAILED(errorCode))
|
||||
return false;
|
||||
uint32_t beckyStatusFlag =
|
||||
static_cast<uint32_t>(statusString.ToInteger(&errorCode, 16));
|
||||
if (NS_FAILED(errorCode)) return false;
|
||||
|
||||
if (beckyStatusFlag & BECKY_STATUS_READ)
|
||||
*aMozillaStatusFlag |= nsMsgMessageFlags::Read;
|
||||
|
@ -329,54 +301,41 @@ ConvertBeckyStatusToMozillaStatus(const nsCString &aHeader,
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
CheckHeaderKey(const nsCString &aHeader, const char *aKeyString)
|
||||
{
|
||||
static inline bool CheckHeaderKey(const nsCString &aHeader,
|
||||
const char *aKeyString) {
|
||||
nsAutoCString key(StringHead(aHeader, aHeader.FindChar(':')));
|
||||
key.Trim(" \t");
|
||||
return key.Equals(aKeyString);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsBeckyStatusHeader(const nsCString &aHeader)
|
||||
{
|
||||
static inline bool IsBeckyStatusHeader(const nsCString &aHeader) {
|
||||
return CheckHeaderKey(aHeader, X_BECKY_STATUS_HEADER);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsBeckyIncludeLine(const nsCString &aLine)
|
||||
{
|
||||
static inline bool IsBeckyIncludeLine(const nsCString &aLine) {
|
||||
return CheckHeaderKey(aLine, X_BECKY_INCLUDE_HEADER);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsEndOfHeaders(const nsCString &aLine)
|
||||
{
|
||||
static inline bool IsEndOfHeaders(const nsCString &aLine) {
|
||||
return aLine.IsEmpty();
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsEndOfMessage(const nsCString &aLine)
|
||||
{
|
||||
static inline bool IsEndOfMessage(const nsCString &aLine) {
|
||||
return aLine.EqualsLiteral(".");
|
||||
}
|
||||
|
||||
class ImportMessageRunnable: public mozilla::Runnable
|
||||
{
|
||||
public:
|
||||
ImportMessageRunnable(nsIFile *aMessageFile,
|
||||
nsIMsgFolder *aFolder);
|
||||
class ImportMessageRunnable : public mozilla::Runnable {
|
||||
public:
|
||||
ImportMessageRunnable(nsIFile *aMessageFile, nsIMsgFolder *aFolder);
|
||||
NS_DECL_NSIRUNNABLE
|
||||
nsresult mResult;
|
||||
|
||||
private:
|
||||
private:
|
||||
nsresult WriteHeaders(nsCString &aHeaders, nsIOutputStream *aOutputStream);
|
||||
nsresult HandleHeaderLine(const nsCString &aHeaderLine, nsACString &aHeaders);
|
||||
nsresult GetAttachmentFile(nsIFile *aMailboxFile,
|
||||
const nsCString &aHeader,
|
||||
nsresult GetAttachmentFile(nsIFile *aMailboxFile, const nsCString &aHeader,
|
||||
nsIFile **_retval);
|
||||
nsresult WriteAttachmentFile(nsIFile *aMailboxFile,
|
||||
const nsCString &aHeader,
|
||||
nsresult WriteAttachmentFile(nsIFile *aMailboxFile, const nsCString &aHeader,
|
||||
nsIOutputStream *aOutputStream);
|
||||
|
||||
nsCOMPtr<nsIFile> mMessageFile;
|
||||
|
@ -384,16 +343,13 @@ private:
|
|||
};
|
||||
|
||||
ImportMessageRunnable::ImportMessageRunnable(nsIFile *aMessageFile,
|
||||
nsIMsgFolder *aFolder) :
|
||||
mozilla::Runnable("ImportMessageRunnable"),
|
||||
mMessageFile(aMessageFile), mFolder(aFolder)
|
||||
{
|
||||
}
|
||||
nsIMsgFolder *aFolder)
|
||||
: mozilla::Runnable("ImportMessageRunnable"),
|
||||
mMessageFile(aMessageFile),
|
||||
mFolder(aFolder) {}
|
||||
|
||||
nsresult
|
||||
ImportMessageRunnable::WriteHeaders(nsCString &aHeaders,
|
||||
nsIOutputStream *aOutputStream)
|
||||
{
|
||||
nsresult ImportMessageRunnable::WriteHeaders(nsCString &aHeaders,
|
||||
nsIOutputStream *aOutputStream) {
|
||||
nsresult rv;
|
||||
uint32_t writtenBytes = 0;
|
||||
|
||||
|
@ -401,17 +357,16 @@ ImportMessageRunnable::WriteHeaders(nsCString &aHeaders,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = aOutputStream->Write(aHeaders.get(), aHeaders.Length(), &writtenBytes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = aOutputStream->Write(MSG_LINEBREAK, strlen(MSG_LINEBREAK), &writtenBytes);
|
||||
rv =
|
||||
aOutputStream->Write(MSG_LINEBREAK, strlen(MSG_LINEBREAK), &writtenBytes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aHeaders.Truncate();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ImportMessageRunnable::HandleHeaderLine(const nsCString &aHeaderLine,
|
||||
nsACString &aHeaders)
|
||||
{
|
||||
nsresult ImportMessageRunnable::HandleHeaderLine(const nsCString &aHeaderLine,
|
||||
nsACString &aHeaders) {
|
||||
aHeaders.Append(aHeaderLine);
|
||||
aHeaders.AppendLiteral(MSG_LINEBREAK);
|
||||
|
||||
|
@ -428,11 +383,9 @@ ImportMessageRunnable::HandleHeaderLine(const nsCString &aHeaderLine,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ImportMessageRunnable::GetAttachmentFile(nsIFile *aMailboxFile,
|
||||
const nsCString &aHeader,
|
||||
nsIFile **_retval)
|
||||
{
|
||||
nsresult ImportMessageRunnable::GetAttachmentFile(nsIFile *aMailboxFile,
|
||||
const nsCString &aHeader,
|
||||
nsIFile **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> attachmentFile;
|
||||
|
||||
|
@ -451,50 +404,44 @@ ImportMessageRunnable::GetAttachmentFile(nsIFile *aMailboxFile,
|
|||
|
||||
bool exists = false;
|
||||
attachmentFile->Exists(&exists);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
attachmentFile.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ImportMessageRunnable::WriteAttachmentFile(nsIFile *aMailboxFile,
|
||||
const nsCString &aHeader,
|
||||
nsIOutputStream *aOutputStream)
|
||||
{
|
||||
nsresult ImportMessageRunnable::WriteAttachmentFile(
|
||||
nsIFile *aMailboxFile, const nsCString &aHeader,
|
||||
nsIOutputStream *aOutputStream) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> parentDirectory;
|
||||
rv = aMailboxFile->GetParent(getter_AddRefs(parentDirectory));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> attachmentFile;
|
||||
rv = GetAttachmentFile(parentDirectory,
|
||||
aHeader,
|
||||
rv = GetAttachmentFile(parentDirectory, aHeader,
|
||||
getter_AddRefs(attachmentFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream),
|
||||
attachmentFile);
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), attachmentFile);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
char buffer[FILE_IO_BUFFER_SIZE];
|
||||
uint32_t readBytes = 0;
|
||||
uint32_t writtenBytes = 0;
|
||||
rv = aOutputStream->Write(MSG_LINEBREAK, strlen(MSG_LINEBREAK), &writtenBytes);
|
||||
rv =
|
||||
aOutputStream->Write(MSG_LINEBREAK, strlen(MSG_LINEBREAK), &writtenBytes);
|
||||
while (NS_SUCCEEDED(inputStream->Read(buffer, sizeof(buffer), &readBytes)) &&
|
||||
readBytes > 0) {
|
||||
rv = aOutputStream->Write(buffer, readBytes, &writtenBytes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportMessageRunnable::Run()
|
||||
{
|
||||
NS_IMETHODIMP ImportMessageRunnable::Run() {
|
||||
nsCOMPtr<nsIMsgPluggableStore> msgStore;
|
||||
mResult = mFolder->GetMsgStore(getter_AddRefs(msgStore));
|
||||
NS_ENSURE_SUCCESS(mResult, NS_OK);
|
||||
|
@ -507,8 +454,8 @@ NS_IMETHODIMP ImportMessageRunnable::Run()
|
|||
bool reusable;
|
||||
nsCOMPtr<nsIMsgDBHdr> msgHdr;
|
||||
nsCOMPtr<nsIOutputStream> outputStream;
|
||||
mResult = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
|
||||
getter_AddRefs(outputStream));
|
||||
mResult = msgStore->GetNewMsgOutputStream(
|
||||
mFolder, getter_AddRefs(msgHdr), &reusable, getter_AddRefs(outputStream));
|
||||
NS_ENSURE_SUCCESS(mResult, NS_OK);
|
||||
|
||||
bool inHeader = true;
|
||||
|
@ -517,8 +464,7 @@ NS_IMETHODIMP ImportMessageRunnable::Run()
|
|||
while (NS_SUCCEEDED(mResult) && more) {
|
||||
nsAutoCString line;
|
||||
mResult = lineStream->ReadLine(line, &more);
|
||||
if (NS_FAILED(mResult))
|
||||
break;
|
||||
if (NS_FAILED(mResult)) break;
|
||||
|
||||
if (inHeader) {
|
||||
if (IsEndOfHeaders(line)) {
|
||||
|
@ -530,9 +476,9 @@ NS_IMETHODIMP ImportMessageRunnable::Run()
|
|||
} else if (IsEndOfMessage(line)) {
|
||||
inHeader = true;
|
||||
mResult = msgStore->FinishNewMessage(outputStream, msgHdr);
|
||||
if (!reusable)
|
||||
outputStream->Close();
|
||||
mResult = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
|
||||
if (!reusable) outputStream->Close();
|
||||
mResult = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr),
|
||||
&reusable,
|
||||
getter_AddRefs(outputStream));
|
||||
} else if (IsBeckyIncludeLine(line)) {
|
||||
mResult = WriteAttachmentFile(mMessageFile, line, outputStream);
|
||||
|
@ -549,44 +495,35 @@ NS_IMETHODIMP ImportMessageRunnable::Run()
|
|||
}
|
||||
|
||||
if (outputStream) {
|
||||
if (NS_FAILED(mResult))
|
||||
msgStore->DiscardNewMessage(outputStream, msgHdr);
|
||||
if (NS_FAILED(mResult)) msgStore->DiscardNewMessage(outputStream, msgHdr);
|
||||
outputStream->Close();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static
|
||||
nsresult ProxyImportMessage(nsIFile *aMessageFile,
|
||||
nsIMsgFolder *aFolder)
|
||||
{
|
||||
static nsresult ProxyImportMessage(nsIFile *aMessageFile,
|
||||
nsIMsgFolder *aFolder) {
|
||||
RefPtr<ImportMessageRunnable> importMessage =
|
||||
new ImportMessageRunnable(aMessageFile, aFolder);
|
||||
new ImportMessageRunnable(aMessageFile, aFolder);
|
||||
nsresult rv = NS_DispatchToMainThread(importMessage, NS_DISPATCH_SYNC);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return importMessage->mResult;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyMail::ImportMailFile(nsIFile *aMailFile,
|
||||
nsIMsgFolder *aDestination)
|
||||
{
|
||||
nsresult nsBeckyMail::ImportMailFile(nsIFile *aMailFile,
|
||||
nsIMsgFolder *aDestination) {
|
||||
int64_t size;
|
||||
aMailFile->GetFileSize(&size);
|
||||
if (size == 0)
|
||||
return NS_OK;
|
||||
if (size == 0) return NS_OK;
|
||||
|
||||
return ProxyImportMessage(aMailFile, aDestination);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyMail::ImportMailbox(nsIImportMailboxDescriptor *aSource,
|
||||
nsIMsgFolder *aDestination,
|
||||
char16_t **aErrorLog,
|
||||
char16_t **aSuccessLog,
|
||||
bool *aFatalError)
|
||||
{
|
||||
nsIMsgFolder *aDestination, char16_t **aErrorLog,
|
||||
char16_t **aSuccessLog, bool *aFatalError) {
|
||||
NS_ENSURE_ARG_POINTER(aSource);
|
||||
NS_ENSURE_ARG_POINTER(aDestination);
|
||||
NS_ENSURE_ARG_POINTER(aErrorLog);
|
||||
|
@ -611,12 +548,9 @@ nsBeckyMail::ImportMailbox(nsIImportMailboxDescriptor *aSource,
|
|||
aSource->GetDisplayName(getter_Copies(name));
|
||||
|
||||
nsAutoString successMessage;
|
||||
const char16_t *format = { name.get() };
|
||||
rv =
|
||||
nsBeckyStringBundle::FormatStringFromName("BeckyImportMailboxSuccess",
|
||||
&format,
|
||||
1,
|
||||
successMessage);
|
||||
const char16_t *format = {name.get()};
|
||||
rv = nsBeckyStringBundle::FormatStringFromName("BeckyImportMailboxSuccess",
|
||||
&format, 1, successMessage);
|
||||
successMessage.AppendLiteral("\n");
|
||||
*aSuccessLog = ToNewUnicode(successMessage);
|
||||
|
||||
|
@ -624,17 +558,14 @@ nsBeckyMail::ImportMailbox(nsIImportMailboxDescriptor *aSource,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyMail::GetImportProgress(uint32_t *_retval)
|
||||
{
|
||||
nsBeckyMail::GetImportProgress(uint32_t *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = mReadBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckyMail::TranslateFolderName(const nsAString & aFolderName,
|
||||
nsAString & _retval)
|
||||
{
|
||||
nsBeckyMail::TranslateFolderName(const nsAString &aFolderName,
|
||||
nsAString &_retval) {
|
||||
return nsBeckyUtils::TranslateFolderName(aFolderName, _retval);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,32 +12,27 @@ class nsIFile;
|
|||
class nsIMutableArray;
|
||||
class nsIMsgFolder;
|
||||
|
||||
class nsBeckyMail final : public nsIImportMail
|
||||
{
|
||||
public:
|
||||
class nsBeckyMail final : public nsIImportMail {
|
||||
public:
|
||||
nsBeckyMail();
|
||||
static nsresult Create(nsIImportMail **aImport);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTMAIL
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsBeckyMail();
|
||||
|
||||
uint32_t mReadBytes;
|
||||
|
||||
nsresult CollectMailboxesInDirectory(nsIFile *aDirectory,
|
||||
uint32_t aDepth,
|
||||
nsresult CollectMailboxesInDirectory(nsIFile *aDirectory, uint32_t aDepth,
|
||||
nsIMutableArray *aCollected);
|
||||
nsresult CollectMailboxesInFolderListFile(nsIFile *aListFile,
|
||||
uint32_t aDepth,
|
||||
nsresult CollectMailboxesInFolderListFile(nsIFile *aListFile, uint32_t aDepth,
|
||||
nsIMutableArray *aCollected);
|
||||
nsresult AppendMailboxDescriptor(nsIFile *aEntry,
|
||||
const nsString &aName,
|
||||
nsresult AppendMailboxDescriptor(nsIFile *aEntry, const nsString &aName,
|
||||
uint32_t aDepth,
|
||||
nsIMutableArray *aCollected);
|
||||
nsresult ImportMailFile(nsIFile *aMailFile,
|
||||
nsIMsgFolder *aDestination);
|
||||
nsresult ImportMailFile(nsIFile *aMailFile, nsIMsgFolder *aDestination);
|
||||
nsresult CreateMailboxDescriptor(nsIImportMailboxDescriptor **aDescriptor);
|
||||
nsresult GetMailboxName(nsIFile *aMailbox, nsAString &aName);
|
||||
};
|
||||
|
|
|
@ -20,38 +20,30 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsBeckySettings, nsIImportSettings)
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::Create(nsIImportSettings **aImport)
|
||||
{
|
||||
nsresult nsBeckySettings::Create(nsIImportSettings **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsBeckySettings());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsBeckySettings::nsBeckySettings()
|
||||
{
|
||||
}
|
||||
nsBeckySettings::nsBeckySettings() {}
|
||||
|
||||
nsBeckySettings::~nsBeckySettings()
|
||||
{
|
||||
}
|
||||
nsBeckySettings::~nsBeckySettings() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckySettings::AutoLocate(char16_t **aDescription,
|
||||
nsIFile **aLocation,
|
||||
bool *_retval)
|
||||
{
|
||||
nsBeckySettings::AutoLocate(char16_t **aDescription, nsIFile **aLocation,
|
||||
bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aDescription);
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*aDescription =
|
||||
nsBeckyStringBundle::GetStringByName("BeckyImportName");
|
||||
*aDescription = nsBeckyStringBundle::GetStringByName("BeckyImportName");
|
||||
*aLocation = nullptr;
|
||||
*_retval = false;
|
||||
|
||||
nsCOMPtr<nsIFile> location;
|
||||
nsresult rv = nsBeckyUtils::GetDefaultMailboxINIFile(getter_AddRefs(location));
|
||||
nsresult rv =
|
||||
nsBeckyUtils::GetDefaultMailboxINIFile(getter_AddRefs(location));
|
||||
if (NS_FAILED(rv))
|
||||
location = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
else
|
||||
|
@ -62,44 +54,41 @@ nsBeckySettings::AutoLocate(char16_t **aDescription,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckySettings::SetLocation(nsIFile *aLocation)
|
||||
{
|
||||
nsBeckySettings::SetLocation(nsIFile *aLocation) {
|
||||
mLocation = aLocation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::CreateParser()
|
||||
{
|
||||
nsresult nsBeckySettings::CreateParser() {
|
||||
if (!mLocation) {
|
||||
nsresult rv = nsBeckyUtils::GetDefaultMailboxINIFile(getter_AddRefs(mLocation));
|
||||
nsresult rv =
|
||||
nsBeckyUtils::GetDefaultMailboxINIFile(getter_AddRefs(mLocation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// nsIINIParser accepts only UTF-8 encoding, so we need to convert the file
|
||||
// first.
|
||||
nsresult rv;
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(mLocation, getter_AddRefs(mConvertedFile));
|
||||
rv = nsBeckyUtils::ConvertToUTF8File(mLocation,
|
||||
getter_AddRefs(mConvertedFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return nsBeckyUtils::CreateINIParserForFile(mConvertedFile,
|
||||
getter_AddRefs(mParser));
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::CreateSmtpServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
nsISmtpServer **aServer,
|
||||
bool *existing)
|
||||
{
|
||||
nsresult nsBeckySettings::CreateSmtpServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
nsISmtpServer **aServer,
|
||||
bool *existing) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsISmtpService> smtpService = do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsISmtpService> smtpService =
|
||||
do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISmtpServer> server;
|
||||
rv = smtpService->FindServer(aUserName.get(),
|
||||
aServerName.get(),
|
||||
rv = smtpService->FindServer(aUserName.get(), aServerName.get(),
|
||||
getter_AddRefs(server));
|
||||
|
||||
if (NS_FAILED(rv) || !server) {
|
||||
|
@ -118,26 +107,21 @@ nsBeckySettings::CreateSmtpServer(const nsCString &aUserName,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::CreateIncomingServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
const nsCString &aProtocol,
|
||||
nsIMsgIncomingServer **aServer)
|
||||
{
|
||||
nsresult nsBeckySettings::CreateIncomingServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
const nsCString &aProtocol,
|
||||
nsIMsgIncomingServer **aServer) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> incomingServer;
|
||||
rv = accountManager->FindServer(aUserName,
|
||||
aServerName,
|
||||
aProtocol,
|
||||
rv = accountManager->FindServer(aUserName, aServerName, aProtocol,
|
||||
getter_AddRefs(incomingServer));
|
||||
|
||||
if (NS_FAILED(rv) || !incomingServer) {
|
||||
rv = accountManager->CreateIncomingServer(aUserName,
|
||||
aServerName,
|
||||
aProtocol,
|
||||
rv = accountManager->CreateIncomingServer(aUserName, aServerName, aProtocol,
|
||||
getter_AddRefs(incomingServer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -146,22 +130,19 @@ nsBeckySettings::CreateIncomingServer(const nsCString &aUserName,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::SetupSmtpServer(nsISmtpServer **aServer)
|
||||
{
|
||||
nsresult nsBeckySettings::SetupSmtpServer(nsISmtpServer **aServer) {
|
||||
nsresult rv;
|
||||
nsAutoCString userName, serverName;
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SMTPServer"),
|
||||
serverName);
|
||||
NS_LITERAL_CSTRING("SMTPServer"), serverName);
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("UserID"),
|
||||
userName);
|
||||
NS_LITERAL_CSTRING("UserID"), userName);
|
||||
|
||||
nsCOMPtr<nsISmtpServer> server;
|
||||
bool existing = false;
|
||||
rv = CreateSmtpServer(userName, serverName, getter_AddRefs(server), &existing);
|
||||
rv =
|
||||
CreateSmtpServer(userName, serverName, getter_AddRefs(server), &existing);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// If we already have an existing server, do not touch it's settings.
|
||||
|
@ -172,8 +153,7 @@ nsBeckySettings::SetupSmtpServer(nsISmtpServer **aServer)
|
|||
|
||||
nsAutoCString value;
|
||||
rv = mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SMTPPort"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("SMTPPort"), value);
|
||||
int32_t port = 25;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsresult errorCode;
|
||||
|
@ -182,23 +162,18 @@ nsBeckySettings::SetupSmtpServer(nsISmtpServer **aServer)
|
|||
server->SetPort(port);
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SSLSMTP"),
|
||||
value);
|
||||
if (value.EqualsLiteral("1"))
|
||||
server->SetSocketType(nsMsgSocketType::SSL);
|
||||
NS_LITERAL_CSTRING("SSLSMTP"), value);
|
||||
if (value.EqualsLiteral("1")) server->SetSocketType(nsMsgSocketType::SSL);
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SMTPAUTH"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("SMTPAUTH"), value);
|
||||
if (value.EqualsLiteral("1")) {
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SMTPAUTHMODE"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("SMTPAUTHMODE"), value);
|
||||
nsMsgAuthMethodValue authMethod = nsMsgAuthMethod::none;
|
||||
if (value.EqualsLiteral("1")) {
|
||||
authMethod = nsMsgAuthMethod::passwordEncrypted;
|
||||
} else if (value.EqualsLiteral("2") ||
|
||||
value.EqualsLiteral("4") ||
|
||||
} else if (value.EqualsLiteral("2") || value.EqualsLiteral("4") ||
|
||||
value.EqualsLiteral("6")) {
|
||||
authMethod = nsMsgAuthMethod::passwordCleartext;
|
||||
} else {
|
||||
|
@ -212,15 +187,14 @@ nsBeckySettings::SetupSmtpServer(nsISmtpServer **aServer)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::SetPop3ServerProperties(nsIMsgIncomingServer *aServer)
|
||||
{
|
||||
nsresult nsBeckySettings::SetPop3ServerProperties(
|
||||
nsIMsgIncomingServer *aServer) {
|
||||
nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(aServer);
|
||||
|
||||
nsAutoCString value;
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("POP3Auth"),
|
||||
value); // 0: plain, 1: APOP, 2: CRAM-MD5, 3: NTLM
|
||||
value); // 0: plain, 1: APOP, 2: CRAM-MD5, 3: NTLM
|
||||
nsMsgAuthMethodValue authMethod;
|
||||
if (value.IsEmpty() || value.EqualsLiteral("0")) {
|
||||
authMethod = nsMsgAuthMethod::passwordCleartext;
|
||||
|
@ -236,15 +210,12 @@ nsBeckySettings::SetPop3ServerProperties(nsIMsgIncomingServer *aServer)
|
|||
aServer->SetAuthMethod(authMethod);
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("LeaveServer"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("LeaveServer"), value);
|
||||
if (value.EqualsLiteral("1")) {
|
||||
pop3Server->SetLeaveMessagesOnServer(true);
|
||||
nsresult rv = mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("KeepDays"),
|
||||
value);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
NS_LITERAL_CSTRING("KeepDays"), value);
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
||||
nsresult errorCode;
|
||||
int32_t leftDays = value.ToInteger(&errorCode, 10);
|
||||
|
@ -257,13 +228,10 @@ nsBeckySettings::SetPop3ServerProperties(nsIMsgIncomingServer *aServer)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::SetupIncomingServer(nsIMsgIncomingServer **aServer)
|
||||
{
|
||||
nsresult nsBeckySettings::SetupIncomingServer(nsIMsgIncomingServer **aServer) {
|
||||
nsAutoCString value;
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("Protocol"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("Protocol"), value);
|
||||
nsCString protocol;
|
||||
if (value.EqualsLiteral("1")) {
|
||||
protocol = NS_LITERAL_CSTRING("imap");
|
||||
|
@ -273,15 +241,14 @@ nsBeckySettings::SetupIncomingServer(nsIMsgIncomingServer **aServer)
|
|||
|
||||
nsAutoCString userName, serverName;
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("MailServer"),
|
||||
serverName);
|
||||
NS_LITERAL_CSTRING("MailServer"), serverName);
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("UserID"),
|
||||
userName);
|
||||
NS_LITERAL_CSTRING("UserID"), userName);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
rv = CreateIncomingServer(userName, serverName, protocol, getter_AddRefs(server));
|
||||
rv = CreateIncomingServer(userName, serverName, protocol,
|
||||
getter_AddRefs(server));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bool isSecure = false;
|
||||
|
@ -290,48 +257,37 @@ nsBeckySettings::SetupIncomingServer(nsIMsgIncomingServer **aServer)
|
|||
if (protocol.EqualsLiteral("pop3")) {
|
||||
SetPop3ServerProperties(server);
|
||||
rv = mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("POP3Port"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("POP3Port"), value);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
port = value.ToInteger(&errorCode, 10);
|
||||
else
|
||||
port = 110;
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SSLPOP"),
|
||||
value);
|
||||
if (value.EqualsLiteral("1"))
|
||||
isSecure = true;
|
||||
NS_LITERAL_CSTRING("SSLPOP"), value);
|
||||
if (value.EqualsLiteral("1")) isSecure = true;
|
||||
} else if (protocol.EqualsLiteral("imap")) {
|
||||
rv = mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("IMAP4Port"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("IMAP4Port"), value);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
port = value.ToInteger(&errorCode, 10);
|
||||
else
|
||||
port = 143;
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("SSLIMAP"),
|
||||
value);
|
||||
if (value.EqualsLiteral("1"))
|
||||
isSecure = true;
|
||||
NS_LITERAL_CSTRING("SSLIMAP"), value);
|
||||
if (value.EqualsLiteral("1")) isSecure = true;
|
||||
}
|
||||
|
||||
server->SetPort(port);
|
||||
if (isSecure)
|
||||
server->SetSocketType(nsMsgSocketType::SSL);
|
||||
if (isSecure) server->SetSocketType(nsMsgSocketType::SSL);
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("CheckInt"),
|
||||
value);
|
||||
if (value.EqualsLiteral("1"))
|
||||
server->SetDoBiff(true);
|
||||
NS_LITERAL_CSTRING("CheckInt"), value);
|
||||
if (value.EqualsLiteral("1")) server->SetDoBiff(true);
|
||||
rv = mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("CheckEvery"),
|
||||
value);
|
||||
NS_LITERAL_CSTRING("CheckEvery"), value);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
int32_t minutes = value.ToInteger(&errorCode, 10);
|
||||
if (NS_SUCCEEDED(errorCode))
|
||||
server->SetBiffMinutes(minutes);
|
||||
if (NS_SUCCEEDED(errorCode)) server->SetBiffMinutes(minutes);
|
||||
}
|
||||
|
||||
server.forget(aServer);
|
||||
|
@ -339,27 +295,21 @@ nsBeckySettings::SetupIncomingServer(nsIMsgIncomingServer **aServer)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::CreateIdentity(nsIMsgIdentity **aIdentity)
|
||||
{
|
||||
nsresult nsBeckySettings::CreateIdentity(nsIMsgIdentity **aIdentity) {
|
||||
nsAutoCString email, fullName, identityName, bccAddress;
|
||||
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("Name"),
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"), NS_LITERAL_CSTRING("Name"),
|
||||
identityName);
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("YourName"),
|
||||
fullName);
|
||||
NS_LITERAL_CSTRING("YourName"), fullName);
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("MailAddress"),
|
||||
email);
|
||||
NS_LITERAL_CSTRING("MailAddress"), email);
|
||||
mParser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("PermBcc"),
|
||||
bccAddress);
|
||||
NS_LITERAL_CSTRING("PermBcc"), bccAddress);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMsgIdentity> identity;
|
||||
|
@ -379,14 +329,12 @@ nsBeckySettings::CreateIdentity(nsIMsgIdentity **aIdentity)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::CreateAccount(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgIncomingServer *aIncomingServer,
|
||||
nsIMsgAccount **aAccount)
|
||||
{
|
||||
nsresult nsBeckySettings::CreateAccount(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgIncomingServer *aIncomingServer,
|
||||
nsIMsgAccount **aAccount) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
|
@ -404,14 +352,11 @@ nsBeckySettings::CreateAccount(nsIMsgIdentity *aIdentity,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckySettings::RemoveConvertedFile()
|
||||
{
|
||||
nsresult nsBeckySettings::RemoveConvertedFile() {
|
||||
if (mConvertedFile) {
|
||||
bool exists;
|
||||
mConvertedFile->Exists(&exists);
|
||||
if (exists)
|
||||
mConvertedFile->Remove(false);
|
||||
if (exists) mConvertedFile->Remove(false);
|
||||
mConvertedFile = nullptr;
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -424,9 +369,7 @@ nsBeckySettings::RemoveConvertedFile()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBeckySettings::Import(nsIMsgAccount **aLocalMailAccount,
|
||||
bool *_retval)
|
||||
{
|
||||
nsBeckySettings::Import(nsIMsgAccount **aLocalMailAccount, bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(aLocalMailAccount);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -454,9 +397,7 @@ nsBeckySettings::Import(nsIMsgAccount **aLocalMailAccount,
|
|||
NS_RETURN_IF_FAILED_WITH_REMOVE_CONVERTED_FILE(rv, rv);
|
||||
|
||||
RemoveConvertedFile();
|
||||
if (aLocalMailAccount)
|
||||
account.forget(aLocalMailAccount);
|
||||
if (aLocalMailAccount) account.forget(aLocalMailAccount);
|
||||
*_retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,16 +14,15 @@ class nsIMsgIncomingServer;
|
|||
class nsIMsgIdentity;
|
||||
class nsISmtpServer;
|
||||
|
||||
class nsBeckySettings final : public nsIImportSettings
|
||||
{
|
||||
public:
|
||||
class nsBeckySettings final : public nsIImportSettings {
|
||||
public:
|
||||
nsBeckySettings();
|
||||
static nsresult Create(nsIImportSettings **aImport);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTSETTINGS
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsBeckySettings();
|
||||
|
||||
nsCOMPtr<nsIFile> mLocation;
|
||||
|
@ -37,8 +36,7 @@ private:
|
|||
nsIMsgAccount **aAccount);
|
||||
nsresult CreateSmtpServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
nsISmtpServer **aServer,
|
||||
bool *existing);
|
||||
nsISmtpServer **aServer, bool *existing);
|
||||
nsresult CreateIncomingServer(const nsCString &aUserName,
|
||||
const nsCString &aServerName,
|
||||
const nsCString &aProtocol,
|
||||
|
|
|
@ -12,32 +12,27 @@
|
|||
|
||||
#include "nsBeckyStringBundle.h"
|
||||
|
||||
#define BECKY_MESSAGES_URL "chrome://messenger/locale/beckyImportMsgs.properties"
|
||||
#define BECKY_MESSAGES_URL \
|
||||
"chrome://messenger/locale/beckyImportMsgs.properties"
|
||||
|
||||
nsCOMPtr<nsIStringBundle> nsBeckyStringBundle::mBundle = nullptr;
|
||||
|
||||
void
|
||||
nsBeckyStringBundle::GetStringBundle(void)
|
||||
{
|
||||
if (mBundle)
|
||||
return;
|
||||
void nsBeckyStringBundle::GetStringBundle(void) {
|
||||
if (mBundle) return;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && bundleService)
|
||||
rv = bundleService->CreateBundle(BECKY_MESSAGES_URL, getter_AddRefs(mBundle));
|
||||
rv = bundleService->CreateBundle(BECKY_MESSAGES_URL,
|
||||
getter_AddRefs(mBundle));
|
||||
}
|
||||
|
||||
void
|
||||
nsBeckyStringBundle::EnsureStringBundle(void)
|
||||
{
|
||||
if (!mBundle)
|
||||
GetStringBundle();
|
||||
void nsBeckyStringBundle::EnsureStringBundle(void) {
|
||||
if (!mBundle) GetStringBundle();
|
||||
}
|
||||
|
||||
char16_t *
|
||||
nsBeckyStringBundle::GetStringByName(const char *aName)
|
||||
{
|
||||
char16_t *nsBeckyStringBundle::GetStringByName(const char *aName) {
|
||||
EnsureStringBundle();
|
||||
|
||||
if (mBundle) {
|
||||
|
@ -49,22 +44,13 @@ nsBeckyStringBundle::GetStringByName(const char *aName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyStringBundle::FormatStringFromName(const char *name,
|
||||
const char16_t **params,
|
||||
uint32_t length,
|
||||
nsAString& _retval)
|
||||
{
|
||||
nsresult nsBeckyStringBundle::FormatStringFromName(const char *name,
|
||||
const char16_t **params,
|
||||
uint32_t length,
|
||||
nsAString &_retval) {
|
||||
EnsureStringBundle();
|
||||
|
||||
return mBundle->FormatStringFromName(name,
|
||||
params,
|
||||
length,
|
||||
_retval);
|
||||
return mBundle->FormatStringFromName(name, params, length, _retval);
|
||||
}
|
||||
|
||||
void
|
||||
nsBeckyStringBundle::Cleanup(void)
|
||||
{
|
||||
mBundle = nullptr;
|
||||
}
|
||||
void nsBeckyStringBundle::Cleanup(void) { mBundle = nullptr; }
|
||||
|
|
|
@ -9,25 +9,24 @@
|
|||
class nsIStringBundle;
|
||||
|
||||
class nsBeckyStringBundle final {
|
||||
public:
|
||||
public:
|
||||
static char16_t *GetStringByName(const char *name);
|
||||
static nsresult FormatStringFromName(const char *name,
|
||||
const char16_t **params,
|
||||
uint32_t length,
|
||||
nsAString& _retval);
|
||||
const char16_t **params, uint32_t length,
|
||||
nsAString &_retval);
|
||||
static void GetStringBundle(void);
|
||||
static void EnsureStringBundle(void);
|
||||
static void Cleanup(void);
|
||||
private:
|
||||
|
||||
private:
|
||||
static nsCOMPtr<nsIStringBundle> mBundle;
|
||||
};
|
||||
|
||||
#define BECKYIMPORT_NAME 2000
|
||||
#define BECKYIMPORT_DESCRIPTION 2001
|
||||
#define BECKYIMPORT_MAILBOX_SUCCESS 2002
|
||||
#define BECKYIMPORT_MAILBOX_BADPARAM 2003
|
||||
#define BECKYIMPORT_MAILBOX_CONVERTERROR 2004
|
||||
#define BECKYIMPORT_ADDRESS_SUCCESS 2005
|
||||
|
||||
#define BECKYIMPORT_NAME 2000
|
||||
#define BECKYIMPORT_DESCRIPTION 2001
|
||||
#define BECKYIMPORT_MAILBOX_SUCCESS 2002
|
||||
#define BECKYIMPORT_MAILBOX_BADPARAM 2003
|
||||
#define BECKYIMPORT_MAILBOX_CONVERTERROR 2004
|
||||
#define BECKYIMPORT_ADDRESS_SUCCESS 2005
|
||||
|
||||
#endif /* _nsBeckyStringBundle_H__ */
|
||||
|
|
|
@ -29,9 +29,7 @@
|
|||
#include "nsBeckyUtils.h"
|
||||
#include "SpecialSystemDirectory.h"
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::FindUserDirectoryOnWindows7(nsIFile **aLocation)
|
||||
{
|
||||
nsresult nsBeckyUtils::FindUserDirectoryOnWindows7(nsIFile **aLocation) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
|
||||
nsresult rv;
|
||||
|
@ -44,26 +42,23 @@ nsBeckyUtils::FindUserDirectoryOnWindows7(nsIFile **aLocation)
|
|||
bool exists = false;
|
||||
rv = directory->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
bool isDirectory = false;
|
||||
rv = directory->IsDirectory(&isDirectory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!isDirectory)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!isDirectory) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
directory.forget(aLocation);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::FindUserDirectoryOnWindowsXP(nsIFile **aLocation)
|
||||
{
|
||||
nsresult nsBeckyUtils::FindUserDirectoryOnWindowsXP(nsIFile **aLocation) {
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> directory = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIFile> directory =
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = directory->InitWithPath(NS_LITERAL_STRING("C:\\Becky!"));
|
||||
|
@ -72,14 +67,12 @@ nsBeckyUtils::FindUserDirectoryOnWindowsXP(nsIFile **aLocation)
|
|||
bool exists = false;
|
||||
rv = directory->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
bool isDirectory = false;
|
||||
rv = directory->IsDirectory(&isDirectory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!isDirectory)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!isDirectory) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = directory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
|
@ -105,9 +98,7 @@ nsBeckyUtils::FindUserDirectoryOnWindowsXP(nsIFile **aLocation)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::FindUserDirectory(nsIFile **aLocation)
|
||||
{
|
||||
nsresult nsBeckyUtils::FindUserDirectory(nsIFile **aLocation) {
|
||||
nsresult rv = FindUserDirectoryOnWindows7(aLocation);
|
||||
if (rv == NS_ERROR_FILE_NOT_FOUND) {
|
||||
rv = FindUserDirectoryOnWindowsXP(aLocation);
|
||||
|
@ -115,10 +106,8 @@ nsBeckyUtils::FindUserDirectory(nsIFile **aLocation)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::ConvertNativeStringToUTF8(const nsACString& aOriginal,
|
||||
nsACString& _retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::ConvertNativeStringToUTF8(const nsACString &aOriginal,
|
||||
nsACString &_retval) {
|
||||
nsresult rv;
|
||||
nsAutoString unicodeString;
|
||||
rv = NS_CopyNativeToUnicode(aOriginal, unicodeString);
|
||||
|
@ -128,10 +117,8 @@ nsBeckyUtils::ConvertNativeStringToUTF8(const nsACString& aOriginal,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::CreateLineInputStream(nsIFile *aFile,
|
||||
nsILineInputStream **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::CreateLineInputStream(nsIFile *aFile,
|
||||
nsILineInputStream **_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
|
@ -141,9 +128,8 @@ nsBeckyUtils::CreateLineInputStream(nsIFile *aFile,
|
|||
return CallQueryInterface(inputStream, _retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetFolderListFile(nsIFile *aLocation, nsIFile **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetFolderListFile(nsIFile *aLocation,
|
||||
nsIFile **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> folderListFile;
|
||||
rv = aLocation->Clone(getter_AddRefs(folderListFile));
|
||||
|
@ -156,16 +142,14 @@ nsBeckyUtils::GetFolderListFile(nsIFile *aLocation, nsIFile **_retval)
|
|||
rv = folderListFile->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
folderListFile.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetDefaultFolderName(nsIFile *aFolderListFile, nsACString& name)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetDefaultFolderName(nsIFile *aFolderListFile,
|
||||
nsACString &name) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILineInputStream> lineStream;
|
||||
rv = CreateLineInputStream(aFolderListFile, getter_AddRefs(lineStream));
|
||||
|
@ -178,9 +162,7 @@ nsBeckyUtils::GetDefaultFolderName(nsIFile *aFolderListFile, nsACString& name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetDefaultMailboxDirectory(nsIFile **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetDefaultMailboxDirectory(nsIFile **_retval) {
|
||||
nsCOMPtr<nsIFile> userDirectory;
|
||||
nsresult rv = FindUserDirectory(getter_AddRefs(userDirectory));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -199,22 +181,18 @@ nsBeckyUtils::GetDefaultMailboxDirectory(nsIFile **_retval)
|
|||
bool exists;
|
||||
rv = userDirectory->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
bool isDirectory = false;
|
||||
rv = userDirectory->IsDirectory(&isDirectory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!isDirectory)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!isDirectory) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
userDirectory.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetDefaultMailboxINIFile(nsIFile **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetDefaultMailboxINIFile(nsIFile **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> mailboxDirectory;
|
||||
rv = GetDefaultMailboxDirectory(getter_AddRefs(mailboxDirectory));
|
||||
|
@ -223,9 +201,8 @@ nsBeckyUtils::GetDefaultMailboxINIFile(nsIFile **_retval)
|
|||
return GetMailboxINIFile(mailboxDirectory, _retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetMailboxINIFile(nsIFile *aDirectory, nsIFile **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetMailboxINIFile(nsIFile *aDirectory,
|
||||
nsIFile **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> target;
|
||||
rv = aDirectory->Clone(getter_AddRefs(target));
|
||||
|
@ -235,42 +212,35 @@ nsBeckyUtils::GetMailboxINIFile(nsIFile *aDirectory, nsIFile **_retval)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
bool exists;
|
||||
rv = target->Exists(&exists);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
target.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::CreateINIParserForFile(nsIFile *aFile,
|
||||
nsIINIParser **aParser)
|
||||
{
|
||||
nsresult nsBeckyUtils::CreateINIParserForFile(nsIFile *aFile,
|
||||
nsIINIParser **aParser) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIINIParserFactory> factory =
|
||||
do_GetService("@mozilla.org/xpcom/ini-processor-factory;1", &rv);
|
||||
do_GetService("@mozilla.org/xpcom/ini-processor-factory;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return factory->CreateINIParser(aFile, aParser);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::GetMailboxNameFromINIFile(nsIFile *aFile, nsCString &aName)
|
||||
{
|
||||
nsresult nsBeckyUtils::GetMailboxNameFromINIFile(nsIFile *aFile,
|
||||
nsCString &aName) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIINIParser> parser;
|
||||
rv = CreateINIParserForFile(aFile, getter_AddRefs(parser));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return parser->GetString(NS_LITERAL_CSTRING("Account"),
|
||||
NS_LITERAL_CSTRING("Name"),
|
||||
aName);
|
||||
NS_LITERAL_CSTRING("Name"), aName);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::ConvertToUTF8File(nsIFile *aSourceFile,
|
||||
nsIFile **_retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::ConvertToUTF8File(nsIFile *aSourceFile,
|
||||
nsIFile **_retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> convertedFile;
|
||||
rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR,
|
||||
|
@ -285,21 +255,19 @@ nsBeckyUtils::ConvertToUTF8File(nsIFile *aSourceFile,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIOutputStream> destination;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(destination),
|
||||
convertedFile);
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(destination), convertedFile);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
const uint32_t kBlock = 8192;
|
||||
|
||||
nsCOMPtr<nsIConverterInputStream> convertedInput =
|
||||
do_CreateInstance("@mozilla.org/intl/converter-input-stream;1");
|
||||
do_CreateInstance("@mozilla.org/intl/converter-input-stream;1");
|
||||
convertedInput->Init(source,
|
||||
PromiseFlatCString(nsMsgI18NFileSystemCharset()).get(),
|
||||
kBlock,
|
||||
0x0000);
|
||||
kBlock, 0x0000);
|
||||
|
||||
nsCOMPtr<nsIConverterOutputStream> convertedOutput =
|
||||
do_CreateInstance("@mozilla.org/intl/converter-output-stream;1");
|
||||
do_CreateInstance("@mozilla.org/intl/converter-output-stream;1");
|
||||
convertedOutput->Init(destination, "UTF-8");
|
||||
|
||||
char16_t *line = (char16_t *)moz_xmalloc(kBlock);
|
||||
|
@ -316,10 +284,8 @@ nsBeckyUtils::ConvertToUTF8File(nsIFile *aSourceFile,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBeckyUtils::TranslateFolderName(const nsAString & aFolderName,
|
||||
nsAString & _retval)
|
||||
{
|
||||
nsresult nsBeckyUtils::TranslateFolderName(const nsAString &aFolderName,
|
||||
nsAString &_retval) {
|
||||
if (aFolderName.LowerCaseEqualsLiteral("!trash"))
|
||||
_retval = NS_LITERAL_STRING(kDestTrashFolderName);
|
||||
else if (aFolderName.LowerCaseEqualsLiteral("!!!!inbox"))
|
||||
|
|
|
@ -10,29 +10,26 @@ class nsILineInputStream;
|
|||
class nsIINIParser;
|
||||
|
||||
class nsBeckyUtils final {
|
||||
public:
|
||||
public:
|
||||
static nsresult FindUserDirectoryOnWindows7(nsIFile **aLocation);
|
||||
static nsresult FindUserDirectoryOnWindowsXP(nsIFile **aLocation);
|
||||
static nsresult FindUserDirectory(nsIFile **aFile);
|
||||
static nsresult ConvertNativeStringToUTF8(const nsACString& aOriginal,
|
||||
nsACString& _retval);
|
||||
static nsresult ConvertNativeStringToUTF8(const nsACString &aOriginal,
|
||||
nsACString &_retval);
|
||||
static nsresult CreateLineInputStream(nsIFile *aFile,
|
||||
nsILineInputStream **_retval);
|
||||
static nsresult GetDefaultMailboxDirectory(nsIFile **_retval);
|
||||
static nsresult GetFolderListFile(nsIFile *aLocation,
|
||||
nsIFile **_retval);
|
||||
static nsresult GetFolderListFile(nsIFile *aLocation, nsIFile **_retval);
|
||||
static nsresult GetDefaultFolderName(nsIFile *aFolderListFile,
|
||||
nsACString& name);
|
||||
nsACString &name);
|
||||
static nsresult GetDefaultMailboxINIFile(nsIFile **_retval);
|
||||
static nsresult GetMailboxINIFile(nsIFile *aDirectory, nsIFile **_retval);
|
||||
static nsresult CreateINIParserForFile(nsIFile *aFile,
|
||||
nsIINIParser **aParser);
|
||||
static nsresult GetMailboxNameFromINIFile(nsIFile *aFile, nsCString &aName);
|
||||
static nsresult ConvertToUTF8File(nsIFile *aSourceFile,
|
||||
nsIFile **_retval);
|
||||
static nsresult TranslateFolderName(const nsAString & aFolderName,
|
||||
nsAString & _retval);
|
||||
static nsresult ConvertToUTF8File(nsIFile *aSourceFile, nsIFile **_retval);
|
||||
static nsresult TranslateFolderName(const nsAString &aFolderName,
|
||||
nsAString &_retval);
|
||||
};
|
||||
|
||||
|
||||
#endif /* _nsBeckyUtils_H__ */
|
||||
|
|
|
@ -35,7 +35,7 @@ NS_DEFINE_NAMED_CID(NS_VCARDIMPORT_CID);
|
|||
// Apple Mail import Include Files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(XP_MACOSX)
|
||||
#include "nsAppleMailImport.h"
|
||||
# include "nsAppleMailImport.h"
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_APPLEMAILIMPORT_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_APPLEMAILIMPL_CID);
|
||||
|
@ -45,28 +45,28 @@ NS_DEFINE_NAMED_CID(NS_APPLEMAILIMPL_CID);
|
|||
// outlook import Include Files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef XP_WIN
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
#include "nsOutlookImport.h"
|
||||
#include "nsOutlookStringBundle.h"
|
||||
#endif
|
||||
#include "nsWMImport.h"
|
||||
#include "nsWMStringBundle.h"
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
# include "nsOutlookImport.h"
|
||||
# include "nsOutlookStringBundle.h"
|
||||
# endif
|
||||
# include "nsWMImport.h"
|
||||
# include "nsWMStringBundle.h"
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_WMIMPORT_CID);
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
NS_DEFINE_NAMED_CID(NS_OUTLOOKIMPORT_CID);
|
||||
#endif
|
||||
#endif // XP_WIN
|
||||
# endif
|
||||
#endif // XP_WIN
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// becky import Include Files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef XP_WIN
|
||||
#include "nsBeckyImport.h"
|
||||
#include "nsBeckyStringBundle.h"
|
||||
# include "nsBeckyImport.h"
|
||||
# include "nsBeckyStringBundle.h"
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_BECKYIMPORT_CID);
|
||||
#endif // XP_WIN
|
||||
#endif // XP_WIN
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// core import factories
|
||||
|
@ -97,93 +97,95 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppleMailImportMail, Initialize)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef XP_WIN
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWMImport)
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsOutlookImport)
|
||||
#endif
|
||||
#endif // XP_WIN
|
||||
# endif
|
||||
#endif // XP_WIN
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// becky import factory
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef XP_WIN
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBeckyImport)
|
||||
#endif // XP_WIN
|
||||
#endif // XP_WIN
|
||||
|
||||
static const mozilla::Module::CategoryEntry kMailNewsImportCategories[] = {
|
||||
// XXX These CIDs should match the explicit CIDs defined in the header files,
|
||||
// or be changed so that they are contract IDs (with appropriate code updates)
|
||||
{ "mailnewsimport", "{A5991D01-ADA7-11d3-A9C2-00A0CC26DA63}", NS_IMPORT_ADDRESS_STR },
|
||||
{ "mailnewsimport", "{0eb034a3-964a-4e2f-92eb-cc55d9ae9dd2}", NS_IMPORT_ADDRESS_STR },
|
||||
// XXX These CIDs should match the explicit CIDs defined in the header
|
||||
// files,
|
||||
// or be changed so that they are contract IDs (with appropriate code
|
||||
// updates)
|
||||
{"mailnewsimport", "{A5991D01-ADA7-11d3-A9C2-00A0CC26DA63}",
|
||||
NS_IMPORT_ADDRESS_STR},
|
||||
{"mailnewsimport", "{0eb034a3-964a-4e2f-92eb-cc55d9ae9dd2}",
|
||||
NS_IMPORT_ADDRESS_STR},
|
||||
#ifdef XP_WIN
|
||||
{ "mailnewsimport", "{42bc82bc-8e9f-4597-8b6e-e529daaf3af1}", kWMSupportsString },
|
||||
{ "mailnewsimport", "{7952a6cf-2442-4c04-9f02-150b15a0a841}", kBeckySupportsString },
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
{ "mailnewsimport", "{1DB469A0-8B00-11d3-A206-00A0CC26DA63}", kOutlookSupportsString },
|
||||
#endif
|
||||
{"mailnewsimport", "{42bc82bc-8e9f-4597-8b6e-e529daaf3af1}",
|
||||
kWMSupportsString},
|
||||
{"mailnewsimport", "{7952a6cf-2442-4c04-9f02-150b15a0a841}",
|
||||
kBeckySupportsString},
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
{"mailnewsimport", "{1DB469A0-8B00-11d3-A206-00A0CC26DA63}",
|
||||
kOutlookSupportsString},
|
||||
# endif
|
||||
#endif
|
||||
#if defined(XP_MACOSX)
|
||||
{ "mailnewsimport", "{6d3f101c-70ec-4e04-b68d-9908d1aeddf3}", kAppleMailSupportsString },
|
||||
{"mailnewsimport", "{6d3f101c-70ec-4e04-b68d-9908d1aeddf3}",
|
||||
kAppleMailSupportsString},
|
||||
#endif
|
||||
{ NULL }
|
||||
};
|
||||
{NULL}};
|
||||
|
||||
const mozilla::Module::CIDEntry kMailNewsImportCIDs[] = {
|
||||
{ &kNS_IMPORTSERVICE_CID, false, NULL, nsImportServiceConstructor },
|
||||
{ &kNS_IMPORTMIMEENCODE_CID, false, NULL, nsIImportMimeEncodeImplConstructor },
|
||||
{ &kNS_TEXTIMPORT_CID, false, NULL, nsTextImportConstructor },
|
||||
{ &kNS_VCARDIMPORT_CID, false, NULL, nsVCardImportConstructor },
|
||||
{&kNS_IMPORTSERVICE_CID, false, NULL, nsImportServiceConstructor},
|
||||
{&kNS_IMPORTMIMEENCODE_CID, false, NULL,
|
||||
nsIImportMimeEncodeImplConstructor},
|
||||
{&kNS_TEXTIMPORT_CID, false, NULL, nsTextImportConstructor},
|
||||
{&kNS_VCARDIMPORT_CID, false, NULL, nsVCardImportConstructor},
|
||||
#if defined(XP_MACOSX)
|
||||
{ &kNS_APPLEMAILIMPORT_CID, false, NULL, nsAppleMailImportModuleConstructor },
|
||||
{ &kNS_APPLEMAILIMPL_CID, false, NULL, nsAppleMailImportMailConstructor },
|
||||
{&kNS_APPLEMAILIMPORT_CID, false, NULL, nsAppleMailImportModuleConstructor},
|
||||
{&kNS_APPLEMAILIMPL_CID, false, NULL, nsAppleMailImportMailConstructor},
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
{ &kNS_WMIMPORT_CID, false, NULL, nsWMImportConstructor },
|
||||
{ &kNS_BECKYIMPORT_CID, false, NULL, nsBeckyImportConstructor },
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
{ &kNS_OUTLOOKIMPORT_CID, false, NULL, nsOutlookImportConstructor },
|
||||
{&kNS_WMIMPORT_CID, false, NULL, nsWMImportConstructor},
|
||||
{&kNS_BECKYIMPORT_CID, false, NULL, nsBeckyImportConstructor},
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
{&kNS_OUTLOOKIMPORT_CID, false, NULL, nsOutlookImportConstructor},
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
{ NULL }
|
||||
};
|
||||
{NULL}};
|
||||
|
||||
const mozilla::Module::ContractIDEntry kMailNewsImportContracts[] = {
|
||||
{ NS_IMPORTSERVICE_CONTRACTID, &kNS_IMPORTSERVICE_CID },
|
||||
{ "@mozilla.org/import/import-mimeencode;1", &kNS_IMPORTMIMEENCODE_CID },
|
||||
{ "@mozilla.org/import/import-text;1", &kNS_TEXTIMPORT_CID },
|
||||
{ "@mozilla.org/import/import-vcard;1", &kNS_VCARDIMPORT_CID },
|
||||
{NS_IMPORTSERVICE_CONTRACTID, &kNS_IMPORTSERVICE_CID},
|
||||
{"@mozilla.org/import/import-mimeencode;1", &kNS_IMPORTMIMEENCODE_CID},
|
||||
{"@mozilla.org/import/import-text;1", &kNS_TEXTIMPORT_CID},
|
||||
{"@mozilla.org/import/import-vcard;1", &kNS_VCARDIMPORT_CID},
|
||||
#if defined(XP_MACOSX)
|
||||
{ "@mozilla.org/import/import-applemail;1", &kNS_APPLEMAILIMPORT_CID },
|
||||
{ NS_APPLEMAILIMPL_CONTRACTID, &kNS_APPLEMAILIMPL_CID },
|
||||
{"@mozilla.org/import/import-applemail;1", &kNS_APPLEMAILIMPORT_CID},
|
||||
{NS_APPLEMAILIMPL_CONTRACTID, &kNS_APPLEMAILIMPL_CID},
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
{ "@mozilla.org/import/import-wm;1", &kNS_WMIMPORT_CID },
|
||||
{ "@mozilla.org/import/import-becky;1", &kNS_BECKYIMPORT_CID },
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
{ "@mozilla.org/import/import-outlook;1", &kNS_OUTLOOKIMPORT_CID },
|
||||
{"@mozilla.org/import/import-wm;1", &kNS_WMIMPORT_CID},
|
||||
{"@mozilla.org/import/import-becky;1", &kNS_BECKYIMPORT_CID},
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
{"@mozilla.org/import/import-outlook;1", &kNS_OUTLOOKIMPORT_CID},
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
{ NULL }
|
||||
};
|
||||
{NULL}};
|
||||
|
||||
|
||||
static void importModuleDtor()
|
||||
{
|
||||
static void importModuleDtor() {
|
||||
#ifdef XP_WIN
|
||||
nsWMStringBundle::Cleanup();
|
||||
nsBeckyStringBundle::Cleanup();
|
||||
#ifdef MOZ_MAPI_SUPPORT
|
||||
nsOutlookStringBundle::Cleanup();
|
||||
#endif
|
||||
nsWMStringBundle::Cleanup();
|
||||
nsBeckyStringBundle::Cleanup();
|
||||
# ifdef MOZ_MAPI_SUPPORT
|
||||
nsOutlookStringBundle::Cleanup();
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
extern const mozilla::Module kMailNewsImportModule = {
|
||||
mozilla::Module::kVersion,
|
||||
kMailNewsImportCIDs,
|
||||
kMailNewsImportContracts,
|
||||
kMailNewsImportCategories,
|
||||
NULL,
|
||||
NULL,
|
||||
importModuleDtor
|
||||
};
|
||||
extern const mozilla::Module kMailNewsImportModule = {mozilla::Module::kVersion,
|
||||
kMailNewsImportCIDs,
|
||||
kMailNewsImportContracts,
|
||||
kMailNewsImportCategories,
|
||||
NULL,
|
||||
NULL,
|
||||
importModuleDtor};
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -23,28 +23,28 @@
|
|||
#define _MAPIUTIL_H
|
||||
|
||||
#ifndef PR_INTERNET_CPID
|
||||
#define PR_INTERNET_CPID (PROP_TAG(PT_LONG,0x3FDE))
|
||||
# define PR_INTERNET_CPID (PROP_TAG(PT_LONG, 0x3FDE))
|
||||
#endif
|
||||
#ifndef MAPI_NATIVE_BODY
|
||||
#define MAPI_NATIVE_BODY (0x00010000)
|
||||
# define MAPI_NATIVE_BODY (0x00010000)
|
||||
#endif
|
||||
#ifndef MAPI_NATIVE_BODY_TYPE_RTF
|
||||
#define MAPI_NATIVE_BODY_TYPE_RTF (0x00000001)
|
||||
# define MAPI_NATIVE_BODY_TYPE_RTF (0x00000001)
|
||||
#endif
|
||||
#ifndef MAPI_NATIVE_BODY_TYPE_HTML
|
||||
#define MAPI_NATIVE_BODY_TYPE_HTML (0x00000002)
|
||||
# define MAPI_NATIVE_BODY_TYPE_HTML (0x00000002)
|
||||
#endif
|
||||
#ifndef MAPI_NATIVE_BODY_TYPE_PLAINTEXT
|
||||
#define MAPI_NATIVE_BODY_TYPE_PLAINTEXT (0x00000004)
|
||||
# define MAPI_NATIVE_BODY_TYPE_PLAINTEXT (0x00000004)
|
||||
#endif
|
||||
#ifndef PR_BODY_HTML_A
|
||||
#define PR_BODY_HTML_A (PROP_TAG(PT_STRING8,0x1013))
|
||||
# define PR_BODY_HTML_A (PROP_TAG(PT_STRING8, 0x1013))
|
||||
#endif
|
||||
#ifndef PR_BODY_HTML_W
|
||||
#define PR_BODY_HTML_W (PROP_TAG(PT_UNICODE,0x1013))
|
||||
# define PR_BODY_HTML_W (PROP_TAG(PT_UNICODE, 0x1013))
|
||||
#endif
|
||||
#ifndef PR_BODY_HTML
|
||||
#define PR_BODY_HTML (PROP_TAG(PT_TSTRING,0x1013))
|
||||
# define PR_BODY_HTML (PROP_TAG(PT_TSTRING, 0x1013))
|
||||
#endif
|
||||
|
||||
class CMapiFolderList;
|
||||
|
@ -52,214 +52,233 @@ class CMsgStore;
|
|||
class CMapiFolder;
|
||||
|
||||
class CMapiContentIter {
|
||||
public:
|
||||
public:
|
||||
virtual BOOL HandleContentItem(ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiHierarchyIter {
|
||||
public:
|
||||
public:
|
||||
virtual BOOL HandleHierarchyItem(ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiApi {
|
||||
public:
|
||||
public:
|
||||
CMapiApi();
|
||||
~CMapiApi();
|
||||
|
||||
static BOOL LoadMapi(void);
|
||||
static BOOL LoadMapiEntryPoints(void);
|
||||
static void UnloadMapi(void);
|
||||
static BOOL LoadMapi(void);
|
||||
static BOOL LoadMapiEntryPoints(void);
|
||||
static void UnloadMapi(void);
|
||||
|
||||
static HINSTANCE m_hMapi32;
|
||||
static HINSTANCE m_hMapi32;
|
||||
|
||||
static void MAPIUninitialize(void);
|
||||
static HRESULT MAPIInitialize(LPVOID lpInit);
|
||||
static SCODE MAPIAllocateBuffer(ULONG cbSize, LPVOID FAR * lppBuffer);
|
||||
static ULONG MAPIFreeBuffer(LPVOID lpBuff);
|
||||
static HRESULT MAPILogonEx(ULONG ulUIParam, LPTSTR lpszProfileName, LPTSTR lpszPassword, FLAGS flFlags, LPMAPISESSION FAR * lppSession);
|
||||
static HRESULT OpenStreamOnFile(LPALLOCATEBUFFER lpAllocateBuffer, LPFREEBUFFER lpFreeBuffer, ULONG ulFlags, LPCTSTR lpszFileName, LPTSTR lpszPrefix, LPSTREAM FAR * lppStream);
|
||||
static void FreeProws(LPSRowSet prows);
|
||||
static void MAPIUninitialize(void);
|
||||
static HRESULT MAPIInitialize(LPVOID lpInit);
|
||||
static SCODE MAPIAllocateBuffer(ULONG cbSize, LPVOID FAR *lppBuffer);
|
||||
static ULONG MAPIFreeBuffer(LPVOID lpBuff);
|
||||
static HRESULT MAPILogonEx(ULONG ulUIParam, LPTSTR lpszProfileName,
|
||||
LPTSTR lpszPassword, FLAGS flFlags,
|
||||
LPMAPISESSION FAR *lppSession);
|
||||
static HRESULT OpenStreamOnFile(LPALLOCATEBUFFER lpAllocateBuffer,
|
||||
LPFREEBUFFER lpFreeBuffer, ULONG ulFlags,
|
||||
LPCTSTR lpszFileName, LPTSTR lpszPrefix,
|
||||
LPSTREAM FAR *lppStream);
|
||||
static void FreeProws(LPSRowSet prows);
|
||||
|
||||
BOOL Initialize(void);
|
||||
BOOL LogOn(void);
|
||||
|
||||
BOOL Initialize(void);
|
||||
BOOL LogOn(void);
|
||||
|
||||
void AddMessageStore(CMsgStore *pStore);
|
||||
void SetCurrentMsgStore(LPMDB lpMdb) { m_lpMdb = lpMdb;}
|
||||
void AddMessageStore(CMsgStore *pStore);
|
||||
void SetCurrentMsgStore(LPMDB lpMdb) { m_lpMdb = lpMdb; }
|
||||
|
||||
// Open any given entry from the current Message Store
|
||||
BOOL OpenEntry(ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
static BOOL OpenMdbEntry(LPMDB lpMdb, ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
BOOL OpenEntry(ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
static BOOL OpenMdbEntry(LPMDB lpMdb, ULONG cbEntry, LPENTRYID pEntryId,
|
||||
LPUNKNOWN *ppOpen);
|
||||
|
||||
// Fill in the folders list with the hierarchy from the given
|
||||
// message store.
|
||||
BOOL GetStoreFolders(ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& folders, int startDepth);
|
||||
BOOL GetStoreAddressFolders(ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& folders);
|
||||
BOOL OpenStore(ULONG cbEid, LPENTRYID lpEid, LPMDB *ppMdb);
|
||||
BOOL GetStoreFolders(ULONG cbEid, LPENTRYID lpEid, CMapiFolderList &folders,
|
||||
int startDepth);
|
||||
BOOL GetStoreAddressFolders(ULONG cbEid, LPENTRYID lpEid,
|
||||
CMapiFolderList &folders);
|
||||
BOOL OpenStore(ULONG cbEid, LPENTRYID lpEid, LPMDB *ppMdb);
|
||||
|
||||
// Iteration
|
||||
BOOL IterateStores(CMapiFolderList& list);
|
||||
BOOL IterateContents(CMapiContentIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
BOOL IterateHierarchy(CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
BOOL IterateStores(CMapiFolderList &list);
|
||||
BOOL IterateContents(CMapiContentIter *pIter, LPMAPIFOLDER pFolder,
|
||||
ULONG flags = 0);
|
||||
BOOL IterateHierarchy(CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder,
|
||||
ULONG flags = 0);
|
||||
|
||||
// Properties
|
||||
static LPSPropValue GetMapiProperty(LPMAPIPROP pProp, ULONG tag);
|
||||
static LPSPropValue GetMapiProperty(LPMAPIPROP pProp, ULONG tag);
|
||||
// If delVal is true, functions will call CMapiApi::MAPIFreeBuffer on pVal.
|
||||
static BOOL GetEntryIdFromProp(LPSPropValue pVal, ULONG& cbEntryId,
|
||||
LPENTRYID& lpEntryId, BOOL delVal = TRUE);
|
||||
static BOOL GetStringFromProp(LPSPropValue pVal, nsCString& val, BOOL delVal = TRUE);
|
||||
static BOOL GetStringFromProp(LPSPropValue pVal, nsString& val, BOOL delVal = TRUE);
|
||||
static LONG GetLongFromProp(LPSPropValue pVal, BOOL delVal = TRUE);
|
||||
static BOOL GetLargeStringProperty(LPMAPIPROP pProp, ULONG tag, nsCString& val);
|
||||
static BOOL GetLargeStringProperty(LPMAPIPROP pProp, ULONG tag, nsString& val);
|
||||
static BOOL IsLargeProperty(LPSPropValue pVal);
|
||||
static ULONG GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID);
|
||||
static BOOL GetEntryIdFromProp(LPSPropValue pVal, ULONG &cbEntryId,
|
||||
LPENTRYID &lpEntryId, BOOL delVal = TRUE);
|
||||
static BOOL GetStringFromProp(LPSPropValue pVal, nsCString &val,
|
||||
BOOL delVal = TRUE);
|
||||
static BOOL GetStringFromProp(LPSPropValue pVal, nsString &val,
|
||||
BOOL delVal = TRUE);
|
||||
static LONG GetLongFromProp(LPSPropValue pVal, BOOL delVal = TRUE);
|
||||
static BOOL GetLargeStringProperty(LPMAPIPROP pProp, ULONG tag,
|
||||
nsCString &val);
|
||||
static BOOL GetLargeStringProperty(LPMAPIPROP pProp, ULONG tag,
|
||||
nsString &val);
|
||||
static BOOL IsLargeProperty(LPSPropValue pVal);
|
||||
static ULONG GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID);
|
||||
|
||||
static BOOL GetRTFPropertyDecodedAsUTF16(LPMAPIPROP pProp, nsString& val,
|
||||
unsigned long& nativeBodyType,
|
||||
static BOOL GetRTFPropertyDecodedAsUTF16(LPMAPIPROP pProp, nsString &val,
|
||||
unsigned long &nativeBodyType,
|
||||
unsigned long codepage = 0);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void ListProperties(LPMAPIPROP lpProp, BOOL getValues = TRUE);
|
||||
static void ListPropertyValue(LPSPropValue pVal, nsCString& s);
|
||||
static void ListProperties(LPMAPIPROP lpProp, BOOL getValues = TRUE);
|
||||
static void ListPropertyValue(LPSPropValue pVal, nsCString &s);
|
||||
|
||||
protected:
|
||||
BOOL HandleHierarchyItem(ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
BOOL HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
void GetStoreInfo(CMapiFolder *pFolder, long *pSzContents);
|
||||
protected:
|
||||
BOOL HandleHierarchyItem(ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
BOOL HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
void GetStoreInfo(CMapiFolder *pFolder, long *pSzContents);
|
||||
|
||||
// array of available message stores, cached so that
|
||||
// message stores are only opened once, preventing multiple
|
||||
// logon's by the user if the store requires a logon.
|
||||
CMsgStore * FindMessageStore(ULONG cbEid, LPENTRYID lpEid);
|
||||
void ClearMessageStores(void);
|
||||
CMsgStore *FindMessageStore(ULONG cbEid, LPENTRYID lpEid);
|
||||
void ClearMessageStores(void);
|
||||
|
||||
static void CStrToUnicode(const char *pStr, nsString& result);
|
||||
static void CStrToUnicode(const char *pStr, nsString &result);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void GetPropTagName(ULONG tag, nsCString& s);
|
||||
static void ReportStringProp(const char *pTag, LPSPropValue pVal);
|
||||
static void ReportUIDProp(const char *pTag, LPSPropValue pVal);
|
||||
static void ReportLongProp(const char *pTag, LPSPropValue pVal);
|
||||
static void GetPropTagName(ULONG tag, nsCString &s);
|
||||
static void ReportStringProp(const char *pTag, LPSPropValue pVal);
|
||||
static void ReportUIDProp(const char *pTag, LPSPropValue pVal);
|
||||
static void ReportLongProp(const char *pTag, LPSPropValue pVal);
|
||||
|
||||
private:
|
||||
static int m_clients;
|
||||
static BOOL m_initialized;
|
||||
static nsTArray<CMsgStore *> *m_pStores;
|
||||
static LPMAPISESSION m_lpSession;
|
||||
static LPMDB m_lpMdb;
|
||||
static HRESULT m_lastError;
|
||||
static char16_t *m_pUniBuff;
|
||||
static int m_uniBuffLen;
|
||||
|
||||
private:
|
||||
static int m_clients;
|
||||
static BOOL m_initialized;
|
||||
static nsTArray<CMsgStore*> * m_pStores;
|
||||
static LPMAPISESSION m_lpSession;
|
||||
static LPMDB m_lpMdb;
|
||||
static HRESULT m_lastError;
|
||||
static char16_t * m_pUniBuff;
|
||||
static int m_uniBuffLen;
|
||||
|
||||
static BOOL GetLargeProperty(LPMAPIPROP pProp, ULONG tag, void** result);
|
||||
static BOOL GetLargeProperty(LPMAPIPROP pProp, ULONG tag, void **result);
|
||||
};
|
||||
|
||||
class CMapiFolder {
|
||||
public:
|
||||
public:
|
||||
CMapiFolder();
|
||||
explicit CMapiFolder(const CMapiFolder *pCopyFrom);
|
||||
CMapiFolder(const char16_t *pDisplayName, ULONG cbEid, LPENTRYID lpEid, int depth, LONG oType = MAPI_FOLDER);
|
||||
CMapiFolder(const char16_t *pDisplayName, ULONG cbEid, LPENTRYID lpEid,
|
||||
int depth, LONG oType = MAPI_FOLDER);
|
||||
~CMapiFolder();
|
||||
|
||||
void SetDoImport(BOOL doIt) { m_doImport = doIt;}
|
||||
void SetObjectType(long oType) { m_objectType = oType;}
|
||||
void SetDisplayName(const char16_t *pDisplayName) { m_displayName = pDisplayName;}
|
||||
void SetEntryID(ULONG cbEid, LPENTRYID lpEid);
|
||||
void SetDepth(int depth) { m_depth = depth;}
|
||||
void SetFilePath(const char16_t *pFilePath) { m_mailFilePath = pFilePath;}
|
||||
void SetDoImport(BOOL doIt) { m_doImport = doIt; }
|
||||
void SetObjectType(long oType) { m_objectType = oType; }
|
||||
void SetDisplayName(const char16_t *pDisplayName) {
|
||||
m_displayName = pDisplayName;
|
||||
}
|
||||
void SetEntryID(ULONG cbEid, LPENTRYID lpEid);
|
||||
void SetDepth(int depth) { m_depth = depth; }
|
||||
void SetFilePath(const char16_t *pFilePath) { m_mailFilePath = pFilePath; }
|
||||
|
||||
BOOL GetDoImport(void) const { return m_doImport;}
|
||||
LONG GetObjectType(void) const { return m_objectType;}
|
||||
void GetDisplayName(nsString& name) const { name = m_displayName;}
|
||||
void GetFilePath(nsString& path) const { path = m_mailFilePath;}
|
||||
BOOL IsStore(void) const { return m_objectType == MAPI_STORE;}
|
||||
BOOL IsFolder(void) const { return m_objectType == MAPI_FOLDER;}
|
||||
int GetDepth(void) const { return m_depth;}
|
||||
BOOL GetDoImport(void) const { return m_doImport; }
|
||||
LONG GetObjectType(void) const { return m_objectType; }
|
||||
void GetDisplayName(nsString &name) const { name = m_displayName; }
|
||||
void GetFilePath(nsString &path) const { path = m_mailFilePath; }
|
||||
BOOL IsStore(void) const { return m_objectType == MAPI_STORE; }
|
||||
BOOL IsFolder(void) const { return m_objectType == MAPI_FOLDER; }
|
||||
int GetDepth(void) const { return m_depth; }
|
||||
|
||||
LPENTRYID GetEntryID(ULONG *pCb = NULL) const { if (pCb) *pCb = m_cbEid; return (LPENTRYID) m_lpEid;}
|
||||
ULONG GetCBEntryID(void) const { return m_cbEid;}
|
||||
|
||||
private:
|
||||
LONG m_objectType;
|
||||
ULONG m_cbEid;
|
||||
BYTE * m_lpEid;
|
||||
nsString m_displayName;
|
||||
int m_depth;
|
||||
nsString m_mailFilePath;
|
||||
BOOL m_doImport;
|
||||
LPENTRYID GetEntryID(ULONG *pCb = NULL) const {
|
||||
if (pCb) *pCb = m_cbEid;
|
||||
return (LPENTRYID)m_lpEid;
|
||||
}
|
||||
ULONG GetCBEntryID(void) const { return m_cbEid; }
|
||||
|
||||
private:
|
||||
LONG m_objectType;
|
||||
ULONG m_cbEid;
|
||||
BYTE *m_lpEid;
|
||||
nsString m_displayName;
|
||||
int m_depth;
|
||||
nsString m_mailFilePath;
|
||||
BOOL m_doImport;
|
||||
};
|
||||
|
||||
class CMapiFolderList {
|
||||
public:
|
||||
public:
|
||||
CMapiFolderList();
|
||||
~CMapiFolderList();
|
||||
|
||||
void AddItem(CMapiFolder *pFolder);
|
||||
CMapiFolder * GetItem(int index) { if ((index >= 0) && (index < (int)m_array.Length())) return GetAt(index); else return NULL;}
|
||||
void ClearAll(void);
|
||||
void AddItem(CMapiFolder *pFolder);
|
||||
CMapiFolder *GetItem(int index) {
|
||||
if ((index >= 0) && (index < (int)m_array.Length()))
|
||||
return GetAt(index);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
void ClearAll(void);
|
||||
|
||||
// Debugging and reporting
|
||||
void DumpList(void);
|
||||
void DumpList(void);
|
||||
|
||||
CMapiFolder * GetAt(int index) { return m_array.ElementAt(index);}
|
||||
int GetSize(void) { return m_array.Length();}
|
||||
CMapiFolder *GetAt(int index) { return m_array.ElementAt(index); }
|
||||
int GetSize(void) { return m_array.Length(); }
|
||||
|
||||
protected:
|
||||
void EnsureUniqueName(CMapiFolder *pFolder);
|
||||
void GenerateFilePath(CMapiFolder *pFolder);
|
||||
void ChangeName(nsString& name);
|
||||
protected:
|
||||
void EnsureUniqueName(CMapiFolder *pFolder);
|
||||
void GenerateFilePath(CMapiFolder *pFolder);
|
||||
void ChangeName(nsString &name);
|
||||
|
||||
private:
|
||||
nsTArray<CMapiFolder*> m_array;
|
||||
private:
|
||||
nsTArray<CMapiFolder *> m_array;
|
||||
};
|
||||
|
||||
|
||||
class CMsgStore {
|
||||
public:
|
||||
public:
|
||||
explicit CMsgStore(ULONG cbEid = 0, LPENTRYID lpEid = NULL);
|
||||
~CMsgStore();
|
||||
|
||||
void SetEntryID(ULONG cbEid, LPENTRYID lpEid);
|
||||
BOOL Open(LPMAPISESSION pSession, LPMDB *ppMdb);
|
||||
void SetEntryID(ULONG cbEid, LPENTRYID lpEid);
|
||||
BOOL Open(LPMAPISESSION pSession, LPMDB *ppMdb);
|
||||
|
||||
ULONG GetCBEntryID(void) { return m_cbEid;}
|
||||
LPENTRYID GetLPEntryID(void) { return (LPENTRYID) m_lpEid;}
|
||||
ULONG GetCBEntryID(void) { return m_cbEid; }
|
||||
LPENTRYID GetLPEntryID(void) { return (LPENTRYID)m_lpEid; }
|
||||
|
||||
private:
|
||||
ULONG m_cbEid;
|
||||
BYTE * m_lpEid;
|
||||
LPMDB m_lpMdb;
|
||||
private:
|
||||
ULONG m_cbEid;
|
||||
BYTE *m_lpEid;
|
||||
LPMDB m_lpMdb;
|
||||
};
|
||||
|
||||
|
||||
class CMapiFolderContents {
|
||||
public:
|
||||
public:
|
||||
CMapiFolderContents(LPMDB lpMdb, ULONG cbEID, LPENTRYID lpEid);
|
||||
~CMapiFolderContents();
|
||||
|
||||
BOOL GetNext(ULONG *pcbEid, LPENTRYID *ppEid, ULONG *poType, BOOL *pDone);
|
||||
BOOL GetNext(ULONG *pcbEid, LPENTRYID *ppEid, ULONG *poType, BOOL *pDone);
|
||||
|
||||
ULONG GetCount(void) { return m_count;}
|
||||
ULONG GetCount(void) { return m_count; }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
BOOL SetUpIter(void);
|
||||
|
||||
private:
|
||||
HRESULT m_lastError;
|
||||
BOOL m_failure;
|
||||
LPMDB m_lpMdb;
|
||||
LPMAPIFOLDER m_lpFolder;
|
||||
LPMAPITABLE m_lpTable;
|
||||
ULONG m_fCbEid;
|
||||
BYTE * m_fLpEid;
|
||||
ULONG m_count;
|
||||
ULONG m_iterCount;
|
||||
BYTE * m_lastLpEid;
|
||||
ULONG m_lastCbEid;
|
||||
private:
|
||||
HRESULT m_lastError;
|
||||
BOOL m_failure;
|
||||
LPMDB m_lpMdb;
|
||||
LPMAPIFOLDER m_lpFolder;
|
||||
LPMAPITABLE m_lpTable;
|
||||
ULONG m_fCbEid;
|
||||
BYTE *m_fLpEid;
|
||||
ULONG m_count;
|
||||
ULONG m_iterCount;
|
||||
BYTE *m_lastLpEid;
|
||||
ULONG m_lastCbEid;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MapiApi_h__ */
|
||||
|
|
|
@ -13,28 +13,24 @@
|
|||
*/
|
||||
|
||||
#ifdef MAPI_DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAPI_DUMP_STRING(x) printf("%s", (const char *)x)
|
||||
#define MAPI_TRACE0(x) printf(x)
|
||||
#define MAPI_TRACE1(x, y) printf(x, y)
|
||||
#define MAPI_TRACE2(x, y, z) printf(x, y, z)
|
||||
#define MAPI_TRACE3(x, y, z, a) printf(x, y, z, a)
|
||||
#define MAPI_TRACE4(x, y, z, a, b) printf(x, y, z, a, b)
|
||||
# include <stdio.h>
|
||||
|
||||
# define MAPI_DUMP_STRING(x) printf("%s", (const char *)x)
|
||||
# define MAPI_TRACE0(x) printf(x)
|
||||
# define MAPI_TRACE1(x, y) printf(x, y)
|
||||
# define MAPI_TRACE2(x, y, z) printf(x, y, z)
|
||||
# define MAPI_TRACE3(x, y, z, a) printf(x, y, z, a)
|
||||
# define MAPI_TRACE4(x, y, z, a, b) printf(x, y, z, a, b)
|
||||
|
||||
#else
|
||||
|
||||
#define MAPI_DUMP_STRING(x)
|
||||
#define MAPI_TRACE0(x)
|
||||
#define MAPI_TRACE1(x, y)
|
||||
#define MAPI_TRACE2(x, y, z)
|
||||
#define MAPI_TRACE3(x, y, z, a)
|
||||
#define MAPI_TRACE4(x, y, z, a, b)
|
||||
# define MAPI_DUMP_STRING(x)
|
||||
# define MAPI_TRACE0(x)
|
||||
# define MAPI_TRACE1(x, y)
|
||||
# define MAPI_TRACE2(x, y, z)
|
||||
# define MAPI_TRACE3(x, y, z, a)
|
||||
# define MAPI_TRACE4(x, y, z, a, b)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* MapiDbgLog_h___ */
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -13,57 +13,59 @@
|
|||
#include <vector>
|
||||
|
||||
#ifndef PR_LAST_VERB_EXECUTED
|
||||
#define PR_LAST_VERB_EXECUTED PROP_TAG(PT_LONG, 0x1081)
|
||||
# define PR_LAST_VERB_EXECUTED PROP_TAG(PT_LONG, 0x1081)
|
||||
#endif
|
||||
|
||||
#define EXCHIVERB_REPLYTOSENDER (102)
|
||||
#define EXCHIVERB_REPLYTOALL (103)
|
||||
#define EXCHIVERB_FORWARD (104)
|
||||
#define EXCHIVERB_REPLYTOALL (103)
|
||||
#define EXCHIVERB_FORWARD (104)
|
||||
|
||||
#ifndef PR_ATTACH_CONTENT_ID
|
||||
#define PR_ATTACH_CONTENT_ID PROP_TAG(PT_TSTRING, 0x3712)
|
||||
# define PR_ATTACH_CONTENT_ID PROP_TAG(PT_TSTRING, 0x3712)
|
||||
#endif
|
||||
#ifndef PR_ATTACH_CONTENT_ID_W
|
||||
#define PR_ATTACH_CONTENT_ID_W PROP_TAG(PT_UNICODE, 0x3712)
|
||||
# define PR_ATTACH_CONTENT_ID_W PROP_TAG(PT_UNICODE, 0x3712)
|
||||
#endif
|
||||
#ifndef PR_ATTACH_CONTENT_ID_A
|
||||
#define PR_ATTACH_CONTENT_ID_A PROP_TAG(PT_STRING8, 0x3712)
|
||||
# define PR_ATTACH_CONTENT_ID_A PROP_TAG(PT_STRING8, 0x3712)
|
||||
#endif
|
||||
|
||||
#ifndef PR_ATTACH_FLAGS
|
||||
#define PR_ATTACH_FLAGS PROP_TAG(PT_LONG, 0x3714)
|
||||
# define PR_ATTACH_FLAGS PROP_TAG(PT_LONG, 0x3714)
|
||||
#endif
|
||||
|
||||
#ifndef ATT_INVISIBLE_IN_HTML
|
||||
#define ATT_INVISIBLE_IN_HTML (0x1)
|
||||
# define ATT_INVISIBLE_IN_HTML (0x1)
|
||||
#endif
|
||||
#ifndef ATT_INVISIBLE_IN_RTF
|
||||
#define ATT_INVISIBLE_IN_RTF (0x2)
|
||||
# define ATT_INVISIBLE_IN_RTF (0x2)
|
||||
#endif
|
||||
#ifndef ATT_MHTML_REF
|
||||
#define ATT_MHTML_REF (0x4)
|
||||
# define ATT_MHTML_REF (0x4)
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CMapiMessageHeaders {
|
||||
public:
|
||||
public:
|
||||
// Special headers that MUST appear at most once (see RFC822)
|
||||
enum SpecialHeader { hdrNone=-1, hdrFirst = 0, // utility values
|
||||
hdrDate=hdrFirst,
|
||||
hdrFrom,
|
||||
hdrSender,
|
||||
hdrReplyTo,
|
||||
hdrTo,
|
||||
hdrCc,
|
||||
hdrBcc,
|
||||
hdrMessageID,
|
||||
hdrSubject,
|
||||
hdrMimeVersion,
|
||||
hdrContentType,
|
||||
hdrContentTransferEncoding,
|
||||
hdrMax // utility value
|
||||
};
|
||||
enum SpecialHeader {
|
||||
hdrNone = -1,
|
||||
hdrFirst = 0, // utility values
|
||||
hdrDate = hdrFirst,
|
||||
hdrFrom,
|
||||
hdrSender,
|
||||
hdrReplyTo,
|
||||
hdrTo,
|
||||
hdrCc,
|
||||
hdrBcc,
|
||||
hdrMessageID,
|
||||
hdrSubject,
|
||||
hdrMimeVersion,
|
||||
hdrContentType,
|
||||
hdrContentTransferEncoding,
|
||||
hdrMax // utility value
|
||||
};
|
||||
|
||||
explicit CMapiMessageHeaders(const char* headers = 0) { Assign(headers); }
|
||||
~CMapiMessageHeaders();
|
||||
|
@ -75,8 +77,10 @@ public:
|
|||
// if no such header exists then 0 is returned
|
||||
const char* Value(SpecialHeader special) const;
|
||||
|
||||
void UnfoldValue(const char* name, nsString& dest, const char* fallbackCharset) const;
|
||||
void UnfoldValue(SpecialHeader special, nsString& dest, const char* fallbackCharset) const;
|
||||
void UnfoldValue(const char* name, nsString& dest,
|
||||
const char* fallbackCharset) const;
|
||||
void UnfoldValue(SpecialHeader special, nsString& dest,
|
||||
const char* fallbackCharset) const;
|
||||
|
||||
// value must be utf-8 or 7-bit; supposed that this function will be called
|
||||
// when the charset of the value is known
|
||||
|
@ -88,10 +92,11 @@ public:
|
|||
|
||||
static const char* SpecialName(SpecialHeader special);
|
||||
|
||||
nsresult ToStream(nsIOutputStream *pDst) const;
|
||||
private:
|
||||
nsresult ToStream(nsIOutputStream* pDst) const;
|
||||
|
||||
private:
|
||||
class CHeaderField {
|
||||
public:
|
||||
public:
|
||||
CHeaderField(const char* begin, int len);
|
||||
CHeaderField(const char* name, const char* body, bool utf8 = false);
|
||||
~CHeaderField();
|
||||
|
@ -104,60 +109,68 @@ private:
|
|||
void set_fbody(const char* txt);
|
||||
|
||||
void GetUnfoldedString(nsString& dest, const char* fallbackCharset) const;
|
||||
private:
|
||||
|
||||
private:
|
||||
char* m_fname;
|
||||
char* m_fbody;
|
||||
bool m_fbody_utf8;
|
||||
}; //class HeaderField
|
||||
}; // class HeaderField
|
||||
|
||||
class write_to_stream {
|
||||
public:
|
||||
explicit write_to_stream(nsIOutputStream *pDst) : m_pDst(pDst), m_rv(NS_OK) {}
|
||||
void operator () (const CHeaderField* f);
|
||||
public:
|
||||
explicit write_to_stream(nsIOutputStream* pDst)
|
||||
: m_pDst(pDst), m_rv(NS_OK) {}
|
||||
void operator()(const CHeaderField* f);
|
||||
inline operator nsresult() const { return m_rv; }
|
||||
private:
|
||||
nsIOutputStream *m_pDst;
|
||||
|
||||
private:
|
||||
nsIOutputStream* m_pDst;
|
||||
nsresult m_rv;
|
||||
};
|
||||
|
||||
// Search helper
|
||||
class fname_equals {
|
||||
public:
|
||||
public:
|
||||
explicit fname_equals(const char* search) : m_search(search) {}
|
||||
inline bool operator () (const CHeaderField* f) const { return stricmp(f->fname(), m_search) == 0; }
|
||||
private:
|
||||
inline bool operator()(const CHeaderField* f) const {
|
||||
return stricmp(f->fname(), m_search) == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* m_search;
|
||||
}; // class fname_equals
|
||||
}; // class fname_equals
|
||||
|
||||
// The common array of special headers' names
|
||||
static const char* Specials[hdrMax];
|
||||
|
||||
std::vector<CHeaderField*> m_headerFields;
|
||||
CHeaderField* m_SpecialHeaders[hdrMax]; // Pointers into the m_headerFields
|
||||
CHeaderField* m_SpecialHeaders[hdrMax]; // Pointers into the m_headerFields
|
||||
|
||||
void ClearHeaderFields();
|
||||
void Add(CHeaderField* f);
|
||||
static void Delete(CHeaderField* p);
|
||||
static SpecialHeader CheckSpecialHeader(const char* fname);
|
||||
const CHeaderField* CFind(const char* name) const;
|
||||
inline CHeaderField* Find(const char* name) { return const_cast<CHeaderField*>(CFind(name)); }
|
||||
inline CHeaderField* Find(const char* name) {
|
||||
return const_cast<CHeaderField*>(CFind(name));
|
||||
}
|
||||
|
||||
}; // class CMapiMessageHeaders
|
||||
}; // class CMapiMessageHeaders
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
class CMapiMessage {
|
||||
public:
|
||||
public:
|
||||
explicit CMapiMessage(LPMESSAGE lpMsg);
|
||||
~CMapiMessage();
|
||||
|
||||
// Attachments
|
||||
// Ordinary (not embedded) attachments.
|
||||
nsresult GetAttachments(nsIArray **aArray);
|
||||
nsresult GetAttachments(nsIArray** aArray);
|
||||
// Embedded attachments
|
||||
size_t EmbeddedAttachmentsCount() const { return m_embattachments.size(); }
|
||||
bool GetEmbeddedAttachmentInfo(unsigned int i, nsIURI **uri, const char **cid,
|
||||
const char **name) const;
|
||||
bool GetEmbeddedAttachmentInfo(unsigned int i, nsIURI** uri, const char** cid,
|
||||
const char** name) const;
|
||||
// We don't check MSGFLAG_HASATTACH, since it returns true even if there are
|
||||
// only embedded attachmentsin the message. TB only counts the ordinary
|
||||
// attachments when shows the message status, so here we check only for the
|
||||
|
@ -165,73 +178,75 @@ public:
|
|||
inline bool HasAttach() const { return !m_stdattachments.empty(); }
|
||||
|
||||
// Retrieve info for message
|
||||
inline bool BodyIsHtml(void) const { return m_bodyIsHtml;}
|
||||
const char *GetFromLine(int& len) const {
|
||||
inline bool BodyIsHtml(void) const { return m_bodyIsHtml; }
|
||||
const char* GetFromLine(int& len) const {
|
||||
if (m_fromLine.IsEmpty())
|
||||
return NULL;
|
||||
else {
|
||||
len = m_fromLine.Length();
|
||||
return m_fromLine.get();}
|
||||
return m_fromLine.get();
|
||||
}
|
||||
}
|
||||
inline CMapiMessageHeaders *GetHeaders() { return &m_headers; }
|
||||
inline const wchar_t *GetBody(void) const { return m_body.get(); }
|
||||
inline CMapiMessageHeaders* GetHeaders() { return &m_headers; }
|
||||
inline const wchar_t* GetBody(void) const { return m_body.get(); }
|
||||
inline size_t GetBodyLen(void) const { return m_body.Length(); }
|
||||
void GetBody(nsCString& dest) const;
|
||||
inline const char *GetBodyCharset(void) const { return m_mimeCharset.get();}
|
||||
inline const char* GetBodyCharset(void) const { return m_mimeCharset.get(); }
|
||||
inline bool IsRead() const { return m_msgFlags & MSGFLAG_READ; }
|
||||
inline bool IsReplied() const {
|
||||
return (m_msgLastVerb == EXCHIVERB_REPLYTOSENDER) ||
|
||||
(m_msgLastVerb == EXCHIVERB_REPLYTOALL); }
|
||||
inline bool IsForvarded() const {
|
||||
return m_msgLastVerb == EXCHIVERB_FORWARD; }
|
||||
(m_msgLastVerb == EXCHIVERB_REPLYTOALL);
|
||||
}
|
||||
inline bool IsForvarded() const { return m_msgLastVerb == EXCHIVERB_FORWARD; }
|
||||
|
||||
bool HasContentHeader(void) const {
|
||||
return !m_mimeContentType.IsEmpty();}
|
||||
bool HasMimeVersion(void) const {
|
||||
return m_headers.Value(CMapiMessageHeaders::hdrMimeVersion); }
|
||||
const char *GetMimeContent(void) const { return m_mimeContentType.get();}
|
||||
int32_t GetMimeContentLen(void) const { return m_mimeContentType.Length();}
|
||||
const char *GetMimeBoundary(void) const { return m_mimeBoundary.get();}
|
||||
bool HasContentHeader(void) const { return !m_mimeContentType.IsEmpty(); }
|
||||
bool HasMimeVersion(void) const {
|
||||
return m_headers.Value(CMapiMessageHeaders::hdrMimeVersion);
|
||||
}
|
||||
const char* GetMimeContent(void) const { return m_mimeContentType.get(); }
|
||||
int32_t GetMimeContentLen(void) const { return m_mimeContentType.Length(); }
|
||||
const char* GetMimeBoundary(void) const { return m_mimeBoundary.get(); }
|
||||
|
||||
// The only required part of a message is its header
|
||||
// The only required part of a message is its header
|
||||
inline bool ValidState() const { return !m_headers.IsEmpty(); }
|
||||
inline bool FullMessageDownloaded() const { return !m_dldStateHeadersOnly; }
|
||||
|
||||
private:
|
||||
private:
|
||||
struct attach_data {
|
||||
nsCOMPtr<nsIURI> orig_url;
|
||||
nsCOMPtr<nsIFile> tmp_file;
|
||||
char *type;
|
||||
char *encoding;
|
||||
char *real_name;
|
||||
char *cid;
|
||||
char* type;
|
||||
char* encoding;
|
||||
char* real_name;
|
||||
char* cid;
|
||||
bool delete_file;
|
||||
attach_data() : type(0), encoding(0), real_name(0), cid(0), delete_file(false) {}
|
||||
attach_data()
|
||||
: type(0), encoding(0), real_name(0), cid(0), delete_file(false) {}
|
||||
};
|
||||
|
||||
static const nsCString m_whitespace;
|
||||
static const nsCString m_whitespace;
|
||||
|
||||
LPMESSAGE m_lpMsg;
|
||||
LPMESSAGE m_lpMsg;
|
||||
|
||||
bool m_dldStateHeadersOnly; // if the message has not been downloaded yet
|
||||
CMapiMessageHeaders m_headers;
|
||||
nsCString m_fromLine; // utf-8
|
||||
nsCString m_mimeContentType; // utf-8
|
||||
nsCString m_mimeBoundary; // utf-8
|
||||
nsCString m_mimeCharset; // utf-8
|
||||
bool m_dldStateHeadersOnly; // if the message has not been downloaded yet
|
||||
CMapiMessageHeaders m_headers;
|
||||
nsCString m_fromLine; // utf-8
|
||||
nsCString m_mimeContentType; // utf-8
|
||||
nsCString m_mimeBoundary; // utf-8
|
||||
nsCString m_mimeCharset; // utf-8
|
||||
|
||||
std::vector<attach_data*> m_stdattachments;
|
||||
std::vector<attach_data*> m_embattachments; // Embedded
|
||||
std::vector<attach_data*> m_embattachments; // Embedded
|
||||
|
||||
nsString m_body; // to be converted from UTF-16 using m_mimeCharset
|
||||
bool m_bodyIsHtml;
|
||||
nsString m_body; // to be converted from UTF-16 using m_mimeCharset
|
||||
bool m_bodyIsHtml;
|
||||
|
||||
uint32_t m_msgFlags;
|
||||
uint32_t m_msgLastVerb;
|
||||
|
||||
nsCOMPtr<nsIIOService> m_pIOService;
|
||||
|
||||
void GetDownloadState();
|
||||
void GetDownloadState();
|
||||
|
||||
// Headers - fetch will get PR_TRANSPORT_MESSAGE_HEADERS
|
||||
// or if they do not exist will build a header from
|
||||
|
@ -239,33 +254,36 @@ private:
|
|||
// PR_SUBJECT
|
||||
// PR_MESSAGE_RECIPIENTS
|
||||
// and PR_CREATION_TIME if needed?
|
||||
bool FetchHeaders(void);
|
||||
bool FetchBody(void);
|
||||
void FetchFlags(void);
|
||||
bool FetchHeaders(void);
|
||||
bool FetchBody(void);
|
||||
void FetchFlags(void);
|
||||
|
||||
static bool GetTmpFile(/*out*/ nsIFile **aResult);
|
||||
static bool CopyMsgAttachToFile(LPATTACH lpAttach, /*out*/ nsIFile **tmp_file);
|
||||
static bool CopyBinAttachToFile(LPATTACH lpAttach, nsIFile **tmp_file);
|
||||
static bool GetTmpFile(/*out*/ nsIFile** aResult);
|
||||
static bool CopyMsgAttachToFile(LPATTACH lpAttach,
|
||||
/*out*/ nsIFile** tmp_file);
|
||||
static bool CopyBinAttachToFile(LPATTACH lpAttach, nsIFile** tmp_file);
|
||||
|
||||
static void ClearAttachment(attach_data* data);
|
||||
void ClearAttachments();
|
||||
bool AddAttachment(DWORD aNum);
|
||||
bool IterateAttachTable(LPMAPITABLE tbl);
|
||||
bool GetURL(nsIFile *aFile, nsIURI **url);
|
||||
void ProcessAttachments();
|
||||
void ClearAttachments();
|
||||
bool AddAttachment(DWORD aNum);
|
||||
bool IterateAttachTable(LPMAPITABLE tbl);
|
||||
bool GetURL(nsIFile* aFile, nsIURI** url);
|
||||
void ProcessAttachments();
|
||||
|
||||
bool EnsureHeader(CMapiMessageHeaders::SpecialHeader special, ULONG mapiTag);
|
||||
bool EnsureDate();
|
||||
bool EnsureHeader(CMapiMessageHeaders::SpecialHeader special, ULONG mapiTag);
|
||||
bool EnsureDate();
|
||||
|
||||
void ProcessContentType();
|
||||
bool CheckBodyInCharsetRange(const char* charset);
|
||||
void FormatDateTime(SYSTEMTIME& tm, nsCString& s, bool includeTZ = true);
|
||||
void BuildFromLine(void);
|
||||
void ProcessContentType();
|
||||
bool CheckBodyInCharsetRange(const char* charset);
|
||||
void FormatDateTime(SYSTEMTIME& tm, nsCString& s, bool includeTZ = true);
|
||||
void BuildFromLine(void);
|
||||
|
||||
inline static bool IsSpace(char c) {
|
||||
return c == ' ' || c == '\r' || c == '\n' || c == '\b' || c == '\t';}
|
||||
return c == ' ' || c == '\r' || c == '\n' || c == '\b' || c == '\t';
|
||||
}
|
||||
inline static bool IsSpace(wchar_t c) {
|
||||
return ((c & 0xFF) == c) && IsSpace(static_cast<char>(c)); } // Avoid false detections
|
||||
return ((c & 0xFF) == c) && IsSpace(static_cast<char>(c));
|
||||
} // Avoid false detections
|
||||
};
|
||||
|
||||
#endif /* MapiMessage_h__ */
|
||||
|
|
|
@ -9,17 +9,16 @@
|
|||
|
||||
uint8_t CMimeTypes::m_mimeBuffer[kMaxMimeTypeSize];
|
||||
|
||||
|
||||
BOOL CMimeTypes::GetKey(HKEY root, LPCTSTR pName, PHKEY pKey)
|
||||
{
|
||||
LONG result = RegOpenKeyEx(root, pName, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, pKey);
|
||||
BOOL CMimeTypes::GetKey(HKEY root, LPCTSTR pName, PHKEY pKey) {
|
||||
LONG result = RegOpenKeyEx(root, pName, 0,
|
||||
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, pKey);
|
||||
return result == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL CMimeTypes::GetValueBytes(HKEY rootKey, LPCTSTR pValName, LPBYTE *ppBytes)
|
||||
{
|
||||
LONG err;
|
||||
DWORD bufSz;
|
||||
BOOL CMimeTypes::GetValueBytes(HKEY rootKey, LPCTSTR pValName,
|
||||
LPBYTE* ppBytes) {
|
||||
LONG err;
|
||||
DWORD bufSz;
|
||||
|
||||
*ppBytes = NULL;
|
||||
// Get the installed directory
|
||||
|
@ -36,16 +35,13 @@ BOOL CMimeTypes::GetValueBytes(HKEY rootKey, LPCTSTR pValName, LPBYTE *ppBytes)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void CMimeTypes::ReleaseValueBytes(LPBYTE pBytes)
|
||||
{
|
||||
if (pBytes)
|
||||
delete pBytes;
|
||||
void CMimeTypes::ReleaseValueBytes(LPBYTE pBytes) {
|
||||
if (pBytes) delete pBytes;
|
||||
}
|
||||
|
||||
BOOL CMimeTypes::GetMimeTypeFromReg(const nsCString& ext, LPBYTE *ppBytes)
|
||||
{
|
||||
HKEY extensionKey;
|
||||
BOOL result = FALSE;
|
||||
BOOL CMimeTypes::GetMimeTypeFromReg(const nsCString& ext, LPBYTE* ppBytes) {
|
||||
HKEY extensionKey;
|
||||
BOOL result = FALSE;
|
||||
*ppBytes = NULL;
|
||||
if (GetKey(HKEY_CLASSES_ROOT, ext.get(), &extensionKey)) {
|
||||
result = GetValueBytes(extensionKey, "Content Type", ppBytes);
|
||||
|
@ -55,16 +51,14 @@ BOOL CMimeTypes::GetMimeTypeFromReg(const nsCString& ext, LPBYTE *ppBytes)
|
|||
return result;
|
||||
}
|
||||
|
||||
uint8_t * CMimeTypes::GetMimeType(const nsString& theExt)
|
||||
{
|
||||
uint8_t* CMimeTypes::GetMimeType(const nsString& theExt) {
|
||||
nsCString ext;
|
||||
LossyCopyUTF16toASCII(theExt, ext);
|
||||
return GetMimeType(ext);
|
||||
}
|
||||
|
||||
uint8_t * CMimeTypes::GetMimeType(const nsCString& theExt)
|
||||
{
|
||||
nsCString ext = theExt;
|
||||
uint8_t* CMimeTypes::GetMimeType(const nsCString& theExt) {
|
||||
nsCString ext = theExt;
|
||||
if (ext.Length()) {
|
||||
if (ext.First() != '.') {
|
||||
ext = ".";
|
||||
|
@ -72,15 +66,13 @@ uint8_t * CMimeTypes::GetMimeType(const nsCString& theExt)
|
|||
}
|
||||
}
|
||||
|
||||
BOOL result = FALSE;
|
||||
int len;
|
||||
|
||||
BOOL result = FALSE;
|
||||
int len;
|
||||
|
||||
if (!ext.Length())
|
||||
return NULL;
|
||||
LPBYTE pByte;
|
||||
if (!ext.Length()) return NULL;
|
||||
LPBYTE pByte;
|
||||
if (GetMimeTypeFromReg(ext, &pByte)) {
|
||||
len = strlen((const char *) pByte);
|
||||
len = strlen((const char*)pByte);
|
||||
if (len && (len < kMaxMimeTypeSize)) {
|
||||
memcpy(m_mimeBuffer, pByte, len);
|
||||
m_mimeBuffer[len] = 0;
|
||||
|
@ -89,8 +81,7 @@ uint8_t * CMimeTypes::GetMimeType(const nsCString& theExt)
|
|||
ReleaseValueBytes(pByte);
|
||||
}
|
||||
|
||||
if (result)
|
||||
return m_mimeBuffer;
|
||||
if (result) return m_mimeBuffer;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -8,24 +8,21 @@
|
|||
|
||||
#include <windows.h>
|
||||
|
||||
#define kMaxMimeTypeSize 256
|
||||
#define kMaxMimeTypeSize 256
|
||||
|
||||
class CMimeTypes {
|
||||
public:
|
||||
public:
|
||||
static uint8_t* GetMimeType(const nsCString& theExt);
|
||||
static uint8_t* GetMimeType(const nsString& theExt);
|
||||
|
||||
static uint8_t * GetMimeType(const nsCString& theExt);
|
||||
static uint8_t * GetMimeType(const nsString& theExt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
// Registry stuff
|
||||
static BOOL GetKey(HKEY root, LPCTSTR pName, PHKEY pKey);
|
||||
static BOOL GetValueBytes(HKEY rootKey, LPCTSTR pValName, LPBYTE *ppBytes);
|
||||
static void ReleaseValueBytes(LPBYTE pBytes);
|
||||
static BOOL GetMimeTypeFromReg(const nsCString& ext, LPBYTE *ppBytes);
|
||||
static BOOL GetKey(HKEY root, LPCTSTR pName, PHKEY pKey);
|
||||
static BOOL GetValueBytes(HKEY rootKey, LPCTSTR pValName, LPBYTE* ppBytes);
|
||||
static void ReleaseValueBytes(LPBYTE pBytes);
|
||||
static BOOL GetMimeTypeFromReg(const nsCString& ext, LPBYTE* ppBytes);
|
||||
|
||||
|
||||
static uint8_t m_mimeBuffer[kMaxMimeTypeSize];
|
||||
static uint8_t m_mimeBuffer[kMaxMimeTypeSize];
|
||||
};
|
||||
|
||||
#endif /* MapiMimeTypes_h__ */
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -43,8 +43,8 @@
|
|||
static NS_DEFINE_CID(kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID);
|
||||
|
||||
#ifdef IMPORT_DEBUG
|
||||
static const char *p_test_headers =
|
||||
"Received: from netppl.invalid (IDENT:monitor@get.freebsd.because.microsoftsucks.invalid [209.3.31.115])\n\
|
||||
static const char* p_test_headers =
|
||||
"Received: from netppl.invalid (IDENT:monitor@get.freebsd.because.microsoftsucks.invalid [209.3.31.115])\n\
|
||||
by mail4.sirius.invalid (8.9.1/8.9.1) with SMTP id PAA27232;\n\
|
||||
Mon, 17 May 1999 15:27:43 -0700 (PDT)\n\
|
||||
Message-ID: <ikGD3jRTsKklU.Ggm2HmE2A1Jsqd0p@netppl.invalid>\n\
|
||||
|
@ -57,89 +57,107 @@ Content-Transfer-Encoding: 7bit\n\
|
|||
X-UIDL: 19990517.152941\n\
|
||||
Status: RO";
|
||||
|
||||
static const char *p_test_body =
|
||||
"Hello world?\n\
|
||||
static const char* p_test_body =
|
||||
"Hello world?\n\
|
||||
";
|
||||
#else
|
||||
#define p_test_headers nullptr
|
||||
#define p_test_body nullptr
|
||||
# define p_test_headers nullptr
|
||||
# define p_test_body nullptr
|
||||
#endif
|
||||
|
||||
#define kWhitespace "\b\t\r\n "
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// A replacement for SimpleBufferTonyRCopiedTwice round-robin buffer and ReadFileState classes
|
||||
// A replacement for SimpleBufferTonyRCopiedTwice round-robin buffer and
|
||||
// ReadFileState classes
|
||||
class CCompositionFile {
|
||||
public:
|
||||
public:
|
||||
// fifoBuffer is used for memory allocation optimization
|
||||
// convertCRs controls if we want to convert standalone CRs to CRLFs
|
||||
CCompositionFile(nsIFile* aFile, void* fifoBuffer, uint32_t fifoBufferSize, bool convertCRs=false);
|
||||
CCompositionFile(nsIFile* aFile, void* fifoBuffer, uint32_t fifoBufferSize,
|
||||
bool convertCRs = false);
|
||||
|
||||
explicit operator bool() const { return m_fileSize && m_pInputStream; }
|
||||
|
||||
// Reads up to and including the term sequence, or entire file if term isn't found
|
||||
// termSize may be used to include NULLs in the terminator sequences.
|
||||
// termSize value of -1 means "zero-terminated string" -> size is calculated with strlen
|
||||
nsresult ToString(nsCString& dest, const char* term=0, int termSize=-1);
|
||||
nsresult ToStream(nsIOutputStream *dest, const char* term=0, int termSize=-1);
|
||||
// Reads up to and including the term sequence, or entire file if term isn't
|
||||
// found termSize may be used to include NULLs in the terminator sequences.
|
||||
// termSize value of -1 means "zero-terminated string" -> size is calculated
|
||||
// with strlen
|
||||
nsresult ToString(nsCString& dest, const char* term = 0, int termSize = -1);
|
||||
nsresult ToStream(nsIOutputStream* dest, const char* term = 0,
|
||||
int termSize = -1);
|
||||
char LastChar() { return m_lastChar; }
|
||||
private:
|
||||
nsCOMPtr<nsIFile> m_pFile;
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIFile> m_pFile;
|
||||
nsCOMPtr<nsIInputStream> m_pInputStream;
|
||||
int64_t m_fileSize;
|
||||
int64_t m_fileReadPos;
|
||||
char* m_fifoBuffer;
|
||||
uint32_t m_fifoBufferSize;
|
||||
char* m_fifoBufferReadPos; // next character to read
|
||||
char* m_fifoBufferWrittenPos; // if we have read less than buffer size then this will show it
|
||||
char* m_fifoBufferReadPos; // next character to read
|
||||
char* m_fifoBufferWrittenPos; // if we have read less than buffer size then
|
||||
// this will show it
|
||||
bool m_convertCRs;
|
||||
char m_lastChar;
|
||||
|
||||
nsresult EnsureHasDataInBuffer();
|
||||
template <class _OutFn> nsresult ToDest(_OutFn dest, const char* term, int termSize);
|
||||
template <class _OutFn>
|
||||
nsresult ToDest(_OutFn dest, const char* term, int termSize);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// First off, a listener
|
||||
class OutlookSendListener : public nsIMsgSendListener
|
||||
{
|
||||
public:
|
||||
OutlookSendListener() {
|
||||
m_done = false;
|
||||
}
|
||||
class OutlookSendListener : public nsIMsgSendListener {
|
||||
public:
|
||||
OutlookSendListener() { m_done = false; }
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
/* void OnStartSending (in string aMsgID, in uint32_t aMsgSize); */
|
||||
NS_IMETHOD OnStartSending(const char *aMsgID, uint32_t aMsgSize) {return NS_OK;}
|
||||
NS_IMETHOD OnStartSending(const char* aMsgID, uint32_t aMsgSize) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void OnProgress (in string aMsgID, in uint32_t aProgress, in uint32_t aProgressMax); */
|
||||
NS_IMETHOD OnProgress(const char *aMsgID, uint32_t aProgress, uint32_t aProgressMax) {return NS_OK;}
|
||||
/* void OnProgress (in string aMsgID, in uint32_t aProgress, in uint32_t
|
||||
* aProgressMax); */
|
||||
NS_IMETHOD OnProgress(const char* aMsgID, uint32_t aProgress,
|
||||
uint32_t aProgressMax) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void OnStatus (in string aMsgID, in wstring aMsg); */
|
||||
NS_IMETHOD OnStatus(const char *aMsgID, const char16_t *aMsg) {return NS_OK;}
|
||||
NS_IMETHOD OnStatus(const char* aMsgID, const char16_t* aMsg) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void OnStopSending (in string aMsgID, in nsresult aStatus, in wstring aMsg, in nsIFile returnFile); */
|
||||
NS_IMETHOD OnStopSending(const char *aMsgID, nsresult aStatus, const char16_t *aMsg,
|
||||
nsIFile *returnFile) {
|
||||
/* void OnStopSending (in string aMsgID, in nsresult aStatus, in wstring aMsg,
|
||||
* in nsIFile returnFile); */
|
||||
NS_IMETHOD OnStopSending(const char* aMsgID, nsresult aStatus,
|
||||
const char16_t* aMsg, nsIFile* returnFile) {
|
||||
m_done = true;
|
||||
m_location = returnFile;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void OnSendNotPerformed */
|
||||
NS_IMETHOD OnSendNotPerformed(const char *aMsgID, nsresult aStatus) {return NS_OK;}
|
||||
/* void OnSendNotPerformed */
|
||||
NS_IMETHOD OnSendNotPerformed(const char* aMsgID, nsresult aStatus) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void OnGetDraftFolderURI (); */
|
||||
NS_IMETHOD OnGetDraftFolderURI(const char *aFolderURI) {return NS_OK;}
|
||||
NS_IMETHOD OnGetDraftFolderURI(const char* aFolderURI) { return NS_OK; }
|
||||
|
||||
static nsresult CreateSendListener(nsIMsgSendListener **ppListener);
|
||||
void Reset() { m_done = false; m_location = nullptr; }
|
||||
static nsresult CreateSendListener(nsIMsgSendListener** ppListener);
|
||||
void Reset() {
|
||||
m_done = false;
|
||||
m_location = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual ~OutlookSendListener() {}
|
||||
|
||||
bool m_done;
|
||||
|
@ -148,8 +166,8 @@ public:
|
|||
|
||||
NS_IMPL_ISUPPORTS(OutlookSendListener, nsIMsgSendListener)
|
||||
|
||||
nsresult OutlookSendListener::CreateSendListener(nsIMsgSendListener **ppListener)
|
||||
{
|
||||
nsresult OutlookSendListener::CreateSendListener(
|
||||
nsIMsgSendListener** ppListener) {
|
||||
NS_ENSURE_ARG_POINTER(ppListener);
|
||||
NS_ADDREF(*ppListener = new OutlookSendListener());
|
||||
return NS_OK;
|
||||
|
@ -160,32 +178,27 @@ nsresult OutlookSendListener::CreateSendListener(nsIMsgSendListener **ppListener
|
|||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsOutlookCompose::nsOutlookCompose()
|
||||
{
|
||||
nsOutlookCompose::nsOutlookCompose() {
|
||||
m_optimizationBuffer = new char[FILE_IO_BUFFER_SIZE];
|
||||
}
|
||||
|
||||
nsOutlookCompose::~nsOutlookCompose()
|
||||
{
|
||||
nsOutlookCompose::~nsOutlookCompose() {
|
||||
if (m_pIdentity) {
|
||||
nsresult rv = m_pIdentity->ClearAllValues();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"failed to clear values");
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to clear values");
|
||||
if (NS_FAILED(rv)) return;
|
||||
}
|
||||
delete[] m_optimizationBuffer;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMsgIdentity> nsOutlookCompose::m_pIdentity = nullptr;
|
||||
|
||||
nsresult nsOutlookCompose::CreateIdentity(void)
|
||||
{
|
||||
if (m_pIdentity)
|
||||
return NS_OK;
|
||||
nsresult nsOutlookCompose::CreateIdentity(void) {
|
||||
if (m_pIdentity) return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accMgr =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = accMgr->CreateIdentity(getter_AddRefs(m_pIdentity));
|
||||
nsString name;
|
||||
|
@ -197,13 +210,9 @@ nsresult nsOutlookCompose::CreateIdentity(void)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void nsOutlookCompose::ReleaseIdentity()
|
||||
{
|
||||
m_pIdentity = nullptr;
|
||||
}
|
||||
void nsOutlookCompose::ReleaseIdentity() { m_pIdentity = nullptr; }
|
||||
|
||||
nsresult nsOutlookCompose::CreateComponents(void)
|
||||
{
|
||||
nsresult nsOutlookCompose::CreateComponents(void) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
m_pMsgFields = nullptr;
|
||||
|
@ -211,7 +220,7 @@ nsresult nsOutlookCompose::CreateComponents(void)
|
|||
rv = OutlookSendListener::CreateSendListener(getter_AddRefs(m_pListener));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
m_pMsgFields = do_CreateInstance(kMsgCompFieldsCID, &rv);
|
||||
m_pMsgFields = do_CreateInstance(kMsgCompFieldsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && m_pMsgFields) {
|
||||
// IMPORT_LOG0("nsOutlookCompose - CreateComponents succeeded\n");
|
||||
m_pMsgFields->SetForcePlainText(false);
|
||||
|
@ -222,8 +231,9 @@ nsresult nsOutlookCompose::CreateComponents(void)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage &msg, nsIFile **pMsg)
|
||||
{
|
||||
nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode,
|
||||
CMapiMessage& msg,
|
||||
nsIFile** pMsg) {
|
||||
nsresult rv = CreateComponents();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = CreateIdentity();
|
||||
|
@ -234,16 +244,21 @@ nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage
|
|||
CMapiMessageHeaders* headers = msg.GetHeaders();
|
||||
|
||||
nsString unival;
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrFrom, unival, msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrFrom, unival,
|
||||
msg.GetBodyCharset());
|
||||
m_pMsgFields->SetFrom(unival);
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrTo, unival, msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrTo, unival,
|
||||
msg.GetBodyCharset());
|
||||
m_pMsgFields->SetTo(unival);
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrSubject, unival, msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrSubject, unival,
|
||||
msg.GetBodyCharset());
|
||||
m_pMsgFields->SetSubject(unival);
|
||||
m_pMsgFields->SetCharacterSet(msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrCc, unival, msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrCc, unival,
|
||||
msg.GetBodyCharset());
|
||||
m_pMsgFields->SetCc(unival);
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrReplyTo, unival, msg.GetBodyCharset());
|
||||
headers->UnfoldValue(CMapiMessageHeaders::hdrReplyTo, unival,
|
||||
msg.GetBodyCharset());
|
||||
m_pMsgFields->SetReplyTo(unival);
|
||||
m_pMsgFields->SetMessageId(headers->Value(CMapiMessageHeaders::hdrMessageID));
|
||||
|
||||
|
@ -261,8 +276,8 @@ nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage
|
|||
nsCOMPtr<nsIMutableArray> embeddedObjects;
|
||||
|
||||
if (msg.BodyIsHtml()) {
|
||||
for (unsigned int i = 0; i <msg.EmbeddedAttachmentsCount(); i++) {
|
||||
nsIURI *uri;
|
||||
for (unsigned int i = 0; i < msg.EmbeddedAttachmentsCount(); i++) {
|
||||
nsIURI* uri;
|
||||
const char* cid;
|
||||
const char* name;
|
||||
if (msg.GetEmbeddedAttachmentInfo(i, &uri, &cid, &name)) {
|
||||
|
@ -271,36 +286,39 @@ nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
nsCOMPtr<nsIMsgEmbeddedImageData> imageData =
|
||||
new nsImportEmbeddedImageData(uri, nsDependentCString(cid),
|
||||
nsDependentCString(name));
|
||||
new nsImportEmbeddedImageData(uri, nsDependentCString(cid),
|
||||
nsDependentCString(name));
|
||||
embeddedObjects->AppendElement(imageData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCString bodyA;
|
||||
const char *charset = msg.GetBodyCharset();
|
||||
nsMsgI18NConvertFromUnicode(charset ? nsDependentCString(charset) : EmptyCString(), bodyW, bodyA);
|
||||
const char* charset = msg.GetBodyCharset();
|
||||
nsMsgI18NConvertFromUnicode(
|
||||
charset ? nsDependentCString(charset) : EmptyCString(), bodyW, bodyA);
|
||||
|
||||
nsCOMPtr<nsIImportService> impService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impService(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// nsIImportService::CreateRFC822Message creates a runnable and dispatches to the main thread.
|
||||
// nsIImportService::CreateRFC822Message creates a runnable and dispatches to
|
||||
// the main thread.
|
||||
rv = impService->CreateRFC822Message(
|
||||
m_pIdentity, // dummy identity
|
||||
m_pMsgFields, // message fields
|
||||
msg.BodyIsHtml() ? "text/html" : "text/plain",
|
||||
bodyA, // body pointer
|
||||
mode == nsIMsgSend::nsMsgSaveAsDraft,
|
||||
pAttach, // local attachments
|
||||
embeddedObjects,
|
||||
m_pListener); // listener
|
||||
m_pIdentity, // dummy identity
|
||||
m_pMsgFields, // message fields
|
||||
msg.BodyIsHtml() ? "text/html" : "text/plain",
|
||||
bodyA, // body pointer
|
||||
mode == nsIMsgSend::nsMsgSaveAsDraft,
|
||||
pAttach, // local attachments
|
||||
embeddedObjects,
|
||||
m_pListener); // listener
|
||||
|
||||
OutlookSendListener *pListen = static_cast<OutlookSendListener *>(m_pListener.get());
|
||||
OutlookSendListener* pListen =
|
||||
static_cast<OutlookSendListener*>(m_pListener.get());
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG1("*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Wait for the listener to get done.
|
||||
nsCOMPtr<nsIThread> thread(do_GetCurrentThread());
|
||||
while (!pListen->m_done) {
|
||||
|
@ -311,8 +329,7 @@ nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage
|
|||
if (pListen->m_location) {
|
||||
pListen->m_location->Clone(pMsg);
|
||||
rv = NS_OK;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
IMPORT_LOG0("*** Error, Outlook compose unsuccessful\n");
|
||||
}
|
||||
|
@ -321,21 +338,22 @@ nsresult nsOutlookCompose::ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsOutlookCompose::CopyComposedMessage(nsIFile *pSrc,
|
||||
nsIOutputStream *pDst,
|
||||
CMapiMessage& origMsg)
|
||||
{
|
||||
nsresult nsOutlookCompose::CopyComposedMessage(nsIFile* pSrc,
|
||||
nsIOutputStream* pDst,
|
||||
CMapiMessage& origMsg) {
|
||||
// I'm unsure if we really need the convertCRs feature here.
|
||||
// The headers in the file are generated by TB, the body was generated by rtf reader that always used CRLF,
|
||||
// and the attachments were processed by TB either... However, I let it stay as it was in the original code.
|
||||
// The headers in the file are generated by TB, the body was generated by rtf
|
||||
// reader that always used CRLF, and the attachments were processed by TB
|
||||
// either... However, I let it stay as it was in the original code.
|
||||
CCompositionFile f(pSrc, m_optimizationBuffer, FILE_IO_BUFFER_SIZE, true);
|
||||
if (!f) {
|
||||
IMPORT_LOG0("*** Error, unexpected zero file size for composed message\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// The "From ..." separates the messages. Without it, TB cannot see the messages in the mailbox file.
|
||||
// Thus, the lines that look like "From ..." in the message must be escaped (see EscapeFromSpaceLine())
|
||||
// The "From ..." separates the messages. Without it, TB cannot see the
|
||||
// messages in the mailbox file. Thus, the lines that look like "From ..." in
|
||||
// the message must be escaped (see EscapeFromSpaceLine())
|
||||
int fromLineLen;
|
||||
const char* fromLine = origMsg.GetFromLine(fromLineLen);
|
||||
uint32_t written;
|
||||
|
@ -345,19 +363,16 @@ nsresult nsOutlookCompose::CopyComposedMessage(nsIFile *pSrc,
|
|||
// Write out the x-mozilla-status headers.
|
||||
char statusLine[50];
|
||||
uint32_t msgFlags = 0;
|
||||
if (origMsg.IsRead())
|
||||
msgFlags |= nsMsgMessageFlags::Read;
|
||||
if (!origMsg.FullMessageDownloaded())
|
||||
msgFlags |= nsMsgMessageFlags::Partial;
|
||||
if (origMsg.IsForvarded())
|
||||
msgFlags |= nsMsgMessageFlags::Forwarded;
|
||||
if (origMsg.IsReplied())
|
||||
msgFlags |= nsMsgMessageFlags::Replied;
|
||||
if (origMsg.HasAttach())
|
||||
msgFlags |= nsMsgMessageFlags::Attachment;
|
||||
_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF);
|
||||
if (origMsg.IsRead()) msgFlags |= nsMsgMessageFlags::Read;
|
||||
if (!origMsg.FullMessageDownloaded()) msgFlags |= nsMsgMessageFlags::Partial;
|
||||
if (origMsg.IsForvarded()) msgFlags |= nsMsgMessageFlags::Forwarded;
|
||||
if (origMsg.IsReplied()) msgFlags |= nsMsgMessageFlags::Replied;
|
||||
if (origMsg.HasAttach()) msgFlags |= nsMsgMessageFlags::Attachment;
|
||||
_snprintf(statusLine, sizeof(statusLine),
|
||||
X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF);
|
||||
rv = pDst->Write(statusLine, strlen(statusLine), &written);
|
||||
_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF0000);
|
||||
_snprintf(statusLine, sizeof(statusLine),
|
||||
X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF0000);
|
||||
rv = pDst->Write(statusLine, strlen(statusLine), &written);
|
||||
// End Bug 219269
|
||||
|
||||
|
@ -367,37 +382,39 @@ nsresult nsOutlookCompose::CopyComposedMessage(nsIFile *pSrc,
|
|||
// along with all of the other headers from the "old" message!
|
||||
|
||||
nsCString newHeadersStr;
|
||||
rv = f.ToString(newHeadersStr, MSG_LINEBREAK MSG_LINEBREAK); // Read all the headers
|
||||
rv = f.ToString(newHeadersStr,
|
||||
MSG_LINEBREAK MSG_LINEBREAK); // Read all the headers
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
UpdateHeaders(*origMsg.GetHeaders(), CMapiMessageHeaders(newHeadersStr.get()));
|
||||
UpdateHeaders(*origMsg.GetHeaders(),
|
||||
CMapiMessageHeaders(newHeadersStr.get()));
|
||||
rv = origMsg.GetHeaders()->ToStream(pDst);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// I use the terminating sequence here to avoid a possible situation when a "From " line
|
||||
// gets split over two sequential reads and thus will not be escaped.
|
||||
// This is done by reading up to CRLF (one line every time), though it may be slower
|
||||
// I use the terminating sequence here to avoid a possible situation when a
|
||||
// "From " line gets split over two sequential reads and thus will not be
|
||||
// escaped. This is done by reading up to CRLF (one line every time), though
|
||||
// it may be slower
|
||||
|
||||
// Here I revert the changes that were made when the multipart/related message
|
||||
// was composed in nsMsgSend::ProcessMultipartRelated() - the Content-Ids of
|
||||
// attachments were replaced with new ones.
|
||||
nsCString line;
|
||||
while (NS_SUCCEEDED(f.ToString(line, MSG_LINEBREAK))) {
|
||||
EscapeFromSpaceLine(pDst, const_cast<char*>(line.get()), line.get()+line.Length());
|
||||
EscapeFromSpaceLine(pDst, const_cast<char*>(line.get()),
|
||||
line.get() + line.Length());
|
||||
}
|
||||
|
||||
if (f.LastChar() != nsCRT::LF) {
|
||||
rv = pDst->Write(MSG_LINEBREAK, 2, &written);
|
||||
if (written != 2)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (written != 2) rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsOutlookCompose::ProcessMessage(nsMsgDeliverMode mode,
|
||||
CMapiMessage &msg,
|
||||
nsIOutputStream *pDst)
|
||||
{
|
||||
CMapiMessage& msg,
|
||||
nsIOutputStream* pDst) {
|
||||
nsCOMPtr<nsIFile> compositionFile;
|
||||
nsresult rv = ComposeTheMessage(mode, msg, getter_AddRefs(compositionFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -412,23 +429,20 @@ nsresult nsOutlookCompose::ProcessMessage(nsMsgDeliverMode mode,
|
|||
void nsOutlookCompose::UpdateHeader(CMapiMessageHeaders& oldHeaders,
|
||||
const CMapiMessageHeaders& newHeaders,
|
||||
CMapiMessageHeaders::SpecialHeader header,
|
||||
bool addIfAbsent)
|
||||
{
|
||||
bool addIfAbsent) {
|
||||
const char* oldVal = oldHeaders.Value(header);
|
||||
if (!addIfAbsent && !oldVal)
|
||||
return;
|
||||
if (!addIfAbsent && !oldVal) return;
|
||||
const char* newVal = newHeaders.Value(header);
|
||||
if (!newVal)
|
||||
return;
|
||||
// Bug 145150 - Turn "Content-Type: application/ms-tnef" into "Content-Type: text/plain"
|
||||
// so the body text can be displayed normally (instead of in an attachment).
|
||||
if (!newVal) return;
|
||||
// Bug 145150 - Turn "Content-Type: application/ms-tnef" into "Content-Type:
|
||||
// text/plain"
|
||||
// so the body text can be displayed normally (instead of in an
|
||||
// attachment).
|
||||
if (header == CMapiMessageHeaders::hdrContentType)
|
||||
if (stricmp(newVal, "application/ms-tnef") == 0)
|
||||
newVal = "text/plain";
|
||||
if (stricmp(newVal, "application/ms-tnef") == 0) newVal = "text/plain";
|
||||
// End Bug 145150
|
||||
if (oldVal) {
|
||||
if (strcmp(oldVal, newVal) == 0)
|
||||
return;
|
||||
if (strcmp(oldVal, newVal) == 0) return;
|
||||
// Backup the old header value
|
||||
nsCString backupHdrName("X-MozillaBackup-");
|
||||
backupHdrName += CMapiMessageHeaders::SpecialName(header);
|
||||
|
@ -438,10 +452,11 @@ void nsOutlookCompose::UpdateHeader(CMapiMessageHeaders& oldHeaders,
|
|||
oldHeaders.SetValue(header, newVal);
|
||||
}
|
||||
|
||||
void nsOutlookCompose::UpdateHeaders(CMapiMessageHeaders& oldHeaders, const CMapiMessageHeaders& newHeaders)
|
||||
{
|
||||
void nsOutlookCompose::UpdateHeaders(CMapiMessageHeaders& oldHeaders,
|
||||
const CMapiMessageHeaders& newHeaders) {
|
||||
// Well, ain't this a peach?
|
||||
// This is rather disgusting but there really isn't much to be done about it....
|
||||
// This is rather disgusting but there really isn't much to be done about
|
||||
// it....
|
||||
|
||||
// 1. For each "old" header, replace it with the new one if we want,
|
||||
// then right it out.
|
||||
|
@ -456,7 +471,8 @@ void nsOutlookCompose::UpdateHeaders(CMapiMessageHeaders& oldHeaders, const CMap
|
|||
|
||||
UpdateHeader(oldHeaders, newHeaders, CMapiMessageHeaders::hdrContentType);
|
||||
UpdateHeader(oldHeaders, newHeaders, CMapiMessageHeaders::hdrMimeVersion);
|
||||
UpdateHeader(oldHeaders, newHeaders, CMapiMessageHeaders::hdrContentTransferEncoding);
|
||||
UpdateHeader(oldHeaders, newHeaders,
|
||||
CMapiMessageHeaders::hdrContentTransferEncoding);
|
||||
|
||||
// Other replaced headers (only if they exist):
|
||||
// "From",
|
||||
|
@ -476,44 +492,41 @@ void nsOutlookCompose::UpdateHeaders(CMapiMessageHeaders& oldHeaders, const CMap
|
|||
|
||||
CCompositionFile::CCompositionFile(nsIFile* aFile, void* fifoBuffer,
|
||||
uint32_t fifoBufferSize, bool convertCRs)
|
||||
: m_pFile(aFile), m_fileSize(0), m_fileReadPos(0),
|
||||
m_fifoBuffer(static_cast<char*>(fifoBuffer)),
|
||||
m_fifoBufferSize(fifoBufferSize),
|
||||
m_fifoBufferReadPos(static_cast<char*>(fifoBuffer)),
|
||||
m_fifoBufferWrittenPos(static_cast<char*>(fifoBuffer)),
|
||||
m_convertCRs(convertCRs),
|
||||
m_lastChar(0)
|
||||
{
|
||||
: m_pFile(aFile),
|
||||
m_fileSize(0),
|
||||
m_fileReadPos(0),
|
||||
m_fifoBuffer(static_cast<char*>(fifoBuffer)),
|
||||
m_fifoBufferSize(fifoBufferSize),
|
||||
m_fifoBufferReadPos(static_cast<char*>(fifoBuffer)),
|
||||
m_fifoBufferWrittenPos(static_cast<char*>(fifoBuffer)),
|
||||
m_convertCRs(convertCRs),
|
||||
m_lastChar(0) {
|
||||
m_pFile->GetFileSize(&m_fileSize);
|
||||
if (!m_fileSize) {
|
||||
IMPORT_LOG0("*** Error, unexpected zero file size for composed message\n");
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(m_pInputStream), m_pFile);
|
||||
nsresult rv =
|
||||
NS_NewLocalFileInputStream(getter_AddRefs(m_pInputStream), m_pFile);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error, unable to open composed message file\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult CCompositionFile::EnsureHasDataInBuffer()
|
||||
{
|
||||
if (m_fifoBufferReadPos < m_fifoBufferWrittenPos)
|
||||
return NS_OK;
|
||||
nsresult CCompositionFile::EnsureHasDataInBuffer() {
|
||||
if (m_fifoBufferReadPos < m_fifoBufferWrittenPos) return NS_OK;
|
||||
// Populate the buffer with new data!
|
||||
uint32_t count = m_fifoBufferSize;
|
||||
if ((m_fileReadPos + count) > m_fileSize)
|
||||
count = m_fileSize - m_fileReadPos;
|
||||
if (!count)
|
||||
return NS_ERROR_FAILURE; // Isn't there a "No more data" error?
|
||||
if ((m_fileReadPos + count) > m_fileSize) count = m_fileSize - m_fileReadPos;
|
||||
if (!count) return NS_ERROR_FAILURE; // Isn't there a "No more data" error?
|
||||
|
||||
uint32_t bytesRead = 0;
|
||||
nsresult rv = m_pInputStream->Read(m_fifoBuffer, count, &bytesRead);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!bytesRead || (bytesRead > count))
|
||||
return NS_ERROR_FAILURE;
|
||||
m_fifoBufferWrittenPos = m_fifoBuffer+bytesRead;
|
||||
if (!bytesRead || (bytesRead > count)) return NS_ERROR_FAILURE;
|
||||
m_fifoBufferWrittenPos = m_fifoBuffer + bytesRead;
|
||||
m_fifoBufferReadPos = m_fifoBuffer;
|
||||
m_fileReadPos += bytesRead;
|
||||
|
||||
|
@ -521,42 +534,42 @@ nsresult CCompositionFile::EnsureHasDataInBuffer()
|
|||
}
|
||||
|
||||
class CTermGuard {
|
||||
public:
|
||||
public:
|
||||
CTermGuard(const char* term, int termSize)
|
||||
: m_term(term),
|
||||
m_termSize(term ? ((termSize!=-1) ? termSize : strlen(term)) : 0),
|
||||
m_matchPos(0)
|
||||
{}
|
||||
: m_term(term),
|
||||
m_termSize(term ? ((termSize != -1) ? termSize : strlen(term)) : 0),
|
||||
m_matchPos(0) {}
|
||||
|
||||
// if the guard triggered
|
||||
// if the guard triggered
|
||||
inline bool IsTriggered() const {
|
||||
return m_termSize && (m_matchPos == m_termSize); }
|
||||
return m_termSize && (m_matchPos == m_termSize);
|
||||
}
|
||||
// indicates if the guard has something to check
|
||||
inline bool IsChecking() const { return m_termSize; }
|
||||
|
||||
bool Check(char c) // returns true only if the whole sequence passed
|
||||
bool Check(char c) // returns true only if the whole sequence passed
|
||||
{
|
||||
if (!m_termSize) // no guard
|
||||
if (!m_termSize) // no guard
|
||||
return false;
|
||||
if (m_matchPos >= m_termSize) // check past success!
|
||||
if (m_matchPos >= m_termSize) // check past success!
|
||||
m_matchPos = 0;
|
||||
if (m_term[m_matchPos] != c) // Reset sequence
|
||||
if (m_term[m_matchPos] != c) // Reset sequence
|
||||
m_matchPos = 0;
|
||||
if (m_term[m_matchPos] == c) { // Sequence continues
|
||||
return ++m_matchPos == m_termSize; // If equal then sequence complete!
|
||||
if (m_term[m_matchPos] == c) { // Sequence continues
|
||||
return ++m_matchPos == m_termSize; // If equal then sequence complete!
|
||||
}
|
||||
// Sequence broken
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
const char* m_term;
|
||||
int m_termSize;
|
||||
int m_matchPos;
|
||||
};
|
||||
|
||||
template <class _OutFn>
|
||||
nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize)
|
||||
{
|
||||
nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize) {
|
||||
CTermGuard guard(term, termSize);
|
||||
|
||||
// We already know the required string size, so reduce future reallocations
|
||||
|
@ -567,10 +580,11 @@ nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize)
|
|||
char c = 0;
|
||||
nsresult rv;
|
||||
while (NS_SUCCEEDED(rv = EnsureHasDataInBuffer())) {
|
||||
if (!guard.IsChecking() && !m_convertCRs) { // Use efficient algorithm
|
||||
dest.Append(m_fifoBufferReadPos, m_fifoBufferWrittenPos-m_fifoBufferReadPos);
|
||||
}
|
||||
else { // Check character by character to convert CRs and find terminating sequence
|
||||
if (!guard.IsChecking() && !m_convertCRs) { // Use efficient algorithm
|
||||
dest.Append(m_fifoBufferReadPos,
|
||||
m_fifoBufferWrittenPos - m_fifoBufferReadPos);
|
||||
} else { // Check character by character to convert CRs and find
|
||||
// terminating sequence
|
||||
while (m_fifoBufferReadPos < m_fifoBufferWrittenPos) {
|
||||
c = *m_fifoBufferReadPos;
|
||||
if (m_convertCRs && wasCR) {
|
||||
|
@ -579,7 +593,7 @@ nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize)
|
|||
const char kTmpLF = nsCRT::LF;
|
||||
dest.Append(&kTmpLF, 1);
|
||||
if (guard.Check(nsCRT::LF)) {
|
||||
c = nsCRT::LF; // save last char
|
||||
c = nsCRT::LF; // save last char
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -587,19 +601,16 @@ nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize)
|
|||
dest.Append(&c, 1);
|
||||
m_fifoBufferReadPos++;
|
||||
|
||||
if (guard.Check(c))
|
||||
break;
|
||||
if (guard.Check(c)) break;
|
||||
|
||||
if (m_convertCRs && (c == nsCRT::CR))
|
||||
wasCR = true;
|
||||
if (m_convertCRs && (c == nsCRT::CR)) wasCR = true;
|
||||
}
|
||||
if (guard.IsTriggered())
|
||||
break;
|
||||
if (guard.IsTriggered()) break;
|
||||
}
|
||||
}
|
||||
|
||||
// check for trailing CR (only if caller didn't specify the terminating sequence that ends with CR -
|
||||
// in this case he knows what he does!)
|
||||
// check for trailing CR (only if caller didn't specify the terminating
|
||||
// sequence that ends with CR - in this case he knows what he does!)
|
||||
if (m_convertCRs && !guard.IsTriggered() && (c == nsCRT::CR)) {
|
||||
c = nsCRT::LF;
|
||||
dest.Append(&c, 1);
|
||||
|
@ -612,35 +623,39 @@ nsresult CCompositionFile::ToDest(_OutFn dest, const char* term, int termSize)
|
|||
}
|
||||
|
||||
class dest_nsCString {
|
||||
public:
|
||||
public:
|
||||
explicit dest_nsCString(nsCString& str) : m_str(str) { m_str.Truncate(); }
|
||||
void SetCapacity(int32_t sz) { m_str.SetCapacity(sz); }
|
||||
nsresult Append(const char* buf, uint32_t count) {
|
||||
m_str.Append(buf, count); return NS_OK; }
|
||||
private:
|
||||
m_str.Append(buf, count);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString& m_str;
|
||||
};
|
||||
|
||||
class dest_Stream {
|
||||
public:
|
||||
explicit dest_Stream(nsIOutputStream *dest) : m_stream(dest) {}
|
||||
void SetCapacity(int32_t) { /*do nothing*/ }
|
||||
public:
|
||||
explicit dest_Stream(nsIOutputStream* dest) : m_stream(dest) {}
|
||||
void SetCapacity(int32_t) { /*do nothing*/
|
||||
}
|
||||
// const_cast here is due to the poor design of the EscapeFromSpaceLine()
|
||||
// that requires a non-constant pointer while doesn't modify its data
|
||||
nsresult Append(const char* buf, uint32_t count) {
|
||||
return EscapeFromSpaceLine(m_stream, const_cast<char*>(buf), buf+count); }
|
||||
private:
|
||||
nsIOutputStream *m_stream;
|
||||
return EscapeFromSpaceLine(m_stream, const_cast<char*>(buf), buf + count);
|
||||
}
|
||||
|
||||
private:
|
||||
nsIOutputStream* m_stream;
|
||||
};
|
||||
|
||||
nsresult CCompositionFile::ToString(nsCString& dest, const char* term,
|
||||
int termSize)
|
||||
{
|
||||
int termSize) {
|
||||
return ToDest(dest_nsCString(dest), term, termSize);
|
||||
}
|
||||
|
||||
nsresult CCompositionFile::ToStream(nsIOutputStream *dest, const char* term,
|
||||
int termSize)
|
||||
{
|
||||
nsresult CCompositionFile::ToStream(nsIOutputStream* dest, const char* term,
|
||||
int termSize) {
|
||||
return ToDest(dest_Stream(dest), term, termSize);
|
||||
}
|
||||
|
|
|
@ -28,28 +28,36 @@ class nsIMsgSendListener;
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsOutlookCompose {
|
||||
public:
|
||||
public:
|
||||
nsOutlookCompose();
|
||||
~nsOutlookCompose();
|
||||
|
||||
nsresult ProcessMessage(nsMsgDeliverMode mode, CMapiMessage &msg, nsIOutputStream *pDst);
|
||||
nsresult ProcessMessage(nsMsgDeliverMode mode, CMapiMessage& msg,
|
||||
nsIOutputStream* pDst);
|
||||
static nsresult CreateIdentity(void);
|
||||
static void ReleaseIdentity(void);
|
||||
private:
|
||||
nsresult CreateComponents(void);
|
||||
|
||||
void UpdateHeader(CMapiMessageHeaders& oldHeaders, const CMapiMessageHeaders& newHeaders, CMapiMessageHeaders::SpecialHeader header, bool addIfAbsent = true);
|
||||
void UpdateHeaders(CMapiMessageHeaders& oldHeaders, const CMapiMessageHeaders& newHeaders);
|
||||
private:
|
||||
nsresult CreateComponents(void);
|
||||
|
||||
nsresult ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage &msg, nsIFile **pMsg);
|
||||
nsresult CopyComposedMessage(nsIFile *pSrc, nsIOutputStream *pDst, CMapiMessage& origMsg);
|
||||
void UpdateHeader(CMapiMessageHeaders& oldHeaders,
|
||||
const CMapiMessageHeaders& newHeaders,
|
||||
CMapiMessageHeaders::SpecialHeader header,
|
||||
bool addIfAbsent = true);
|
||||
void UpdateHeaders(CMapiMessageHeaders& oldHeaders,
|
||||
const CMapiMessageHeaders& newHeaders);
|
||||
|
||||
private:
|
||||
nsresult ComposeTheMessage(nsMsgDeliverMode mode, CMapiMessage& msg,
|
||||
nsIFile** pMsg);
|
||||
nsresult CopyComposedMessage(nsIFile* pSrc, nsIOutputStream* pDst,
|
||||
CMapiMessage& origMsg);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIMsgSendListener> m_pListener;
|
||||
nsCOMPtr<nsIMsgCompFields> m_pMsgFields;
|
||||
static nsCOMPtr<nsIMsgIdentity> m_pIdentity;
|
||||
char* m_optimizationBuffer;
|
||||
nsCOMPtr<nsIImportService> m_pImportService;
|
||||
nsCOMPtr<nsIImportService> m_pImportService;
|
||||
};
|
||||
|
||||
#endif /* nsOutlookCompose_h__ */
|
||||
|
|
|
@ -31,184 +31,180 @@
|
|||
|
||||
#include "MapiApi.h"
|
||||
|
||||
class ImportOutlookMailImpl : public nsIImportMail
|
||||
{
|
||||
public:
|
||||
class ImportOutlookMailImpl : public nsIImportMail {
|
||||
public:
|
||||
ImportOutlookMailImpl();
|
||||
|
||||
static nsresult Create(nsIImportMail** aImport);
|
||||
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);
|
||||
/* 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);
|
||||
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);
|
||||
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);
|
||||
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:
|
||||
private:
|
||||
virtual ~ImportOutlookMailImpl();
|
||||
nsOutlookMail m_mail;
|
||||
uint32_t m_bytesDone;
|
||||
nsOutlookMail m_mail;
|
||||
uint32_t m_bytesDone;
|
||||
};
|
||||
|
||||
|
||||
class ImportOutlookAddressImpl : public nsIImportAddressBooks
|
||||
{
|
||||
public:
|
||||
class ImportOutlookAddressImpl : public nsIImportAddressBooks {
|
||||
public:
|
||||
ImportOutlookAddressImpl();
|
||||
|
||||
static nsresult Create(nsIImportAddressBooks** aImport);
|
||||
static nsresult Create(nsIImportAddressBooks **aImport);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
// nsIImportAddressBooks interface
|
||||
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) { *_retval = true; return NS_OK;}
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) {
|
||||
*_retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAutoFind(char16_t **description, bool *_retval);
|
||||
|
||||
NS_IMETHOD GetNeedsFieldMap(nsIFile *location, bool *_retval) { *_retval = false; return NS_OK;}
|
||||
NS_IMETHOD GetNeedsFieldMap(nsIFile *location, bool *_retval) {
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found, bool *userVerify)
|
||||
{ return NS_ERROR_FAILURE;}
|
||||
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found,
|
||||
bool *userVerify) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHOD FindAddressBooks(nsIFile *location, nsIArray **_retval);
|
||||
|
||||
NS_IMETHOD InitFieldMap(nsIImportFieldMap *fieldMap)
|
||||
{ return NS_ERROR_FAILURE; }
|
||||
NS_IMETHOD InitFieldMap(nsIImportFieldMap *fieldMap) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHOD ImportAddressBook(nsIImportABDescriptor *source,
|
||||
nsIAddrDatabase *destination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t **errorLog,
|
||||
char16_t **successLog,
|
||||
char16_t **errorLog, char16_t **successLog,
|
||||
bool *fatalError);
|
||||
|
||||
NS_IMETHOD GetImportProgress(uint32_t *_retval);
|
||||
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound, char16_t **pStr)
|
||||
{ return NS_ERROR_FAILURE;}
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound, char16_t **pStr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHOD SetSampleLocation(nsIFile *) { return NS_OK; }
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~ImportOutlookAddressImpl();
|
||||
void ReportSuccess(nsString& name, nsString *pStream);
|
||||
void ReportSuccess(nsString &name, nsString *pStream);
|
||||
|
||||
private:
|
||||
uint32_t m_msgCount;
|
||||
uint32_t m_msgTotal;
|
||||
nsOutlookMail m_address;
|
||||
private:
|
||||
uint32_t m_msgCount;
|
||||
uint32_t m_msgTotal;
|
||||
nsOutlookMail m_address;
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
nsOutlookImport::nsOutlookImport()
|
||||
{
|
||||
nsOutlookImport::nsOutlookImport() {
|
||||
IMPORT_LOG0("nsOutlookImport Module Created\n");
|
||||
|
||||
nsOutlookStringBundle::GetStringBundle();
|
||||
}
|
||||
|
||||
|
||||
nsOutlookImport::~nsOutlookImport()
|
||||
{
|
||||
nsOutlookImport::~nsOutlookImport() {
|
||||
IMPORT_LOG0("nsOutlookImport Module Deleted\n");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsOutlookImport, nsIImportModule)
|
||||
|
||||
NS_IMETHODIMP nsOutlookImport::GetName(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookImport::GetName(char16_t **name) {
|
||||
NS_ASSERTION(name != nullptr, "null ptr");
|
||||
if (! name)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!name) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*name = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_NAME);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookImport::GetDescription(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookImport::GetDescription(char16_t **name) {
|
||||
NS_ASSERTION(name != nullptr, "null ptr");
|
||||
if (!name)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!name) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*name = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_DESCRIPTION);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookImport::GetSupports(char **supports)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookImport::GetSupports(char **supports) {
|
||||
NS_ASSERTION(supports != nullptr, "null ptr");
|
||||
if (! supports)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!supports) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*supports = strdup(kOutlookSupportsString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookImport::GetSupportsUpgrade(bool *pUpgrade)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookImport::GetSupportsUpgrade(bool *pUpgrade) {
|
||||
NS_ASSERTION(pUpgrade != nullptr, "null ptr");
|
||||
if (! pUpgrade)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pUpgrade) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*pUpgrade = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookImport::GetImportInterface(const char *pImportType,
|
||||
nsISupports **ppInterface) {
|
||||
NS_ASSERTION(pImportType != nullptr, "null ptr");
|
||||
if (! pImportType)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pImportType) return NS_ERROR_NULL_POINTER;
|
||||
NS_ASSERTION(ppInterface != nullptr, "null ptr");
|
||||
if (! ppInterface)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!ppInterface) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*ppInterface = nullptr;
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
if (!strcmp(pImportType, "mail")) {
|
||||
// create the nsIImportMail interface and return it!
|
||||
nsCOMPtr<nsIImportMail> pMail;
|
||||
nsCOMPtr<nsIImportGeneric> pGeneric;
|
||||
rv = ImportOutlookMailImpl::Create(getter_AddRefs(pMail));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = impSvc->CreateNewGenericMail(getter_AddRefs(pGeneric));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
pGeneric->SetData("mailInterface", pMail);
|
||||
nsString name;
|
||||
nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_NAME, name);
|
||||
nsCOMPtr<nsISupportsString> nameString (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsISupportsString> nameString(
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nameString->SetData(name);
|
||||
pGeneric->SetData("name", nameString);
|
||||
|
@ -227,7 +223,8 @@ NS_IMETHODIMP nsOutlookImport::GetImportInterface(const char *pImportType, nsISu
|
|||
nsCOMPtr<nsIImportGeneric> pGeneric;
|
||||
rv = ImportOutlookAddressImpl::Create(getter_AddRefs(pAddress));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = impSvc->CreateNewGenericAddressBooks(getter_AddRefs(pGeneric));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -254,56 +251,48 @@ NS_IMETHODIMP nsOutlookImport::GetImportInterface(const char *pImportType, nsISu
|
|||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
nsresult ImportOutlookMailImpl::Create(nsIImportMail** aImport)
|
||||
{
|
||||
nsresult ImportOutlookMailImpl::Create(nsIImportMail **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new ImportOutlookMailImpl());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ImportOutlookMailImpl::ImportOutlookMailImpl()
|
||||
{
|
||||
ImportOutlookMailImpl::ImportOutlookMailImpl() {
|
||||
nsOutlookCompose::CreateIdentity();
|
||||
}
|
||||
|
||||
ImportOutlookMailImpl::~ImportOutlookMailImpl()
|
||||
{
|
||||
ImportOutlookMailImpl::~ImportOutlookMailImpl() {
|
||||
nsOutlookCompose::ReleaseIdentity();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImportOutlookMailImpl, nsIImportMail)
|
||||
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::GetDefaultLocation(nsIFile **ppLoc, bool *found, bool *userVerify)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::GetDefaultLocation(nsIFile **ppLoc,
|
||||
bool *found,
|
||||
bool *userVerify) {
|
||||
NS_ASSERTION(ppLoc != nullptr, "null ptr");
|
||||
NS_ASSERTION(found != nullptr, "null ptr");
|
||||
NS_ASSERTION(userVerify != nullptr, "null ptr");
|
||||
if (!ppLoc || !found || !userVerify)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!ppLoc || !found || !userVerify) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*found = false;
|
||||
*ppLoc = nullptr;
|
||||
*userVerify = false;
|
||||
// We need to verify here that we can get the mail, if true then
|
||||
// return a dummy location, otherwise return no location
|
||||
CMapiApi mapi;
|
||||
if (!mapi.Initialize())
|
||||
return NS_OK;
|
||||
if (!mapi.LogOn())
|
||||
return NS_OK;
|
||||
CMapiApi mapi;
|
||||
if (!mapi.Initialize()) return NS_OK;
|
||||
if (!mapi.LogOn()) return NS_OK;
|
||||
|
||||
CMapiFolderList store;
|
||||
if (!mapi.IterateStores(store))
|
||||
return NS_OK;
|
||||
CMapiFolderList store;
|
||||
if (!mapi.IterateStores(store)) return NS_OK;
|
||||
|
||||
if (store.GetSize() == 0)
|
||||
return NS_OK;
|
||||
if (store.GetSize() == 0) return NS_OK;
|
||||
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIFile> resultFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> resultFile =
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*found = true;
|
||||
resultFile.forget(ppLoc);
|
||||
|
@ -312,28 +301,24 @@ NS_IMETHODIMP ImportOutlookMailImpl::GetDefaultLocation(nsIFile **ppLoc, bool *f
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::FindMailboxes(nsIFile *pLoc, nsIArray **ppArray)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::FindMailboxes(nsIFile *pLoc,
|
||||
nsIArray **ppArray) {
|
||||
NS_ASSERTION(pLoc != nullptr, "null ptr");
|
||||
NS_ASSERTION(ppArray != nullptr, "null ptr");
|
||||
if (!pLoc || !ppArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pLoc || !ppArray) return NS_ERROR_NULL_POINTER;
|
||||
return m_mail.GetMailFolders(ppArray);
|
||||
}
|
||||
|
||||
void ImportOutlookMailImpl::AddLinebreak(nsString *pStream)
|
||||
{
|
||||
if (pStream)
|
||||
pStream->Append(char16_t('\n'));
|
||||
void ImportOutlookMailImpl::AddLinebreak(nsString *pStream) {
|
||||
if (pStream) pStream->Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
void ImportOutlookMailImpl::ReportSuccess(nsString& name, int32_t count, nsString *pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportOutlookMailImpl::ReportSuccess(nsString &name, int32_t count,
|
||||
nsString *pStream) {
|
||||
if (!pStream) return;
|
||||
// load the success string
|
||||
char16_t *pFmt = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_MAILBOX_SUCCESS);
|
||||
char16_t *pFmt =
|
||||
nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_MAILBOX_SUCCESS);
|
||||
nsString pText;
|
||||
nsTextFormatter::ssprintf(pText, pFmt, name.get(), count);
|
||||
pStream->Append(pText);
|
||||
|
@ -341,10 +326,9 @@ void ImportOutlookMailImpl::ReportSuccess(nsString& name, int32_t count, nsStrin
|
|||
AddLinebreak(pStream);
|
||||
}
|
||||
|
||||
void ImportOutlookMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportOutlookMailImpl::ReportError(int32_t errorNum, nsString &name,
|
||||
nsString *pStream) {
|
||||
if (!pStream) return;
|
||||
// load the error string
|
||||
char16_t *pFmt = nsOutlookStringBundle::GetStringByID(errorNum);
|
||||
nsString pText;
|
||||
|
@ -354,35 +338,30 @@ void ImportOutlookMailImpl::ReportError(int32_t errorNum, nsString& name, nsStri
|
|||
AddLinebreak(pStream);
|
||||
}
|
||||
|
||||
|
||||
void ImportOutlookMailImpl::SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess)
|
||||
{
|
||||
if (pError)
|
||||
*pError = ToNewUnicode(error);
|
||||
if (pSuccess)
|
||||
*pSuccess = ToNewUnicode(success);
|
||||
void ImportOutlookMailImpl::SetLogs(nsString &success, nsString &error,
|
||||
char16_t **pError, char16_t **pSuccess) {
|
||||
if (pError) *pError = ToNewUnicode(error);
|
||||
if (pSuccess) *pSuccess = ToNewUnicode(success);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ImportOutlookMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
|
||||
nsIMsgFolder *dstFolder,
|
||||
char16_t **pErrorLog,
|
||||
char16_t **pSuccessLog,
|
||||
bool *fatalError)
|
||||
{
|
||||
char16_t **pSuccessLog, bool *fatalError) {
|
||||
NS_ENSURE_ARG_POINTER(pSource);
|
||||
NS_ENSURE_ARG_POINTER(dstFolder);
|
||||
NS_ENSURE_ARG_POINTER(fatalError);
|
||||
|
||||
nsString success;
|
||||
nsString error;
|
||||
nsString success;
|
||||
nsString error;
|
||||
bool abort = false;
|
||||
nsString name;
|
||||
char16_t *pName;
|
||||
if (NS_SUCCEEDED( pSource->GetDisplayName( &pName))) {
|
||||
if (NS_SUCCEEDED(pSource->GetDisplayName(&pName))) {
|
||||
name = pName;
|
||||
free( pName);
|
||||
}
|
||||
free(pName);
|
||||
}
|
||||
|
||||
uint32_t mailSize = 0;
|
||||
pSource->GetSize(&mailSize);
|
||||
|
@ -394,7 +373,7 @@ ImportOutlookMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
|
|||
|
||||
uint32_t index = 0;
|
||||
pSource->GetIdentifier(&index);
|
||||
int32_t msgCount = 0;
|
||||
int32_t msgCount = 0;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
m_bytesDone = 0;
|
||||
|
@ -412,19 +391,16 @@ ImportOutlookMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::GetImportProgress(uint32_t *pDoneSoFar)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::GetImportProgress(uint32_t *pDoneSoFar) {
|
||||
NS_ASSERTION(pDoneSoFar != nullptr, "null ptr");
|
||||
if (! pDoneSoFar)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pDoneSoFar) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*pDoneSoFar = m_bytesDone;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookMailImpl::TranslateFolderName(
|
||||
const nsAString &aFolderName, nsAString &_retval) {
|
||||
if (aFolderName.LowerCaseEqualsLiteral("deleted items"))
|
||||
_retval = NS_LITERAL_STRING(kDestTrashFolderName);
|
||||
else if (aFolderName.LowerCaseEqualsLiteral("sent items"))
|
||||
|
@ -436,31 +412,26 @@ NS_IMETHODIMP ImportOutlookMailImpl::TranslateFolderName(const nsAString & aFold
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ImportOutlookAddressImpl::Create(nsIImportAddressBooks** aImport)
|
||||
{
|
||||
nsresult ImportOutlookAddressImpl::Create(nsIImportAddressBooks **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new ImportOutlookAddressImpl());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ImportOutlookAddressImpl::ImportOutlookAddressImpl()
|
||||
{
|
||||
ImportOutlookAddressImpl::ImportOutlookAddressImpl() {
|
||||
m_msgCount = 0;
|
||||
m_msgTotal = 0;
|
||||
}
|
||||
|
||||
ImportOutlookAddressImpl::~ImportOutlookAddressImpl()
|
||||
{
|
||||
}
|
||||
ImportOutlookAddressImpl::~ImportOutlookAddressImpl() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImportOutlookAddressImpl, nsIImportAddressBooks)
|
||||
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::GetAutoFind(char16_t **description, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::GetAutoFind(char16_t **description,
|
||||
bool *_retval) {
|
||||
NS_ASSERTION(description != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (! description || !_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!description || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = true;
|
||||
nsString str;
|
||||
|
@ -469,91 +440,83 @@ NS_IMETHODIMP ImportOutlookAddressImpl::GetAutoFind(char16_t **description, bool
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::FindAddressBooks(nsIFile *location, nsIArray **_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::FindAddressBooks(nsIFile *location,
|
||||
nsIArray **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return m_address.GetAddressBooks(_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::ImportAddressBook(nsIImportABDescriptor *source,
|
||||
nsIAddrDatabase *destination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t **pErrorLog,
|
||||
char16_t **pSuccessLog,
|
||||
bool *fatalError)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::ImportAddressBook(
|
||||
nsIImportABDescriptor *source, nsIAddrDatabase *destination,
|
||||
nsIImportFieldMap *fieldMap, nsISupports *aSupportService,
|
||||
char16_t **pErrorLog, char16_t **pSuccessLog, bool *fatalError) {
|
||||
m_msgCount = 0;
|
||||
m_msgTotal = 0;
|
||||
NS_ASSERTION(source != nullptr, "null ptr");
|
||||
NS_ASSERTION(destination != nullptr, "null ptr");
|
||||
NS_ASSERTION(fatalError != nullptr, "null ptr");
|
||||
|
||||
nsString success;
|
||||
nsString error;
|
||||
if (!source || !destination || !fatalError) {
|
||||
nsString success;
|
||||
nsString error;
|
||||
if (!source || !destination || !fatalError) {
|
||||
IMPORT_LOG0("*** Bad param passed to outlook address import\n");
|
||||
nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_ADDRESS_BADPARAM, error);
|
||||
if (fatalError)
|
||||
*fatalError = true;
|
||||
if (fatalError) *fatalError = true;
|
||||
ImportOutlookMailImpl::SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsString name;
|
||||
source->GetPreferredName(name);
|
||||
nsString name;
|
||||
source->GetPreferredName(name);
|
||||
|
||||
uint32_t id;
|
||||
uint32_t id;
|
||||
if (NS_FAILED(source->GetIdentifier(&id))) {
|
||||
ImportOutlookMailImpl::ReportError(OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE, name, &error);
|
||||
ImportOutlookMailImpl::ReportError(OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE,
|
||||
name, &error);
|
||||
ImportOutlookMailImpl::SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = m_address.ImportAddresses(&m_msgCount, &m_msgTotal, name.get(), id, destination, error);
|
||||
rv = m_address.ImportAddresses(&m_msgCount, &m_msgTotal, name.get(), id,
|
||||
destination, error);
|
||||
if (NS_SUCCEEDED(rv) && error.IsEmpty())
|
||||
ReportSuccess(name, &success);
|
||||
else
|
||||
ImportOutlookMailImpl::ReportError(OUTLOOKIMPORT_ADDRESS_CONVERTERROR, name, &error);
|
||||
ImportOutlookMailImpl::ReportError(OUTLOOKIMPORT_ADDRESS_CONVERTERROR, name,
|
||||
&error);
|
||||
|
||||
ImportOutlookMailImpl::SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
IMPORT_LOG0("*** Returning from outlook address import\n");
|
||||
return destination->Commit(nsAddrDBCommitType::kLargeCommit);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::GetImportProgress(uint32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportOutlookAddressImpl::GetImportProgress(uint32_t *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
uint32_t result = m_msgCount;
|
||||
if (m_msgTotal) {
|
||||
result *= 100;
|
||||
result /= m_msgTotal;
|
||||
}
|
||||
else
|
||||
} else
|
||||
result = 0;
|
||||
|
||||
if (result > 100)
|
||||
result = 100;
|
||||
if (result > 100) result = 100;
|
||||
|
||||
*_retval = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void ImportOutlookAddressImpl::ReportSuccess(nsString& name, nsString *pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportOutlookAddressImpl::ReportSuccess(nsString &name,
|
||||
nsString *pStream) {
|
||||
if (!pStream) return;
|
||||
// load the success string
|
||||
char16_t *pFmt = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_ADDRESS_SUCCESS);
|
||||
char16_t *pFmt =
|
||||
nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_ADDRESS_SUCCESS);
|
||||
nsString pText;
|
||||
nsTextFormatter::ssprintf(pText, pFmt, name.get());
|
||||
pStream->Append(pText);
|
||||
|
|
|
@ -9,21 +9,18 @@
|
|||
#include "nsIImportModule.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_OUTLOOKIMPORT_CID \
|
||||
{ /* 1DB469A0-8B00-11d3-A206-00A0CC26DA63 */ \
|
||||
0x1db469a0, 0x8b00, 0x11d3, { \
|
||||
0xa2, 0x6, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_OUTLOOKIMPORT_CID \
|
||||
{ /* 1DB469A0-8B00-11d3-A206-00A0CC26DA63 */ \
|
||||
0x1db469a0, 0x8b00, 0x11d3, \
|
||||
{0xa2, 0x6, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 }}
|
||||
|
||||
|
||||
|
||||
|
||||
#define kOutlookSupportsString NS_IMPORT_MAIL_STR "," NS_IMPORT_ADDRESS_STR "," NS_IMPORT_SETTINGS_STR
|
||||
|
||||
class nsOutlookImport : public nsIImportModule
|
||||
{
|
||||
public:
|
||||
#define kOutlookSupportsString \
|
||||
NS_IMPORT_MAIL_STR "," NS_IMPORT_ADDRESS_STR "," NS_IMPORT_SETTINGS_STR
|
||||
|
||||
class nsOutlookImport : public nsIImportModule {
|
||||
public:
|
||||
nsOutlookImport();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -34,11 +31,8 @@ public:
|
|||
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual ~nsOutlookImport();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* nsOutlookImport_h___ */
|
||||
|
|
|
@ -31,53 +31,49 @@
|
|||
|
||||
/* ------------ Address book stuff ----------------- */
|
||||
typedef struct {
|
||||
int32_t mozField;
|
||||
int32_t multiLine;
|
||||
ULONG mapiTag;
|
||||
int32_t mozField;
|
||||
int32_t multiLine;
|
||||
ULONG mapiTag;
|
||||
} MAPIFields;
|
||||
|
||||
/*
|
||||
Fields in MAPI, not in Mozilla
|
||||
PR_OFFICE_LOCATION
|
||||
FIX - PR_BIRTHDAY - stored as PT_SYSTIME - FIX to extract for moz address book birthday
|
||||
PR_DISPLAY_NAME_PREFIX - Mr., Mrs. Dr., etc.
|
||||
PR_SPOUSE_NAME
|
||||
PR_GENDER - integer, not text
|
||||
FIX - PR_CONTACT_EMAIL_ADDRESSES - multiuline strings for email addresses, needs
|
||||
parsing to get secondary email address for mozilla
|
||||
FIX - PR_BIRTHDAY - stored as PT_SYSTIME - FIX to extract for moz address book
|
||||
birthday PR_DISPLAY_NAME_PREFIX - Mr., Mrs. Dr., etc. PR_SPOUSE_NAME PR_GENDER
|
||||
- integer, not text FIX - PR_CONTACT_EMAIL_ADDRESSES - multiuline strings for
|
||||
email addresses, needs parsing to get secondary email address for mozilla
|
||||
*/
|
||||
|
||||
#define kIsMultiLine -2
|
||||
#define kNoMultiLine -1
|
||||
#define kIsMultiLine -2
|
||||
#define kNoMultiLine -1
|
||||
|
||||
static MAPIFields gMapiFields[] = {
|
||||
{ 35, kIsMultiLine, PR_BODY},
|
||||
{ 6, kNoMultiLine, PR_BUSINESS_TELEPHONE_NUMBER},
|
||||
{ 7, kNoMultiLine, PR_HOME_TELEPHONE_NUMBER},
|
||||
{ 25, kNoMultiLine, PR_COMPANY_NAME},
|
||||
{ 23, kNoMultiLine, PR_TITLE},
|
||||
{ 10, kNoMultiLine, PR_CELLULAR_TELEPHONE_NUMBER},
|
||||
{ 9, kNoMultiLine, PR_PAGER_TELEPHONE_NUMBER},
|
||||
{ 8, kNoMultiLine, PR_BUSINESS_FAX_NUMBER},
|
||||
{ 8, kNoMultiLine, PR_HOME_FAX_NUMBER},
|
||||
{ 22, kNoMultiLine, PR_COUNTRY},
|
||||
{ 19, kNoMultiLine, PR_LOCALITY},
|
||||
{ 20, kNoMultiLine, PR_STATE_OR_PROVINCE},
|
||||
{ 17, 18, PR_STREET_ADDRESS},
|
||||
{ 21, kNoMultiLine, PR_POSTAL_CODE},
|
||||
{ 27, kNoMultiLine, PR_PERSONAL_HOME_PAGE},
|
||||
{ 26, kNoMultiLine, PR_BUSINESS_HOME_PAGE},
|
||||
{ 13, kNoMultiLine, PR_HOME_ADDRESS_CITY},
|
||||
{ 16, kNoMultiLine, PR_HOME_ADDRESS_COUNTRY},
|
||||
{ 15, kNoMultiLine, PR_HOME_ADDRESS_POSTAL_CODE},
|
||||
{ 14, kNoMultiLine, PR_HOME_ADDRESS_STATE_OR_PROVINCE},
|
||||
{ 11, 12, PR_HOME_ADDRESS_STREET},
|
||||
{ 24, kNoMultiLine, PR_DEPARTMENT_NAME}
|
||||
};
|
||||
static MAPIFields gMapiFields[] = {
|
||||
{35, kIsMultiLine, PR_BODY},
|
||||
{6, kNoMultiLine, PR_BUSINESS_TELEPHONE_NUMBER},
|
||||
{7, kNoMultiLine, PR_HOME_TELEPHONE_NUMBER},
|
||||
{25, kNoMultiLine, PR_COMPANY_NAME},
|
||||
{23, kNoMultiLine, PR_TITLE},
|
||||
{10, kNoMultiLine, PR_CELLULAR_TELEPHONE_NUMBER},
|
||||
{9, kNoMultiLine, PR_PAGER_TELEPHONE_NUMBER},
|
||||
{8, kNoMultiLine, PR_BUSINESS_FAX_NUMBER},
|
||||
{8, kNoMultiLine, PR_HOME_FAX_NUMBER},
|
||||
{22, kNoMultiLine, PR_COUNTRY},
|
||||
{19, kNoMultiLine, PR_LOCALITY},
|
||||
{20, kNoMultiLine, PR_STATE_OR_PROVINCE},
|
||||
{17, 18, PR_STREET_ADDRESS},
|
||||
{21, kNoMultiLine, PR_POSTAL_CODE},
|
||||
{27, kNoMultiLine, PR_PERSONAL_HOME_PAGE},
|
||||
{26, kNoMultiLine, PR_BUSINESS_HOME_PAGE},
|
||||
{13, kNoMultiLine, PR_HOME_ADDRESS_CITY},
|
||||
{16, kNoMultiLine, PR_HOME_ADDRESS_COUNTRY},
|
||||
{15, kNoMultiLine, PR_HOME_ADDRESS_POSTAL_CODE},
|
||||
{14, kNoMultiLine, PR_HOME_ADDRESS_STATE_OR_PROVINCE},
|
||||
{11, 12, PR_HOME_ADDRESS_STREET},
|
||||
{24, kNoMultiLine, PR_DEPARTMENT_NAME}};
|
||||
/* ---------------------------------------------------- */
|
||||
|
||||
|
||||
#define kCopyBufferSize (16 * 1024)
|
||||
#define kCopyBufferSize (16 * 1024)
|
||||
|
||||
// The email address in Outlook Contacts doesn't have a named
|
||||
// property, we need to use this mapi name ID to access the email
|
||||
|
@ -86,28 +82,25 @@ static MAPIFields gMapiFields[] = {
|
|||
// 32915/32916 for Email2, 32931/32932 for Email3
|
||||
// Current we use OUTLOOK_EMAIL1_MAPI_ID1 for primary email
|
||||
// OUTLOOK_EMAIL2_MAPI_ID1 for secondary email
|
||||
#define OUTLOOK_EMAIL1_MAPI_ID1 32899
|
||||
#define OUTLOOK_EMAIL1_MAPI_ID2 32900
|
||||
#define OUTLOOK_EMAIL2_MAPI_ID1 32915
|
||||
#define OUTLOOK_EMAIL2_MAPI_ID2 32916
|
||||
#define OUTLOOK_EMAIL3_MAPI_ID1 32931
|
||||
#define OUTLOOK_EMAIL3_MAPI_ID2 32932
|
||||
#define OUTLOOK_EMAIL1_MAPI_ID1 32899
|
||||
#define OUTLOOK_EMAIL1_MAPI_ID2 32900
|
||||
#define OUTLOOK_EMAIL2_MAPI_ID1 32915
|
||||
#define OUTLOOK_EMAIL2_MAPI_ID2 32916
|
||||
#define OUTLOOK_EMAIL3_MAPI_ID1 32931
|
||||
#define OUTLOOK_EMAIL3_MAPI_ID2 32932
|
||||
|
||||
nsOutlookMail::nsOutlookMail()
|
||||
{
|
||||
nsOutlookMail::nsOutlookMail() {
|
||||
m_gotAddresses = false;
|
||||
m_gotFolders = false;
|
||||
m_haveMapi = CMapiApi::LoadMapi();
|
||||
m_lpMdb = NULL;
|
||||
}
|
||||
|
||||
nsOutlookMail::~nsOutlookMail()
|
||||
{
|
||||
// EmptyAttachments();
|
||||
nsOutlookMail::~nsOutlookMail() {
|
||||
// EmptyAttachments();
|
||||
}
|
||||
|
||||
nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
||||
{
|
||||
nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray) {
|
||||
if (!m_haveMapi) {
|
||||
IMPORT_LOG0("GetMailFolders called before Mapi is initialized\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -116,13 +109,14 @@ nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("FAILED to allocate the nsIMutableArray for the mail folder list\n");
|
||||
IMPORT_LOG0(
|
||||
"FAILED to allocate the nsIMutableArray for the mail folder list\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
m_gotFolders = true;
|
||||
|
||||
|
@ -131,8 +125,7 @@ nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
|||
m_mapi.Initialize();
|
||||
m_mapi.LogOn();
|
||||
|
||||
if (m_storeList.GetSize() == 0)
|
||||
m_mapi.IterateStores(m_storeList);
|
||||
if (m_storeList.GetSize() == 0) m_mapi.IterateStores(m_storeList);
|
||||
|
||||
int i = 0;
|
||||
CMapiFolder *pFolder;
|
||||
|
@ -141,15 +134,16 @@ nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
|||
CMapiFolder *pItem = new CMapiFolder(pFolder);
|
||||
pItem->SetDepth(1);
|
||||
m_folderList.AddItem(pItem);
|
||||
if (!m_mapi.GetStoreFolders(pItem->GetCBEntryID(), pItem->GetEntryID(), m_folderList, 2)) {
|
||||
if (!m_mapi.GetStoreFolders(pItem->GetCBEntryID(), pItem->GetEntryID(),
|
||||
m_folderList, 2)) {
|
||||
IMPORT_LOG1("GetStoreFolders for index %d failed.\n", i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((pFolder = m_storeList.GetItem(i))) {
|
||||
if (!m_mapi.GetStoreFolders(pFolder->GetCBEntryID(), pFolder->GetEntryID(), m_folderList, 1)) {
|
||||
if (!m_mapi.GetStoreFolders(pFolder->GetCBEntryID(),
|
||||
pFolder->GetEntryID(), m_folderList, 1)) {
|
||||
IMPORT_LOG1("GetStoreFolders for index %d failed.\n", i);
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +151,8 @@ nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
|||
|
||||
// Create the mailbox descriptors for the list of folders
|
||||
nsCOMPtr<nsIImportMailboxDescriptor> pID;
|
||||
nsString name;
|
||||
nsString uniName;
|
||||
nsString name;
|
||||
nsString uniName;
|
||||
|
||||
for (i = 0; i < m_folderList.GetSize(); i++) {
|
||||
pFolder = m_folderList.GetItem(i);
|
||||
|
@ -179,9 +173,8 @@ nsresult nsOutlookMail::GetMailFolders(nsIArray **pArray)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool nsOutlookMail::IsAddressBookNameUnique(nsString& name, nsString& list)
|
||||
{
|
||||
nsString usedName;
|
||||
bool nsOutlookMail::IsAddressBookNameUnique(nsString &name, nsString &list) {
|
||||
nsString usedName;
|
||||
usedName.Append('[');
|
||||
usedName.Append(name);
|
||||
usedName.AppendLiteral("],");
|
||||
|
@ -189,16 +182,15 @@ bool nsOutlookMail::IsAddressBookNameUnique(nsString& name, nsString& list)
|
|||
return list.Find(usedName) == -1;
|
||||
}
|
||||
|
||||
void nsOutlookMail::MakeAddressBookNameUnique(nsString& name, nsString& list)
|
||||
{
|
||||
nsString newName;
|
||||
int idx = 1;
|
||||
void nsOutlookMail::MakeAddressBookNameUnique(nsString &name, nsString &list) {
|
||||
nsString newName;
|
||||
int idx = 1;
|
||||
|
||||
newName = name;
|
||||
while (!IsAddressBookNameUnique(newName, list)) {
|
||||
newName = name;
|
||||
newName.Append(char16_t(' '));
|
||||
newName.AppendInt((int32_t) idx);
|
||||
newName.AppendInt((int32_t)idx);
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
@ -208,8 +200,7 @@ void nsOutlookMail::MakeAddressBookNameUnique(nsString& name, nsString& list)
|
|||
list.AppendLiteral("],");
|
||||
}
|
||||
|
||||
nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray)
|
||||
{
|
||||
nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray) {
|
||||
if (!m_haveMapi) {
|
||||
IMPORT_LOG0("GetAddressBooks called before Mapi is initialized\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -218,21 +209,21 @@ nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray)
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("FAILED to allocate the nsIMutableArray for the address book list\n");
|
||||
IMPORT_LOG0(
|
||||
"FAILED to allocate the nsIMutableArray for the address book list\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
m_gotAddresses = true;
|
||||
|
||||
m_addressList.ClearAll();
|
||||
m_mapi.Initialize();
|
||||
m_mapi.LogOn();
|
||||
if (m_storeList.GetSize() == 0)
|
||||
m_mapi.IterateStores(m_storeList);
|
||||
if (m_storeList.GetSize() == 0) m_mapi.IterateStores(m_storeList);
|
||||
|
||||
int i = 0;
|
||||
CMapiFolder *pFolder;
|
||||
|
@ -241,15 +232,16 @@ nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray)
|
|||
CMapiFolder *pItem = new CMapiFolder(pFolder);
|
||||
pItem->SetDepth(1);
|
||||
m_addressList.AddItem(pItem);
|
||||
if (!m_mapi.GetStoreAddressFolders(pItem->GetCBEntryID(), pItem->GetEntryID(), m_addressList)) {
|
||||
if (!m_mapi.GetStoreAddressFolders(pItem->GetCBEntryID(),
|
||||
pItem->GetEntryID(), m_addressList)) {
|
||||
IMPORT_LOG1("GetStoreAddressFolders for index %d failed.\n", i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((pFolder = m_storeList.GetItem(i))) {
|
||||
if (!m_mapi.GetStoreAddressFolders(pFolder->GetCBEntryID(), pFolder->GetEntryID(), m_addressList)) {
|
||||
if (!m_mapi.GetStoreAddressFolders(
|
||||
pFolder->GetCBEntryID(), pFolder->GetEntryID(), m_addressList)) {
|
||||
IMPORT_LOG1("GetStoreFolders for index %d failed.\n", i);
|
||||
}
|
||||
}
|
||||
|
@ -257,8 +249,8 @@ nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray)
|
|||
|
||||
// Create the mailbox descriptors for the list of folders
|
||||
nsCOMPtr<nsIImportABDescriptor> pID;
|
||||
nsString name;
|
||||
nsString list;
|
||||
nsString name;
|
||||
nsString list;
|
||||
|
||||
for (i = 0; i < m_addressList.GetSize(); i++) {
|
||||
pFolder = m_addressList.GetItem(i);
|
||||
|
@ -279,11 +271,11 @@ nsresult nsOutlookMail::GetAddressBooks(nsIArray **pArray)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsOutlookMail::OpenMessageStore(CMapiFolder *pNextFolder)
|
||||
{
|
||||
void nsOutlookMail::OpenMessageStore(CMapiFolder *pNextFolder) {
|
||||
// Open the store specified
|
||||
if (pNextFolder->IsStore()) {
|
||||
if (!m_mapi.OpenStore(pNextFolder->GetCBEntryID(), pNextFolder->GetEntryID(), &m_lpMdb)) {
|
||||
if (!m_mapi.OpenStore(pNextFolder->GetCBEntryID(),
|
||||
pNextFolder->GetEntryID(), &m_lpMdb)) {
|
||||
m_lpMdb = NULL;
|
||||
IMPORT_LOG0("CMapiApi::OpenStore failed\n");
|
||||
}
|
||||
|
@ -294,19 +286,19 @@ void nsOutlookMail::OpenMessageStore(CMapiFolder *pNextFolder)
|
|||
// Check to see if we should open the one and only store
|
||||
if (!m_lpMdb) {
|
||||
if (m_storeList.GetSize() == 1) {
|
||||
CMapiFolder * pFolder = m_storeList.GetItem(0);
|
||||
CMapiFolder *pFolder = m_storeList.GetItem(0);
|
||||
if (pFolder) {
|
||||
if (!m_mapi.OpenStore(pFolder->GetCBEntryID(), pFolder->GetEntryID(), &m_lpMdb)) {
|
||||
if (!m_mapi.OpenStore(pFolder->GetCBEntryID(), pFolder->GetEntryID(),
|
||||
&m_lpMdb)) {
|
||||
m_lpMdb = NULL;
|
||||
IMPORT_LOG0("CMapiApi::OpenStore failed\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
IMPORT_LOG0("Error retrieving the one & only message store\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
IMPORT_LOG0("*** Error importing a folder without a valid message store\n");
|
||||
} else {
|
||||
IMPORT_LOG0(
|
||||
"*** Error importing a folder without a valid message store\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +314,8 @@ void nsOutlookMail::OpenMessageStore(CMapiFolder *pNextFolder)
|
|||
// nsOutlookCompose
|
||||
// - Establish a TB session
|
||||
// - Connect to all required services
|
||||
// - Perform the composition of the RC822 document from the data gathered by CMapiMessage
|
||||
// - Perform the composition of the RC822 document from the data gathered by
|
||||
// CMapiMessage
|
||||
// - Save the composed message to the TB mailbox
|
||||
// - Ensure the proper cleanup
|
||||
//
|
||||
|
@ -330,24 +323,19 @@ void nsOutlookMail::OpenMessageStore(CMapiFolder *pNextFolder)
|
|||
// - Encapsulate the MAPI message interface
|
||||
// - Gather the information required to (re)compose the message
|
||||
|
||||
ImportMailboxRunnable::ImportMailboxRunnable(uint32_t *pDoneSoFar, bool *pAbort,
|
||||
int32_t index, const char16_t *pName,
|
||||
nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount,
|
||||
nsOutlookMail *aCaller) :
|
||||
mozilla::Runnable("ImportMailboxRunnable"),
|
||||
mResult(NS_OK),
|
||||
mCaller(aCaller),
|
||||
mDoneSoFar(pDoneSoFar),
|
||||
mAbort(pAbort),
|
||||
mIndex(index),
|
||||
mName(pName),
|
||||
mDstFolder(dstFolder),
|
||||
mMsgCount(pMsgCount)
|
||||
{
|
||||
}
|
||||
NS_IMETHODIMP ImportMailboxRunnable::Run()
|
||||
{
|
||||
ImportMailboxRunnable::ImportMailboxRunnable(
|
||||
uint32_t *pDoneSoFar, bool *pAbort, int32_t index, const char16_t *pName,
|
||||
nsIMsgFolder *dstFolder, int32_t *pMsgCount, nsOutlookMail *aCaller)
|
||||
: mozilla::Runnable("ImportMailboxRunnable"),
|
||||
mResult(NS_OK),
|
||||
mCaller(aCaller),
|
||||
mDoneSoFar(pDoneSoFar),
|
||||
mAbort(pAbort),
|
||||
mIndex(index),
|
||||
mName(pName),
|
||||
mDstFolder(dstFolder),
|
||||
mMsgCount(pMsgCount) {}
|
||||
NS_IMETHODIMP ImportMailboxRunnable::Run() {
|
||||
if ((mIndex < 0) || (mIndex >= mCaller->m_folderList.GetSize())) {
|
||||
IMPORT_LOG0("*** Bad mailbox identifier, unable to import\n");
|
||||
*mAbort = true;
|
||||
|
@ -355,7 +343,7 @@ NS_IMETHODIMP ImportMailboxRunnable::Run()
|
|||
return NS_OK; // Sync runnable must return OK.
|
||||
}
|
||||
|
||||
int32_t dummyMsgCount = 0;
|
||||
int32_t dummyMsgCount = 0;
|
||||
if (mMsgCount)
|
||||
*mMsgCount = 0;
|
||||
else
|
||||
|
@ -364,24 +352,25 @@ NS_IMETHODIMP ImportMailboxRunnable::Run()
|
|||
CMapiFolder *pFolder = mCaller->m_folderList.GetItem(mIndex);
|
||||
mCaller->OpenMessageStore(pFolder);
|
||||
if (!mCaller->m_lpMdb) {
|
||||
IMPORT_LOG1("*** Unable to obtain mapi message store for mailbox: %S\n", mName);
|
||||
IMPORT_LOG1("*** Unable to obtain mapi message store for mailbox: %S\n",
|
||||
mName);
|
||||
mResult = NS_ERROR_FAILURE;
|
||||
return NS_OK; // Sync runnable must return OK.
|
||||
}
|
||||
|
||||
if (pFolder->IsStore())
|
||||
return NS_OK;
|
||||
if (pFolder->IsStore()) return NS_OK;
|
||||
|
||||
// now what?
|
||||
CMapiFolderContents contents(mCaller->m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID());
|
||||
CMapiFolderContents contents(mCaller->m_lpMdb, pFolder->GetCBEntryID(),
|
||||
pFolder->GetEntryID());
|
||||
|
||||
BOOL done = FALSE;
|
||||
ULONG cbEid;
|
||||
LPENTRYID lpEid;
|
||||
ULONG oType;
|
||||
LPMESSAGE lpMsg = nullptr;
|
||||
ULONG totalCount;
|
||||
double doneCalc;
|
||||
BOOL done = FALSE;
|
||||
ULONG cbEid;
|
||||
LPENTRYID lpEid;
|
||||
ULONG oType;
|
||||
LPMESSAGE lpMsg = nullptr;
|
||||
ULONG totalCount;
|
||||
double doneCalc;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outputStream;
|
||||
nsCOMPtr<nsIMsgPluggableStore> msgStore;
|
||||
|
@ -398,7 +387,8 @@ NS_IMETHODIMP ImportMailboxRunnable::Run()
|
|||
nsCOMPtr<nsIMsgDBHdr> msgHdr;
|
||||
bool reusable;
|
||||
|
||||
rv = msgStore->GetNewMsgOutputStream(mDstFolder, getter_AddRefs(msgHdr), &reusable,
|
||||
rv = msgStore->GetNewMsgOutputStream(mDstFolder, getter_AddRefs(msgHdr),
|
||||
&reusable,
|
||||
getter_AddRefs(outputStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG1("*** Error getting nsIOutputStream of mailbox: %S\n", mName);
|
||||
|
@ -410,13 +400,13 @@ NS_IMETHODIMP ImportMailboxRunnable::Run()
|
|||
doneCalc /= totalCount;
|
||||
doneCalc *= 1000;
|
||||
if (mDoneSoFar) {
|
||||
*mDoneSoFar = (uint32_t) doneCalc;
|
||||
if (*mDoneSoFar > 1000)
|
||||
*mDoneSoFar = 1000;
|
||||
*mDoneSoFar = (uint32_t)doneCalc;
|
||||
if (*mDoneSoFar > 1000) *mDoneSoFar = 1000;
|
||||
}
|
||||
|
||||
if (!done && (oType == MAPI_MESSAGE)) {
|
||||
if (!mCaller->m_mapi.OpenMdbEntry(mCaller->m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) {
|
||||
if (!mCaller->m_mapi.OpenMdbEntry(mCaller->m_lpMdb, cbEid, lpEid,
|
||||
(LPUNKNOWN *)&lpMsg)) {
|
||||
IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", mName);
|
||||
mResult = NS_ERROR_FAILURE;
|
||||
return NS_OK; // Sync runnable must return OK.
|
||||
|
@ -431,32 +421,26 @@ NS_IMETHODIMP ImportMailboxRunnable::Run()
|
|||
mode = nsIMsgSend::nsMsgSaveAsDraft;
|
||||
|
||||
rv = ImportMessage(lpMsg, outputStream, mode);
|
||||
if (NS_SUCCEEDED(rv)){ // No errors & really imported
|
||||
(*mMsgCount)++;
|
||||
if (NS_SUCCEEDED(rv)) { // No errors & really imported
|
||||
(*mMsgCount)++;
|
||||
msgStore->FinishNewMessage(outputStream, msgHdr);
|
||||
}
|
||||
else {
|
||||
IMPORT_LOG1( "*** Error reading message from mailbox: %S\n", mName);
|
||||
} else {
|
||||
IMPORT_LOG1("*** Error reading message from mailbox: %S\n", mName);
|
||||
msgStore->DiscardNewMessage(outputStream, msgHdr);
|
||||
}
|
||||
if (!reusable)
|
||||
outputStream->Close();
|
||||
if (!reusable) outputStream->Close();
|
||||
}
|
||||
}
|
||||
|
||||
if (outputStream)
|
||||
outputStream->Close();
|
||||
if (outputStream) outputStream->Close();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ProxyImportMailbox(uint32_t *pDoneSoFar, bool *pAbort,
|
||||
int32_t index, const char16_t *pName,
|
||||
nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount,
|
||||
nsOutlookMail *aCaller)
|
||||
{
|
||||
RefPtr<ImportMailboxRunnable> importMailbox =
|
||||
new ImportMailboxRunnable(pDoneSoFar, pAbort, index, pName, dstFolder, pMsgCount, aCaller);
|
||||
nsresult ProxyImportMailbox(uint32_t *pDoneSoFar, bool *pAbort, int32_t index,
|
||||
const char16_t *pName, nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount, nsOutlookMail *aCaller) {
|
||||
RefPtr<ImportMailboxRunnable> importMailbox = new ImportMailboxRunnable(
|
||||
pDoneSoFar, pAbort, index, pName, dstFolder, pMsgCount, aCaller);
|
||||
nsresult rv = NS_DispatchToMainThread(importMailbox, NS_DISPATCH_SYNC);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -466,32 +450,33 @@ nsresult ProxyImportMailbox(uint32_t *pDoneSoFar, bool *pAbort,
|
|||
nsresult nsOutlookMail::ImportMailbox(uint32_t *pDoneSoFar, bool *pAbort,
|
||||
int32_t index, const char16_t *pName,
|
||||
nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount)
|
||||
{
|
||||
return ProxyImportMailbox(pDoneSoFar, pAbort, index, pName, dstFolder, pMsgCount, this);
|
||||
int32_t *pMsgCount) {
|
||||
return ProxyImportMailbox(pDoneSoFar, pAbort, index, pName, dstFolder,
|
||||
pMsgCount, this);
|
||||
}
|
||||
|
||||
nsresult ImportMailboxRunnable::ImportMessage(LPMESSAGE lpMsg, nsIOutputStream *pDest, nsMsgDeliverMode mode)
|
||||
{
|
||||
CMapiMessage msg(lpMsg);
|
||||
nsresult ImportMailboxRunnable::ImportMessage(LPMESSAGE lpMsg,
|
||||
nsIOutputStream *pDest,
|
||||
nsMsgDeliverMode mode) {
|
||||
CMapiMessage msg(lpMsg);
|
||||
// If we wanted to skip messages that were downloaded in header only mode, we
|
||||
// would return NS_ERROR_FAILURE if !msg.FullMessageDownloaded. However, we
|
||||
// don't do this because it may cause seemingly wrong import results.
|
||||
// A user will get less mails in his imported folder than were in the original folder,
|
||||
// and this may make user feel like TB import is bad.
|
||||
// In reality, the skipped messages are those that have not been downloaded yet, because
|
||||
// they were downloaded in the "headers-only" mode. This is different from the case when
|
||||
// the message is downloaded completely, but consists only of headers - in this case
|
||||
// the message will be imported anyway.
|
||||
// A user will get less mails in his imported folder than were in the original
|
||||
// folder, and this may make user feel like TB import is bad. In reality, the
|
||||
// skipped messages are those that have not been downloaded yet, because they
|
||||
// were downloaded in the "headers-only" mode. This is different from the case
|
||||
// when the message is downloaded completely, but consists only of headers -
|
||||
// in this case the message will be imported anyway.
|
||||
|
||||
if (!msg.ValidState())
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!msg.ValidState()) return NS_ERROR_FAILURE;
|
||||
|
||||
// I have to create a composer for each message, since it turns out that if we create
|
||||
// one composer for several messages, the Send Proxy object that is shared between those messages
|
||||
// isn't reset properly (at least in the current implementation), which leads to crash.
|
||||
// If there's a proper way to reinitialize the Send Proxy object,
|
||||
// then we could slightly optimize the send process.
|
||||
// I have to create a composer for each message, since it turns out that if we
|
||||
// create one composer for several messages, the Send Proxy object that is
|
||||
// shared between those messages isn't reset properly (at least in the current
|
||||
// implementation), which leads to crash. If there's a proper way to
|
||||
// reinitialize the Send Proxy object, then we could slightly optimize the
|
||||
// send process.
|
||||
nsOutlookCompose compose;
|
||||
nsresult rv = compose.ProcessMessage(mode, msg, pDest);
|
||||
|
||||
|
@ -501,21 +486,23 @@ nsresult ImportMailboxRunnable::ImportMessage(LPMESSAGE lpMsg, nsIOutputStream *
|
|||
return rv;
|
||||
}
|
||||
|
||||
BOOL nsOutlookMail::WriteData(nsIOutputStream *pDest, const char *pData, int32_t len)
|
||||
{
|
||||
uint32_t written;
|
||||
BOOL nsOutlookMail::WriteData(nsIOutputStream *pDest, const char *pData,
|
||||
int32_t len) {
|
||||
uint32_t written;
|
||||
nsresult rv = pDest->Write(pData, len, &written);
|
||||
return NS_SUCCEEDED(rv) && written == len;
|
||||
}
|
||||
|
||||
nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, const char16_t *pName, uint32_t id, nsIAddrDatabase *pDb, nsString& errors)
|
||||
{
|
||||
nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal,
|
||||
const char16_t *pName, uint32_t id,
|
||||
nsIAddrDatabase *pDb,
|
||||
nsString &errors) {
|
||||
if (id >= (uint32_t)(m_addressList.GetSize())) {
|
||||
IMPORT_LOG0("*** Bad address identifier, unable to import\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
uint32_t dummyCount = 0;
|
||||
uint32_t dummyCount = 0;
|
||||
if (pCount)
|
||||
*pCount = 0;
|
||||
else
|
||||
|
@ -523,7 +510,7 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
|
||||
CMapiFolder *pFolder;
|
||||
if (id > 0) {
|
||||
int32_t idx = (int32_t) id;
|
||||
int32_t idx = (int32_t)id;
|
||||
idx--;
|
||||
while (idx >= 0) {
|
||||
pFolder = m_addressList.GetItem(idx);
|
||||
|
@ -538,32 +525,35 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
pFolder = m_addressList.GetItem(id);
|
||||
OpenMessageStore(pFolder);
|
||||
if (!m_lpMdb) {
|
||||
IMPORT_LOG1("*** Unable to obtain mapi message store for address book: %S\n", pName);
|
||||
IMPORT_LOG1(
|
||||
"*** Unable to obtain mapi message store for address book: %S\n",
|
||||
pName);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (pFolder->IsStore())
|
||||
return NS_OK;
|
||||
if (pFolder->IsStore()) return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIImportFieldMap> pFieldMap;
|
||||
nsCOMPtr<nsIImportFieldMap> pFieldMap;
|
||||
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = impSvc->CreateNewFieldMap(getter_AddRefs(pFieldMap));
|
||||
}
|
||||
|
||||
CMapiFolderContents contents(m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID());
|
||||
CMapiFolderContents contents(m_lpMdb, pFolder->GetCBEntryID(),
|
||||
pFolder->GetEntryID());
|
||||
|
||||
BOOL done = FALSE;
|
||||
ULONG cbEid;
|
||||
LPENTRYID lpEid;
|
||||
ULONG oType;
|
||||
LPMESSAGE lpMsg;
|
||||
nsCString type;
|
||||
LPSPropValue pVal;
|
||||
nsString subject;
|
||||
BOOL done = FALSE;
|
||||
ULONG cbEid;
|
||||
LPENTRYID lpEid;
|
||||
ULONG oType;
|
||||
LPMESSAGE lpMsg;
|
||||
nsCString type;
|
||||
LPSPropValue pVal;
|
||||
nsString subject;
|
||||
|
||||
while (!done) {
|
||||
(*pCount)++;
|
||||
|
@ -573,11 +563,10 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (pTotal && (*pTotal == 0))
|
||||
*pTotal = contents.GetCount();
|
||||
if (pTotal && (*pTotal == 0)) *pTotal = contents.GetCount();
|
||||
|
||||
if (!done && (oType == MAPI_MESSAGE)) {
|
||||
if (!m_mapi.OpenMdbEntry(m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) {
|
||||
if (!m_mapi.OpenMdbEntry(m_lpMdb, cbEid, lpEid, (LPUNKNOWN *)&lpMsg)) {
|
||||
IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -592,10 +581,9 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
// This is a contact, add it to the address book!
|
||||
subject.Truncate();
|
||||
pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT);
|
||||
if (pVal)
|
||||
m_mapi.GetStringFromProp(pVal, subject);
|
||||
if (pVal) m_mapi.GetStringFromProp(pVal, subject);
|
||||
|
||||
nsIMdbRow* newRow = nullptr;
|
||||
nsIMdbRow *newRow = nullptr;
|
||||
pDb->GetNewRow(&newRow);
|
||||
// FIXME: Check with Candice about releasing the newRow if it
|
||||
// isn't added to the database. Candice's code in nsAddressBook
|
||||
|
@ -605,14 +593,11 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
pDb->AddCardRowToDB(newRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type.EqualsLiteral("IPM.DistList"))
|
||||
{
|
||||
} else if (type.EqualsLiteral("IPM.DistList")) {
|
||||
// This is a list/group, add it to the address book!
|
||||
subject.Truncate();
|
||||
pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT);
|
||||
if (pVal)
|
||||
m_mapi.GetStringFromProp(pVal, subject);
|
||||
if (pVal) m_mapi.GetStringFromProp(pVal, subject);
|
||||
CreateList(subject.get(), pDb, lpMsg, pFieldMap);
|
||||
}
|
||||
}
|
||||
|
@ -624,21 +609,17 @@ nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, cons
|
|||
rv = pDb->Commit(nsAddrDBCommitType::kLargeCommit);
|
||||
return rv;
|
||||
}
|
||||
nsresult nsOutlookMail::CreateList(const char16_t * pName,
|
||||
nsIAddrDatabase *pDb,
|
||||
nsresult nsOutlookMail::CreateList(const char16_t *pName, nsIAddrDatabase *pDb,
|
||||
LPMAPIPROP pUserList,
|
||||
nsIImportFieldMap *pFieldMap)
|
||||
{
|
||||
nsIImportFieldMap *pFieldMap) {
|
||||
// If no name provided then we're done.
|
||||
if (!pName || !(*pName))
|
||||
return NS_OK;
|
||||
if (!pName || !(*pName)) return NS_OK;
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
// Make sure we have db to work with.
|
||||
if (!pDb)
|
||||
return rv;
|
||||
if (!pDb) return rv;
|
||||
|
||||
nsCOMPtr <nsIMdbRow> newListRow;
|
||||
nsCOMPtr<nsIMdbRow> newListRow;
|
||||
rv = pDb->GetNewListRow(getter_AddRefs(newListRow));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsAutoCString column;
|
||||
|
@ -646,47 +627,41 @@ nsresult nsOutlookMail::CreateList(const char16_t * pName,
|
|||
rv = pDb->AddListName(newListRow, column.get());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
HRESULT hr;
|
||||
HRESULT hr;
|
||||
LPSPropValue value = NULL;
|
||||
ULONG valueCount = 0;
|
||||
|
||||
LPSPropTagArray properties = NULL;
|
||||
m_mapi.MAPIAllocateBuffer(CbNewSPropTagArray(1),
|
||||
(void **)&properties);
|
||||
m_mapi.MAPIAllocateBuffer(CbNewSPropTagArray(1), (void **)&properties);
|
||||
properties->cValues = 1;
|
||||
properties->aulPropTag [0] = m_mapi.GetEmailPropertyTag(pUserList, 0x8054);
|
||||
properties->aulPropTag[0] = m_mapi.GetEmailPropertyTag(pUserList, 0x8054);
|
||||
hr = pUserList->GetProps(properties, 0, &valueCount, &value);
|
||||
m_mapi.MAPIFreeBuffer(properties);
|
||||
if (HR_FAILED(hr))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!value)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
if (HR_FAILED(hr)) return NS_ERROR_FAILURE;
|
||||
if (!value) return NS_ERROR_NOT_AVAILABLE;
|
||||
// XXX from here out, value must be freed with MAPIFreeBuffer
|
||||
|
||||
SBinaryArray *sa=(SBinaryArray *)&value->Value.bin;
|
||||
SBinaryArray *sa = (SBinaryArray *)&value->Value.bin;
|
||||
if (!sa || !sa->lpbin) {
|
||||
m_mapi.MAPIFreeBuffer(value);
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
LPENTRYID lpEid;
|
||||
ULONG cbEid;
|
||||
ULONG idx;
|
||||
LPMESSAGE lpMsg;
|
||||
nsCString type;
|
||||
LPENTRYID lpEid;
|
||||
ULONG cbEid;
|
||||
ULONG idx;
|
||||
LPMESSAGE lpMsg;
|
||||
nsCString type;
|
||||
LPSPropValue pVal;
|
||||
nsString subject;
|
||||
ULONG total;
|
||||
nsString subject;
|
||||
ULONG total;
|
||||
|
||||
total = sa->cValues;
|
||||
for (idx = 0; idx < total; idx++)
|
||||
{
|
||||
lpEid= (LPENTRYID) sa->lpbin[idx].lpb;
|
||||
for (idx = 0; idx < total; idx++) {
|
||||
lpEid = (LPENTRYID)sa->lpbin[idx].lpb;
|
||||
cbEid = sa->lpbin[idx].cb;
|
||||
|
||||
if (!m_mapi.OpenEntry(cbEid, lpEid, (LPUNKNOWN *) &lpMsg))
|
||||
{
|
||||
|
||||
if (!m_mapi.OpenEntry(cbEid, lpEid, (LPUNKNOWN *)&lpMsg)) {
|
||||
IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName);
|
||||
m_mapi.MAPIFreeBuffer(value);
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -694,32 +669,30 @@ nsresult nsOutlookMail::CreateList(const char16_t * pName,
|
|||
// This is a contact, add it to the address book!
|
||||
subject.Truncate();
|
||||
pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT);
|
||||
if (pVal)
|
||||
m_mapi.GetStringFromProp(pVal, subject);
|
||||
if (pVal) m_mapi.GetStringFromProp(pVal, subject);
|
||||
|
||||
nsCOMPtr <nsIMdbRow> newRow;
|
||||
nsCOMPtr <nsIMdbRow> oldRow;
|
||||
nsCOMPtr<nsIMdbRow> newRow;
|
||||
nsCOMPtr<nsIMdbRow> oldRow;
|
||||
pDb->GetNewRow(getter_AddRefs(newRow));
|
||||
if (newRow) {
|
||||
if (BuildCard(subject.get(), pDb, newRow, lpMsg, pFieldMap))
|
||||
{
|
||||
nsCOMPtr <nsIAbCard> userCard;
|
||||
nsCOMPtr <nsIAbCard> newCard;
|
||||
if (BuildCard(subject.get(), pDb, newRow, lpMsg, pFieldMap)) {
|
||||
nsCOMPtr<nsIAbCard> userCard;
|
||||
nsCOMPtr<nsIAbCard> newCard;
|
||||
userCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
pDb->InitCardFromRow(userCard,newRow);
|
||||
pDb->InitCardFromRow(userCard, newRow);
|
||||
|
||||
//add card to db
|
||||
pDb->FindRowByCard(userCard,getter_AddRefs(oldRow));
|
||||
// add card to db
|
||||
pDb->FindRowByCard(userCard, getter_AddRefs(oldRow));
|
||||
if (oldRow)
|
||||
newRow = oldRow;
|
||||
else
|
||||
pDb->AddCardRowToDB(newRow);
|
||||
|
||||
//add card list
|
||||
pDb->AddListCardColumnsToRow(userCard,
|
||||
newListRow,idx+1, getter_AddRefs(newCard),
|
||||
true, nullptr, nullptr);
|
||||
// add card list
|
||||
pDb->AddListCardColumnsToRow(userCard, newListRow, idx + 1,
|
||||
getter_AddRefs(newCard), true, nullptr,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -733,23 +706,20 @@ nsresult nsOutlookMail::CreateList(const char16_t * pName,
|
|||
return rv;
|
||||
}
|
||||
|
||||
void nsOutlookMail::SanitizeValue(nsString& val)
|
||||
{
|
||||
void nsOutlookMail::SanitizeValue(nsString &val) {
|
||||
MsgReplaceSubstring(val, NS_LITERAL_STRING("\r\n"), NS_LITERAL_STRING(", "));
|
||||
MsgReplaceChar(val, "\r\n", ',');
|
||||
}
|
||||
|
||||
void nsOutlookMail::SplitString(nsString& val1, nsString& val2)
|
||||
{
|
||||
void nsOutlookMail::SplitString(nsString &val1, nsString &val2) {
|
||||
// Find the last line if there is more than one!
|
||||
int32_t idx = val1.RFind("\x0D\x0A");
|
||||
int32_t cnt = 2;
|
||||
int32_t cnt = 2;
|
||||
if (idx == -1) {
|
||||
cnt = 1;
|
||||
idx = val1.RFindChar(13);
|
||||
}
|
||||
if (idx == -1)
|
||||
idx= val1.RFindChar(10);
|
||||
if (idx == -1) idx = val1.RFindChar(10);
|
||||
if (idx != -1) {
|
||||
val2 = Substring(val1, idx + cnt);
|
||||
val1.SetLength(idx);
|
||||
|
@ -757,18 +727,18 @@ void nsOutlookMail::SplitString(nsString& val1, nsString& val2)
|
|||
}
|
||||
}
|
||||
|
||||
bool nsOutlookMail::BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap)
|
||||
{
|
||||
bool nsOutlookMail::BuildCard(const char16_t *pName, nsIAddrDatabase *pDb,
|
||||
nsIMdbRow *newRow, LPMAPIPROP pUser,
|
||||
nsIImportFieldMap *pFieldMap) {
|
||||
nsString lastName;
|
||||
nsString firstName;
|
||||
nsString eMail;
|
||||
nsString nickName;
|
||||
nsString middleName;
|
||||
nsString secondEMail;
|
||||
ULONG emailTag;
|
||||
|
||||
nsString lastName;
|
||||
nsString firstName;
|
||||
nsString eMail;
|
||||
nsString nickName;
|
||||
nsString middleName;
|
||||
nsString secondEMail;
|
||||
ULONG emailTag;
|
||||
|
||||
LPSPropValue pProp = m_mapi.GetMapiProperty(pUser, PR_EMAIL_ADDRESS);
|
||||
LPSPropValue pProp = m_mapi.GetMapiProperty(pUser, PR_EMAIL_ADDRESS);
|
||||
if (!pProp) {
|
||||
emailTag = m_mapi.GetEmailPropertyTag(pUser, OUTLOOK_EMAIL1_MAPI_ID1);
|
||||
if (emailTag) {
|
||||
|
@ -814,7 +784,7 @@ bool nsOutlookMail::BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMd
|
|||
firstName = pName;
|
||||
}
|
||||
|
||||
nsString displayName;
|
||||
nsString displayName;
|
||||
pProp = m_mapi.GetMapiProperty(pUser, PR_DISPLAY_NAME);
|
||||
if (pProp) {
|
||||
m_mapi.GetStringFromProp(pProp, displayName);
|
||||
|
@ -859,8 +829,8 @@ bool nsOutlookMail::BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMd
|
|||
|
||||
// Do all of the extra fields!
|
||||
|
||||
nsString value;
|
||||
nsString line2;
|
||||
nsString value;
|
||||
nsString line2;
|
||||
|
||||
if (pFieldMap) {
|
||||
int max = sizeof(gMapiFields) / sizeof(MAPIFields);
|
||||
|
@ -871,18 +841,20 @@ bool nsOutlookMail::BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMd
|
|||
if (!value.IsEmpty()) {
|
||||
if (gMapiFields[i].multiLine == kNoMultiLine) {
|
||||
SanitizeValue(value);
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField, value.get());
|
||||
}
|
||||
else if (gMapiFields[i].multiLine == kIsMultiLine) {
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField, value.get());
|
||||
}
|
||||
else {
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField,
|
||||
value.get());
|
||||
} else if (gMapiFields[i].multiLine == kIsMultiLine) {
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField,
|
||||
value.get());
|
||||
} else {
|
||||
line2.Truncate();
|
||||
SplitString(value, line2);
|
||||
if (!value.IsEmpty())
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField, value.get());
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].mozField,
|
||||
value.get());
|
||||
if (!line2.IsEmpty())
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].multiLine, line2.get());
|
||||
pFieldMap->SetFieldValue(pDb, newRow, gMapiFields[i].multiLine,
|
||||
line2.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class nsIAddrDatabase;
|
|||
class nsIImportFieldMap;
|
||||
|
||||
class nsOutlookMail {
|
||||
public:
|
||||
public:
|
||||
nsOutlookMail();
|
||||
~nsOutlookMail();
|
||||
|
||||
|
@ -28,53 +28,55 @@ public:
|
|||
nsresult ImportMailbox(uint32_t *pDoneSoFar, bool *pAbort, int32_t index,
|
||||
const char16_t *pName, nsIMsgFolder *pDest,
|
||||
int32_t *pMsgCount);
|
||||
nsresult ImportAddresses(uint32_t *pCount, uint32_t *pTotal, const char16_t *pName, uint32_t id, nsIAddrDatabase *pDb, nsString& errors);
|
||||
void OpenMessageStore(CMapiFolder *pNextFolder);
|
||||
static BOOL WriteData(nsIOutputStream *pDest, const char *pData, int32_t len);
|
||||
nsresult ImportAddresses(uint32_t *pCount, uint32_t *pTotal,
|
||||
const char16_t *pName, uint32_t id,
|
||||
nsIAddrDatabase *pDb, nsString &errors);
|
||||
void OpenMessageStore(CMapiFolder *pNextFolder);
|
||||
static BOOL WriteData(nsIOutputStream *pDest, const char *pData, int32_t len);
|
||||
|
||||
private:
|
||||
bool IsAddressBookNameUnique(nsString& name, nsString& list);
|
||||
void MakeAddressBookNameUnique(nsString& name, nsString& list);
|
||||
void SanitizeValue(nsString& val);
|
||||
void SplitString(nsString& val1, nsString& val2);
|
||||
bool BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
|
||||
nsresult CreateList(const char16_t * pName, nsIAddrDatabase *pDb, LPMAPIPROP pUserList, nsIImportFieldMap *pFieldMap);
|
||||
private:
|
||||
bool IsAddressBookNameUnique(nsString &name, nsString &list);
|
||||
void MakeAddressBookNameUnique(nsString &name, nsString &list);
|
||||
void SanitizeValue(nsString &val);
|
||||
void SplitString(nsString &val1, nsString &val2);
|
||||
bool BuildCard(const char16_t *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow,
|
||||
LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
|
||||
nsresult CreateList(const char16_t *pName, nsIAddrDatabase *pDb,
|
||||
LPMAPIPROP pUserList, nsIImportFieldMap *pFieldMap);
|
||||
|
||||
private:
|
||||
bool m_gotFolders;
|
||||
bool m_gotAddresses;
|
||||
bool m_haveMapi;
|
||||
CMapiFolderList m_addressList;
|
||||
CMapiFolderList m_storeList;
|
||||
private:
|
||||
bool m_gotFolders;
|
||||
bool m_gotAddresses;
|
||||
bool m_haveMapi;
|
||||
CMapiFolderList m_addressList;
|
||||
CMapiFolderList m_storeList;
|
||||
|
||||
public:
|
||||
public:
|
||||
// Needed for the proxy class.
|
||||
CMapiApi m_mapi;
|
||||
CMapiFolderList m_folderList;
|
||||
LPMDB m_lpMdb;
|
||||
CMapiApi m_mapi;
|
||||
CMapiFolderList m_folderList;
|
||||
LPMDB m_lpMdb;
|
||||
};
|
||||
|
||||
class ImportMailboxRunnable: public mozilla::Runnable
|
||||
{
|
||||
public:
|
||||
ImportMailboxRunnable(uint32_t *pDoneSoFar, bool *pAbort,
|
||||
int32_t index, const char16_t *pName,
|
||||
nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount,
|
||||
nsOutlookMail *aCaller);
|
||||
class ImportMailboxRunnable : public mozilla::Runnable {
|
||||
public:
|
||||
ImportMailboxRunnable(uint32_t *pDoneSoFar, bool *pAbort, int32_t index,
|
||||
const char16_t *pName, nsIMsgFolder *dstFolder,
|
||||
int32_t *pMsgCount, nsOutlookMail *aCaller);
|
||||
NS_DECL_NSIRUNNABLE
|
||||
static nsresult ImportMessage(LPMESSAGE lpMsg, nsIOutputStream *pDest, nsMsgDeliverMode mode);
|
||||
nsresult mResult;
|
||||
static nsresult ImportMessage(LPMESSAGE lpMsg, nsIOutputStream *pDest,
|
||||
nsMsgDeliverMode mode);
|
||||
nsresult mResult;
|
||||
|
||||
private:
|
||||
nsOutlookMail *mCaller;
|
||||
uint32_t *mDoneSoFar;
|
||||
bool *mAbort;
|
||||
int32_t mIndex;
|
||||
const char16_t *mName;
|
||||
private:
|
||||
nsOutlookMail *mCaller;
|
||||
uint32_t *mDoneSoFar;
|
||||
bool *mAbort;
|
||||
int32_t mIndex;
|
||||
const char16_t *mName;
|
||||
nsCOMPtr<nsIFile> mMessageFile;
|
||||
nsCOMPtr<nsIMsgFolder> mDstFolder;
|
||||
int32_t *mMsgCount;
|
||||
int32_t *mMsgCount;
|
||||
};
|
||||
|
||||
#endif /* nsOutlookMail_h___ */
|
||||
|
|
|
@ -29,93 +29,81 @@
|
|||
#include "nsNativeCharsetUtils.h"
|
||||
|
||||
class OutlookSettings {
|
||||
public:
|
||||
public:
|
||||
static nsresult FindAccountsKey(nsIWindowsRegKey **aKey);
|
||||
static nsresult QueryAccountSubKey(nsIWindowsRegKey **aKey);
|
||||
static nsresult GetDefaultMailAccountName(nsAString &aName);
|
||||
|
||||
static bool DoImport(nsIMsgAccount **aAccount);
|
||||
|
||||
static bool DoIMAPServer(nsIMsgAccountManager *aMgr,
|
||||
nsIWindowsRegKey *aKey,
|
||||
static bool DoIMAPServer(nsIMsgAccountManager *aMgr, nsIWindowsRegKey *aKey,
|
||||
const nsString &aServerName,
|
||||
nsIMsgAccount **aAccount);
|
||||
static bool DoPOP3Server(nsIMsgAccountManager *aMgr,
|
||||
nsIWindowsRegKey *aKey,
|
||||
static bool DoPOP3Server(nsIMsgAccountManager *aMgr, nsIWindowsRegKey *aKey,
|
||||
const nsString &aServerName,
|
||||
nsIMsgAccount **aAccount);
|
||||
|
||||
static void SetIdentities(nsIMsgAccountManager *pMgr,
|
||||
nsIMsgAccount *pAcc,
|
||||
static void SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
|
||||
nsIWindowsRegKey *aKey);
|
||||
|
||||
static nsresult SetSmtpServer(nsIMsgAccountManager *aMgr,
|
||||
nsIMsgAccount *aAcc,
|
||||
nsIMsgIdentity *aId,
|
||||
const nsString &aServer,
|
||||
static nsresult SetSmtpServer(nsIMsgAccountManager *aMgr, nsIMsgAccount *aAcc,
|
||||
nsIMsgIdentity *aId, const nsString &aServer,
|
||||
const nsString &aUser);
|
||||
static nsresult SetSmtpServerKey(nsIMsgIdentity *aId,
|
||||
nsISmtpServer *aServer);
|
||||
static nsresult SetSmtpServerKey(nsIMsgIdentity *aId, nsISmtpServer *aServer);
|
||||
static nsresult GetAccountName(nsIWindowsRegKey *aKey,
|
||||
const nsString &aDefaultName,
|
||||
nsAString &aAccountName);
|
||||
};
|
||||
|
||||
#define OUTLOOK2003_REGISTRY_KEY "Software\\Microsoft\\Office\\Outlook\\OMI Account Manager"
|
||||
#define OUTLOOK98_REGISTRY_KEY "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager"
|
||||
#define OUTLOOK2003_REGISTRY_KEY \
|
||||
"Software\\Microsoft\\Office\\Outlook\\OMI Account Manager"
|
||||
#define OUTLOOK98_REGISTRY_KEY \
|
||||
"Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult nsOutlookSettings::Create(nsIImportSettings** aImport)
|
||||
{
|
||||
nsresult nsOutlookSettings::Create(nsIImportSettings **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsOutlookSettings());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsOutlookSettings::nsOutlookSettings()
|
||||
{
|
||||
}
|
||||
nsOutlookSettings::nsOutlookSettings() {}
|
||||
|
||||
nsOutlookSettings::~nsOutlookSettings()
|
||||
{
|
||||
}
|
||||
nsOutlookSettings::~nsOutlookSettings() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsOutlookSettings, nsIImportSettings)
|
||||
|
||||
NS_IMETHODIMP nsOutlookSettings::AutoLocate(char16_t **description, nsIFile **location, bool *_retval)
|
||||
{
|
||||
NS_ASSERTION(description != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!description || !_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_IMETHODIMP nsOutlookSettings::AutoLocate(char16_t **description,
|
||||
nsIFile **location, bool *_retval) {
|
||||
NS_ASSERTION(description != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!description || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*description = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_NAME);
|
||||
*_retval = false;
|
||||
|
||||
if (location)
|
||||
*location = nullptr;
|
||||
if (location) *location = nullptr;
|
||||
|
||||
// look for the registry key for the accounts
|
||||
nsCOMPtr<nsIWindowsRegKey> key;
|
||||
*_retval = NS_SUCCEEDED(OutlookSettings::FindAccountsKey(getter_AddRefs(key)));
|
||||
*_retval =
|
||||
NS_SUCCEEDED(OutlookSettings::FindAccountsKey(getter_AddRefs(key)));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookSettings::SetLocation(nsIFile *location)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookSettings::SetLocation(nsIFile *location) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOutlookSettings::Import(nsIMsgAccount **localMailAccount, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsOutlookSettings::Import(nsIMsgAccount **localMailAccount,
|
||||
bool *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
|
||||
if (OutlookSettings::DoImport(localMailAccount)) {
|
||||
*_retval = true;
|
||||
IMPORT_LOG0("Settings import appears successful\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*_retval = false;
|
||||
IMPORT_LOG0("Settings import returned FALSE\n");
|
||||
}
|
||||
|
@ -123,43 +111,39 @@ NS_IMETHODIMP nsOutlookSettings::Import(nsIMsgAccount **localMailAccount, bool *
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult OutlookSettings::FindAccountsKey(nsIWindowsRegKey **aKey)
|
||||
{
|
||||
nsresult OutlookSettings::FindAccountsKey(nsIWindowsRegKey **aKey) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIWindowsRegKey> key =
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
||||
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(OUTLOOK2003_REGISTRY_KEY),
|
||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE |
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = key->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||
NS_LITERAL_STRING(OUTLOOK98_REGISTRY_KEY),
|
||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE |
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
key.forget(aKey);
|
||||
if (NS_SUCCEEDED(rv)) key.forget(aKey);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult OutlookSettings::QueryAccountSubKey(nsIWindowsRegKey **aKey)
|
||||
{
|
||||
nsresult OutlookSettings::QueryAccountSubKey(nsIWindowsRegKey **aKey) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIWindowsRegKey> key =
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
||||
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(OUTLOOK2003_REGISTRY_KEY),
|
||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE |
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
key.forget(aKey);
|
||||
return rv;
|
||||
|
@ -168,7 +152,7 @@ nsresult OutlookSettings::QueryAccountSubKey(nsIWindowsRegKey **aKey)
|
|||
rv = key->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||
NS_LITERAL_STRING(OUTLOOK98_REGISTRY_KEY),
|
||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE |
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
key.forget(aKey);
|
||||
return rv;
|
||||
|
@ -177,18 +161,15 @@ nsresult OutlookSettings::QueryAccountSubKey(nsIWindowsRegKey **aKey)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult OutlookSettings::GetDefaultMailAccountName(nsAString &aName)
|
||||
{
|
||||
nsresult OutlookSettings::GetDefaultMailAccountName(nsAString &aName) {
|
||||
nsCOMPtr<nsIWindowsRegKey> key;
|
||||
nsresult rv = QueryAccountSubKey(getter_AddRefs(key));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return key->ReadStringValue(NS_LITERAL_STRING("Default Mail Account"), aName);
|
||||
}
|
||||
|
||||
bool OutlookSettings::DoImport(nsIMsgAccount **aAccount)
|
||||
{
|
||||
bool OutlookSettings::DoImport(nsIMsgAccount **aAccount) {
|
||||
nsCOMPtr<nsIWindowsRegKey> key;
|
||||
nsresult rv = OutlookSettings::FindAccountsKey(getter_AddRefs(key));
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -197,7 +178,7 @@ bool OutlookSettings::DoImport(nsIMsgAccount **aAccount)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accMgr =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Failed to create a account manager!\n");
|
||||
return false;
|
||||
|
@ -215,11 +196,9 @@ bool OutlookSettings::DoImport(nsIMsgAccount **aAccount)
|
|||
nsAutoString keyName;
|
||||
key->GetChildName(i, keyName);
|
||||
nsCOMPtr<nsIWindowsRegKey> subKey;
|
||||
rv = key->OpenChild(keyName,
|
||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE,
|
||||
rv = key->OpenChild(keyName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
|
||||
getter_AddRefs(subKey));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
// Get the values for this account.
|
||||
nsAutoCString nativeKeyName;
|
||||
|
@ -262,12 +241,10 @@ bool OutlookSettings::DoImport(nsIMsgAccount **aAccount)
|
|||
|
||||
nsresult OutlookSettings::GetAccountName(nsIWindowsRegKey *aKey,
|
||||
const nsString &aDefaultName,
|
||||
nsAString &aAccountName)
|
||||
{
|
||||
nsAString &aAccountName) {
|
||||
nsresult rv;
|
||||
rv = aKey->ReadStringValue(NS_LITERAL_STRING("Account Name"), aAccountName);
|
||||
if (NS_FAILED(rv))
|
||||
aAccountName.Assign(aDefaultName);
|
||||
if (NS_FAILED(rv)) aAccountName.Assign(aDefaultName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -275,13 +252,11 @@ nsresult OutlookSettings::GetAccountName(nsIWindowsRegKey *aKey,
|
|||
bool OutlookSettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
|
||||
nsIWindowsRegKey *aKey,
|
||||
const nsString &aServerName,
|
||||
nsIMsgAccount **aAccount)
|
||||
{
|
||||
nsIMsgAccount **aAccount) {
|
||||
nsAutoString userName;
|
||||
nsresult rv;
|
||||
rv = aKey->ReadStringValue(NS_LITERAL_STRING("IMAP User Name"), userName);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
bool result = false;
|
||||
|
||||
|
@ -291,14 +266,11 @@ bool OutlookSettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
|
|||
nsAutoCString nativeServerName;
|
||||
NS_CopyUnicodeToNative(aServerName, nativeServerName);
|
||||
nsCOMPtr<nsIMsgIncomingServer> in;
|
||||
rv = aMgr->FindServer(nativeUserName,
|
||||
nativeServerName,
|
||||
NS_LITERAL_CSTRING("imap"),
|
||||
getter_AddRefs(in));
|
||||
rv = aMgr->FindServer(nativeUserName, nativeServerName,
|
||||
NS_LITERAL_CSTRING("imap"), getter_AddRefs(in));
|
||||
if (NS_FAILED(rv) || (in == nullptr)) {
|
||||
// Create the incoming server and an account for it?
|
||||
rv = aMgr->CreateIncomingServer(nativeUserName,
|
||||
nativeServerName,
|
||||
rv = aMgr->CreateIncomingServer(nativeUserName, nativeServerName,
|
||||
NS_LITERAL_CSTRING("imap"),
|
||||
getter_AddRefs(in));
|
||||
if (NS_SUCCEEDED(rv) && in) {
|
||||
|
@ -312,22 +284,22 @@ bool OutlookSettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
|
|||
if (NS_SUCCEEDED(GetAccountName(aKey, aServerName, prettyName)))
|
||||
rv = in->SetPrettyName(prettyName);
|
||||
// We have a server, create an account.
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
rv = aMgr->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");
|
||||
IMPORT_LOG0(
|
||||
"Created an account and set the IMAP server as the incoming "
|
||||
"server\n");
|
||||
|
||||
// Fiddle with the identities
|
||||
SetIdentities(aMgr, account, aKey);
|
||||
result = true;
|
||||
if (aAccount)
|
||||
account.forget(aAccount);
|
||||
if (aAccount) account.forget(aAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
|
@ -336,13 +308,11 @@ bool OutlookSettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
|
|||
bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
|
||||
nsIWindowsRegKey *aKey,
|
||||
const nsString &aServerName,
|
||||
nsIMsgAccount **aAccount)
|
||||
{
|
||||
nsIMsgAccount **aAccount) {
|
||||
nsAutoString userName;
|
||||
nsresult rv;
|
||||
rv = aKey->ReadStringValue(NS_LITERAL_STRING("POP3 User Name"), userName);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
// I now have a user name/server name pair, find out if it already exists?
|
||||
nsAutoCString nativeUserName;
|
||||
|
@ -350,16 +320,12 @@ bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
|
|||
nsAutoCString nativeServerName;
|
||||
NS_CopyUnicodeToNative(aServerName, nativeServerName);
|
||||
nsCOMPtr<nsIMsgIncomingServer> in;
|
||||
rv = aMgr->FindServer(nativeUserName,
|
||||
nativeServerName,
|
||||
NS_LITERAL_CSTRING("pop3"),
|
||||
getter_AddRefs(in));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return true;
|
||||
rv = aMgr->FindServer(nativeUserName, nativeServerName,
|
||||
NS_LITERAL_CSTRING("pop3"), getter_AddRefs(in));
|
||||
if (NS_SUCCEEDED(rv)) return true;
|
||||
|
||||
// Create the incoming server and an account for it?
|
||||
rv = aMgr->CreateIncomingServer(nativeUserName,
|
||||
nativeServerName,
|
||||
rv = aMgr->CreateIncomingServer(nativeUserName, nativeServerName,
|
||||
NS_LITERAL_CSTRING("pop3"),
|
||||
getter_AddRefs(in));
|
||||
rv = in->SetType(NS_LITERAL_CSTRING("pop3"));
|
||||
|
@ -374,9 +340,9 @@ bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
|
|||
aMgr->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
|
||||
// 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 = aMgr->CreateLocalMailAccount();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Failed to create Local Folders!\n");
|
||||
|
@ -387,7 +353,8 @@ bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
|
|||
|
||||
// now get the account for this server
|
||||
nsCOMPtr<nsIMsgAccount> localFoldersAccount;
|
||||
aMgr->FindAccountForServer(localFoldersServer, getter_AddRefs(localFoldersAccount));
|
||||
aMgr->FindAccountForServer(localFoldersServer,
|
||||
getter_AddRefs(localFoldersAccount));
|
||||
if (localFoldersAccount) {
|
||||
nsCString localFoldersAcctKey;
|
||||
localFoldersAccount->GetKey(localFoldersAcctKey);
|
||||
|
@ -396,43 +363,41 @@ bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
|
|||
}
|
||||
|
||||
IMPORT_LOG2("Created POP3 server named: %s, userName: %s\n",
|
||||
nativeServerName.get(),
|
||||
nativeUserName.get());
|
||||
nativeServerName.get(), nativeUserName.get());
|
||||
|
||||
nsString prettyName;
|
||||
rv = GetAccountName(aKey, aServerName, prettyName);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
rv = in->SetPrettyName(prettyName);
|
||||
// We have a server, create an account.
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
rv = aMgr->CreateAccount(getter_AddRefs(account));
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
rv = account->SetIncomingServer(in);
|
||||
|
||||
IMPORT_LOG0("Created a new account and set the incoming server to the POP3 server.\n");
|
||||
IMPORT_LOG0(
|
||||
"Created a new account and set the incoming server to the POP3 "
|
||||
"server.\n");
|
||||
|
||||
uint32_t leaveOnServer;
|
||||
rv = aKey->ReadIntValue(NS_LITERAL_STRING("Leave Mail On Server"), &leaveOnServer);
|
||||
rv = aKey->ReadIntValue(NS_LITERAL_STRING("Leave Mail On Server"),
|
||||
&leaveOnServer);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
pop3Server->SetLeaveMessagesOnServer(leaveOnServer == 1 ? true : false);
|
||||
|
||||
// Fiddle with the identities
|
||||
SetIdentities(aMgr, account, aKey);
|
||||
|
||||
if (aAccount)
|
||||
account.forget(aAccount);
|
||||
if (aAccount) account.forget(aAccount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
|
||||
nsIMsgAccount *aAcc,
|
||||
nsIWindowsRegKey *aKey)
|
||||
{
|
||||
nsIWindowsRegKey *aKey) {
|
||||
// Get the relevant information for an identity
|
||||
nsAutoString name;
|
||||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Display Name"), name);
|
||||
|
@ -444,7 +409,8 @@ void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
|
|||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Email Address"), email);
|
||||
|
||||
nsAutoString reply;
|
||||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Reply To Email Address"), reply);
|
||||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Reply To Email Address"),
|
||||
reply);
|
||||
|
||||
nsAutoString userName;
|
||||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP User Name"), userName);
|
||||
|
@ -453,7 +419,7 @@ void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
|
|||
aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Organization Name"), orgName);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgIdentity> id;
|
||||
nsCOMPtr<nsIMsgIdentity> id;
|
||||
if (!email.IsEmpty() && !name.IsEmpty() && !server.IsEmpty()) {
|
||||
// The default identity, nor any other identities matched,
|
||||
// create a new one and add it to the account.
|
||||
|
@ -481,12 +447,13 @@ void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
|
|||
}
|
||||
|
||||
if (userName.IsEmpty()) {
|
||||
nsCOMPtr<nsIMsgIncomingServer> incomingServer;
|
||||
nsCOMPtr<nsIMsgIncomingServer> incomingServer;
|
||||
rv = aAcc->GetIncomingServer(getter_AddRefs(incomingServer));
|
||||
if (NS_SUCCEEDED(rv) && incomingServer) {
|
||||
nsAutoCString nativeUserName;
|
||||
rv = incomingServer->GetUsername(nativeUserName);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get UserName from incomingServer");
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Unable to get UserName from incomingServer");
|
||||
NS_CopyNativeToUnicode(nativeUserName, userName);
|
||||
}
|
||||
}
|
||||
|
@ -495,8 +462,7 @@ void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
|
|||
}
|
||||
|
||||
nsresult OutlookSettings::SetSmtpServerKey(nsIMsgIdentity *aId,
|
||||
nsISmtpServer *aServer)
|
||||
{
|
||||
nsISmtpServer *aServer) {
|
||||
nsAutoCString smtpServerKey;
|
||||
aServer->GetKey(getter_Copies(smtpServerKey));
|
||||
return aId->SetSmtpServerKey(smtpServerKey);
|
||||
|
@ -506,10 +472,10 @@ nsresult OutlookSettings::SetSmtpServer(nsIMsgAccountManager *aMgr,
|
|||
nsIMsgAccount *aAcc,
|
||||
nsIMsgIdentity *aId,
|
||||
const nsString &aServer,
|
||||
const nsString &aUser)
|
||||
{
|
||||
const nsString &aUser) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsISmtpService> smtpService(
|
||||
do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString nativeUserName;
|
||||
|
@ -517,14 +483,11 @@ nsresult OutlookSettings::SetSmtpServer(nsIMsgAccountManager *aMgr,
|
|||
nsAutoCString nativeServerName;
|
||||
NS_CopyUnicodeToNative(aServer, nativeServerName);
|
||||
nsCOMPtr<nsISmtpServer> foundServer;
|
||||
rv = smtpService->FindServer(nativeUserName.get(),
|
||||
nativeServerName.get(),
|
||||
rv = smtpService->FindServer(nativeUserName.get(), nativeServerName.get(),
|
||||
getter_AddRefs(foundServer));
|
||||
if (NS_SUCCEEDED(rv) && foundServer) {
|
||||
if (aId)
|
||||
SetSmtpServerKey(aId, foundServer);
|
||||
IMPORT_LOG1("SMTP server already exists: %s\n",
|
||||
nativeServerName.get());
|
||||
if (aId) SetSmtpServerKey(aId, foundServer);
|
||||
IMPORT_LOG1("SMTP server already exists: %s\n", nativeServerName.get());
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -533,15 +496,11 @@ nsresult OutlookSettings::SetSmtpServer(nsIMsgAccountManager *aMgr,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
smtpServer->SetHostname(nativeServerName);
|
||||
if (!aUser.IsEmpty())
|
||||
smtpServer->SetUsername(nativeUserName);
|
||||
if (!aUser.IsEmpty()) smtpServer->SetUsername(nativeUserName);
|
||||
|
||||
if (aId)
|
||||
SetSmtpServerKey(aId, smtpServer);
|
||||
if (aId) SetSmtpServerKey(aId, smtpServer);
|
||||
|
||||
// TODO SSL, auth method
|
||||
IMPORT_LOG1("Created new SMTP server: %s\n",
|
||||
nativeServerName.get());
|
||||
IMPORT_LOG1("Created new SMTP server: %s\n", nativeServerName.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,22 +8,20 @@
|
|||
|
||||
#include "nsIImportSettings.h"
|
||||
|
||||
|
||||
class nsOutlookSettings : public nsIImportSettings {
|
||||
public:
|
||||
nsOutlookSettings();
|
||||
public:
|
||||
nsOutlookSettings();
|
||||
|
||||
static nsresult Create(nsIImportSettings** aImport);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIImportSettings interface
|
||||
NS_DECL_NSIIMPORTSETTINGS
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsOutlookSettings();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsOutlookSettings_h___ */
|
||||
|
|
|
@ -11,40 +11,35 @@
|
|||
#include "nsOutlookStringBundle.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#define OUTLOOK_MSGS_URL "chrome://messenger/locale/outlookImportMsgs.properties"
|
||||
#define OUTLOOK_MSGS_URL \
|
||||
"chrome://messenger/locale/outlookImportMsgs.properties"
|
||||
|
||||
nsCOMPtr<nsIStringBundle> nsOutlookStringBundle::m_pBundle = nullptr;
|
||||
|
||||
void nsOutlookStringBundle::GetStringBundle(void)
|
||||
{
|
||||
if (m_pBundle)
|
||||
return;
|
||||
void nsOutlookStringBundle::GetStringBundle(void) {
|
||||
if (m_pBundle) return;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> sBundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
mozilla::services::GetStringBundleService();
|
||||
if (sBundleService) {
|
||||
sBundleService->CreateBundle(OUTLOOK_MSGS_URL, getter_AddRefs(m_pBundle));
|
||||
}
|
||||
}
|
||||
|
||||
void nsOutlookStringBundle::GetStringByID(int32_t stringID, nsString& result)
|
||||
{
|
||||
void nsOutlookStringBundle::GetStringByID(int32_t stringID, nsString &result) {
|
||||
char16_t *ptrv = GetStringByID(stringID);
|
||||
result = ptrv;
|
||||
FreeString(ptrv);
|
||||
}
|
||||
|
||||
char16_t *nsOutlookStringBundle::GetStringByID(int32_t stringID)
|
||||
{
|
||||
if (m_pBundle)
|
||||
GetStringBundle();
|
||||
char16_t *nsOutlookStringBundle::GetStringByID(int32_t stringID) {
|
||||
if (m_pBundle) GetStringBundle();
|
||||
|
||||
if (m_pBundle) {
|
||||
nsAutoString str;
|
||||
nsresult rv = m_pBundle->GetStringFromID(stringID, str);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return ToNewUnicode(str);
|
||||
if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
|
||||
}
|
||||
|
||||
nsString resultString;
|
||||
|
@ -55,7 +50,4 @@ char16_t *nsOutlookStringBundle::GetStringByID(int32_t stringID)
|
|||
return ToNewUnicode(resultString);
|
||||
}
|
||||
|
||||
void nsOutlookStringBundle::Cleanup(void)
|
||||
{
|
||||
m_pBundle = nullptr;
|
||||
}
|
||||
void nsOutlookStringBundle::Cleanup(void) { m_pBundle = nullptr; }
|
||||
|
|
|
@ -11,28 +11,26 @@
|
|||
class nsIStringBundle;
|
||||
|
||||
class nsOutlookStringBundle {
|
||||
public:
|
||||
static char16_t * GetStringByID(int32_t stringID);
|
||||
public:
|
||||
static char16_t* GetStringByID(int32_t stringID);
|
||||
static void GetStringByID(int32_t stringID, nsString& result);
|
||||
static void GetStringBundle(void);
|
||||
static void FreeString(char16_t *pStr) { free(pStr);}
|
||||
static void FreeString(char16_t* pStr) { free(pStr); }
|
||||
static void Cleanup(void);
|
||||
private:
|
||||
|
||||
private:
|
||||
static nsCOMPtr<nsIStringBundle> m_pBundle;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define OUTLOOKIMPORT_NAME 2000
|
||||
#define OUTLOOKIMPORT_DESCRIPTION 2010
|
||||
#define OUTLOOKIMPORT_MAILBOX_SUCCESS 2002
|
||||
#define OUTLOOKIMPORT_MAILBOX_BADPARAM 2003
|
||||
#define OUTLOOKIMPORT_MAILBOX_CONVERTERROR 2004
|
||||
#define OUTLOOKIMPORT_ADDRNAME 2005
|
||||
#define OUTLOOKIMPORT_ADDRESS_SUCCESS 2006
|
||||
#define OUTLOOKIMPORT_ADDRESS_BADPARAM 2007
|
||||
#define OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE 2008
|
||||
#define OUTLOOKIMPORT_ADDRESS_CONVERTERROR 2009
|
||||
|
||||
#define OUTLOOKIMPORT_NAME 2000
|
||||
#define OUTLOOKIMPORT_DESCRIPTION 2010
|
||||
#define OUTLOOKIMPORT_MAILBOX_SUCCESS 2002
|
||||
#define OUTLOOKIMPORT_MAILBOX_BADPARAM 2003
|
||||
#define OUTLOOKIMPORT_MAILBOX_CONVERTERROR 2004
|
||||
#define OUTLOOKIMPORT_ADDRNAME 2005
|
||||
#define OUTLOOKIMPORT_ADDRESS_SUCCESS 2006
|
||||
#define OUTLOOKIMPORT_ADDRESS_BADPARAM 2007
|
||||
#define OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE 2008
|
||||
#define OUTLOOKIMPORT_ADDRESS_CONVERTERROR 2009
|
||||
|
||||
#endif /* _nsOutlookStringBundle_H__ */
|
||||
|
|
|
@ -8,91 +8,141 @@
|
|||
#include "windows.h"
|
||||
#include "rtfDecoder.h"
|
||||
|
||||
#define SIZEOF(x) (sizeof(x)/sizeof((x)[0]))
|
||||
#define IS_DIGIT(i) ((i) >= '0' && (i) <= '9')
|
||||
#define IS_ALPHA(VAL) (((VAL) >= 'a' && (VAL) <= 'z') || ((VAL) >= 'A' && (VAL) <= 'Z'))
|
||||
#define SIZEOF(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#define IS_DIGIT(i) ((i) >= '0' && (i) <= '9')
|
||||
#define IS_ALPHA(VAL) \
|
||||
(((VAL) >= 'a' && (VAL) <= 'z') || ((VAL) >= 'A' && (VAL) <= 'Z'))
|
||||
|
||||
inline int HexToInt(char ch)
|
||||
{
|
||||
inline int HexToInt(char ch) {
|
||||
switch (ch) {
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
||||
return ch-'0';
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
return ch-'A'+10;
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
return ch-'a'+10;
|
||||
default:
|
||||
return 0;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
return ch - '0';
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'E':
|
||||
case 'F':
|
||||
return ch - 'A' + 10;
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
return ch - 'a' + 10;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline int CharsetToCP(int charset)
|
||||
{
|
||||
inline int CharsetToCP(int charset) {
|
||||
// We don't know the Code page for the commented out charsets.
|
||||
switch (charset) {
|
||||
case 0: return 1252; // ANSI
|
||||
case 1: return 0; // Default
|
||||
//case 2: return 42; // Symbol
|
||||
case 2: return 1252; // Symbol
|
||||
case 77: return 10000; // Mac Roman
|
||||
case 78: return 10001; // Mac Shift Jis
|
||||
case 79: return 10003; // Mac Hangul
|
||||
case 80: return 10008; // Mac GB2312
|
||||
case 81: return 10002; // Mac Big5
|
||||
//case 82: Mac Johab (old)
|
||||
case 83: return 10005; // Mac Hebrew
|
||||
case 84: return 10004; // Mac Arabic
|
||||
case 85: return 10006; // Mac Greek
|
||||
case 86: return 10081; // Mac Turkish
|
||||
case 87: return 10021; // Mac Thai
|
||||
case 88: return 10029; // Mac East Europe
|
||||
case 89: return 10007; // Mac Russian
|
||||
case 128: return 932; // Shift JIS
|
||||
case 129: return 949; // Hangul
|
||||
case 130: return 1361; // Johab
|
||||
case 134: return 936; // GB2312
|
||||
case 136: return 950; // Big5
|
||||
case 161: return 1253; // Greek
|
||||
case 162: return 1254; // Turkish
|
||||
case 163: return 1258; // Vietnamese
|
||||
case 177: return 1255; // Hebrew
|
||||
case 178: return 1256; // Arabic
|
||||
//case 179: Arabic Traditional (old)
|
||||
//case 180: Arabic user (old)
|
||||
//case 181: Hebrew user (old)
|
||||
case 186: return 1257; // Baltic
|
||||
case 204: return 1251; // Russian
|
||||
case 222: return 874; // Thai
|
||||
case 238: return 1250; // Eastern European
|
||||
case 254: return 437; // PC 437
|
||||
case 255: return 850; // OEM
|
||||
default: return CP_ACP;
|
||||
case 0:
|
||||
return 1252; // ANSI
|
||||
case 1:
|
||||
return 0; // Default
|
||||
// case 2: return 42; // Symbol
|
||||
case 2:
|
||||
return 1252; // Symbol
|
||||
case 77:
|
||||
return 10000; // Mac Roman
|
||||
case 78:
|
||||
return 10001; // Mac Shift Jis
|
||||
case 79:
|
||||
return 10003; // Mac Hangul
|
||||
case 80:
|
||||
return 10008; // Mac GB2312
|
||||
case 81:
|
||||
return 10002; // Mac Big5
|
||||
// case 82: Mac Johab (old)
|
||||
case 83:
|
||||
return 10005; // Mac Hebrew
|
||||
case 84:
|
||||
return 10004; // Mac Arabic
|
||||
case 85:
|
||||
return 10006; // Mac Greek
|
||||
case 86:
|
||||
return 10081; // Mac Turkish
|
||||
case 87:
|
||||
return 10021; // Mac Thai
|
||||
case 88:
|
||||
return 10029; // Mac East Europe
|
||||
case 89:
|
||||
return 10007; // Mac Russian
|
||||
case 128:
|
||||
return 932; // Shift JIS
|
||||
case 129:
|
||||
return 949; // Hangul
|
||||
case 130:
|
||||
return 1361; // Johab
|
||||
case 134:
|
||||
return 936; // GB2312
|
||||
case 136:
|
||||
return 950; // Big5
|
||||
case 161:
|
||||
return 1253; // Greek
|
||||
case 162:
|
||||
return 1254; // Turkish
|
||||
case 163:
|
||||
return 1258; // Vietnamese
|
||||
case 177:
|
||||
return 1255; // Hebrew
|
||||
case 178:
|
||||
return 1256; // Arabic
|
||||
// case 179: Arabic Traditional (old)
|
||||
// case 180: Arabic user (old)
|
||||
// case 181: Hebrew user (old)
|
||||
case 186:
|
||||
return 1257; // Baltic
|
||||
case 204:
|
||||
return 1251; // Russian
|
||||
case 222:
|
||||
return 874; // Thai
|
||||
case 238:
|
||||
return 1250; // Eastern European
|
||||
case 254:
|
||||
return 437; // PC 437
|
||||
case 255:
|
||||
return 850; // OEM
|
||||
default:
|
||||
return CP_ACP;
|
||||
}
|
||||
}
|
||||
|
||||
struct FontInfo {
|
||||
enum Options {has_fcharset = 0x0001,
|
||||
has_cpg = 0x0002};
|
||||
enum Options { has_fcharset = 0x0001, has_cpg = 0x0002 };
|
||||
unsigned int options;
|
||||
int fcharset;
|
||||
unsigned int cpg;
|
||||
FontInfo() : options(0), fcharset(0), cpg(0xFFFFFFFF) {}
|
||||
unsigned int Codepage()
|
||||
{
|
||||
unsigned int Codepage() {
|
||||
if (options & has_cpg)
|
||||
return cpg;
|
||||
else if (options & has_fcharset)
|
||||
return CharsetToCP(fcharset);
|
||||
else return 0xFFFFFFFF;
|
||||
else
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
};
|
||||
typedef std::map<int, FontInfo> Fonttbl;
|
||||
|
||||
struct LocalState {
|
||||
bool fonttbl; // When fonts are being defined
|
||||
int f; // Index of the font being defined/used; defines the codepage if no \cpg
|
||||
unsigned int uc; // ucN keyword value; its default is 1
|
||||
unsigned int codepage;// defined by \cpg
|
||||
bool fonttbl; // When fonts are being defined
|
||||
int f; // Index of the font being defined/used; defines the codepage if no
|
||||
// \cpg
|
||||
unsigned int uc; // ucN keyword value; its default is 1
|
||||
unsigned int codepage; // defined by \cpg
|
||||
};
|
||||
typedef std::stack<LocalState> StateStack;
|
||||
|
||||
|
@ -101,15 +151,14 @@ struct GlobalState {
|
|||
std::istream& stream;
|
||||
Fonttbl fonttbl;
|
||||
StateStack stack;
|
||||
unsigned int codepage; // defined by \ansi, \mac, \pc, \pca, and \ansicpgN
|
||||
unsigned int codepage; // defined by \ansi, \mac, \pc, \pca, and \ansicpgN
|
||||
int deff;
|
||||
std::stringstream pcdata_a;
|
||||
unsigned int pcdata_a_codepage;
|
||||
Pcdata_state pcdata_a_state;
|
||||
|
||||
explicit GlobalState(std::istream& s)
|
||||
: stream(s), codepage(CP_ACP), deff(-1), pcdata_a_state(pcdsno)
|
||||
{
|
||||
: stream(s), codepage(CP_ACP), deff(-1), pcdata_a_state(pcdsno) {
|
||||
LocalState st;
|
||||
st.fonttbl = false;
|
||||
st.f = -1;
|
||||
|
@ -117,9 +166,8 @@ struct GlobalState {
|
|||
st.codepage = 0xFFFFFFFF;
|
||||
stack.push(st);
|
||||
}
|
||||
unsigned int GetCurrentCP()
|
||||
{
|
||||
if (stack.top().codepage != 0xFFFFFFFF) // \cpg in use
|
||||
unsigned int GetCurrentCP() {
|
||||
if (stack.top().codepage != 0xFFFFFFFF) // \cpg in use
|
||||
return stack.top().codepage;
|
||||
// \cpg not used; use font settings
|
||||
int f = (stack.top().f != -1) ? stack.top().f : deff;
|
||||
|
@ -127,11 +175,10 @@ struct GlobalState {
|
|||
Fonttbl::iterator iter = fonttbl.find(f);
|
||||
if (iter != fonttbl.end()) {
|
||||
unsigned int cp = iter->second.Codepage();
|
||||
if (cp != 0xFFFFFFFF)
|
||||
return cp;
|
||||
if (cp != 0xFFFFFFFF) return cp;
|
||||
}
|
||||
}
|
||||
return codepage; // No overrides; use the top-level legacy setting
|
||||
return codepage; // No overrides; use the top-level legacy setting
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -142,34 +189,20 @@ struct Keyword {
|
|||
};
|
||||
|
||||
class Lexem {
|
||||
public:
|
||||
enum Type {ltGroupBegin, ltGroupEnd, ltKeyword, ltPCDATA_A, ltPCDATA_W,
|
||||
ltBDATA, ltEOF, ltError};
|
||||
explicit Lexem(Type t=ltError) : m_type(t) {}
|
||||
Lexem(Lexem& from)
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
ltGroupBegin,
|
||||
ltGroupEnd,
|
||||
ltKeyword,
|
||||
ltPCDATA_A,
|
||||
ltPCDATA_W,
|
||||
ltBDATA,
|
||||
ltEOF,
|
||||
ltError
|
||||
};
|
||||
explicit Lexem(Type t = ltError) : m_type(t) {}
|
||||
Lexem(Lexem& from) {
|
||||
switch (m_type = from.m_type) {
|
||||
case ltKeyword:
|
||||
m_keyword = from.m_keyword;
|
||||
break;
|
||||
case ltPCDATA_A:
|
||||
m_pcdata_a = from.m_pcdata_a;
|
||||
break;
|
||||
case ltPCDATA_W:
|
||||
m_pcdata_w = from.m_pcdata_w;
|
||||
break;
|
||||
case ltBDATA:
|
||||
m_bdata = from.m_bdata; // Move pointers when copying.
|
||||
from.m_type = ltError; // Invalidate the original. Not nice.
|
||||
break;
|
||||
}
|
||||
}
|
||||
~Lexem() { Clear(); }
|
||||
Lexem& operator = (Lexem& from)
|
||||
{
|
||||
if (&from != this) {
|
||||
Clear();
|
||||
switch (m_type = from.m_type) {
|
||||
case ltKeyword:
|
||||
m_keyword = from.m_keyword;
|
||||
break;
|
||||
|
@ -183,56 +216,74 @@ public:
|
|||
m_bdata = from.m_bdata; // Move pointers when copying.
|
||||
from.m_type = ltError; // Invalidate the original. Not nice.
|
||||
break;
|
||||
}
|
||||
}
|
||||
~Lexem() { Clear(); }
|
||||
Lexem& operator=(Lexem& from) {
|
||||
if (&from != this) {
|
||||
Clear();
|
||||
switch (m_type = from.m_type) {
|
||||
case ltKeyword:
|
||||
m_keyword = from.m_keyword;
|
||||
break;
|
||||
case ltPCDATA_A:
|
||||
m_pcdata_a = from.m_pcdata_a;
|
||||
break;
|
||||
case ltPCDATA_W:
|
||||
m_pcdata_w = from.m_pcdata_w;
|
||||
break;
|
||||
case ltBDATA:
|
||||
m_bdata = from.m_bdata; // Move pointers when copying.
|
||||
from.m_type = ltError; // Invalidate the original. Not nice.
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Type type() const { return m_type; }
|
||||
void SetPCDATA_A(char chdata)
|
||||
{
|
||||
void SetPCDATA_A(char chdata) {
|
||||
Clear();
|
||||
m_pcdata_a = chdata;
|
||||
m_type = ltPCDATA_A;
|
||||
}
|
||||
void SetPCDATA_W(wchar_t chdata)
|
||||
{
|
||||
void SetPCDATA_W(wchar_t chdata) {
|
||||
Clear();
|
||||
m_pcdata_w = chdata;
|
||||
m_type = ltPCDATA_W;
|
||||
}
|
||||
void SetBDATA(const char* data, int sz)
|
||||
{
|
||||
char* tmp = new char[sz]; // to allow getting the data from itself
|
||||
void SetBDATA(const char* data, int sz) {
|
||||
char* tmp = new char[sz]; // to allow getting the data from itself
|
||||
if (tmp) {
|
||||
memcpy(tmp, data, sz);
|
||||
Clear();
|
||||
m_bdata.data = tmp;
|
||||
m_bdata.sz = sz;
|
||||
m_type = ltBDATA;
|
||||
}
|
||||
else m_type = ltError;
|
||||
} else
|
||||
m_type = ltError;
|
||||
}
|
||||
void SetKeyword(const Keyword& src)
|
||||
{
|
||||
void SetKeyword(const Keyword& src) {
|
||||
Clear();
|
||||
m_type = ltKeyword;
|
||||
m_keyword = src;
|
||||
}
|
||||
void SetKeyword(const char* name, bool hasVal=false, int val=0)
|
||||
{
|
||||
void SetKeyword(const char* name, bool hasVal = false, int val = 0) {
|
||||
char tmp[SIZEOF(m_keyword.name)];
|
||||
strncpy(tmp, name, SIZEOF(m_keyword.name)-1); // to allow copy drom itself
|
||||
tmp[SIZEOF(m_keyword.name)-1]=0;
|
||||
strncpy(tmp, name,
|
||||
SIZEOF(m_keyword.name) - 1); // to allow copy drom itself
|
||||
tmp[SIZEOF(m_keyword.name) - 1] = 0;
|
||||
Clear();
|
||||
m_type = ltKeyword;
|
||||
memcpy(m_keyword.name, tmp, SIZEOF(m_keyword.name));
|
||||
m_keyword.hasVal=hasVal;
|
||||
m_keyword.val=val;
|
||||
m_keyword.hasVal = hasVal;
|
||||
m_keyword.val = val;
|
||||
}
|
||||
const char* KeywordName() const {
|
||||
return (m_type == ltKeyword) ? m_keyword.name : 0; }
|
||||
return (m_type == ltKeyword) ? m_keyword.name : 0;
|
||||
}
|
||||
const int* KeywordVal() const {
|
||||
return ((m_type == ltKeyword) && m_keyword.hasVal) ? &m_keyword.val : 0; }
|
||||
return ((m_type == ltKeyword) && m_keyword.hasVal) ? &m_keyword.val : 0;
|
||||
}
|
||||
char pcdata_a() const { return (m_type == ltPCDATA_A) ? m_pcdata_a : 0; }
|
||||
wchar_t pcdata_w() const { return (m_type == ltPCDATA_W) ? m_pcdata_w : 0; }
|
||||
const char* bdata() const { return (m_type == ltBDATA) ? m_bdata.data : 0; }
|
||||
|
@ -241,7 +292,8 @@ public:
|
|||
static Lexem groupBegin;
|
||||
static Lexem groupEnd;
|
||||
static Lexem error;
|
||||
private:
|
||||
|
||||
private:
|
||||
struct BDATA {
|
||||
size_t sz;
|
||||
char* data;
|
||||
|
@ -256,14 +308,13 @@ private:
|
|||
};
|
||||
// This function leaves the object in the broken state. Must be followed
|
||||
// by a correct initialization.
|
||||
void Clear()
|
||||
{
|
||||
void Clear() {
|
||||
switch (m_type) {
|
||||
case ltBDATA:
|
||||
delete[] m_bdata.data;
|
||||
break;
|
||||
case ltBDATA:
|
||||
delete[] m_bdata.data;
|
||||
break;
|
||||
}
|
||||
// m_type = ltError;
|
||||
// m_type = ltError;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -274,23 +325,20 @@ Lexem Lexem::error(ltError);
|
|||
|
||||
// This function moves pos. When calling the function, pos must be next to the
|
||||
// backslash; pos must be in the same sequence and before end!
|
||||
Keyword GetKeyword(std::istream& stream)
|
||||
{
|
||||
Keyword GetKeyword(std::istream& stream) {
|
||||
Keyword keyword = {"", false, 0};
|
||||
char ch;
|
||||
if (stream.get(ch).eof())
|
||||
return keyword;
|
||||
if (stream.get(ch).eof()) return keyword;
|
||||
// Control word; maybe delimiter and value
|
||||
if (IS_ALPHA(ch)) {
|
||||
int i = 0;
|
||||
do {
|
||||
// We take up to 32 characters into account, skipping over extra
|
||||
// characters (allowing for some non-conformant implementation).
|
||||
if (i < 32)
|
||||
keyword.name[i++] = ch;
|
||||
if (i < 32) keyword.name[i++] = ch;
|
||||
} while (!stream.get(ch).eof() && IS_ALPHA(ch));
|
||||
keyword.name[i] = 0; // NULL-terminating
|
||||
if (!stream.eof() && (IS_DIGIT(ch) || (ch == '-'))) { // Value begin
|
||||
keyword.name[i] = 0; // NULL-terminating
|
||||
if (!stream.eof() && (IS_DIGIT(ch) || (ch == '-'))) { // Value begin
|
||||
keyword.hasVal = true;
|
||||
bool negative = (ch == '-');
|
||||
if (negative) stream.get(ch);
|
||||
|
@ -298,24 +346,20 @@ Keyword GetKeyword(std::istream& stream)
|
|||
while (!stream.eof() && IS_DIGIT(ch)) {
|
||||
// We take into account only 10 digits, skip other. Older specs stated
|
||||
// that we must be ready for an arbitrary number of digits.
|
||||
if (i++ < 10)
|
||||
keyword.val = keyword.val*10 + (ch - '0');
|
||||
if (i++ < 10) keyword.val = keyword.val * 10 + (ch - '0');
|
||||
stream.get(ch);
|
||||
}
|
||||
if (negative) keyword.val = -keyword.val;
|
||||
}
|
||||
// End of control word; the space is just a delimiter - skip it
|
||||
if (!stream.eof() && !(ch == ' '))
|
||||
stream.unget();
|
||||
}
|
||||
else { // Control symbol
|
||||
// End of control word; the space is just a delimiter - skip it
|
||||
if (!stream.eof() && !(ch == ' ')) stream.unget();
|
||||
} else { // Control symbol
|
||||
keyword.name[0] = ch, keyword.name[1] = 0;
|
||||
}
|
||||
return keyword;
|
||||
}
|
||||
|
||||
void GetLexem(std::istream& stream, Lexem& result)
|
||||
{
|
||||
void GetLexem(std::istream& stream, Lexem& result) {
|
||||
// We always stay at the beginning of the next lexem or a crlf
|
||||
// If it's a brace then it's group begin/end
|
||||
// If it's a backslash -> Preprocess
|
||||
|
@ -326,50 +370,48 @@ void GetLexem(std::istream& stream, Lexem& result)
|
|||
// - if it's 0x09 -> it's the keyword \tab
|
||||
// - else it's a PCDATA
|
||||
char ch;
|
||||
while (!stream.get(ch).eof() && ((ch == '\n') || (ch == '\r'))); // Skip crlf
|
||||
while (!stream.get(ch).eof() && ((ch == '\n') || (ch == '\r')))
|
||||
; // Skip crlf
|
||||
if (stream.eof())
|
||||
result = Lexem::eof;
|
||||
else {
|
||||
switch (ch) {
|
||||
case '{': // Group begin
|
||||
case '}': // Group end
|
||||
result = (ch == '{') ? Lexem::groupBegin : Lexem::groupEnd;
|
||||
break;
|
||||
case '\\': // Keyword
|
||||
result.SetKeyword(GetKeyword(stream));
|
||||
break;
|
||||
case '\t': // tab
|
||||
result.SetKeyword("tab");
|
||||
break;
|
||||
default: // PSDATA?
|
||||
result.SetPCDATA_A(ch);
|
||||
break;
|
||||
case '{': // Group begin
|
||||
case '}': // Group end
|
||||
result = (ch == '{') ? Lexem::groupBegin : Lexem::groupEnd;
|
||||
break;
|
||||
case '\\': // Keyword
|
||||
result.SetKeyword(GetKeyword(stream));
|
||||
break;
|
||||
case '\t': // tab
|
||||
result.SetKeyword("tab");
|
||||
break;
|
||||
default: // PSDATA?
|
||||
result.SetPCDATA_A(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PreprocessLexem(/*inout*/Lexem& lexem, std::istream& stream, int uc)
|
||||
{
|
||||
void PreprocessLexem(/*inout*/ Lexem& lexem, std::istream& stream, int uc) {
|
||||
if (lexem.type() == Lexem::ltKeyword) {
|
||||
if (lexem.KeywordName()[0] == 0) // Empty keyword - maybe eof?
|
||||
if (lexem.KeywordName()[0] == 0) // Empty keyword - maybe eof?
|
||||
lexem = Lexem::error;
|
||||
else if (eq(lexem.KeywordName(), "u")) {
|
||||
// Unicode character - get the UTF16 and skip the uc characters
|
||||
// Unicode character - get the UTF16 and skip the uc characters
|
||||
if (const int* val = lexem.KeywordVal()) {
|
||||
lexem.SetPCDATA_W(*val);
|
||||
stream.ignore(uc);
|
||||
}
|
||||
else lexem = Lexem::error;
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "'")) {
|
||||
// 8-bit character (\'hh) -> use current codepage
|
||||
} else
|
||||
lexem = Lexem::error;
|
||||
} else if (eq(lexem.KeywordName(), "'")) {
|
||||
// 8-bit character (\'hh) -> use current codepage
|
||||
char ch = 0, ch1 = 0;
|
||||
if (!stream.get(ch).eof()) ch1 = HexToInt(ch);
|
||||
if (!stream.get(ch).eof()) (ch1 <<= 4) += HexToInt(ch);
|
||||
lexem.SetPCDATA_A(ch1);
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "\\") || eq(lexem.KeywordName(), "{") ||
|
||||
eq(lexem.KeywordName(), "}")) // escaped characters
|
||||
} else if (eq(lexem.KeywordName(), "\\") || eq(lexem.KeywordName(), "{") ||
|
||||
eq(lexem.KeywordName(), "}")) // escaped characters
|
||||
lexem.SetPCDATA_A(lexem.KeywordName()[0]);
|
||||
else if (eq(lexem.KeywordName(), "bin")) {
|
||||
if (const int* i = lexem.KeywordVal()) {
|
||||
|
@ -381,91 +423,89 @@ void PreprocessLexem(/*inout*/Lexem& lexem, std::istream& stream, int uc)
|
|||
else
|
||||
lexem.SetBDATA(data, *i);
|
||||
delete[] data;
|
||||
}
|
||||
else lexem = Lexem::error;
|
||||
}
|
||||
else lexem = Lexem::error;
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "\n") || eq(lexem.KeywordName(), "\r")) {
|
||||
} else
|
||||
lexem = Lexem::error;
|
||||
} else
|
||||
lexem = Lexem::error;
|
||||
} else if (eq(lexem.KeywordName(), "\n") || eq(lexem.KeywordName(), "\r")) {
|
||||
// escaped cr or lf
|
||||
lexem.SetKeyword("par");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateState(const Lexem& lexem, /*inout*/GlobalState& globalState)
|
||||
{
|
||||
void UpdateState(const Lexem& lexem, /*inout*/ GlobalState& globalState) {
|
||||
switch (globalState.pcdata_a_state) {
|
||||
case GlobalState::pcdsfinished: // Last time we finished the pcdata
|
||||
globalState.pcdata_a_state = GlobalState::pcdsno;
|
||||
break;
|
||||
case GlobalState::pcdsin:
|
||||
// to be reset later if still in the pcdata
|
||||
globalState.pcdata_a_state = GlobalState::pcdsfinished;
|
||||
break;
|
||||
case GlobalState::pcdsfinished: // Last time we finished the pcdata
|
||||
globalState.pcdata_a_state = GlobalState::pcdsno;
|
||||
break;
|
||||
case GlobalState::pcdsin:
|
||||
// to be reset later if still in the pcdata
|
||||
globalState.pcdata_a_state = GlobalState::pcdsfinished;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (lexem.type()) {
|
||||
case Lexem::ltGroupBegin:
|
||||
globalState.stack.push(globalState.stack.top());
|
||||
break;
|
||||
case Lexem::ltGroupEnd:
|
||||
globalState.stack.pop();
|
||||
break;
|
||||
case Lexem::ltKeyword:
|
||||
{
|
||||
case Lexem::ltGroupBegin:
|
||||
globalState.stack.push(globalState.stack.top());
|
||||
break;
|
||||
case Lexem::ltGroupEnd:
|
||||
globalState.stack.pop();
|
||||
break;
|
||||
case Lexem::ltKeyword: {
|
||||
const int* val = lexem.KeywordVal();
|
||||
if (eq(lexem.KeywordName(), "ansi")) globalState.codepage = CP_ACP;
|
||||
else if (eq(lexem.KeywordName(), "mac")) globalState.codepage = CP_MACCP;
|
||||
else if (eq(lexem.KeywordName(), "pc")) globalState.codepage = 437;
|
||||
else if (eq(lexem.KeywordName(), "pca")) globalState.codepage = 850;
|
||||
if (eq(lexem.KeywordName(), "ansi"))
|
||||
globalState.codepage = CP_ACP;
|
||||
else if (eq(lexem.KeywordName(), "mac"))
|
||||
globalState.codepage = CP_MACCP;
|
||||
else if (eq(lexem.KeywordName(), "pc"))
|
||||
globalState.codepage = 437;
|
||||
else if (eq(lexem.KeywordName(), "pca"))
|
||||
globalState.codepage = 850;
|
||||
else if (eq(lexem.KeywordName(), "ansicpg") && val)
|
||||
globalState.codepage = static_cast<unsigned int>(*val);
|
||||
else if (eq(lexem.KeywordName(), "deff") && val)
|
||||
globalState.deff = *val;
|
||||
else if (eq(lexem.KeywordName(), "fonttbl")) globalState.stack.top().fonttbl = true;
|
||||
else if (eq(lexem.KeywordName(), "fonttbl"))
|
||||
globalState.stack.top().fonttbl = true;
|
||||
else if (eq(lexem.KeywordName(), "f") && val) {
|
||||
globalState.stack.top().f = *val;
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "fcharset") &&
|
||||
globalState.stack.top().fonttbl &&
|
||||
(globalState.stack.top().f != -1) && val) {
|
||||
} else if (eq(lexem.KeywordName(), "fcharset") &&
|
||||
globalState.stack.top().fonttbl &&
|
||||
(globalState.stack.top().f != -1) && val) {
|
||||
FontInfo& f = globalState.fonttbl[globalState.stack.top().f];
|
||||
f.options |= FontInfo::has_fcharset;
|
||||
f.fcharset = *val;
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "cpg") && val) {
|
||||
if (globalState.stack.top().fonttbl && (globalState.stack.top().f != -1)) { // Defining a font
|
||||
} else if (eq(lexem.KeywordName(), "cpg") && val) {
|
||||
if (globalState.stack.top().fonttbl &&
|
||||
(globalState.stack.top().f != -1)) { // Defining a font
|
||||
FontInfo& f = globalState.fonttbl[globalState.stack.top().f];
|
||||
f.options |= FontInfo::has_cpg;
|
||||
f.cpg = *val;
|
||||
}
|
||||
else { // Overriding the codepage for the block - may be in filenames
|
||||
} else { // Overriding the codepage for the block - may be in filenames
|
||||
globalState.stack.top().codepage = *val;
|
||||
}
|
||||
}
|
||||
else if (eq(lexem.KeywordName(), "plain"))
|
||||
} else if (eq(lexem.KeywordName(), "plain"))
|
||||
globalState.stack.top().f = -1;
|
||||
else if (eq(lexem.KeywordName(), "uc") && val)
|
||||
globalState.stack.top().uc = *val;
|
||||
}
|
||||
break;
|
||||
case Lexem::ltPCDATA_A:
|
||||
if (globalState.pcdata_a_state == GlobalState::pcdsno) // Beginning of the pcdata
|
||||
globalState.pcdata_a_codepage = globalState.GetCurrentCP(); // to use later to convert to utf16
|
||||
globalState.pcdata_a_state = GlobalState::pcdsin;
|
||||
globalState.pcdata_a << lexem.pcdata_a();
|
||||
break;
|
||||
} break;
|
||||
case Lexem::ltPCDATA_A:
|
||||
if (globalState.pcdata_a_state ==
|
||||
GlobalState::pcdsno) // Beginning of the pcdata
|
||||
globalState.pcdata_a_codepage =
|
||||
globalState.GetCurrentCP(); // to use later to convert to utf16
|
||||
globalState.pcdata_a_state = GlobalState::pcdsin;
|
||||
globalState.pcdata_a << lexem.pcdata_a();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DecodeRTF(std::istream& rtf, CRTFDecoder& decoder)
|
||||
{
|
||||
void DecodeRTF(std::istream& rtf, CRTFDecoder& decoder) {
|
||||
// Check if this is the rtf
|
||||
Lexem lexem;
|
||||
GetLexem(rtf, lexem);
|
||||
if (lexem.type() != Lexem::ltGroupBegin)
|
||||
return;
|
||||
if (lexem.type() != Lexem::ltGroupBegin) return;
|
||||
decoder.BeginGroup();
|
||||
GetLexem(rtf, lexem);
|
||||
if ((lexem.type() != Lexem::ltKeyword) || !eq(lexem.KeywordName(), "rtf") ||
|
||||
|
@ -476,44 +516,45 @@ void DecodeRTF(std::istream& rtf, CRTFDecoder& decoder)
|
|||
GlobalState state(rtf);
|
||||
// Level is the count of elements in the stack
|
||||
|
||||
while (!state.stream.eof() && (state.stack.size()>0)) { // Don't go past the global group
|
||||
while (!state.stream.eof() &&
|
||||
(state.stack.size() > 0)) { // Don't go past the global group
|
||||
GetLexem(state.stream, lexem);
|
||||
PreprocessLexem(lexem, state.stream, state.stack.top().uc);
|
||||
UpdateState(lexem, state);
|
||||
|
||||
if (state.pcdata_a_state == GlobalState::pcdsfinished) {
|
||||
std::string s = state.pcdata_a.str();
|
||||
int sz = ::MultiByteToWideChar(state.pcdata_a_codepage, 0, s.c_str(), s.size(), 0, 0);
|
||||
int sz = ::MultiByteToWideChar(state.pcdata_a_codepage, 0, s.c_str(),
|
||||
s.size(), 0, 0);
|
||||
if (sz) {
|
||||
wchar_t* data = new wchar_t[sz];
|
||||
::MultiByteToWideChar(state.pcdata_a_codepage, 0, s.c_str(), s.size(), data, sz);
|
||||
::MultiByteToWideChar(state.pcdata_a_codepage, 0, s.c_str(), s.size(),
|
||||
data, sz);
|
||||
decoder.PCDATA(data, sz);
|
||||
delete[] data;
|
||||
}
|
||||
state.pcdata_a.str(""); // reset
|
||||
state.pcdata_a.str(""); // reset
|
||||
}
|
||||
|
||||
switch (lexem.type()) {
|
||||
case Lexem::ltGroupBegin:
|
||||
decoder.BeginGroup();
|
||||
break;
|
||||
case Lexem::ltGroupEnd:
|
||||
decoder.EndGroup();
|
||||
break;
|
||||
case Lexem::ltKeyword:
|
||||
decoder.Keyword(lexem.KeywordName(), lexem.KeywordVal());
|
||||
break;
|
||||
case Lexem::ltPCDATA_W:
|
||||
{
|
||||
case Lexem::ltGroupBegin:
|
||||
decoder.BeginGroup();
|
||||
break;
|
||||
case Lexem::ltGroupEnd:
|
||||
decoder.EndGroup();
|
||||
break;
|
||||
case Lexem::ltKeyword:
|
||||
decoder.Keyword(lexem.KeywordName(), lexem.KeywordVal());
|
||||
break;
|
||||
case Lexem::ltPCDATA_W: {
|
||||
wchar_t ch = lexem.pcdata_w();
|
||||
decoder.PCDATA(&ch, 1);
|
||||
}
|
||||
break;
|
||||
case Lexem::ltBDATA:
|
||||
decoder.BDATA(lexem.bdata(), lexem.bdata_sz());
|
||||
break;
|
||||
case Lexem::ltError:
|
||||
break; // Just silently skip the erroneous data - basic error recovery
|
||||
} break;
|
||||
case Lexem::ltBDATA:
|
||||
decoder.BDATA(lexem.bdata(), lexem.bdata_sz());
|
||||
break;
|
||||
case Lexem::ltError:
|
||||
break; // Just silently skip the erroneous data - basic error recovery
|
||||
}
|
||||
} // while
|
||||
} // DecodeRTF
|
||||
} // while
|
||||
} // DecodeRTF
|
||||
|
|
|
@ -5,13 +5,12 @@
|
|||
#include <istream>
|
||||
|
||||
template <size_t len>
|
||||
inline bool eq(const char* str1, const char (&str2)[len])
|
||||
{
|
||||
inline bool eq(const char* str1, const char (&str2)[len]) {
|
||||
return ::strncmp(str1, str2, len) == 0;
|
||||
};
|
||||
|
||||
class CRTFDecoder {
|
||||
public:
|
||||
public:
|
||||
virtual void BeginGroup() = 0;
|
||||
virtual void EndGroup() = 0;
|
||||
virtual void Keyword(const char* name, const int* Val) = 0;
|
||||
|
|
|
@ -4,23 +4,18 @@
|
|||
|
||||
#include "rtfMailDecoder.h"
|
||||
|
||||
void CRTFMailDecoder::BeginGroup()
|
||||
{
|
||||
void CRTFMailDecoder::BeginGroup() {
|
||||
ClearState(sAsterisk);
|
||||
SetState(sBeginGroup);
|
||||
if (m_skipLevel)
|
||||
++m_skipLevel;
|
||||
if (m_skipLevel) ++m_skipLevel;
|
||||
}
|
||||
|
||||
void CRTFMailDecoder::EndGroup()
|
||||
{
|
||||
ClearState(sAsterisk|sBeginGroup);
|
||||
if (m_skipLevel)
|
||||
--m_skipLevel;
|
||||
void CRTFMailDecoder::EndGroup() {
|
||||
ClearState(sAsterisk | sBeginGroup);
|
||||
if (m_skipLevel) --m_skipLevel;
|
||||
}
|
||||
|
||||
void CRTFMailDecoder::AddText(const wchar_t* txt, size_t cch)
|
||||
{
|
||||
void CRTFMailDecoder::AddText(const wchar_t* txt, size_t cch) {
|
||||
if (!IsHtmlRtf()) {
|
||||
if (cch == static_cast<size_t>(-1))
|
||||
m_text += txt;
|
||||
|
@ -29,51 +24,48 @@ void CRTFMailDecoder::AddText(const wchar_t* txt, size_t cch)
|
|||
}
|
||||
}
|
||||
|
||||
void CRTFMailDecoder::Keyword(const char* name, const int* Val)
|
||||
{
|
||||
bool asterisk = IsAsterisk(); ClearState(sAsterisk); // for inside use only
|
||||
bool beginGroup = IsBeginGroup(); ClearState(sBeginGroup); // for inside use only
|
||||
void CRTFMailDecoder::Keyword(const char* name, const int* Val) {
|
||||
bool asterisk = IsAsterisk();
|
||||
ClearState(sAsterisk); // for inside use only
|
||||
bool beginGroup = IsBeginGroup();
|
||||
ClearState(sBeginGroup); // for inside use only
|
||||
if (!m_skipLevel) {
|
||||
if (eq(name, "*") && beginGroup) SetState(sAsterisk);
|
||||
if (eq(name, "*") && beginGroup)
|
||||
SetState(sAsterisk);
|
||||
else if (asterisk) {
|
||||
if (eq(name, "htmltag") && (m_mode == mHTML)) { // \*\htmltag -> don't ignore; include the following text
|
||||
}
|
||||
else ++m_skipLevel;
|
||||
}
|
||||
else if (eq(name, "htmlrtf")) {
|
||||
if (Val && (*Val==0))
|
||||
if (eq(name, "htmltag") &&
|
||||
(m_mode ==
|
||||
mHTML)) { // \*\htmltag -> don't ignore; include the following text
|
||||
} else
|
||||
++m_skipLevel;
|
||||
} else if (eq(name, "htmlrtf")) {
|
||||
if (Val && (*Val == 0))
|
||||
ClearState(sHtmlRtf);
|
||||
else
|
||||
SetState(sHtmlRtf);
|
||||
}
|
||||
else if (eq(name, "par") || eq(name, "line")) {
|
||||
} else if (eq(name, "par") || eq(name, "line")) {
|
||||
AddText(L"\r\n");
|
||||
}
|
||||
else if (eq(name, "tab")) {
|
||||
} else if (eq(name, "tab")) {
|
||||
AddText(L"\t");
|
||||
}
|
||||
else if (eq(name, "rquote")) {
|
||||
AddText(L"\x2019"); // Unicode right single quotation mark
|
||||
}
|
||||
else if (eq(name, "fromtext") && (m_mode==mNone)) { // avoid double "fromX"
|
||||
} else if (eq(name, "rquote")) {
|
||||
AddText(L"\x2019"); // Unicode right single quotation mark
|
||||
} else if (eq(name, "fromtext") &&
|
||||
(m_mode == mNone)) { // avoid double "fromX"
|
||||
m_mode = mText;
|
||||
}
|
||||
else if (eq(name, "fromhtml") && (m_mode==mNone)) { // avoid double "fromX"
|
||||
} else if (eq(name, "fromhtml") &&
|
||||
(m_mode == mNone)) { // avoid double "fromX"
|
||||
m_mode = mHTML;
|
||||
}
|
||||
else if (eq(name, "fonttbl") || eq(name, "colortbl") || eq(name, "stylesheet") || eq(name, "pntext"))
|
||||
} else if (eq(name, "fonttbl") || eq(name, "colortbl") ||
|
||||
eq(name, "stylesheet") || eq(name, "pntext"))
|
||||
++m_skipLevel;
|
||||
}
|
||||
}
|
||||
|
||||
void CRTFMailDecoder::PCDATA(const wchar_t* data, size_t cch)
|
||||
{
|
||||
ClearState(sAsterisk|sBeginGroup);
|
||||
if (!m_skipLevel)
|
||||
AddText(data, cch);
|
||||
void CRTFMailDecoder::PCDATA(const wchar_t* data, size_t cch) {
|
||||
ClearState(sAsterisk | sBeginGroup);
|
||||
if (!m_skipLevel) AddText(data, cch);
|
||||
}
|
||||
|
||||
void CRTFMailDecoder::BDATA(const char* data, size_t sz)
|
||||
{
|
||||
ClearState(sAsterisk|sBeginGroup);
|
||||
void CRTFMailDecoder::BDATA(const char* data, size_t sz) {
|
||||
ClearState(sAsterisk | sBeginGroup);
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include <string>
|
||||
#include "rtfDecoder.h"
|
||||
|
||||
class CRTFMailDecoder: public CRTFDecoder {
|
||||
public:
|
||||
enum Mode {mNone, mText, mHTML};
|
||||
class CRTFMailDecoder : public CRTFDecoder {
|
||||
public:
|
||||
enum Mode { mNone, mText, mHTML };
|
||||
CRTFMailDecoder() : m_mode(mNone), m_state(sNormal), m_skipLevel(0) {}
|
||||
void BeginGroup() override;
|
||||
void EndGroup() override;
|
||||
|
@ -18,24 +18,27 @@ public:
|
|||
const wchar_t* text() { return m_text.c_str(); }
|
||||
std::wstring::size_type textSize() { return m_text.size(); }
|
||||
Mode mode() { return m_mode; }
|
||||
private:
|
||||
enum State {sNormal = 0x0000,
|
||||
sBeginGroup = 0x0001,
|
||||
sAsterisk = 0x0002,
|
||||
sHtmlRtf = 0x0004};
|
||||
|
||||
private:
|
||||
enum State {
|
||||
sNormal = 0x0000,
|
||||
sBeginGroup = 0x0001,
|
||||
sAsterisk = 0x0002,
|
||||
sHtmlRtf = 0x0004
|
||||
};
|
||||
|
||||
std::wstring m_text;
|
||||
Mode m_mode;
|
||||
unsigned int m_state; // bitmask of State
|
||||
// bool m_beginGroup; // true just after the {
|
||||
//bool m_asterisk; // true just after the {\*
|
||||
int m_skipLevel; // if >0 then we ignore everything
|
||||
// bool m_htmlrtf;
|
||||
unsigned int m_state; // bitmask of State
|
||||
// bool m_beginGroup; // true just after the {
|
||||
// bool m_asterisk; // true just after the {\*
|
||||
int m_skipLevel; // if >0 then we ignore everything
|
||||
// bool m_htmlrtf;
|
||||
inline void SetState(unsigned int s) { m_state |= s; }
|
||||
inline void ClearState(unsigned int s) { m_state &= ~s; }
|
||||
inline bool CheckState(State s) { return (m_state & s) != 0; }
|
||||
inline bool IsAsterisk() { return CheckState(sAsterisk); }
|
||||
inline bool IsBeginGroup() { return CheckState(sBeginGroup); }
|
||||
inline bool IsHtmlRtf() { return CheckState(sHtmlRtf); }
|
||||
void AddText(const wchar_t* txt, size_t cch=static_cast<size_t>(-1));
|
||||
void AddText(const wchar_t* txt, size_t cch = static_cast<size_t>(-1));
|
||||
};
|
||||
|
|
|
@ -3,42 +3,44 @@
|
|||
* 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 "ImportCharSet.h"
|
||||
|
||||
char ImportCharSet::m_upperCaseMap[256];
|
||||
char ImportCharSet::m_Ascii[256] = {0}; // the initialiser makes it strong
|
||||
char ImportCharSet::m_Ascii[256] = {0}; // the initialiser makes it strong
|
||||
|
||||
class UInitMaps {
|
||||
public:
|
||||
public:
|
||||
UInitMaps();
|
||||
};
|
||||
|
||||
UInitMaps gInitMaps;
|
||||
UInitMaps gInitMaps;
|
||||
|
||||
UInitMaps::UInitMaps()
|
||||
{
|
||||
int i;
|
||||
UInitMaps::UInitMaps() {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
ImportCharSet::m_upperCaseMap[i] = i;
|
||||
for (i = 'a'; i <= 'z'; i++)
|
||||
ImportCharSet::m_upperCaseMap[i] = i - 'a' + 'A';
|
||||
for (i = 0; i < 256; i++) ImportCharSet::m_upperCaseMap[i] = i;
|
||||
for (i = 'a'; i <= 'z'; i++) ImportCharSet::m_upperCaseMap[i] = i - 'a' + 'A';
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
ImportCharSet::m_Ascii[i] = 0;
|
||||
for (i = 0; i < 256; i++) ImportCharSet::m_Ascii[i] = 0;
|
||||
|
||||
for (i = ImportCharSet::cUpperAChar; i <= ImportCharSet::cUpperZChar; i++)
|
||||
ImportCharSet::m_Ascii[i] |= (ImportCharSet::cAlphaNumChar | ImportCharSet::cAlphaChar);
|
||||
ImportCharSet::m_Ascii[i] |=
|
||||
(ImportCharSet::cAlphaNumChar | ImportCharSet::cAlphaChar);
|
||||
for (i = ImportCharSet::cLowerAChar; i <= ImportCharSet::cLowerZChar; i++)
|
||||
ImportCharSet::m_Ascii[i] |= (ImportCharSet::cAlphaNumChar | ImportCharSet::cAlphaChar);
|
||||
ImportCharSet::m_Ascii[i] |=
|
||||
(ImportCharSet::cAlphaNumChar | ImportCharSet::cAlphaChar);
|
||||
for (i = ImportCharSet::cZeroChar; i <= ImportCharSet::cNineChar; i++)
|
||||
ImportCharSet::m_Ascii[i] |= (ImportCharSet::cAlphaNumChar | ImportCharSet::cDigitChar);
|
||||
ImportCharSet::m_Ascii[i] |=
|
||||
(ImportCharSet::cAlphaNumChar | ImportCharSet::cDigitChar);
|
||||
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cTabChar] |= ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cCRChar] |= ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cLinefeedChar] |= ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cSpaceChar] |= ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cTabChar] |=
|
||||
ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cCRChar] |=
|
||||
ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cLinefeedChar] |=
|
||||
ImportCharSet::cWhiteSpaceChar;
|
||||
ImportCharSet::m_Ascii[ImportCharSet::cSpaceChar] |=
|
||||
ImportCharSet::cWhiteSpaceChar;
|
||||
|
||||
ImportCharSet::m_Ascii[uint8_t('(')] |= ImportCharSet::c822SpecialChar;
|
||||
ImportCharSet::m_Ascii[uint8_t(')')] |= ImportCharSet::c822SpecialChar;
|
||||
|
@ -53,6 +55,4 @@ UInitMaps::UInitMaps()
|
|||
ImportCharSet::m_Ascii[uint8_t('.')] |= ImportCharSet::c822SpecialChar;
|
||||
ImportCharSet::m_Ascii[uint8_t('[')] |= ImportCharSet::c822SpecialChar;
|
||||
ImportCharSet::m_Ascii[uint8_t(']')] |= ImportCharSet::c822SpecialChar;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
// Some useful ASCII values
|
||||
// 'A' = 65, 0x41
|
||||
// 'Z' = 90, 0x5a
|
||||
|
@ -19,15 +18,15 @@
|
|||
// '1' = 49, 0x31
|
||||
// '9' = 57, 0x39
|
||||
// ' ' = 32, 0x20
|
||||
// whitespace, 10, 13, 32, 9 (linefeed, cr, space, tab) - 0x0a, 0x0d, 0x20, 0x09
|
||||
// whitespace, 10, 13, 32, 9 (linefeed, cr, space, tab) - 0x0a, 0x0d, 0x20,
|
||||
// 0x09
|
||||
// ':' = 58, 0x3a
|
||||
|
||||
|
||||
// a typedef enum would be nicer but some compilers still have trouble with treating
|
||||
// enum's as plain numbers when needed
|
||||
// a typedef enum would be nicer but some compilers still have trouble with
|
||||
// treating enum's as plain numbers when needed
|
||||
|
||||
class ImportCharSet {
|
||||
public:
|
||||
public:
|
||||
enum {
|
||||
cTabChar = 9,
|
||||
cLinefeedChar = 10,
|
||||
|
@ -48,23 +47,37 @@ public:
|
|||
c822SpecialChar = 16
|
||||
};
|
||||
|
||||
static char m_upperCaseMap[256];
|
||||
static char m_Ascii[256];
|
||||
static char m_upperCaseMap[256];
|
||||
static char m_Ascii[256];
|
||||
|
||||
inline static bool IsUSAscii(uint8_t ch) { return (((ch & (uint8_t)0x80) == 0));}
|
||||
inline static bool Is822CtlChar(uint8_t ch) { return (ch < 32);}
|
||||
inline static bool Is822SpecialChar(uint8_t ch) { return ((m_Ascii[ch] & c822SpecialChar) == c822SpecialChar);}
|
||||
inline static bool IsWhiteSpace(uint8_t ch) { return ((m_Ascii[ch] & cWhiteSpaceChar) == cWhiteSpaceChar); }
|
||||
inline static bool IsAlphaNum(uint8_t ch) { return ((m_Ascii[ch] & cAlphaNumChar) == cAlphaNumChar); }
|
||||
inline static bool IsDigit(uint8_t ch) { return ((m_Ascii[ch] & cDigitChar) == cDigitChar); }
|
||||
inline static bool IsUSAscii(uint8_t ch) {
|
||||
return (((ch & (uint8_t)0x80) == 0));
|
||||
}
|
||||
inline static bool Is822CtlChar(uint8_t ch) { return (ch < 32); }
|
||||
inline static bool Is822SpecialChar(uint8_t ch) {
|
||||
return ((m_Ascii[ch] & c822SpecialChar) == c822SpecialChar);
|
||||
}
|
||||
inline static bool IsWhiteSpace(uint8_t ch) {
|
||||
return ((m_Ascii[ch] & cWhiteSpaceChar) == cWhiteSpaceChar);
|
||||
}
|
||||
inline static bool IsAlphaNum(uint8_t ch) {
|
||||
return ((m_Ascii[ch] & cAlphaNumChar) == cAlphaNumChar);
|
||||
}
|
||||
inline static bool IsDigit(uint8_t ch) {
|
||||
return ((m_Ascii[ch] & cDigitChar) == cDigitChar);
|
||||
}
|
||||
|
||||
inline static uint8_t ToLower(uint8_t ch) { if ((m_Ascii[ch] & cAlphaChar) == cAlphaChar) { return cLowerAChar + (m_upperCaseMap[ch] - cUpperAChar); } else return ch; }
|
||||
inline static uint8_t ToLower(uint8_t ch) {
|
||||
if ((m_Ascii[ch] & cAlphaChar) == cAlphaChar) {
|
||||
return cLowerAChar + (m_upperCaseMap[ch] - cUpperAChar);
|
||||
} else
|
||||
return ch;
|
||||
}
|
||||
|
||||
inline static long AsciiToLong(const uint8_t * pChar, uint32_t len) {
|
||||
inline static long AsciiToLong(const uint8_t* pChar, uint32_t len) {
|
||||
long num = 0;
|
||||
while (len) {
|
||||
if ((m_Ascii[*pChar] & cDigitChar) == 0)
|
||||
return num;
|
||||
if ((m_Ascii[*pChar] & cDigitChar) == 0) return num;
|
||||
num *= 10;
|
||||
num += (*pChar - cZeroChar);
|
||||
len--;
|
||||
|
@ -73,7 +86,7 @@ public:
|
|||
return num;
|
||||
}
|
||||
|
||||
inline static void ByteToHex(uint8_t byte, uint8_t * pHex) {
|
||||
inline static void ByteToHex(uint8_t byte, uint8_t* pHex) {
|
||||
uint8_t val = byte;
|
||||
val /= 16;
|
||||
if (val < 10)
|
||||
|
@ -89,61 +102,76 @@ public:
|
|||
*pHex = 'A' + (val - 10);
|
||||
}
|
||||
|
||||
inline static void LongToHexBytes(uint32_t type, uint8_t * pStr) {
|
||||
ByteToHex((uint8_t) (type >> 24), pStr);
|
||||
inline static void LongToHexBytes(uint32_t type, uint8_t* pStr) {
|
||||
ByteToHex((uint8_t)(type >> 24), pStr);
|
||||
pStr += 2;
|
||||
ByteToHex((uint8_t) ((type >> 16) & 0x0FF), pStr);
|
||||
ByteToHex((uint8_t)((type >> 16) & 0x0FF), pStr);
|
||||
pStr += 2;
|
||||
ByteToHex((uint8_t) ((type >> 8) & 0x0FF), pStr);
|
||||
ByteToHex((uint8_t)((type >> 8) & 0x0FF), pStr);
|
||||
pStr += 2;
|
||||
ByteToHex((uint8_t) (type & 0x0FF), pStr);
|
||||
ByteToHex((uint8_t)(type & 0x0FF), pStr);
|
||||
}
|
||||
|
||||
inline static void SkipWhiteSpace(const uint8_t * & pChar, uint32_t & pos, uint32_t max) {
|
||||
inline static void SkipWhiteSpace(const uint8_t*& pChar, uint32_t& pos,
|
||||
uint32_t max) {
|
||||
while ((pos < max) && (IsWhiteSpace(*pChar))) {
|
||||
pos++; pChar++;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void SkipSpaceTab(const uint8_t * & pChar, uint32_t& pos, uint32_t max) {
|
||||
while ((pos < max) && ((*pChar == (uint8_t)cSpaceChar) || (*pChar == (uint8_t)cTabChar))) {
|
||||
pos++; pChar++;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void SkipTilSpaceTab(const uint8_t * & pChar, uint32_t& pos, uint32_t max) {
|
||||
while ((pos < max) && (*pChar != (uint8_t)cSpaceChar) && (*pChar != (uint8_t)cTabChar)) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
}
|
||||
|
||||
inline static bool StrNICmp(const uint8_t * pChar, const uint8_t * pSrc, uint32_t len) {
|
||||
inline static void SkipSpaceTab(const uint8_t*& pChar, uint32_t& pos,
|
||||
uint32_t max) {
|
||||
while ((pos < max) &&
|
||||
((*pChar == (uint8_t)cSpaceChar) || (*pChar == (uint8_t)cTabChar))) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void SkipTilSpaceTab(const uint8_t*& pChar, uint32_t& pos,
|
||||
uint32_t max) {
|
||||
while ((pos < max) && (*pChar != (uint8_t)cSpaceChar) &&
|
||||
(*pChar != (uint8_t)cTabChar)) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
}
|
||||
|
||||
inline static bool StrNICmp(const uint8_t* pChar, const uint8_t* pSrc,
|
||||
uint32_t len) {
|
||||
while (len && (m_upperCaseMap[*pChar] == m_upperCaseMap[*pSrc])) {
|
||||
pChar++; pSrc++; len--;
|
||||
pChar++;
|
||||
pSrc++;
|
||||
len--;
|
||||
}
|
||||
return len == 0;
|
||||
}
|
||||
|
||||
inline static bool StrNCmp(const uint8_t * pChar, const uint8_t *pSrc, uint32_t len) {
|
||||
inline static bool StrNCmp(const uint8_t* pChar, const uint8_t* pSrc,
|
||||
uint32_t len) {
|
||||
while (len && (*pChar == *pSrc)) {
|
||||
pChar++; pSrc++; len--;
|
||||
pChar++;
|
||||
pSrc++;
|
||||
len--;
|
||||
}
|
||||
return len == 0;
|
||||
}
|
||||
|
||||
inline static int FindChar(const uint8_t * pChar, uint8_t ch, uint32_t max) {
|
||||
uint32_t pos = 0;
|
||||
inline static int FindChar(const uint8_t* pChar, uint8_t ch, uint32_t max) {
|
||||
uint32_t pos = 0;
|
||||
while ((pos < max) && (*pChar != ch)) {
|
||||
pos++; pChar++;
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
if (pos < max)
|
||||
return (int) pos;
|
||||
return (int)pos;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline static bool NextChar(const uint8_t * & pChar, uint8_t ch, uint32_t& pos, uint32_t max) {
|
||||
inline static bool NextChar(const uint8_t*& pChar, uint8_t ch, uint32_t& pos,
|
||||
uint32_t max) {
|
||||
if ((pos < max) && (*pChar == ch)) {
|
||||
pos++;
|
||||
pChar++;
|
||||
|
@ -152,7 +180,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
inline static int32_t strcmp(const char * pS1, const char * pS2) {
|
||||
inline static int32_t strcmp(const char* pS1, const char* pS2) {
|
||||
while (*pS1 && *pS2 && (*pS1 == *pS2)) {
|
||||
pS1++;
|
||||
pS2++;
|
||||
|
@ -160,16 +188,14 @@ public:
|
|||
return *pS1 - *pS2;
|
||||
}
|
||||
|
||||
inline static int32_t stricmp(const char * pS1, const char * pS2) {
|
||||
while (*pS1 && *pS2 && (m_upperCaseMap[uint8_t(*pS1)] == m_upperCaseMap[uint8_t(*pS2)])) {
|
||||
inline static int32_t stricmp(const char* pS1, const char* pS2) {
|
||||
while (*pS1 && *pS2 &&
|
||||
(m_upperCaseMap[uint8_t(*pS1)] == m_upperCaseMap[uint8_t(*pS2)])) {
|
||||
pS1++;
|
||||
pS2++;
|
||||
}
|
||||
return m_upperCaseMap[uint8_t(*pS1)] - m_upperCaseMap[uint8_t(*pS2)];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* ImportCharSet_h__ */
|
||||
|
||||
|
|
|
@ -7,15 +7,19 @@
|
|||
#define ImportDebug_h___
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
#define IMPORT_DEBUG 1
|
||||
# define IMPORT_DEBUG 1
|
||||
#endif
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
extern mozilla::LazyLogModule IMPORTLOGMODULE; // defined in nsImportService.cpp
|
||||
extern mozilla::LazyLogModule
|
||||
IMPORTLOGMODULE; // defined in nsImportService.cpp
|
||||
|
||||
#define IMPORT_LOG0(x) MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x))
|
||||
#define IMPORT_LOG1(x, y) MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x, y))
|
||||
#define IMPORT_LOG2(x, y, z) MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x, y, z))
|
||||
#define IMPORT_LOG3(a, b, c, d) MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (a, b, c, d))
|
||||
#define IMPORT_LOG0(x) MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x))
|
||||
#define IMPORT_LOG1(x, y) \
|
||||
MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x, y))
|
||||
#define IMPORT_LOG2(x, y, z) \
|
||||
MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (x, y, z))
|
||||
#define IMPORT_LOG3(a, b, c, d) \
|
||||
MOZ_LOG(IMPORTLOGMODULE, mozilla::LogLevel::Debug, (a, b, c, d))
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
#endif
|
||||
*/
|
||||
|
||||
ImportOutFile::ImportOutFile()
|
||||
{
|
||||
ImportOutFile::ImportOutFile() {
|
||||
m_ownsFileAndBuffer = false;
|
||||
m_pos = 0;
|
||||
m_pBuf = nullptr;
|
||||
|
@ -35,8 +34,7 @@ ImportOutFile::ImportOutFile()
|
|||
m_pTransBuf = nullptr;
|
||||
}
|
||||
|
||||
ImportOutFile::ImportOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz)
|
||||
{
|
||||
ImportOutFile::ImportOutFile(nsIFile *pFile, uint8_t *pBuf, uint32_t sz) {
|
||||
m_pTransBuf = nullptr;
|
||||
m_pTransOut = nullptr;
|
||||
m_pTrans = nullptr;
|
||||
|
@ -44,82 +42,66 @@ ImportOutFile::ImportOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz)
|
|||
InitOutFile(pFile, pBuf, sz);
|
||||
}
|
||||
|
||||
ImportOutFile::~ImportOutFile()
|
||||
{
|
||||
if (m_ownsFileAndBuffer)
|
||||
{
|
||||
ImportOutFile::~ImportOutFile() {
|
||||
if (m_ownsFileAndBuffer) {
|
||||
Flush();
|
||||
delete [] m_pBuf;
|
||||
delete[] m_pBuf;
|
||||
}
|
||||
|
||||
delete m_pTrans;
|
||||
delete m_pTransOut;
|
||||
delete [] m_pTransBuf;
|
||||
delete[] m_pTransBuf;
|
||||
}
|
||||
|
||||
bool ImportOutFile::Set8bitTranslator(nsImportTranslator *pTrans)
|
||||
{
|
||||
if (!Flush())
|
||||
return false;
|
||||
bool ImportOutFile::Set8bitTranslator(nsImportTranslator *pTrans) {
|
||||
if (!Flush()) return false;
|
||||
|
||||
m_engaged = false;
|
||||
m_pTrans = pTrans;
|
||||
m_supports8to7 = pTrans->Supports8bitEncoding();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImportOutFile::End8bitTranslation(bool *pEngaged, nsCString& useCharset, nsCString& encoding)
|
||||
{
|
||||
if (!m_pTrans)
|
||||
return false;
|
||||
|
||||
bool ImportOutFile::End8bitTranslation(bool *pEngaged, nsCString &useCharset,
|
||||
nsCString &encoding) {
|
||||
if (!m_pTrans) return false;
|
||||
|
||||
bool bResult = Flush();
|
||||
if (m_supports8to7 && m_pTransOut) {
|
||||
if (bResult)
|
||||
bResult = m_pTrans->FinishConvertToFile(m_pTransOut);
|
||||
if (bResult)
|
||||
bResult = Flush();
|
||||
if (bResult) bResult = m_pTrans->FinishConvertToFile(m_pTransOut);
|
||||
if (bResult) bResult = Flush();
|
||||
}
|
||||
|
||||
if (m_supports8to7) {
|
||||
m_pTrans->GetCharset(useCharset);
|
||||
m_pTrans->GetEncoding(encoding);
|
||||
}
|
||||
else
|
||||
} else
|
||||
useCharset.Truncate();
|
||||
*pEngaged = m_engaged;
|
||||
delete m_pTrans;
|
||||
m_pTrans = nullptr;
|
||||
delete m_pTransOut;
|
||||
m_pTransOut = nullptr;
|
||||
delete [] m_pTransBuf;
|
||||
delete[] m_pTransBuf;
|
||||
m_pTransBuf = nullptr;
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
bool ImportOutFile::InitOutFile(nsIFile *pFile, uint32_t bufSz)
|
||||
{
|
||||
if (!bufSz)
|
||||
bufSz = 32 * 1024;
|
||||
if (!m_pBuf)
|
||||
m_pBuf = new uint8_t[ bufSz];
|
||||
bool ImportOutFile::InitOutFile(nsIFile *pFile, uint32_t bufSz) {
|
||||
if (!bufSz) bufSz = 32 * 1024;
|
||||
if (!m_pBuf) m_pBuf = new uint8_t[bufSz];
|
||||
|
||||
if (!m_outputStream)
|
||||
{
|
||||
if (!m_outputStream) {
|
||||
nsresult rv;
|
||||
rv = MsgNewBufferedFileOutputStream(getter_AddRefs(m_outputStream),
|
||||
pFile,
|
||||
PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
|
||||
0644);
|
||||
rv = MsgNewBufferedFileOutputStream(
|
||||
getter_AddRefs(m_outputStream), pFile,
|
||||
PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, 0644);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("Couldn't create outfile\n");
|
||||
delete [] m_pBuf;
|
||||
delete[] m_pBuf;
|
||||
m_pBuf = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
@ -131,8 +113,7 @@ bool ImportOutFile::InitOutFile(nsIFile *pFile, uint32_t bufSz)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ImportOutFile::InitOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz)
|
||||
{
|
||||
void ImportOutFile::InitOutFile(nsIFile *pFile, uint8_t *pBuf, uint32_t sz) {
|
||||
m_ownsFileAndBuffer = false;
|
||||
m_pFile = pFile;
|
||||
m_pBuf = pBuf;
|
||||
|
@ -140,15 +121,11 @@ void ImportOutFile::InitOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz)
|
|||
m_pos = 0;
|
||||
}
|
||||
|
||||
bool ImportOutFile::Flush(void) {
|
||||
if (!m_pos) return true;
|
||||
|
||||
|
||||
bool ImportOutFile::Flush(void)
|
||||
{
|
||||
if (!m_pos)
|
||||
return true;
|
||||
|
||||
uint32_t transLen;
|
||||
bool duddleyDoWrite = false;
|
||||
uint32_t transLen;
|
||||
bool duddleyDoWrite = false;
|
||||
|
||||
// handle translations if appropriate
|
||||
if (m_pTrans) {
|
||||
|
@ -157,27 +134,23 @@ bool ImportOutFile::Flush(void)
|
|||
// TLR: FIXME: Need to update the markers based on
|
||||
// the difference between the translated len and untranslated len
|
||||
|
||||
if (!m_pTrans->ConvertToFile( m_pBuf, m_pos, m_pTransOut, &transLen))
|
||||
return false;
|
||||
if (!m_pTransOut->Flush())
|
||||
if (!m_pTrans->ConvertToFile(m_pBuf, m_pos, m_pTransOut, &transLen))
|
||||
return false;
|
||||
if (!m_pTransOut->Flush()) return false;
|
||||
// now update our buffer...
|
||||
if (transLen < m_pos) {
|
||||
memcpy(m_pBuf, m_pBuf + transLen, m_pos - transLen);
|
||||
}
|
||||
m_pos -= transLen;
|
||||
}
|
||||
else if (m_engaged) {
|
||||
} else if (m_engaged) {
|
||||
// does not actually support translation!
|
||||
duddleyDoWrite = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// should we engage?
|
||||
uint8_t * pChar = m_pBuf;
|
||||
uint32_t len = m_pos;
|
||||
uint8_t *pChar = m_pBuf;
|
||||
uint32_t len = m_pos;
|
||||
while (len) {
|
||||
if (!ImportCharSet::IsUSAscii(*pChar))
|
||||
break;
|
||||
if (!ImportCharSet::IsUSAscii(*pChar)) break;
|
||||
pChar++;
|
||||
len--;
|
||||
}
|
||||
|
@ -188,35 +161,30 @@ bool ImportOutFile::Flush(void)
|
|||
m_pTransBuf = new uint8_t[m_bufSz];
|
||||
m_pTransOut = new ImportOutFile(m_pFile, m_pTransBuf, m_bufSz);
|
||||
return Flush();
|
||||
}
|
||||
else
|
||||
} else
|
||||
duddleyDoWrite = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
duddleyDoWrite = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
duddleyDoWrite = true;
|
||||
|
||||
if (duddleyDoWrite) {
|
||||
uint32_t written = 0;
|
||||
nsresult rv = m_outputStream->Write((const char *)m_pBuf, (int32_t)m_pos, &written);
|
||||
if (NS_FAILED(rv) || ((uint32_t)written != m_pos))
|
||||
return false;
|
||||
nsresult rv =
|
||||
m_outputStream->Write((const char *)m_pBuf, (int32_t)m_pos, &written);
|
||||
if (NS_FAILED(rv) || ((uint32_t)written != m_pos)) return false;
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImportOutFile::WriteU8NullTerm(const uint8_t * pSrc, bool includeNull)
|
||||
{
|
||||
bool ImportOutFile::WriteU8NullTerm(const uint8_t *pSrc, bool includeNull) {
|
||||
while (*pSrc) {
|
||||
if (m_pos >= m_bufSz) {
|
||||
if (!Flush())
|
||||
return false;
|
||||
if (!Flush()) return false;
|
||||
}
|
||||
*(m_pBuf + m_pos) = *pSrc;
|
||||
m_pos++;
|
||||
|
@ -224,8 +192,7 @@ bool ImportOutFile::WriteU8NullTerm(const uint8_t * pSrc, bool includeNull)
|
|||
}
|
||||
if (includeNull) {
|
||||
if (m_pos >= m_bufSz) {
|
||||
if (!Flush())
|
||||
return false;
|
||||
if (!Flush()) return false;
|
||||
}
|
||||
*(m_pBuf + m_pos) = 0;
|
||||
m_pos++;
|
||||
|
@ -234,21 +201,20 @@ bool ImportOutFile::WriteU8NullTerm(const uint8_t * pSrc, bool includeNull)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ImportOutFile::SetMarker(int markerID)
|
||||
{
|
||||
bool ImportOutFile::SetMarker(int markerID) {
|
||||
if (!Flush()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (markerID < kMaxMarkers) {
|
||||
int64_t pos = 0;
|
||||
if (m_outputStream)
|
||||
{
|
||||
// do we need to flush for the seek to give us the right pos?
|
||||
m_outputStream->Flush();
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsISeekableStream> seekStream = do_QueryInterface(m_outputStream, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (m_outputStream) {
|
||||
// do we need to flush for the seek to give us the right pos?
|
||||
m_outputStream->Flush();
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISeekableStream> seekStream =
|
||||
do_QueryInterface(m_outputStream, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
rv = seekStream->Tell(&pos);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error, Tell failed on output stream\n");
|
||||
|
@ -261,39 +227,31 @@ bool ImportOutFile::SetMarker(int markerID)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ImportOutFile::ClearMarker(int markerID)
|
||||
{
|
||||
if (markerID < kMaxMarkers)
|
||||
m_markers[markerID] = 0;
|
||||
void ImportOutFile::ClearMarker(int markerID) {
|
||||
if (markerID < kMaxMarkers) m_markers[markerID] = 0;
|
||||
}
|
||||
|
||||
bool ImportOutFile::WriteStrAtMarker(int markerID, const char *pStr)
|
||||
{
|
||||
if (markerID >= kMaxMarkers)
|
||||
return false;
|
||||
bool ImportOutFile::WriteStrAtMarker(int markerID, const char *pStr) {
|
||||
if (markerID >= kMaxMarkers) return false;
|
||||
|
||||
if (!Flush())
|
||||
return false;
|
||||
int64_t pos;
|
||||
m_outputStream->Flush();
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsISeekableStream> seekStream = do_QueryInterface(m_outputStream, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (!Flush()) return false;
|
||||
int64_t pos;
|
||||
m_outputStream->Flush();
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISeekableStream> seekStream =
|
||||
do_QueryInterface(m_outputStream, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
rv = seekStream->Tell(&pos);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
rv = seekStream->Seek(nsISeekableStream::NS_SEEK_SET, (int32_t) m_markers[markerID]);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
rv = seekStream->Seek(nsISeekableStream::NS_SEEK_SET,
|
||||
(int32_t)m_markers[markerID]);
|
||||
if (NS_FAILED(rv)) return false;
|
||||
uint32_t written;
|
||||
rv = m_outputStream->Write(pStr, strlen(pStr), &written);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
rv = seekStream->Seek(nsISeekableStream::NS_SEEK_SET, pos);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,57 +10,60 @@
|
|||
#include "nsIOutputStream.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
#define kMaxMarkers 10
|
||||
#define kMaxMarkers 10
|
||||
|
||||
class ImportOutFile;
|
||||
|
||||
class ImportOutFile {
|
||||
public:
|
||||
public:
|
||||
ImportOutFile();
|
||||
ImportOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz);
|
||||
ImportOutFile(nsIFile *pFile, uint8_t *pBuf, uint32_t sz);
|
||||
~ImportOutFile();
|
||||
|
||||
bool InitOutFile(nsIFile *pFile, uint32_t bufSz = 4096);
|
||||
void InitOutFile(nsIFile *pFile, uint8_t * pBuf, uint32_t sz);
|
||||
inline bool WriteData(const uint8_t * pSrc, uint32_t len);
|
||||
inline bool WriteByte(uint8_t byte);
|
||||
bool WriteStr(const char *pStr) {return WriteU8NullTerm((const uint8_t *) pStr, false); }
|
||||
bool WriteU8NullTerm(const uint8_t * pSrc, bool includeNull);
|
||||
bool WriteEol(void) { return WriteStr("\x0D\x0A"); }
|
||||
bool Done(void) {return Flush();}
|
||||
bool InitOutFile(nsIFile *pFile, uint32_t bufSz = 4096);
|
||||
void InitOutFile(nsIFile *pFile, uint8_t *pBuf, uint32_t sz);
|
||||
inline bool WriteData(const uint8_t *pSrc, uint32_t len);
|
||||
inline bool WriteByte(uint8_t byte);
|
||||
bool WriteStr(const char *pStr) {
|
||||
return WriteU8NullTerm((const uint8_t *)pStr, false);
|
||||
}
|
||||
bool WriteU8NullTerm(const uint8_t *pSrc, bool includeNull);
|
||||
bool WriteEol(void) { return WriteStr("\x0D\x0A"); }
|
||||
bool Done(void) { return Flush(); }
|
||||
|
||||
// Marker support
|
||||
bool SetMarker(int markerID);
|
||||
void ClearMarker(int markerID);
|
||||
bool WriteStrAtMarker(int markerID, const char *pStr);
|
||||
bool SetMarker(int markerID);
|
||||
void ClearMarker(int markerID);
|
||||
bool WriteStrAtMarker(int markerID, const char *pStr);
|
||||
|
||||
// 8-bit to 7-bit translation
|
||||
bool Set8bitTranslator(nsImportTranslator *pTrans);
|
||||
bool End8bitTranslation(bool *pEngaged, nsCString& useCharset, nsCString& encoding);
|
||||
bool Set8bitTranslator(nsImportTranslator *pTrans);
|
||||
bool End8bitTranslation(bool *pEngaged, nsCString &useCharset,
|
||||
nsCString &encoding);
|
||||
|
||||
protected:
|
||||
bool Flush(void);
|
||||
protected:
|
||||
bool Flush(void);
|
||||
|
||||
protected:
|
||||
nsCOMPtr <nsIFile> m_pFile;
|
||||
nsCOMPtr <nsIOutputStream> m_outputStream;
|
||||
uint8_t * m_pBuf;
|
||||
uint32_t m_bufSz;
|
||||
uint32_t m_pos;
|
||||
bool m_ownsFileAndBuffer;
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> m_pFile;
|
||||
nsCOMPtr<nsIOutputStream> m_outputStream;
|
||||
uint8_t *m_pBuf;
|
||||
uint32_t m_bufSz;
|
||||
uint32_t m_pos;
|
||||
bool m_ownsFileAndBuffer;
|
||||
|
||||
// markers
|
||||
uint32_t m_markers[kMaxMarkers];
|
||||
uint32_t m_markers[kMaxMarkers];
|
||||
|
||||
// 8 bit to 7 bit translations
|
||||
nsImportTranslator * m_pTrans;
|
||||
bool m_engaged;
|
||||
bool m_supports8to7;
|
||||
ImportOutFile * m_pTransOut;
|
||||
uint8_t * m_pTransBuf;
|
||||
nsImportTranslator *m_pTrans;
|
||||
bool m_engaged;
|
||||
bool m_supports8to7;
|
||||
ImportOutFile *m_pTransOut;
|
||||
uint8_t *m_pTransBuf;
|
||||
};
|
||||
|
||||
inline bool ImportOutFile::WriteData(const uint8_t * pSrc, uint32_t len) {
|
||||
inline bool ImportOutFile::WriteData(const uint8_t *pSrc, uint32_t len) {
|
||||
while ((len + m_pos) > m_bufSz) {
|
||||
if ((m_bufSz - m_pos)) {
|
||||
memcpy(m_pBuf + m_pos, pSrc, m_bufSz - m_pos);
|
||||
|
@ -68,8 +71,7 @@ inline bool ImportOutFile::WriteData(const uint8_t * pSrc, uint32_t len) {
|
|||
pSrc += (m_bufSz - m_pos);
|
||||
m_pos = m_bufSz;
|
||||
}
|
||||
if (!Flush())
|
||||
return false;
|
||||
if (!Flush()) return false;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
|
@ -80,10 +82,9 @@ inline bool ImportOutFile::WriteData(const uint8_t * pSrc, uint32_t len) {
|
|||
return true;
|
||||
}
|
||||
|
||||
inline bool ImportOutFile::WriteByte(uint8_t byte) {
|
||||
inline bool ImportOutFile::WriteByte(uint8_t byte) {
|
||||
if (m_pos == m_bufSz) {
|
||||
if (!Flush())
|
||||
return false;
|
||||
if (!Flush()) return false;
|
||||
}
|
||||
*(m_pBuf + m_pos) = byte;
|
||||
m_pos++;
|
||||
|
@ -91,5 +92,3 @@ inline bool ImportOutFile::WriteByte(uint8_t byte) {
|
|||
}
|
||||
|
||||
#endif /* ImportOutFile_h__ */
|
||||
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
|
||||
int ImportTranslate::m_useTranslator = -1;
|
||||
|
||||
|
||||
bool ImportTranslate::ConvertString(const nsCString& inStr, nsCString& outStr, bool mimeHeader)
|
||||
{
|
||||
bool ImportTranslate::ConvertString(const nsCString &inStr, nsCString &outStr,
|
||||
bool mimeHeader) {
|
||||
if (inStr.IsEmpty()) {
|
||||
outStr = inStr;
|
||||
return true;
|
||||
|
@ -18,8 +17,8 @@ bool ImportTranslate::ConvertString(const nsCString& inStr, nsCString& outStr, b
|
|||
nsImportTranslator *pTrans = GetTranslator();
|
||||
// int maxLen = (int) pTrans->GetMaxBufferSize(inStr.Length());
|
||||
// int hLen = 0;
|
||||
nsCString set;
|
||||
nsCString lang;
|
||||
nsCString set;
|
||||
nsCString lang;
|
||||
|
||||
if (mimeHeader) {
|
||||
// add the charset and language
|
||||
|
@ -36,7 +35,7 @@ bool ImportTranslate::ConvertString(const nsCString& inStr, nsCString& outStr, b
|
|||
set.Truncate();
|
||||
lang.Truncate();
|
||||
|
||||
uint8_t * pBuf;
|
||||
uint8_t *pBuf;
|
||||
/*
|
||||
pBuf = (P_U8) outStr.GetBuffer(maxLen);
|
||||
if (!pBuf) {
|
||||
|
@ -49,7 +48,6 @@ bool ImportTranslate::ConvertString(const nsCString& inStr, nsCString& outStr, b
|
|||
outStr = inStr;
|
||||
delete pTrans;
|
||||
|
||||
|
||||
// Now I need to run the string through the mime-header special char
|
||||
// encoder.
|
||||
|
||||
|
@ -65,14 +63,12 @@ bool ImportTranslate::ConvertString(const nsCString& inStr, nsCString& outStr, b
|
|||
outStr += "'";
|
||||
}
|
||||
outStr += (const char *)pBuf;
|
||||
delete [] pBuf;
|
||||
delete[] pBuf;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
nsImportTranslator *ImportTranslate::GetTranslator(void)
|
||||
{
|
||||
nsImportTranslator *ImportTranslate::GetTranslator(void) {
|
||||
if (m_useTranslator == -1) {
|
||||
// get the translator to use...
|
||||
// CString trans;
|
||||
|
@ -82,24 +78,23 @@ nsImportTranslator *ImportTranslate::GetTranslator(void)
|
|||
// gWizData.m_useTranslator = 1;
|
||||
}
|
||||
|
||||
switch(m_useTranslator) {
|
||||
case 0:
|
||||
return new nsImportTranslator;
|
||||
//case 1:
|
||||
// return new CSJis2JisTranslator;
|
||||
default:
|
||||
return new nsImportTranslator;
|
||||
switch (m_useTranslator) {
|
||||
case 0:
|
||||
return new nsImportTranslator;
|
||||
// case 1:
|
||||
// return new CSJis2JisTranslator;
|
||||
default:
|
||||
return new nsImportTranslator;
|
||||
}
|
||||
}
|
||||
|
||||
nsImportTranslator *ImportTranslate::GetMatchingTranslator(const char *pCharSet)
|
||||
{
|
||||
/*
|
||||
CString jp = "iso-2022-jp";
|
||||
if (!jp.CompareNoCase(pCharSet))
|
||||
return new CSJis2JisTranslator;
|
||||
*/
|
||||
nsImportTranslator *ImportTranslate::GetMatchingTranslator(
|
||||
const char *pCharSet) {
|
||||
/*
|
||||
CString jp = "iso-2022-jp";
|
||||
if (!jp.CompareNoCase(pCharSet))
|
||||
return new CSJis2JisTranslator;
|
||||
*/
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
#include "nsImportTranslator.h"
|
||||
|
||||
class ImportTranslate {
|
||||
public:
|
||||
static bool ConvertString(const nsCString& inStr, nsCString& outStr, bool mimeHeader);
|
||||
public:
|
||||
static bool ConvertString(const nsCString &inStr, nsCString &outStr,
|
||||
bool mimeHeader);
|
||||
static nsImportTranslator *GetTranslator(void);
|
||||
static nsImportTranslator *GetMatchingTranslator(const char *pCharSet);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
static int m_useTranslator;
|
||||
};
|
||||
|
||||
|
||||
#endif /* ImportTranslate_h__ */
|
||||
#endif /* ImportTranslate_h__ */
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
* 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 "nscore.h"
|
||||
#include "nsImportABDescriptor.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsImportABDescriptor::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsresult nsImportABDescriptor::Create(nsISupports *aOuter, REFNSIID aIID,
|
||||
void **aResult) {
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
RefPtr<nsImportABDescriptor> it = new nsImportABDescriptor();
|
||||
return it->QueryInterface(aIID, aResult);
|
||||
|
@ -21,6 +19,4 @@ nsresult nsImportABDescriptor::Create(nsISupports *aOuter, REFNSIID aIID, void *
|
|||
NS_IMPL_ISUPPORTS(nsImportABDescriptor, nsIImportABDescriptor)
|
||||
|
||||
nsImportABDescriptor::nsImportABDescriptor()
|
||||
: mId(0), mRef(0), mSize(0), mImport(true)
|
||||
{
|
||||
}
|
||||
: mId(0), mRef(0), mSize(0), mImport(true) {}
|
||||
|
|
|
@ -15,9 +15,8 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsImportABDescriptor : public nsIImportABDescriptor
|
||||
{
|
||||
public:
|
||||
class nsImportABDescriptor : public nsIImportABDescriptor {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetIdentifier(uint32_t *pIdentifier) override {
|
||||
|
@ -60,8 +59,7 @@ public:
|
|||
|
||||
/* readonly attribute nsIFile fileSpec; */
|
||||
NS_IMETHOD GetAbFile(nsIFile **aFile) override {
|
||||
if (!mFile)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!mFile) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return mFile->Clone(aFile);
|
||||
}
|
||||
|
@ -89,15 +87,14 @@ public:
|
|||
|
||||
static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsImportABDescriptor() {}
|
||||
uint32_t mId; // used by creator of the structure
|
||||
uint32_t mRef; // depth in the hierarchy
|
||||
nsString mDisplayName; // name of this mailbox
|
||||
nsCOMPtr<nsIFile> mFile; // source file (if applicable)
|
||||
uint32_t mSize; // size
|
||||
bool mImport; // import it or not?
|
||||
uint32_t mId; // used by creator of the structure
|
||||
uint32_t mRef; // depth in the hierarchy
|
||||
nsString mDisplayName; // name of this mailbox
|
||||
nsCOMPtr<nsIFile> mFile; // source file (if applicable)
|
||||
uint32_t mSize; // size
|
||||
bool mImport; // import it or not?
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,10 +35,8 @@ static void ImportAddressThread(void *stuff);
|
|||
|
||||
class AddressThreadData;
|
||||
|
||||
class nsImportGenericAddressBooks : public nsIImportGeneric
|
||||
{
|
||||
public:
|
||||
|
||||
class nsImportGenericAddressBooks : public nsIImportGeneric {
|
||||
public:
|
||||
nsImportGenericAddressBooks();
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
@ -52,7 +50,8 @@ public:
|
|||
|
||||
NS_IMETHOD WantsProgress(bool *_retval) override;
|
||||
|
||||
NS_IMETHOD BeginImport(nsISupportsString *successLog, nsISupportsString *errorLog, bool *_retval) override;
|
||||
NS_IMETHOD BeginImport(nsISupportsString *successLog,
|
||||
nsISupportsString *errorLog, bool *_retval) override;
|
||||
|
||||
NS_IMETHOD ContinueImport(bool *_retval) override;
|
||||
|
||||
|
@ -60,72 +59,70 @@ public:
|
|||
|
||||
NS_IMETHOD CancelImport(void) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsImportGenericAddressBooks();
|
||||
void GetDefaultLocation(void);
|
||||
void GetDefaultBooks(void);
|
||||
void GetDefaultFieldMap(void);
|
||||
void GetDefaultLocation(void);
|
||||
void GetDefaultBooks(void);
|
||||
void GetDefaultFieldMap(void);
|
||||
|
||||
public:
|
||||
static void SetLogs(nsString& success, nsString& error, nsISupportsString *pSuccess, nsISupportsString *pError);
|
||||
public:
|
||||
static void SetLogs(nsString &success, nsString &error,
|
||||
nsISupportsString *pSuccess, nsISupportsString *pError);
|
||||
static void ReportError(const char16_t *pName, nsString *pStream,
|
||||
nsIStringBundle *aBundle);
|
||||
|
||||
private:
|
||||
private:
|
||||
nsCOMPtr<nsIImportAddressBooks> m_pInterface;
|
||||
nsCOMPtr<nsIArray> m_Books;
|
||||
nsCOMArray<nsIAddrDatabase> m_DBs;
|
||||
nsCOMPtr <nsIFile> m_pLocation;
|
||||
nsCOMPtr<nsIImportFieldMap> m_pFieldMap;
|
||||
bool m_autoFind;
|
||||
char16_t * m_description;
|
||||
bool m_gotLocation;
|
||||
bool m_found;
|
||||
bool m_userVerify;
|
||||
nsCOMPtr<nsISupportsString> m_pSuccessLog;
|
||||
nsCOMPtr<nsISupportsString> m_pErrorLog;
|
||||
uint32_t m_totalSize;
|
||||
bool m_doImport;
|
||||
AddressThreadData * m_pThreadData;
|
||||
nsCString m_pDestinationUri;
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
nsCOMPtr<nsIArray> m_Books;
|
||||
nsCOMArray<nsIAddrDatabase> m_DBs;
|
||||
nsCOMPtr<nsIFile> m_pLocation;
|
||||
nsCOMPtr<nsIImportFieldMap> m_pFieldMap;
|
||||
bool m_autoFind;
|
||||
char16_t *m_description;
|
||||
bool m_gotLocation;
|
||||
bool m_found;
|
||||
bool m_userVerify;
|
||||
nsCOMPtr<nsISupportsString> m_pSuccessLog;
|
||||
nsCOMPtr<nsISupportsString> m_pErrorLog;
|
||||
uint32_t m_totalSize;
|
||||
bool m_doImport;
|
||||
AddressThreadData *m_pThreadData;
|
||||
nsCString m_pDestinationUri;
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
};
|
||||
|
||||
class AddressThreadData {
|
||||
public:
|
||||
bool driverAlive;
|
||||
bool threadAlive;
|
||||
bool abort;
|
||||
bool fatalError;
|
||||
uint32_t currentTotal;
|
||||
uint32_t currentSize;
|
||||
nsCOMPtr<nsIArray> books;
|
||||
nsCOMArray<nsIAddrDatabase>* dBs;
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService;
|
||||
public:
|
||||
bool driverAlive;
|
||||
bool threadAlive;
|
||||
bool abort;
|
||||
bool fatalError;
|
||||
uint32_t currentTotal;
|
||||
uint32_t currentSize;
|
||||
nsCOMPtr<nsIArray> books;
|
||||
nsCOMArray<nsIAddrDatabase> *dBs;
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService;
|
||||
nsCOMPtr<nsIImportAddressBooks> addressImport;
|
||||
nsCOMPtr<nsIImportFieldMap> fieldMap;
|
||||
nsCOMPtr<nsISupportsString> successLog;
|
||||
nsCOMPtr<nsISupportsString> errorLog;
|
||||
nsCString pDestinationUri;
|
||||
nsCOMPtr<nsIStringBundle> stringBundle;
|
||||
nsCOMPtr<nsIImportFieldMap> fieldMap;
|
||||
nsCOMPtr<nsISupportsString> successLog;
|
||||
nsCOMPtr<nsISupportsString> errorLog;
|
||||
nsCString pDestinationUri;
|
||||
nsCOMPtr<nsIStringBundle> stringBundle;
|
||||
|
||||
AddressThreadData();
|
||||
~AddressThreadData();
|
||||
};
|
||||
|
||||
|
||||
nsresult NS_NewGenericAddressBooks(nsIImportGeneric** aImportGeneric)
|
||||
{
|
||||
nsresult NS_NewGenericAddressBooks(nsIImportGeneric **aImportGeneric) {
|
||||
NS_ASSERTION(aImportGeneric != nullptr, "null ptr");
|
||||
if (! aImportGeneric)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!aImportGeneric) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
RefPtr<nsImportGenericAddressBooks> pGen = new nsImportGenericAddressBooks();
|
||||
return pGen->QueryInterface(NS_GET_IID(nsIImportGeneric), (void **)aImportGeneric);
|
||||
return pGen->QueryInterface(NS_GET_IID(nsIImportGeneric),
|
||||
(void **)aImportGeneric);
|
||||
}
|
||||
|
||||
nsImportGenericAddressBooks::nsImportGenericAddressBooks()
|
||||
{
|
||||
nsImportGenericAddressBooks::nsImportGenericAddressBooks() {
|
||||
m_totalSize = 0;
|
||||
m_doImport = false;
|
||||
m_pThreadData = nullptr;
|
||||
|
@ -136,23 +133,18 @@ nsImportGenericAddressBooks::nsImportGenericAddressBooks()
|
|||
m_found = false;
|
||||
m_userVerify = false;
|
||||
|
||||
nsImportStringBundle::GetStringBundle(IMPORT_MSGS_URL, getter_AddRefs(m_stringBundle));
|
||||
nsImportStringBundle::GetStringBundle(IMPORT_MSGS_URL,
|
||||
getter_AddRefs(m_stringBundle));
|
||||
}
|
||||
|
||||
|
||||
nsImportGenericAddressBooks::~nsImportGenericAddressBooks()
|
||||
{
|
||||
if (m_description)
|
||||
free(m_description);
|
||||
nsImportGenericAddressBooks::~nsImportGenericAddressBooks() {
|
||||
if (m_description) free(m_description);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsImportGenericAddressBooks, nsIImportGeneric)
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISupports **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId,
|
||||
nsISupports **_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
nsresult rv;
|
||||
*_retval = nullptr;
|
||||
|
@ -161,22 +153,20 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
|||
}
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressLocation")) {
|
||||
if (!m_pLocation)
|
||||
GetDefaultLocation();
|
||||
if (!m_pLocation) GetDefaultLocation();
|
||||
NS_IF_ADDREF(*_retval = m_pLocation);
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressBooks")) {
|
||||
if (!m_pLocation)
|
||||
GetDefaultLocation();
|
||||
if (!m_Books)
|
||||
GetDefaultBooks();
|
||||
if (!m_pLocation) GetDefaultLocation();
|
||||
if (!m_Books) GetDefaultBooks();
|
||||
*_retval = m_Books;
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressDestination")) {
|
||||
if (!m_pDestinationUri.IsEmpty()) {
|
||||
nsCOMPtr<nsISupportsCString> abString = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsISupportsCString> abString =
|
||||
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
abString->SetData(m_pDestinationUri);
|
||||
abString.forget(_retval);
|
||||
|
@ -186,8 +176,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
|||
if (!PL_strcasecmp(dataId, "fieldMap")) {
|
||||
if (m_pFieldMap) {
|
||||
NS_ADDREF(*_retval = m_pFieldMap);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (m_pInterface && m_pLocation) {
|
||||
bool needsIt = false;
|
||||
m_pInterface->GetNeedsFieldMap(m_pLocation, &needsIt);
|
||||
|
@ -204,7 +193,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
|||
if (!PL_strncasecmp(dataId, "sampleData-", 11)) {
|
||||
// extra the record number
|
||||
const char *pNum = dataId + 11;
|
||||
int32_t rNum = 0;
|
||||
int32_t rNum = 0;
|
||||
while (*pNum) {
|
||||
rNum *= 10;
|
||||
rNum += (*pNum - '0');
|
||||
|
@ -212,14 +201,13 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
|||
}
|
||||
IMPORT_LOG1("Requesting sample data #: %ld\n", (long)rNum);
|
||||
if (m_pInterface) {
|
||||
nsCOMPtr<nsISupportsString> data = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
char16_t * pData = nullptr;
|
||||
bool found = false;
|
||||
nsCOMPtr<nsISupportsString> data =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
char16_t *pData = nullptr;
|
||||
bool found = false;
|
||||
rv = m_pInterface->GetSampleData(rNum, &found, &pData);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (found) {
|
||||
data->SetData(nsDependentString(pData));
|
||||
data.forget(_retval);
|
||||
|
@ -231,21 +219,17 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId, nsISupports *item)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId,
|
||||
nsISupports *item) {
|
||||
NS_ASSERTION(dataId != nullptr, "null ptr");
|
||||
if (!dataId)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!dataId) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressInterface")) {
|
||||
m_pInterface = nullptr;
|
||||
if (item)
|
||||
m_pInterface = do_QueryInterface(item);
|
||||
if (item) m_pInterface = do_QueryInterface(item);
|
||||
}
|
||||
if (!PL_strcasecmp(dataId, "addressBooks")) {
|
||||
if (item)
|
||||
m_Books = do_QueryInterface(item);
|
||||
if (item) m_Books = do_QueryInterface(item);
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressLocation")) {
|
||||
|
@ -254,11 +238,10 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId, nsISuppor
|
|||
if (item) {
|
||||
nsresult rv;
|
||||
m_pLocation = do_QueryInterface(item, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
if (m_pInterface)
|
||||
m_pInterface->SetSampleLocation(m_pLocation);
|
||||
if (m_pInterface) m_pInterface->SetSampleLocation(m_pLocation);
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(dataId, "addressDestination")) {
|
||||
|
@ -272,64 +255,57 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId, nsISuppor
|
|||
|
||||
if (!PL_strcasecmp(dataId, "fieldMap")) {
|
||||
m_pFieldMap = nullptr;
|
||||
if (item)
|
||||
m_pFieldMap = do_QueryInterface(item);
|
||||
if (item) m_pFieldMap = do_QueryInterface(item);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetStatus(const char *statusKind, int32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetStatus(const char *statusKind,
|
||||
int32_t *_retval) {
|
||||
NS_ASSERTION(statusKind != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!statusKind || !_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!statusKind || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = 0;
|
||||
|
||||
if (!PL_strcasecmp(statusKind, "isInstalled")) {
|
||||
GetDefaultLocation();
|
||||
*_retval = (int32_t) m_found;
|
||||
*_retval = (int32_t)m_found;
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(statusKind, "canUserSetLocation")) {
|
||||
GetDefaultLocation();
|
||||
*_retval = (int32_t) m_userVerify;
|
||||
*_retval = (int32_t)m_userVerify;
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(statusKind, "autoFind")) {
|
||||
GetDefaultLocation();
|
||||
*_retval = (int32_t) m_autoFind;
|
||||
*_retval = (int32_t)m_autoFind;
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(statusKind, "supportsMultiple")) {
|
||||
bool multi = false;
|
||||
if (m_pInterface)
|
||||
m_pInterface->GetSupportsMultiple(&multi);
|
||||
*_retval = (int32_t) multi;
|
||||
bool multi = false;
|
||||
if (m_pInterface) m_pInterface->GetSupportsMultiple(&multi);
|
||||
*_retval = (int32_t)multi;
|
||||
}
|
||||
|
||||
if (!PL_strcasecmp(statusKind, "needsFieldMap")) {
|
||||
bool needs = false;
|
||||
bool needs = false;
|
||||
if (m_pInterface && m_pLocation)
|
||||
m_pInterface->GetNeedsFieldMap(m_pLocation, &needs);
|
||||
*_retval = (int32_t) needs;
|
||||
*_retval = (int32_t)needs;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsImportGenericAddressBooks::GetDefaultLocation(void)
|
||||
{
|
||||
if (!m_pInterface)
|
||||
return;
|
||||
void nsImportGenericAddressBooks::GetDefaultLocation(void) {
|
||||
if (!m_pInterface) return;
|
||||
|
||||
if ((m_pLocation && m_gotLocation) || m_autoFind)
|
||||
return;
|
||||
if ((m_pLocation && m_gotLocation) || m_autoFind) return;
|
||||
|
||||
if (m_description)
|
||||
free(m_description);
|
||||
if (m_description) free(m_description);
|
||||
m_description = nullptr;
|
||||
m_pInterface->GetAutoFind(&m_description, &m_autoFind);
|
||||
m_gotLocation = true;
|
||||
|
@ -339,57 +315,49 @@ void nsImportGenericAddressBooks::GetDefaultLocation(void)
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIFile> pLoc;
|
||||
m_pInterface->GetDefaultLocation(getter_AddRefs(pLoc), &m_found, &m_userVerify);
|
||||
if (!m_pLocation)
|
||||
m_pLocation = pLoc;
|
||||
nsCOMPtr<nsIFile> pLoc;
|
||||
m_pInterface->GetDefaultLocation(getter_AddRefs(pLoc), &m_found,
|
||||
&m_userVerify);
|
||||
if (!m_pLocation) m_pLocation = pLoc;
|
||||
}
|
||||
|
||||
void nsImportGenericAddressBooks::GetDefaultBooks(void)
|
||||
{
|
||||
if (!m_pInterface || m_Books)
|
||||
return;
|
||||
void nsImportGenericAddressBooks::GetDefaultBooks(void) {
|
||||
if (!m_pInterface || m_Books) return;
|
||||
|
||||
if (!m_pLocation && !m_autoFind)
|
||||
return;
|
||||
if (!m_pLocation && !m_autoFind) return;
|
||||
|
||||
nsresult rv = m_pInterface->FindAddressBooks(m_pLocation, getter_AddRefs(m_Books));
|
||||
nsresult rv =
|
||||
m_pInterface->FindAddressBooks(m_pLocation, getter_AddRefs(m_Books));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error: FindAddressBooks failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void nsImportGenericAddressBooks::GetDefaultFieldMap(void)
|
||||
{
|
||||
if (!m_pInterface || !m_pLocation)
|
||||
return;
|
||||
void nsImportGenericAddressBooks::GetDefaultFieldMap(void) {
|
||||
if (!m_pInterface || !m_pLocation) return;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Unable to get nsIImportService.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rv = impSvc->CreateNewFieldMap(getter_AddRefs(m_pFieldMap));
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
int32_t sz = 0;
|
||||
int32_t sz = 0;
|
||||
rv = m_pFieldMap->GetNumMozFields(&sz);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = m_pFieldMap->DefaultFieldMap(sz);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = m_pInterface->InitFieldMap(m_pFieldMap);
|
||||
if (NS_SUCCEEDED(rv)) rv = m_pFieldMap->DefaultFieldMap(sz);
|
||||
if (NS_SUCCEEDED(rv)) rv = m_pInterface->InitFieldMap(m_pFieldMap);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error: Unable to initialize field map\n");
|
||||
m_pFieldMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -399,11 +367,11 @@ NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval)
|
|||
bool result = false;
|
||||
|
||||
if (m_Books) {
|
||||
uint32_t count = 0;
|
||||
uint32_t i;
|
||||
bool import;
|
||||
uint32_t size;
|
||||
uint32_t totalSize = 0;
|
||||
uint32_t count = 0;
|
||||
uint32_t i;
|
||||
bool import;
|
||||
uint32_t size;
|
||||
uint32_t totalSize = 0;
|
||||
|
||||
m_Books->GetLength(&count);
|
||||
|
||||
|
@ -414,7 +382,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval)
|
|||
size = 0;
|
||||
nsresult rv = book->GetImport(&import);
|
||||
if (NS_SUCCEEDED(rv) && import) {
|
||||
(void) book->GetSize(&size);
|
||||
(void)book->GetSize(&size);
|
||||
result = true;
|
||||
}
|
||||
totalSize += size;
|
||||
|
@ -431,39 +399,34 @@ NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsImportGenericAddressBooks::SetLogs(nsString& success, nsString& error, nsISupportsString *pSuccess, nsISupportsString *pError)
|
||||
{
|
||||
void nsImportGenericAddressBooks::SetLogs(nsString &success, nsString &error,
|
||||
nsISupportsString *pSuccess,
|
||||
nsISupportsString *pError) {
|
||||
nsAutoString str;
|
||||
if (pSuccess) {
|
||||
pSuccess->GetData(str);
|
||||
str.Append(success);
|
||||
pSuccess->SetData(success);
|
||||
str.Append(success);
|
||||
pSuccess->SetData(success);
|
||||
}
|
||||
if (pError) {
|
||||
pError->GetData(str);
|
||||
str.Append(error);
|
||||
pError->SetData(error);
|
||||
str.Append(error);
|
||||
pError->SetData(error);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsIAddrDatabase> GetAddressBookFromUri(const char *pUri)
|
||||
{
|
||||
if (!pUri)
|
||||
return nullptr;
|
||||
already_AddRefed<nsIAddrDatabase> GetAddressBookFromUri(const char *pUri) {
|
||||
if (!pUri) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID);
|
||||
if (!abManager)
|
||||
return nullptr;
|
||||
if (!abManager) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> directory;
|
||||
abManager->GetDirectory(nsDependentCString(pUri),
|
||||
getter_AddRefs(directory));
|
||||
if (!directory)
|
||||
return nullptr;
|
||||
abManager->GetDirectory(nsDependentCString(pUri), getter_AddRefs(directory));
|
||||
if (!directory) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIAbMDBDirectory> mdbDirectory = do_QueryInterface(directory);
|
||||
if (!mdbDirectory)
|
||||
return nullptr;
|
||||
if (!mdbDirectory) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> pDatabase;
|
||||
mdbDirectory->GetDatabase(getter_AddRefs(pDatabase));
|
||||
|
@ -471,8 +434,7 @@ already_AddRefed<nsIAddrDatabase> GetAddressBookFromUri(const char *pUri)
|
|||
}
|
||||
|
||||
already_AddRefed<nsIAddrDatabase> GetAddressBook(const char16_t *name,
|
||||
bool makeNew)
|
||||
{
|
||||
bool makeNew) {
|
||||
if (!makeNew) {
|
||||
// FIXME: How do I get the list of address books and look for a
|
||||
// specific name. Major bogosity!
|
||||
|
@ -484,28 +446,24 @@ already_AddRefed<nsIAddrDatabase> GetAddressBook(const char16_t *name,
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIAddrDatabase> pDatabase;
|
||||
nsCOMPtr<nsIFile> dbPath;
|
||||
nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIAbManager> abManager =
|
||||
do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
/* Get the profile directory */
|
||||
rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Create a new address book file - we don't care what the file
|
||||
// name is, as long as it's unique
|
||||
rv = dbPath->Append(NS_LITERAL_STRING("impab.mab"));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
IMPORT_LOG0("Getting the address database factory\n");
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return nullptr;
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return nullptr;
|
||||
|
||||
IMPORT_LOG0("Opening the new address book\n");
|
||||
rv = addrDBFactory->Open(dbPath, true, true,
|
||||
|
@ -514,13 +472,13 @@ already_AddRefed<nsIAddrDatabase> GetAddressBook(const char16_t *name,
|
|||
}
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
IMPORT_LOG0("Failed to get the user profile directory from the address book session\n");
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0(
|
||||
"Failed to get the user profile directory from the address book "
|
||||
"session\n");
|
||||
}
|
||||
|
||||
if (pDatabase && dbPath)
|
||||
{
|
||||
if (pDatabase && dbPath) {
|
||||
// We made a database, add it to the UI?!?!?!?!?!?!
|
||||
// This is major bogosity again! Why doesn't the address book
|
||||
// just handle this properly for me? Uggggg...
|
||||
|
@ -528,15 +486,13 @@ already_AddRefed<nsIAddrDatabase> GetAddressBook(const char16_t *name,
|
|||
nsCOMPtr<nsIAbDirectory> parentDir;
|
||||
abManager->GetDirectory(NS_LITERAL_CSTRING(kAllDirectoryRoot),
|
||||
getter_AddRefs(parentDir));
|
||||
if (parentDir)
|
||||
{
|
||||
if (parentDir) {
|
||||
nsAutoCString URI("moz-abmdbdirectory://");
|
||||
nsAutoCString leafName;
|
||||
rv = dbPath->GetNativeLeafName(leafName);
|
||||
if (NS_FAILED(rv))
|
||||
IMPORT_LOG0("*** Error: Unable to get name of database file\n");
|
||||
else
|
||||
{
|
||||
else {
|
||||
URI.Append(leafName);
|
||||
rv = parentDir->CreateDirectoryByURI(nsDependentString(name), URI);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -547,20 +503,21 @@ already_AddRefed<nsIAddrDatabase> GetAddressBook(const char16_t *name,
|
|||
if (NS_SUCCEEDED(rv))
|
||||
IMPORT_LOG0("Added new address book to the UI\n");
|
||||
else
|
||||
IMPORT_LOG0("*** Error: An error occurred while adding the address book to the UI\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Error: An error occurred while adding the address book to the "
|
||||
"UI\n");
|
||||
}
|
||||
|
||||
return pDatabase.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsString *successLog, nsISupportsString *errorLog, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(
|
||||
nsISupportsString *successLog, nsISupportsString *errorLog, bool *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsString success;
|
||||
nsString error;
|
||||
nsString success;
|
||||
nsString error;
|
||||
|
||||
if (!m_doImport) {
|
||||
*_retval = true;
|
||||
|
@ -609,13 +566,10 @@ NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsString *succes
|
|||
// to do so inside the import thread which would just proxy the create
|
||||
// operations back to the main thread anyway.
|
||||
nsCOMPtr<nsIAddrDatabase> db = GetAddressBookFromUri(m_pDestinationUri.get());
|
||||
for (uint32_t i = 0; i < count; ++i)
|
||||
{
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
nsCOMPtr<nsIImportABDescriptor> book = do_QueryElementAt(m_Books, i);
|
||||
if (book)
|
||||
{
|
||||
if (!db)
|
||||
{
|
||||
if (book) {
|
||||
if (!db) {
|
||||
nsString name;
|
||||
book->GetPreferredName(name);
|
||||
db = GetAddressBook(name.get(), true);
|
||||
|
@ -638,29 +592,23 @@ NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsString *succes
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::ContinueImport(bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::ContinueImport(bool *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = true;
|
||||
if (m_pThreadData) {
|
||||
if (m_pThreadData->fatalError)
|
||||
*_retval = false;
|
||||
if (m_pThreadData->fatalError) *_retval = false;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetProgress(int32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::GetProgress(int32_t *_retval) {
|
||||
// This returns the progress from the the currently
|
||||
// running import mail or import address book thread.
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!m_pThreadData || !(m_pThreadData->threadAlive)) {
|
||||
*_retval = 100;
|
||||
|
@ -669,8 +617,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetProgress(int32_t *_retval)
|
|||
|
||||
uint32_t sz = 0;
|
||||
if (m_pThreadData->currentSize && m_pInterface) {
|
||||
if (NS_FAILED(m_pInterface->GetImportProgress(&sz)))
|
||||
sz = 0;
|
||||
if (NS_FAILED(m_pInterface->GetImportProgress(&sz))) sz = 0;
|
||||
}
|
||||
|
||||
if (m_totalSize)
|
||||
|
@ -679,20 +626,16 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetProgress(int32_t *_retval)
|
|||
*_retval = 0;
|
||||
|
||||
// never return less than 5 so it looks like we are doing something!
|
||||
if (*_retval < 5)
|
||||
*_retval = 5;
|
||||
if (*_retval < 5) *_retval = 5;
|
||||
|
||||
// as long as the thread is alive don't return completely
|
||||
// done.
|
||||
if (*_retval > 99)
|
||||
*_retval = 99;
|
||||
if (*_retval > 99) *_retval = 99;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::CancelImport(void)
|
||||
{
|
||||
NS_IMETHODIMP nsImportGenericAddressBooks::CancelImport(void) {
|
||||
if (m_pThreadData) {
|
||||
m_pThreadData->abort = true;
|
||||
m_pThreadData = nullptr;
|
||||
|
@ -701,9 +644,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::CancelImport(void)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
AddressThreadData::AddressThreadData()
|
||||
{
|
||||
AddressThreadData::AddressThreadData() {
|
||||
fatalError = false;
|
||||
driverAlive = true;
|
||||
threadAlive = true;
|
||||
|
@ -712,18 +653,15 @@ AddressThreadData::AddressThreadData()
|
|||
currentSize = 0;
|
||||
}
|
||||
|
||||
AddressThreadData::~AddressThreadData()
|
||||
{
|
||||
}
|
||||
AddressThreadData::~AddressThreadData() {}
|
||||
|
||||
void nsImportGenericAddressBooks::ReportError(const char16_t *pName,
|
||||
nsString *pStream,
|
||||
nsIStringBundle* aBundle)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
nsIStringBundle *aBundle) {
|
||||
if (!pStream) return;
|
||||
// load the error string
|
||||
char16_t *pFmt = nsImportStringBundle::GetStringByID(IMPORT_ERROR_GETABOOK, aBundle);
|
||||
char16_t *pFmt =
|
||||
nsImportStringBundle::GetStringByID(IMPORT_ERROR_GETABOOK, aBundle);
|
||||
nsString pText;
|
||||
nsTextFormatter::ssprintf(pText, pFmt, pName);
|
||||
pStream->Append(pText);
|
||||
|
@ -731,31 +669,28 @@ void nsImportGenericAddressBooks::ReportError(const char16_t *pName,
|
|||
pStream->AppendLiteral(MSG_LINEBREAK);
|
||||
}
|
||||
|
||||
static void ImportAddressThread(void *stuff)
|
||||
{
|
||||
static void ImportAddressThread(void *stuff) {
|
||||
IMPORT_LOG0("In Begin ImportAddressThread\n");
|
||||
|
||||
AddressThreadData *pData = (AddressThreadData *)stuff;
|
||||
uint32_t count = 0;
|
||||
uint32_t i;
|
||||
bool import;
|
||||
uint32_t size;
|
||||
uint32_t count = 0;
|
||||
uint32_t i;
|
||||
bool import;
|
||||
uint32_t size;
|
||||
|
||||
nsString success;
|
||||
nsString error;
|
||||
nsString success;
|
||||
nsString error;
|
||||
|
||||
(void) pData->books->GetLength(&count);
|
||||
(void)pData->books->GetLength(&count);
|
||||
|
||||
for (i = 0; (i < count) && !(pData->abort); i++) {
|
||||
nsCOMPtr<nsIImportABDescriptor> book =
|
||||
do_QueryElementAt(pData->books, i);
|
||||
nsCOMPtr<nsIImportABDescriptor> book = do_QueryElementAt(pData->books, i);
|
||||
|
||||
if (book) {
|
||||
import = false;
|
||||
size = 0;
|
||||
nsresult rv = book->GetImport(&import);
|
||||
if (NS_SUCCEEDED(rv) && import)
|
||||
rv = book->GetSize(&size);
|
||||
if (NS_SUCCEEDED(rv) && import) rv = book->GetSize(&size);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && size && import) {
|
||||
nsString name;
|
||||
|
@ -779,18 +714,15 @@ static void ImportAddressThread(void *stuff)
|
|||
for (int32_t i = 0; i < sz; i++) {
|
||||
pData->fieldMap->GetFieldMap(i, &mapIndex);
|
||||
pData->fieldMap->GetFieldActive(i, &active);
|
||||
IMPORT_LOG3("Field map #%d: index=%d, active=%d\n", (int) i, (int) mapIndex, (int) active);
|
||||
IMPORT_LOG3("Field map #%d: index=%d, active=%d\n", (int) i, (int)
|
||||
mapIndex, (int) active);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
rv = pData->addressImport->ImportAddressBook(book,
|
||||
db,
|
||||
pData->fieldMap,
|
||||
pData->ldifService,
|
||||
&pError,
|
||||
&pSuccess,
|
||||
&fatalError);
|
||||
rv = pData->addressImport->ImportAddressBook(
|
||||
book, db, pData->fieldMap, pData->ldifService, &pError, &pSuccess,
|
||||
&fatalError);
|
||||
if (NS_SUCCEEDED(rv) && pSuccess) {
|
||||
success.Append(pSuccess);
|
||||
free(pSuccess);
|
||||
|
@ -799,16 +731,15 @@ static void ImportAddressThread(void *stuff)
|
|||
error.Append(pError);
|
||||
free(pError);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsImportGenericAddressBooks::ReportError(name.get(), &error, pData->stringBundle);
|
||||
} else {
|
||||
nsImportGenericAddressBooks::ReportError(name.get(), &error,
|
||||
pData->stringBundle);
|
||||
}
|
||||
|
||||
pData->currentSize = 0;
|
||||
pData->currentTotal += size;
|
||||
|
||||
if (db)
|
||||
db->Close(true);
|
||||
if (db) db->Close(true);
|
||||
|
||||
if (fatalError) {
|
||||
pData->fatalError = true;
|
||||
|
@ -818,13 +749,12 @@ static void ImportAddressThread(void *stuff)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
nsImportGenericAddressBooks::SetLogs(success, error, pData->successLog, pData->errorLog);
|
||||
nsImportGenericAddressBooks::SetLogs(success, error, pData->successLog,
|
||||
pData->errorLog);
|
||||
|
||||
if (pData->abort || pData->fatalError) {
|
||||
// FIXME: do what is necessary to get rid of what has been imported so far.
|
||||
// Nothing if we went into an existing address book! Otherwise, delete
|
||||
// the ones we created?
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,58 +7,46 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsImportEmbeddedImageData, nsIMsgEmbeddedImageData)
|
||||
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData()
|
||||
{
|
||||
}
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData() {}
|
||||
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData(
|
||||
nsIURI *aUri, const nsACString &aCid) : m_uri(aUri), m_cid(aCid)
|
||||
{
|
||||
}
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData(nsIURI *aUri,
|
||||
const nsACString &aCid)
|
||||
: m_uri(aUri), m_cid(aCid) {}
|
||||
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData(
|
||||
nsIURI *aUri, const nsACString &aCid, const nsACString &aName)
|
||||
: m_uri(aUri), m_cid(aCid), m_name(aName)
|
||||
{
|
||||
}
|
||||
nsImportEmbeddedImageData::nsImportEmbeddedImageData(nsIURI *aUri,
|
||||
const nsACString &aCid,
|
||||
const nsACString &aName)
|
||||
: m_uri(aUri), m_cid(aCid), m_name(aName) {}
|
||||
|
||||
nsImportEmbeddedImageData::~nsImportEmbeddedImageData()
|
||||
{
|
||||
}
|
||||
nsImportEmbeddedImageData::~nsImportEmbeddedImageData() {}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetUri(nsIURI **aUri)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetUri(nsIURI **aUri) {
|
||||
NS_ENSURE_ARG_POINTER(aUri);
|
||||
NS_IF_ADDREF(*aUri = m_uri);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetUri(nsIURI *aUri)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetUri(nsIURI *aUri) {
|
||||
m_uri = aUri;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetCid(nsACString &aCid)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetCid(nsACString &aCid) {
|
||||
aCid = m_cid;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetCid(const nsACString &aCid)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetCid(const nsACString &aCid) {
|
||||
m_cid = aCid;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetName(nsACString &aName)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::GetName(nsACString &aName) {
|
||||
aName = m_name;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetName(const nsACString &aName)
|
||||
{
|
||||
NS_IMETHODIMP nsImportEmbeddedImageData::SetName(const nsACString &aName) {
|
||||
m_name = aName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
class nsImportEmbeddedImageData final : public nsIMsgEmbeddedImageData
|
||||
{
|
||||
public:
|
||||
class nsImportEmbeddedImageData final : public nsIMsgEmbeddedImageData {
|
||||
public:
|
||||
nsImportEmbeddedImageData(nsIURI *aUri, const nsACString &aCID);
|
||||
nsImportEmbeddedImageData(nsIURI *aUri, const nsACString &aCID, const nsACString &aName);
|
||||
nsImportEmbeddedImageData(nsIURI *aUri, const nsACString &aCID,
|
||||
const nsACString &aName);
|
||||
nsImportEmbeddedImageData();
|
||||
NS_DECL_NSIMSGEMBEDDEDIMAGEDATA
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -24,9 +24,8 @@ public:
|
|||
nsCString m_cid;
|
||||
nsCString m_name;
|
||||
|
||||
private:
|
||||
private:
|
||||
~nsImportEmbeddedImageData();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,42 +7,38 @@
|
|||
#include "nsImportEncodeScan.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#define kBeginAppleSingle 0
|
||||
#define kBeginDataFork 1
|
||||
#define kBeginResourceFork 2
|
||||
#define kAddEntries 3
|
||||
#define kScanningDataFork 4
|
||||
#define kScanningRsrcFork 5
|
||||
#define kDoneWithFile 6
|
||||
#define kBeginAppleSingle 0
|
||||
#define kBeginDataFork 1
|
||||
#define kBeginResourceFork 2
|
||||
#define kAddEntries 3
|
||||
#define kScanningDataFork 4
|
||||
#define kScanningRsrcFork 5
|
||||
#define kDoneWithFile 6
|
||||
|
||||
uint32_t gAppleSingleHeader[6] = {0x00051600, 0x00020000, 0, 0, 0, 0};
|
||||
#define kAppleSingleHeaderSize (6 * sizeof(uint32_t))
|
||||
uint32_t gAppleSingleHeader[6] = {0x00051600, 0x00020000, 0, 0, 0, 0};
|
||||
#define kAppleSingleHeaderSize (6 * sizeof(uint32_t))
|
||||
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
#include "MoreFilesExtras.h"
|
||||
#include "MoreDesktopMgr.h"
|
||||
# include "MoreFilesExtras.h"
|
||||
# include "MoreDesktopMgr.h"
|
||||
|
||||
CInfoPBRec gCatInfoPB;
|
||||
U32 g2000Secs = 0;
|
||||
long gGMTDelta = 0;
|
||||
CInfoPBRec gCatInfoPB;
|
||||
U32 g2000Secs = 0;
|
||||
long gGMTDelta = 0;
|
||||
|
||||
long GetGmtDelta(void);
|
||||
U32 Get2000Secs(void);
|
||||
|
||||
|
||||
long GetGmtDelta(void)
|
||||
{
|
||||
long GetGmtDelta(void) {
|
||||
MachineLocation myLocation;
|
||||
ReadLocation(&myLocation);
|
||||
long myDelta = BitAnd(myLocation.u.gmtDelta, 0x00FFFFFF);
|
||||
if (BitTst(&myDelta, 23))
|
||||
myDelta = BitOr(myDelta, 0xFF000000);
|
||||
long myDelta = BitAnd(myLocation.u.gmtDelta, 0x00FFFFFF);
|
||||
if (BitTst(&myDelta, 23)) myDelta = BitOr(myDelta, 0xFF000000);
|
||||
return myDelta;
|
||||
}
|
||||
|
||||
U32 Get2000Secs(void)
|
||||
{
|
||||
DateTimeRec dr;
|
||||
U32 Get2000Secs(void) {
|
||||
DateTimeRec dr;
|
||||
dr.year = 2000;
|
||||
dr.month = 1;
|
||||
dr.day = 1;
|
||||
|
@ -50,26 +46,24 @@ U32 Get2000Secs(void)
|
|||
dr.minute = 0;
|
||||
dr.second = 0;
|
||||
dr.dayOfWeek = 0;
|
||||
U32 result;
|
||||
U32 result;
|
||||
DateToSeconds(&dr, &result);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsImportEncodeScan::nsImportEncodeScan()
|
||||
{
|
||||
nsImportEncodeScan::nsImportEncodeScan() {
|
||||
m_isAppleSingle = false;
|
||||
m_encodeScanState = 0;
|
||||
m_resourceForkSize = 0;
|
||||
m_dataForkSize = 0;
|
||||
}
|
||||
|
||||
nsImportEncodeScan::~nsImportEncodeScan()
|
||||
{
|
||||
}
|
||||
nsImportEncodeScan::~nsImportEncodeScan() {}
|
||||
|
||||
bool nsImportEncodeScan::InitEncodeScan(bool appleSingleEncode, nsIFile *fileLoc, const char *pName, uint8_t * pBuf, uint32_t sz)
|
||||
{
|
||||
bool nsImportEncodeScan::InitEncodeScan(bool appleSingleEncode,
|
||||
nsIFile *fileLoc, const char *pName,
|
||||
uint8_t *pBuf, uint32_t sz) {
|
||||
CleanUpEncodeScan();
|
||||
m_isAppleSingle = appleSingleEncode;
|
||||
m_encodeScanState = kBeginAppleSingle;
|
||||
|
@ -77,45 +71,39 @@ bool nsImportEncodeScan::InitEncodeScan(bool appleSingleEncode, nsIFile *fileLoc
|
|||
m_useFileName = pName;
|
||||
m_pBuf = pBuf;
|
||||
m_bufSz = sz;
|
||||
if (!m_isAppleSingle)
|
||||
{
|
||||
if (!m_inputStream)
|
||||
{
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(m_inputStream), m_pInputFile);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (!m_isAppleSingle) {
|
||||
if (!m_inputStream) {
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(m_inputStream),
|
||||
m_pInputFile);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
|
||||
InitScan(m_inputStream, pBuf, sz);
|
||||
}
|
||||
else {
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
} else {
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
// Fill in the file sizes
|
||||
m_resourceForkSize = fileLoc.GetMacFileSize(UFileLocation::eResourceFork);
|
||||
m_dataForkSize = fileLoc.GetMacFileSize(UFileLocation::eDataFork);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void nsImportEncodeScan::CleanUpEncodeScan(void)
|
||||
{
|
||||
void nsImportEncodeScan::CleanUpEncodeScan(void) {
|
||||
m_pInputStream->Close();
|
||||
m_pInputStream = nullptr;
|
||||
m_pInputFile = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// 26 + 12 per entry
|
||||
|
||||
void nsImportEncodeScan::FillInEntries(int numEntries)
|
||||
{
|
||||
void nsImportEncodeScan::FillInEntries(int numEntries) {
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
int len = m_useFileName.GetLength();
|
||||
if (len < 32)
|
||||
len = 32;
|
||||
long entry[3];
|
||||
long fileOffset = 26 + (12 * numEntries);
|
||||
int len = m_useFileName.GetLength();
|
||||
if (len < 32) len = 32;
|
||||
long entry[3];
|
||||
long fileOffset = 26 + (12 * numEntries);
|
||||
entry[0] = 3;
|
||||
entry[1] = fileOffset;
|
||||
entry[2] = m_useFileName.GetLength();
|
||||
|
@ -123,12 +111,10 @@ void nsImportEncodeScan::FillInEntries(int numEntries)
|
|||
MemCpy(m_pBuf + m_bytesInBuf, entry, 12);
|
||||
m_bytesInBuf += 12;
|
||||
|
||||
|
||||
Str255 comment;
|
||||
Str255 comment;
|
||||
comment[0] = 0;
|
||||
OSErr err = FSpDTGetComment(m_inputFileLoc, comment);
|
||||
if (comment[0] > 200)
|
||||
comment[0] = 200;
|
||||
if (comment[0] > 200) comment[0] = 200;
|
||||
entry[0] = 4;
|
||||
entry[1] = fileOffset;
|
||||
entry[2] = comment[0];
|
||||
|
@ -136,7 +122,6 @@ void nsImportEncodeScan::FillInEntries(int numEntries)
|
|||
MemCpy(m_pBuf + m_bytesInBuf, entry, 12);
|
||||
m_bytesInBuf += 12;
|
||||
|
||||
|
||||
entry[0] = 8;
|
||||
entry[1] = fileOffset;
|
||||
entry[2] = 16;
|
||||
|
@ -151,7 +136,6 @@ void nsImportEncodeScan::FillInEntries(int numEntries)
|
|||
MemCpy(m_pBuf + m_bytesInBuf, entry, 12);
|
||||
m_bytesInBuf += 12;
|
||||
|
||||
|
||||
entry[0] = 10;
|
||||
entry[1] = fileOffset;
|
||||
entry[2] = 4;
|
||||
|
@ -180,14 +164,14 @@ void nsImportEncodeScan::FillInEntries(int numEntries)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool nsImportEncodeScan::AddEntries(void)
|
||||
{
|
||||
bool nsImportEncodeScan::AddEntries(void) {
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
if (!g2000Secs) {
|
||||
g2000Secs = Get2000Secs();
|
||||
gGMTDelta = GetGmtDelta();
|
||||
}
|
||||
MemCpy(m_pBuf + m_bytesInBuf, (PC_S8) m_useFileName, m_useFileName.GetLength());
|
||||
MemCpy(m_pBuf + m_bytesInBuf, (PC_S8)m_useFileName,
|
||||
m_useFileName.GetLength());
|
||||
m_bytesInBuf += m_useFileName.GetLength();
|
||||
if (m_useFileName.GetLength() < 32) {
|
||||
int len = m_useFileName.GetLength();
|
||||
|
@ -198,14 +182,14 @@ bool nsImportEncodeScan::AddEntries(void)
|
|||
}
|
||||
}
|
||||
|
||||
Str255 comment;
|
||||
Str255 comment;
|
||||
comment[0] = 0;
|
||||
OSErr err = FSpDTGetComment(m_inputFileLoc, comment);
|
||||
comment[0] = 200;
|
||||
MemCpy(m_pBuf + m_bytesInBuf, &(comment[1]), comment[0]);
|
||||
m_bytesInBuf += comment[0];
|
||||
|
||||
long dates[4];
|
||||
long dates[4];
|
||||
dates[0] = gCatInfoPB.hFileInfo.ioFlCrDat;
|
||||
dates[1] = gCatInfoPB.hFileInfo.ioFlMdDat;
|
||||
dates[2] = gCatInfoPB.hFileInfo.ioFlBkDat;
|
||||
|
@ -217,9 +201,8 @@ bool nsImportEncodeScan::AddEntries(void)
|
|||
MemCpy(m_pBuf + m_bytesInBuf, dates, 16);
|
||||
m_bytesInBuf += 16;
|
||||
|
||||
|
||||
FInfo fInfo = gCatInfoPB.hFileInfo.ioFlFndrInfo;
|
||||
FXInfo fxInfo = gCatInfoPB.hFileInfo.ioFlXFndrInfo;
|
||||
FInfo fInfo = gCatInfoPB.hFileInfo.ioFlFndrInfo;
|
||||
FXInfo fxInfo = gCatInfoPB.hFileInfo.ioFlXFndrInfo;
|
||||
fInfo.fdFlags = 0;
|
||||
fInfo.fdLocation.h = 0;
|
||||
fInfo.fdLocation.v = 0;
|
||||
|
@ -230,50 +213,44 @@ bool nsImportEncodeScan::AddEntries(void)
|
|||
MemCpy(m_pBuf + m_bytesInBuf, &fxInfo, 16);
|
||||
m_bytesInBuf += 16;
|
||||
|
||||
|
||||
dates[0] = 0;
|
||||
if ((gCatInfoPB.hFileInfo.ioFlAttrib & 1) != 0)
|
||||
dates[0] |= 1;
|
||||
if ((gCatInfoPB.hFileInfo.ioFlAttrib & 1) != 0) dates[0] |= 1;
|
||||
MemCpy(m_pBuf + m_bytesInBuf, dates, 4);
|
||||
m_bytesInBuf += 4;
|
||||
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nsImportEncodeScan::Scan(bool *pDone)
|
||||
{
|
||||
nsresult rv;
|
||||
bool nsImportEncodeScan::Scan(bool *pDone) {
|
||||
nsresult rv;
|
||||
|
||||
*pDone = false;
|
||||
if (m_isAppleSingle) {
|
||||
// Stuff the buffer with things needed to encode the file...
|
||||
// then just allow UScanFile to handle each fork, but be careful
|
||||
// when handling eof.
|
||||
switch(m_encodeScanState) {
|
||||
switch (m_encodeScanState) {
|
||||
case kBeginAppleSingle: {
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
OSErr err = GetCatInfoNoName(m_inputFileLoc.GetVRefNum(), m_inputFileLoc.GetParID(), m_inputFileLoc.GetFileNamePtr(), &gCatInfoPB);
|
||||
if (err != noErr)
|
||||
return FALSE;
|
||||
OSErr err = GetCatInfoNoName(
|
||||
m_inputFileLoc.GetVRefNum(), m_inputFileLoc.GetParID(),
|
||||
m_inputFileLoc.GetFileNamePtr(), &gCatInfoPB);
|
||||
if (err != noErr) return FALSE;
|
||||
#endif
|
||||
m_eof = false;
|
||||
m_pos = 0;
|
||||
memcpy(m_pBuf, gAppleSingleHeader, kAppleSingleHeaderSize);
|
||||
m_bytesInBuf = kAppleSingleHeaderSize;
|
||||
int numEntries = 5;
|
||||
if (m_dataForkSize)
|
||||
numEntries++;
|
||||
if (m_resourceForkSize)
|
||||
numEntries++;
|
||||
if (m_dataForkSize) numEntries++;
|
||||
if (m_resourceForkSize) numEntries++;
|
||||
memcpy(m_pBuf + m_bytesInBuf, &numEntries, sizeof(numEntries));
|
||||
m_bytesInBuf += sizeof(numEntries);
|
||||
FillInEntries(numEntries);
|
||||
m_encodeScanState = kAddEntries;
|
||||
return ScanBuffer(pDone);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kBeginDataFork: {
|
||||
if (!m_dataForkSize) {
|
||||
|
@ -281,53 +258,44 @@ bool nsImportEncodeScan::Scan(bool *pDone)
|
|||
return true;
|
||||
}
|
||||
// Initialize the scan of the data fork...
|
||||
if (!m_inputStream)
|
||||
{
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(m_inputStream), m_pInputFile);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
if (!m_inputStream) {
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(m_inputStream),
|
||||
m_pInputFile);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
m_encodeScanState = kScanningDataFork;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kScanningDataFork: {
|
||||
bool result = FillBufferFromFile();
|
||||
if (!result)
|
||||
return false;
|
||||
if (!result) return false;
|
||||
if (m_eof) {
|
||||
m_eof = false;
|
||||
result = ScanBuffer(pDone);
|
||||
if (!result)
|
||||
return false;
|
||||
if (!result) return false;
|
||||
m_inputStream->Close();
|
||||
m_inputStream = nullptr;
|
||||
m_inputStream = nullptr;
|
||||
m_encodeScanState = kDoneWithFile;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return ScanBuffer(pDone);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kScanningRsrcFork: {
|
||||
bool result = FillBufferFromFile();
|
||||
if (!result)
|
||||
return false;
|
||||
if (!result) return false;
|
||||
if (m_eof) {
|
||||
m_eof = false;
|
||||
result = ScanBuffer(pDone);
|
||||
if (!result)
|
||||
return false;
|
||||
if (!result) return false;
|
||||
m_inputStream->Close();
|
||||
m_inputStream = nullptr;
|
||||
m_inputStream = nullptr;
|
||||
m_encodeScanState = kBeginDataFork;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return ScanBuffer(pDone);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kBeginResourceFork: {
|
||||
if (!m_resourceForkSize) {
|
||||
|
@ -342,33 +310,26 @@ bool nsImportEncodeScan::Scan(bool *pDone)
|
|||
*/
|
||||
m_encodeScanState = kScanningRsrcFork;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kAddEntries: {
|
||||
ShiftBuffer();
|
||||
if (!AddEntries())
|
||||
return false;
|
||||
if (!AddEntries()) return false;
|
||||
m_encodeScanState = kBeginResourceFork;
|
||||
return ScanBuffer(pDone);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case kDoneWithFile: {
|
||||
ShiftBuffer();
|
||||
m_eof = true;
|
||||
if (!ScanBuffer(pDone))
|
||||
return false;
|
||||
if (!ScanBuffer(pDone)) return false;
|
||||
*pDone = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
} else
|
||||
return nsImportScanFile::Scan(pDone);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,28 +12,28 @@
|
|||
#include "nsString.h"
|
||||
|
||||
class nsImportEncodeScan : public nsImportScanFile {
|
||||
public:
|
||||
public:
|
||||
nsImportEncodeScan();
|
||||
~nsImportEncodeScan();
|
||||
|
||||
bool InitEncodeScan(bool appleSingleEncode, nsIFile *pFile, const char *pName, uint8_t * pBuf, uint32_t sz);
|
||||
void CleanUpEncodeScan(void);
|
||||
bool InitEncodeScan(bool appleSingleEncode, nsIFile *pFile, const char *pName,
|
||||
uint8_t *pBuf, uint32_t sz);
|
||||
void CleanUpEncodeScan(void);
|
||||
|
||||
virtual bool Scan(bool *pDone) override;
|
||||
virtual bool Scan(bool *pDone) override;
|
||||
|
||||
protected:
|
||||
void FillInEntries(int numEntries);
|
||||
bool AddEntries(void);
|
||||
protected:
|
||||
void FillInEntries(int numEntries);
|
||||
bool AddEntries(void);
|
||||
|
||||
protected:
|
||||
bool m_isAppleSingle;
|
||||
nsCOMPtr<nsIFile> m_pInputFile;
|
||||
nsCOMPtr<nsIInputStream> m_inputStream;
|
||||
int m_encodeScanState;
|
||||
long m_resourceForkSize;
|
||||
long m_dataForkSize;
|
||||
nsCString m_useFileName;
|
||||
protected:
|
||||
bool m_isAppleSingle;
|
||||
nsCOMPtr<nsIFile> m_pInputFile;
|
||||
nsCOMPtr<nsIInputStream> m_inputStream;
|
||||
int m_encodeScanState;
|
||||
long m_resourceForkSize;
|
||||
long m_dataForkSize;
|
||||
nsCString m_useFileName;
|
||||
};
|
||||
|
||||
#endif /* nsImportEncodeScan_h__ */
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* 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 "nscore.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsImportFieldMap.h"
|
||||
|
@ -14,10 +13,9 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsImportFieldMap::Create(nsIStringBundle *aBundle, nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsresult nsImportFieldMap::Create(nsIStringBundle *aBundle, nsISupports *aOuter,
|
||||
REFNSIID aIID, void **aResult) {
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
RefPtr<nsImportFieldMap> it = new nsImportFieldMap(aBundle);
|
||||
return it->QueryInterface(aIID, aResult);
|
||||
|
@ -25,50 +23,44 @@ nsresult nsImportFieldMap::Create(nsIStringBundle *aBundle, nsISupports *aOuter,
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsImportFieldMap, nsIImportFieldMap)
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetSkipFirstRecord(bool *result)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetSkipFirstRecord(bool *result) {
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = m_skipFirstRecord;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetSkipFirstRecord(bool aResult)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::SetSkipFirstRecord(bool aResult) {
|
||||
m_skipFirstRecord = aResult;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsImportFieldMap::nsImportFieldMap(nsIStringBundle *aBundle)
|
||||
{
|
||||
nsImportFieldMap::nsImportFieldMap(nsIStringBundle *aBundle) {
|
||||
m_numFields = 0;
|
||||
m_pFields = nullptr;
|
||||
m_pActive = nullptr;
|
||||
m_allocated = 0;
|
||||
// need to init the description array
|
||||
m_mozFieldCount = 0;
|
||||
m_skipFirstRecord = false;
|
||||
m_skipFirstRecord = false;
|
||||
nsCOMPtr<nsIStringBundle> pBundle = aBundle;
|
||||
|
||||
nsString *pStr;
|
||||
for (int32_t i = IMPORT_FIELD_DESC_START; i <= IMPORT_FIELD_DESC_END; i++, m_mozFieldCount++) {
|
||||
for (int32_t i = IMPORT_FIELD_DESC_START; i <= IMPORT_FIELD_DESC_END;
|
||||
i++, m_mozFieldCount++) {
|
||||
pStr = new nsString();
|
||||
if (pBundle) {
|
||||
nsImportStringBundle::GetStringByID(i, pBundle, *pStr);
|
||||
}
|
||||
else
|
||||
} else
|
||||
pStr->AppendInt(i);
|
||||
m_descriptions.AppendElement(pStr);
|
||||
}
|
||||
}
|
||||
|
||||
nsImportFieldMap::~nsImportFieldMap()
|
||||
{
|
||||
if (m_pFields)
|
||||
delete [] m_pFields;
|
||||
if (m_pActive)
|
||||
delete [] m_pActive;
|
||||
nsImportFieldMap::~nsImportFieldMap() {
|
||||
if (m_pFields) delete[] m_pFields;
|
||||
if (m_pActive) delete[] m_pActive;
|
||||
|
||||
nsString * pStr;
|
||||
nsString *pStr;
|
||||
for (int32_t i = 0; i < m_mozFieldCount; i++) {
|
||||
pStr = m_descriptions.ElementAt(i);
|
||||
delete pStr;
|
||||
|
@ -76,32 +68,26 @@ nsImportFieldMap::~nsImportFieldMap()
|
|||
m_descriptions.Clear();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetNumMozFields(int32_t *aNumFields)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetNumMozFields(int32_t *aNumFields) {
|
||||
NS_ASSERTION(aNumFields != nullptr, "null ptr");
|
||||
if (!aNumFields)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!aNumFields) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aNumFields = m_mozFieldCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetMapSize(int32_t *aNumFields)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetMapSize(int32_t *aNumFields) {
|
||||
NS_ASSERTION(aNumFields != nullptr, "null ptr");
|
||||
if (!aNumFields)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!aNumFields) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aNumFields = m_numFields;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldDescription(int32_t index, char16_t **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldDescription(int32_t index,
|
||||
char16_t **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = nullptr;
|
||||
if ((index < 0) || ((size_t)index >= m_descriptions.Length()))
|
||||
|
@ -111,23 +97,18 @@ NS_IMETHODIMP nsImportFieldMap::GetFieldDescription(int32_t index, char16_t **_r
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldMapSize(int32_t size)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldMapSize(int32_t size) {
|
||||
nsresult rv = Allocate(size);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
m_numFields = size;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::DefaultFieldMap(int32_t size)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::DefaultFieldMap(int32_t size) {
|
||||
nsresult rv = SetFieldMapSize(size);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
m_pFields[i] = i;
|
||||
m_pActive[i] = true;
|
||||
|
@ -136,32 +117,24 @@ NS_IMETHODIMP nsImportFieldMap::DefaultFieldMap(int32_t size)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldMap(int32_t index, int32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldMap(int32_t index, int32_t *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((index < 0) || (index >= m_numFields)) return NS_ERROR_FAILURE;
|
||||
|
||||
*_retval = m_pFields[index];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldMap(int32_t index, int32_t fieldNum)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldMap(int32_t index, int32_t fieldNum) {
|
||||
if (index == -1) {
|
||||
nsresult rv = Allocate(m_numFields + 1);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
index = m_numFields;
|
||||
m_numFields++;
|
||||
}
|
||||
else {
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return NS_ERROR_FAILURE;
|
||||
} else {
|
||||
if ((index < 0) || (index >= m_numFields)) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if ((fieldNum != -1) && ((fieldNum < 0) || (fieldNum >= m_mozFieldCount)))
|
||||
|
@ -171,42 +144,34 @@ NS_IMETHODIMP nsImportFieldMap::SetFieldMap(int32_t index, int32_t fieldNum)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldActive(int32_t index, bool *active)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldActive(int32_t index, bool *active) {
|
||||
NS_ASSERTION(active != nullptr, "null ptr");
|
||||
if (!active)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!active) return NS_ERROR_NULL_POINTER;
|
||||
if ((index < 0) || (index >= m_numFields)) return NS_ERROR_FAILURE;
|
||||
|
||||
*active = m_pActive[index];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldActive(int32_t index, bool active)
|
||||
{
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldActive(int32_t index, bool active) {
|
||||
if ((index < 0) || (index >= m_numFields)) return NS_ERROR_FAILURE;
|
||||
|
||||
m_pActive[index] = active;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database, nsIMdbRow *row, int32_t fieldNum, const char16_t *value)
|
||||
{
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database,
|
||||
nsIMdbRow *row, int32_t fieldNum,
|
||||
const char16_t *value) {
|
||||
NS_ASSERTION(database != nullptr, "null ptr");
|
||||
NS_ASSERTION(row != nullptr, "null ptr");
|
||||
NS_ASSERTION(value != nullptr, "null ptr");
|
||||
if (!database || !row || !value)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!database || !row || !value) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Allow the special value for a null field
|
||||
if (fieldNum == -1)
|
||||
return NS_OK;
|
||||
if (fieldNum == -1) return NS_OK;
|
||||
|
||||
if ((fieldNum < 0) || (fieldNum >= m_mozFieldCount))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((fieldNum < 0) || (fieldNum >= m_mozFieldCount)) return NS_ERROR_FAILURE;
|
||||
|
||||
// UGGG!!!!! lot's of typing here!
|
||||
nsresult rv;
|
||||
|
@ -214,124 +179,122 @@ NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database, nsIMdbR
|
|||
nsString str(value);
|
||||
char *pVal = ToNewUTF8String(str);
|
||||
|
||||
switch(fieldNum) {
|
||||
case 0:
|
||||
rv = database->AddFirstName(row, pVal);
|
||||
break;
|
||||
case 1:
|
||||
rv = database->AddLastName(row, pVal);
|
||||
break;
|
||||
case 2:
|
||||
rv = database->AddDisplayName(row, pVal);
|
||||
break;
|
||||
case 3:
|
||||
rv = database->AddNickName(row, pVal);
|
||||
break;
|
||||
case 4:
|
||||
rv = database->AddPrimaryEmail(row, pVal);
|
||||
break;
|
||||
case 5:
|
||||
rv = database->Add2ndEmail(row, pVal);
|
||||
break;
|
||||
case 6:
|
||||
rv = database->AddWorkPhone(row, pVal);
|
||||
break;
|
||||
case 7:
|
||||
rv = database->AddHomePhone(row, pVal);
|
||||
break;
|
||||
case 8:
|
||||
rv = database->AddFaxNumber(row, pVal);
|
||||
break;
|
||||
case 9:
|
||||
rv = database->AddPagerNumber(row, pVal);
|
||||
break;
|
||||
case 10:
|
||||
rv = database->AddCellularNumber(row, pVal);
|
||||
break;
|
||||
case 11:
|
||||
rv = database->AddHomeAddress(row, pVal);
|
||||
break;
|
||||
case 12:
|
||||
rv = database->AddHomeAddress2(row, pVal);
|
||||
break;
|
||||
case 13:
|
||||
rv = database->AddHomeCity(row, pVal);
|
||||
break;
|
||||
case 14:
|
||||
rv = database->AddHomeState(row, pVal);
|
||||
break;
|
||||
case 15:
|
||||
rv = database->AddHomeZipCode(row, pVal);
|
||||
break;
|
||||
case 16:
|
||||
rv = database->AddHomeCountry(row, pVal);
|
||||
break;
|
||||
case 17:
|
||||
rv = database->AddWorkAddress(row, pVal);
|
||||
break;
|
||||
case 18:
|
||||
rv = database->AddWorkAddress2(row, pVal);
|
||||
break;
|
||||
case 19:
|
||||
rv = database->AddWorkCity(row, pVal);
|
||||
break;
|
||||
case 20:
|
||||
rv = database->AddWorkState(row, pVal);
|
||||
break;
|
||||
case 21:
|
||||
rv = database->AddWorkZipCode(row, pVal);
|
||||
break;
|
||||
case 22:
|
||||
rv = database->AddWorkCountry(row, pVal);
|
||||
break;
|
||||
case 23:
|
||||
rv = database->AddJobTitle(row, pVal);
|
||||
break;
|
||||
case 24:
|
||||
rv = database->AddDepartment(row, pVal);
|
||||
break;
|
||||
case 25:
|
||||
rv = database->AddCompany(row, pVal);
|
||||
break;
|
||||
case 26:
|
||||
rv = database->AddWebPage1(row, pVal);
|
||||
break;
|
||||
case 27:
|
||||
rv = database->AddWebPage2(row, pVal);
|
||||
break;
|
||||
case 28:
|
||||
rv = database->AddBirthYear(row, pVal);
|
||||
break;
|
||||
case 29:
|
||||
rv = database->AddBirthMonth(row, pVal);
|
||||
break;
|
||||
case 30:
|
||||
rv = database->AddBirthDay(row, pVal);
|
||||
break;
|
||||
case 31:
|
||||
rv = database->AddCustom1(row, pVal);
|
||||
break;
|
||||
case 32:
|
||||
rv = database->AddCustom2(row, pVal);
|
||||
break;
|
||||
case 33:
|
||||
rv = database->AddCustom3(row, pVal);
|
||||
break;
|
||||
case 34:
|
||||
rv = database->AddCustom4(row, pVal);
|
||||
break;
|
||||
case 35:
|
||||
rv = database->AddNotes(row, pVal);
|
||||
break;
|
||||
case 36:
|
||||
rv = database->AddAimScreenName(row, pVal);
|
||||
break;
|
||||
default:
|
||||
/* Get the field description, and add it as an anonymous attr? */
|
||||
/* OR WHAT???? */
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
switch (fieldNum) {
|
||||
case 0:
|
||||
rv = database->AddFirstName(row, pVal);
|
||||
break;
|
||||
case 1:
|
||||
rv = database->AddLastName(row, pVal);
|
||||
break;
|
||||
case 2:
|
||||
rv = database->AddDisplayName(row, pVal);
|
||||
break;
|
||||
case 3:
|
||||
rv = database->AddNickName(row, pVal);
|
||||
break;
|
||||
case 4:
|
||||
rv = database->AddPrimaryEmail(row, pVal);
|
||||
break;
|
||||
case 5:
|
||||
rv = database->Add2ndEmail(row, pVal);
|
||||
break;
|
||||
case 6:
|
||||
rv = database->AddWorkPhone(row, pVal);
|
||||
break;
|
||||
case 7:
|
||||
rv = database->AddHomePhone(row, pVal);
|
||||
break;
|
||||
case 8:
|
||||
rv = database->AddFaxNumber(row, pVal);
|
||||
break;
|
||||
case 9:
|
||||
rv = database->AddPagerNumber(row, pVal);
|
||||
break;
|
||||
case 10:
|
||||
rv = database->AddCellularNumber(row, pVal);
|
||||
break;
|
||||
case 11:
|
||||
rv = database->AddHomeAddress(row, pVal);
|
||||
break;
|
||||
case 12:
|
||||
rv = database->AddHomeAddress2(row, pVal);
|
||||
break;
|
||||
case 13:
|
||||
rv = database->AddHomeCity(row, pVal);
|
||||
break;
|
||||
case 14:
|
||||
rv = database->AddHomeState(row, pVal);
|
||||
break;
|
||||
case 15:
|
||||
rv = database->AddHomeZipCode(row, pVal);
|
||||
break;
|
||||
case 16:
|
||||
rv = database->AddHomeCountry(row, pVal);
|
||||
break;
|
||||
case 17:
|
||||
rv = database->AddWorkAddress(row, pVal);
|
||||
break;
|
||||
case 18:
|
||||
rv = database->AddWorkAddress2(row, pVal);
|
||||
break;
|
||||
case 19:
|
||||
rv = database->AddWorkCity(row, pVal);
|
||||
break;
|
||||
case 20:
|
||||
rv = database->AddWorkState(row, pVal);
|
||||
break;
|
||||
case 21:
|
||||
rv = database->AddWorkZipCode(row, pVal);
|
||||
break;
|
||||
case 22:
|
||||
rv = database->AddWorkCountry(row, pVal);
|
||||
break;
|
||||
case 23:
|
||||
rv = database->AddJobTitle(row, pVal);
|
||||
break;
|
||||
case 24:
|
||||
rv = database->AddDepartment(row, pVal);
|
||||
break;
|
||||
case 25:
|
||||
rv = database->AddCompany(row, pVal);
|
||||
break;
|
||||
case 26:
|
||||
rv = database->AddWebPage1(row, pVal);
|
||||
break;
|
||||
case 27:
|
||||
rv = database->AddWebPage2(row, pVal);
|
||||
break;
|
||||
case 28:
|
||||
rv = database->AddBirthYear(row, pVal);
|
||||
break;
|
||||
case 29:
|
||||
rv = database->AddBirthMonth(row, pVal);
|
||||
break;
|
||||
case 30:
|
||||
rv = database->AddBirthDay(row, pVal);
|
||||
break;
|
||||
case 31:
|
||||
rv = database->AddCustom1(row, pVal);
|
||||
break;
|
||||
case 32:
|
||||
rv = database->AddCustom2(row, pVal);
|
||||
break;
|
||||
case 33:
|
||||
rv = database->AddCustom3(row, pVal);
|
||||
break;
|
||||
case 34:
|
||||
rv = database->AddCustom4(row, pVal);
|
||||
break;
|
||||
case 35:
|
||||
rv = database->AddNotes(row, pVal);
|
||||
break;
|
||||
case 36:
|
||||
rv = database->AddAimScreenName(row, pVal);
|
||||
break;
|
||||
default:
|
||||
/* Get the field description, and add it as an anonymous attr? */
|
||||
/* OR WHAT???? */
|
||||
{ rv = NS_ERROR_FAILURE; }
|
||||
}
|
||||
|
||||
free(pVal);
|
||||
|
@ -339,26 +302,21 @@ NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database, nsIMdbR
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsImportFieldMap::Allocate(int32_t newSize)
|
||||
{
|
||||
if (newSize <= m_allocated)
|
||||
return NS_OK;
|
||||
nsresult nsImportFieldMap::Allocate(int32_t newSize) {
|
||||
if (newSize <= m_allocated) return NS_OK;
|
||||
|
||||
int32_t sz = m_allocated;
|
||||
while (sz < newSize)
|
||||
sz += 30;
|
||||
while (sz < newSize) sz += 30;
|
||||
|
||||
int32_t *pData = new int32_t[ sz];
|
||||
if (!pData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
int32_t *pData = new int32_t[sz];
|
||||
if (!pData) return NS_ERROR_OUT_OF_MEMORY;
|
||||
bool *pActive = new bool[sz];
|
||||
if (!pActive) {
|
||||
delete [] pData;
|
||||
delete[] pData;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t i;
|
||||
int32_t i;
|
||||
for (i = 0; i < sz; i++) {
|
||||
pData[i] = -1;
|
||||
pActive[i] = true;
|
||||
|
@ -368,8 +326,8 @@ nsresult nsImportFieldMap::Allocate(int32_t newSize)
|
|||
pData[i] = m_pFields[i];
|
||||
pActive[i] = m_pActive[i];
|
||||
}
|
||||
delete [] m_pFields;
|
||||
delete [] m_pActive;
|
||||
delete[] m_pFields;
|
||||
delete[] m_pActive;
|
||||
}
|
||||
m_allocated = sz;
|
||||
m_pFields = pData;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "nscore.h"
|
||||
#include "nsIImportFieldMap.h"
|
||||
#include "nsIAddrDatabase.h" // For SetFieldValue() arguments
|
||||
#include "nsIAddrDatabase.h" // For SetFieldValue() arguments
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
@ -17,30 +17,29 @@
|
|||
|
||||
class nsIStringBundle;
|
||||
|
||||
class nsImportFieldMap : public nsIImportFieldMap
|
||||
{
|
||||
public:
|
||||
class nsImportFieldMap : public nsIImportFieldMap {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIIMPORTFIELDMAP
|
||||
|
||||
explicit nsImportFieldMap(nsIStringBundle *aBundle);
|
||||
|
||||
static nsresult Create(nsIStringBundle *aBundle, nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
static nsresult Create(nsIStringBundle *aBundle, nsISupports *aOuter,
|
||||
REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsImportFieldMap();
|
||||
nsresult Allocate(int32_t newSize);
|
||||
nsresult Allocate(int32_t newSize);
|
||||
|
||||
private:
|
||||
int32_t m_numFields;
|
||||
int32_t * m_pFields;
|
||||
bool * m_pActive;
|
||||
int32_t m_allocated;
|
||||
nsTArray<nsString*> m_descriptions;
|
||||
int32_t m_mozFieldCount;
|
||||
bool m_skipFirstRecord;
|
||||
private:
|
||||
int32_t m_numFields;
|
||||
int32_t *m_pFields;
|
||||
bool *m_pActive;
|
||||
int32_t m_allocated;
|
||||
nsTArray<nsString *> m_descriptions;
|
||||
int32_t m_mozFieldCount;
|
||||
bool m_skipFirstRecord;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -3,19 +3,15 @@
|
|||
* 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 "nscore.h"
|
||||
#include "nsImportMailboxDescriptor.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
nsresult nsImportMailboxDescriptor::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsresult nsImportMailboxDescriptor::Create(nsISupports *aOuter, REFNSIID aIID,
|
||||
void **aResult) {
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
RefPtr<nsImportMailboxDescriptor> it = new nsImportMailboxDescriptor();
|
||||
return it->QueryInterface(aIID, aResult);
|
||||
|
@ -23,11 +19,10 @@ nsresult nsImportMailboxDescriptor::Create(nsISupports *aOuter, REFNSIID aIID, v
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsImportMailboxDescriptor, nsIImportMailboxDescriptor)
|
||||
|
||||
nsImportMailboxDescriptor::nsImportMailboxDescriptor()
|
||||
{
|
||||
nsImportMailboxDescriptor::nsImportMailboxDescriptor() {
|
||||
m_import = true;
|
||||
m_size = 0;
|
||||
m_depth = 0;
|
||||
m_id = 0;
|
||||
m_pFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
m_pFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
}
|
||||
|
|
|
@ -15,49 +15,80 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class nsImportMailboxDescriptor : public nsIImportMailboxDescriptor
|
||||
{
|
||||
public:
|
||||
class nsImportMailboxDescriptor : public nsIImportMailboxDescriptor {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetIdentifier(uint32_t *pIdentifier) override { *pIdentifier = m_id; return NS_OK;}
|
||||
NS_IMETHOD SetIdentifier(uint32_t ident) override { m_id = ident; return NS_OK;}
|
||||
NS_IMETHOD GetIdentifier(uint32_t *pIdentifier) override {
|
||||
*pIdentifier = m_id;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetIdentifier(uint32_t ident) override {
|
||||
m_id = ident;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute unsigned long depth; */
|
||||
NS_IMETHOD GetDepth(uint32_t *pDepth) override { *pDepth = m_depth; return NS_OK;}
|
||||
NS_IMETHOD SetDepth(uint32_t theDepth) override { m_depth = theDepth; return NS_OK;}
|
||||
NS_IMETHOD GetDepth(uint32_t *pDepth) override {
|
||||
*pDepth = m_depth;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetDepth(uint32_t theDepth) override {
|
||||
m_depth = theDepth;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute unsigned long size; */
|
||||
NS_IMETHOD GetSize(uint32_t *pSize) override { *pSize = m_size; return NS_OK;}
|
||||
NS_IMETHOD SetSize(uint32_t theSize) override { m_size = theSize; return NS_OK;}
|
||||
NS_IMETHOD GetSize(uint32_t *pSize) override {
|
||||
*pSize = m_size;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetSize(uint32_t theSize) override {
|
||||
m_size = theSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute wstring displayName; */
|
||||
NS_IMETHOD GetDisplayName(char16_t **pName) override { *pName = ToNewUnicode(m_displayName); return NS_OK;}
|
||||
NS_IMETHOD SetDisplayName(const char16_t * pName) override { m_displayName = pName; return NS_OK;}
|
||||
NS_IMETHOD GetDisplayName(char16_t **pName) override {
|
||||
*pName = ToNewUnicode(m_displayName);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetDisplayName(const char16_t *pName) override {
|
||||
m_displayName = pName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute boolean import; */
|
||||
NS_IMETHOD GetImport(bool *pImport) override { *pImport = m_import; return NS_OK;}
|
||||
NS_IMETHOD SetImport(bool doImport) override { m_import = doImport; return NS_OK;}
|
||||
NS_IMETHOD GetImport(bool *pImport) override {
|
||||
*pImport = m_import;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetImport(bool doImport) override {
|
||||
m_import = doImport;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIFile file; */
|
||||
NS_IMETHOD GetFile(nsIFile * *aFile) override { if (m_pFile) { NS_ADDREF(*aFile = m_pFile); return NS_OK;} else return NS_ERROR_FAILURE; }
|
||||
|
||||
|
||||
NS_IMETHOD GetFile(nsIFile **aFile) override {
|
||||
if (m_pFile) {
|
||||
NS_ADDREF(*aFile = m_pFile);
|
||||
return NS_OK;
|
||||
} else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsImportMailboxDescriptor();
|
||||
|
||||
static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsImportMailboxDescriptor() {}
|
||||
uint32_t m_id; // used by creator of the structure
|
||||
uint32_t m_depth; // depth in the hierarchy
|
||||
nsString m_displayName;// name of this mailbox
|
||||
nsCOMPtr <nsIFile> m_pFile; // source file (if applicable)
|
||||
uint32_t m_size;
|
||||
bool m_import; // import it or not?
|
||||
uint32_t m_id; // used by creator of the structure
|
||||
uint32_t m_depth; // depth in the hierarchy
|
||||
nsString m_displayName; // name of this mailbox
|
||||
nsCOMPtr<nsIFile> m_pFile; // source file (if applicable)
|
||||
uint32_t m_size;
|
||||
bool m_import; // import it or not?
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,28 +9,25 @@
|
|||
#include "ImportCharSet.h"
|
||||
#include "ImportTranslate.h"
|
||||
|
||||
#define kNoState 0
|
||||
#define kStartState 1
|
||||
#define kEncodeState 2
|
||||
#define kDoneState 3
|
||||
#define kNoState 0
|
||||
#define kStartState 1
|
||||
#define kEncodeState 2
|
||||
#define kDoneState 3
|
||||
|
||||
#define kEncodeBufferSz (8192 * 8)
|
||||
#define kEncodeBufferSz (8192 * 8)
|
||||
|
||||
nsImportMimeEncode::nsImportMimeEncode()
|
||||
{
|
||||
nsImportMimeEncode::nsImportMimeEncode() {
|
||||
m_pOut = nullptr;
|
||||
m_state = kNoState;
|
||||
m_bytesProcessed = 0;
|
||||
m_pInputBuf = nullptr;
|
||||
}
|
||||
|
||||
nsImportMimeEncode::~nsImportMimeEncode()
|
||||
{
|
||||
delete [] m_pInputBuf;
|
||||
}
|
||||
nsImportMimeEncode::~nsImportMimeEncode() { delete[] m_pInputBuf; }
|
||||
|
||||
void nsImportMimeEncode::EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const char *pFileName, const char *pMimeType)
|
||||
{
|
||||
void nsImportMimeEncode::EncodeFile(nsIFile *pInFile, ImportOutFile *pOut,
|
||||
const char *pFileName,
|
||||
const char *pMimeType) {
|
||||
m_fileName = pFileName;
|
||||
m_mimeType = pMimeType;
|
||||
|
||||
|
@ -40,14 +37,10 @@ void nsImportMimeEncode::EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const
|
|||
m_state = kStartState;
|
||||
}
|
||||
|
||||
void nsImportMimeEncode::CleanUp(void)
|
||||
{
|
||||
CleanUpEncodeScan();
|
||||
}
|
||||
void nsImportMimeEncode::CleanUp(void) { CleanUpEncodeScan(); }
|
||||
|
||||
bool nsImportMimeEncode::SetUpEncode(void)
|
||||
{
|
||||
nsCString errStr;
|
||||
bool nsImportMimeEncode::SetUpEncode(void) {
|
||||
nsCString errStr;
|
||||
if (!m_pInputBuf) {
|
||||
m_pInputBuf = new uint8_t[kEncodeBufferSz];
|
||||
}
|
||||
|
@ -66,7 +59,8 @@ bool nsImportMimeEncode::SetUpEncode(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!InitEncodeScan(m_appleSingle, m_pMimeFile, m_fileName.get(), m_pInputBuf, kEncodeBufferSz)) {
|
||||
if (!InitEncodeScan(m_appleSingle, m_pMimeFile, m_fileName.get(), m_pInputBuf,
|
||||
kEncodeBufferSz)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -76,47 +70,35 @@ bool nsImportMimeEncode::SetUpEncode(void)
|
|||
// Write out the boundary header
|
||||
bool bResult = true;
|
||||
bResult = m_pOut->WriteStr("Content-type: ");
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr(m_mimeType.get());
|
||||
if (bResult) bResult = m_pOut->WriteStr(m_mimeType.get());
|
||||
|
||||
#ifdef _MAC_IMPORT_CODE
|
||||
// include the type an creator here
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr("; x-mac-type=\"");
|
||||
U8 hex[8];
|
||||
if (bResult) bResult = m_pOut->WriteStr("; x-mac-type=\"");
|
||||
U8 hex[8];
|
||||
LongToHexBytes(m_filePath.GetFileType(), hex);
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteData(hex, 8);
|
||||
if (bResult) bResult = m_pOut->WriteData(hex, 8);
|
||||
LongToHexBytes(m_filePath.GetFileCreator(), hex);
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr("\"; x-mac-creator=\"");
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteData(hex, 8);
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr("\"");
|
||||
if (bResult) bResult = m_pOut->WriteStr("\"; x-mac-creator=\"");
|
||||
if (bResult) bResult = m_pOut->WriteData(hex, 8);
|
||||
if (bResult) bResult = m_pOut->WriteStr("\"");
|
||||
#endif
|
||||
|
||||
/*
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr(gMimeTypeFileName);
|
||||
*/
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr(";\x0D\x0A");
|
||||
if (bResult) bResult = m_pOut->WriteStr(";\x0D\x0A");
|
||||
|
||||
nsCString fName;
|
||||
bool trans = TranslateFileName(m_fileName, fName);
|
||||
if (bResult)
|
||||
bResult = WriteFileName(fName, trans, "name");
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr("Content-transfer-encoding: base64");
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteEol();
|
||||
nsCString fName;
|
||||
bool trans = TranslateFileName(m_fileName, fName);
|
||||
if (bResult) bResult = WriteFileName(fName, trans, "name");
|
||||
if (bResult) bResult = m_pOut->WriteStr("Content-transfer-encoding: base64");
|
||||
if (bResult) bResult = m_pOut->WriteEol();
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteStr("Content-Disposition: attachment;\x0D\x0A");
|
||||
if (bResult)
|
||||
bResult = WriteFileName(fName, trans, "filename");
|
||||
if (bResult)
|
||||
bResult = m_pOut->WriteEol();
|
||||
if (bResult) bResult = WriteFileName(fName, trans, "filename");
|
||||
if (bResult) bResult = m_pOut->WriteEol();
|
||||
|
||||
if (!bResult) {
|
||||
CleanUp();
|
||||
|
@ -125,64 +107,60 @@ bool nsImportMimeEncode::SetUpEncode(void)
|
|||
return bResult;
|
||||
}
|
||||
|
||||
bool nsImportMimeEncode::DoWork(bool *pDone)
|
||||
{
|
||||
bool nsImportMimeEncode::DoWork(bool *pDone) {
|
||||
*pDone = false;
|
||||
switch(m_state) {
|
||||
case kNoState:
|
||||
return false;
|
||||
break;
|
||||
case kStartState:
|
||||
return SetUpEncode();
|
||||
break;
|
||||
case kEncodeState:
|
||||
if (!Scan(pDone)) {
|
||||
CleanUp();
|
||||
switch (m_state) {
|
||||
case kNoState:
|
||||
return false;
|
||||
}
|
||||
if (*pDone) {
|
||||
*pDone = false;
|
||||
m_state = kDoneState;
|
||||
}
|
||||
break;
|
||||
case kDoneState:
|
||||
CleanUp();
|
||||
m_state = kNoState;
|
||||
*pDone = true;
|
||||
break;
|
||||
break;
|
||||
case kStartState:
|
||||
return SetUpEncode();
|
||||
break;
|
||||
case kEncodeState:
|
||||
if (!Scan(pDone)) {
|
||||
CleanUp();
|
||||
return false;
|
||||
}
|
||||
if (*pDone) {
|
||||
*pDone = false;
|
||||
m_state = kDoneState;
|
||||
}
|
||||
break;
|
||||
case kDoneState:
|
||||
CleanUp();
|
||||
m_state = kNoState;
|
||||
*pDone = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint8_t gBase64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static uint8_t gBase64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
bool nsImportMimeEncode::ScanBuffer(bool *pDone)
|
||||
{
|
||||
|
||||
uint32_t pos = m_pos;
|
||||
uint32_t start = pos;
|
||||
uint8_t * pChar = m_pBuf + pos;
|
||||
uint32_t max = m_bytesInBuf;
|
||||
uint8_t byte[4];
|
||||
uint32_t lineLen = m_lineLen;
|
||||
bool nsImportMimeEncode::ScanBuffer(bool *pDone) {
|
||||
uint32_t pos = m_pos;
|
||||
uint32_t start = pos;
|
||||
uint8_t *pChar = m_pBuf + pos;
|
||||
uint32_t max = m_bytesInBuf;
|
||||
uint8_t byte[4];
|
||||
uint32_t lineLen = m_lineLen;
|
||||
|
||||
while ((pos + 2) < max) {
|
||||
// Encode 3 bytes
|
||||
byte[0] = gBase64[*pChar >> 2];
|
||||
byte[1] = gBase64[(((*pChar) & 0x3)<< 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
|
||||
byte[1] = gBase64[(((*pChar) & 0x3) << 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
|
||||
pChar++;
|
||||
byte[2] = gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >>6)];
|
||||
byte[2] = gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >> 6)];
|
||||
pChar++;
|
||||
byte[3] = gBase64[(*pChar) & 0x3F];
|
||||
if (!m_pOut->WriteData(byte, 4))
|
||||
return false;
|
||||
if (!m_pOut->WriteData(byte, 4)) return false;
|
||||
pos += 3;
|
||||
pChar++;
|
||||
lineLen += 4;
|
||||
if (lineLen > 71) {
|
||||
if (!m_pOut->WriteEol())
|
||||
return false;
|
||||
if (!m_pOut->WriteEol()) return false;
|
||||
lineLen = 0;
|
||||
}
|
||||
}
|
||||
|
@ -192,56 +170,51 @@ bool nsImportMimeEncode::ScanBuffer(bool *pDone)
|
|||
byte[0] = gBase64[*pChar >> 2];
|
||||
pos++;
|
||||
if (pos < max) {
|
||||
byte[1] = gBase64[(((*pChar) & 0x3)<< 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
|
||||
byte[1] =
|
||||
gBase64[(((*pChar) & 0x3) << 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
|
||||
pChar++;
|
||||
pos++;
|
||||
if (pos < max) {
|
||||
// Should be dead code!! (Then why is it here doofus?)
|
||||
byte[2] = gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >>6)];
|
||||
byte[2] =
|
||||
gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >> 6)];
|
||||
pChar++;
|
||||
byte[3] = gBase64[(*pChar) & 0x3F];
|
||||
pos++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
byte[2] = gBase64[(((*pChar) & 0xF) << 2)];
|
||||
byte[3] = '=';
|
||||
}
|
||||
}
|
||||
else {
|
||||
byte[1] = gBase64[(((*pChar) & 0x3)<< 4)];
|
||||
} else {
|
||||
byte[1] = gBase64[(((*pChar) & 0x3) << 4)];
|
||||
byte[2] = '=';
|
||||
byte[3] = '=';
|
||||
}
|
||||
|
||||
if (!m_pOut->WriteData(byte, 4))
|
||||
return false;
|
||||
if (!m_pOut->WriteEol())
|
||||
return false;
|
||||
}
|
||||
else if (m_eof) {
|
||||
if (!m_pOut->WriteData(byte, 4)) return false;
|
||||
if (!m_pOut->WriteEol()) return false;
|
||||
} else if (m_eof) {
|
||||
/*
|
||||
byte[0] = '=';
|
||||
if (!m_pOut->WriteData(byte, 1))
|
||||
return FALSE;
|
||||
*/
|
||||
if (!m_pOut->WriteEol())
|
||||
return false;
|
||||
if (!m_pOut->WriteEol()) return false;
|
||||
}
|
||||
|
||||
m_lineLen = (int) lineLen;
|
||||
m_lineLen = (int)lineLen;
|
||||
m_pos = pos;
|
||||
m_bytesProcessed += (pos - start);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nsImportMimeEncode::TranslateFileName(nsCString& inFile, nsCString& outFile)
|
||||
{
|
||||
const uint8_t * pIn = (const uint8_t *) inFile.get();
|
||||
int len = inFile.Length();
|
||||
bool nsImportMimeEncode::TranslateFileName(nsCString &inFile,
|
||||
nsCString &outFile) {
|
||||
const uint8_t *pIn = (const uint8_t *)inFile.get();
|
||||
int len = inFile.Length();
|
||||
|
||||
while (len) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn))
|
||||
break;
|
||||
if (!ImportCharSet::IsUSAscii(*pIn)) break;
|
||||
len--;
|
||||
pIn++;
|
||||
}
|
||||
|
@ -251,24 +224,22 @@ bool nsImportMimeEncode::TranslateFileName(nsCString& inFile, nsCString& outFile
|
|||
if (!ImportTranslate::ConvertString(inFile, outFile, true)) {
|
||||
outFile = inFile;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
outFile = inFile;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool nsImportMimeEncode::WriteFileName(nsCString& fName, bool wasTrans, const char *pTag)
|
||||
{
|
||||
int tagNum = 0;
|
||||
int idx = 0;
|
||||
bool result = true;
|
||||
int len;
|
||||
nsCString numStr;
|
||||
bool nsImportMimeEncode::WriteFileName(nsCString &fName, bool wasTrans,
|
||||
const char *pTag) {
|
||||
int tagNum = 0;
|
||||
int idx = 0;
|
||||
bool result = true;
|
||||
int len;
|
||||
nsCString numStr;
|
||||
|
||||
while ((((fName.Length() - idx) + strlen(pTag)) > 70) && result) {
|
||||
len = 68 - strlen(pTag) - 5;
|
||||
|
@ -279,14 +250,11 @@ bool nsImportMimeEncode::WriteFileName(nsCString& fName, bool wasTrans, const ch
|
|||
len -= 2;
|
||||
}
|
||||
|
||||
if (result)
|
||||
result = m_pOut->WriteStr("\x09");
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(pTag);
|
||||
if (result) result = m_pOut->WriteStr("\x09");
|
||||
if (result) result = m_pOut->WriteStr(pTag);
|
||||
numStr = "*";
|
||||
numStr.AppendInt(tagNum);
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(numStr.get());
|
||||
if (result) result = m_pOut->WriteStr(numStr.get());
|
||||
if (wasTrans && result)
|
||||
result = m_pOut->WriteStr("*=");
|
||||
else if (result)
|
||||
|
@ -303,37 +271,31 @@ bool nsImportMimeEncode::WriteFileName(nsCString& fName, bool wasTrans, const ch
|
|||
|
||||
if (idx) {
|
||||
if ((fName.Length() - idx) > 0) {
|
||||
if (result)
|
||||
result = m_pOut->WriteStr("\x09");
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(pTag);
|
||||
if (result) result = m_pOut->WriteStr("\x09");
|
||||
if (result) result = m_pOut->WriteStr(pTag);
|
||||
numStr = "*";
|
||||
numStr.AppendInt(tagNum);
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(numStr.get());
|
||||
if (result) result = m_pOut->WriteStr(numStr.get());
|
||||
if (wasTrans && result)
|
||||
result = m_pOut->WriteStr("*=");
|
||||
else if (result)
|
||||
result = m_pOut->WriteStr("=\"");
|
||||
if (result)
|
||||
result = m_pOut->WriteData(((const uint8_t *)fName.get()) + idx, fName.Length() - idx);
|
||||
result = m_pOut->WriteData(((const uint8_t *)fName.get()) + idx,
|
||||
fName.Length() - idx);
|
||||
if (wasTrans && result)
|
||||
result = m_pOut->WriteStr("\x0D\x0A");
|
||||
else if (result)
|
||||
result = m_pOut->WriteStr("\"\x0D\x0A");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (result)
|
||||
result = m_pOut->WriteStr("\x09");
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(pTag);
|
||||
} else {
|
||||
if (result) result = m_pOut->WriteStr("\x09");
|
||||
if (result) result = m_pOut->WriteStr(pTag);
|
||||
if (wasTrans && result)
|
||||
result = m_pOut->WriteStr("*=");
|
||||
else if (result)
|
||||
result = m_pOut->WriteStr("=\"");
|
||||
if (result)
|
||||
result = m_pOut->WriteStr(fName.get());
|
||||
if (result) result = m_pOut->WriteStr(fName.get());
|
||||
if (wasTrans && result)
|
||||
result = m_pOut->WriteStr("\x0D\x0A");
|
||||
else if (result)
|
||||
|
@ -341,35 +303,30 @@ bool nsImportMimeEncode::WriteFileName(nsCString& fName, bool wasTrans, const ch
|
|||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
nsIImportMimeEncodeImpl::nsIImportMimeEncodeImpl()
|
||||
{
|
||||
nsIImportMimeEncodeImpl::nsIImportMimeEncodeImpl() {
|
||||
m_pOut = nullptr;
|
||||
m_pEncode = nullptr;
|
||||
}
|
||||
|
||||
nsIImportMimeEncodeImpl::~nsIImportMimeEncodeImpl()
|
||||
{
|
||||
if (m_pOut)
|
||||
delete m_pOut;
|
||||
if (m_pEncode)
|
||||
delete m_pEncode;
|
||||
nsIImportMimeEncodeImpl::~nsIImportMimeEncodeImpl() {
|
||||
if (m_pOut) delete m_pOut;
|
||||
if (m_pEncode) delete m_pEncode;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsIImportMimeEncodeImpl, nsIImportMimeEncode)
|
||||
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::EncodeFile(nsIFile *inFile, nsIFile *outFile, const char *fileName, const char *mimeType)
|
||||
{
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::EncodeFile(nsIFile *inFile,
|
||||
nsIFile *outFile,
|
||||
const char *fileName,
|
||||
const char *mimeType) {
|
||||
return Initialize(inFile, outFile, fileName, mimeType);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::DoWork(bool *done, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::DoWork(bool *done, bool *_retval) {
|
||||
if (done && _retval && m_pEncode) {
|
||||
*_retval = m_pEncode->DoWork(done);
|
||||
return NS_OK;
|
||||
|
@ -377,26 +334,26 @@ NS_IMETHODIMP nsIImportMimeEncodeImpl::DoWork(bool *done, bool *_retval)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::NumBytesProcessed(int32_t *_retval)
|
||||
{
|
||||
if (m_pEncode && _retval)
|
||||
*_retval = m_pEncode->NumBytesProcessed();
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::NumBytesProcessed(int32_t *_retval) {
|
||||
if (m_pEncode && _retval) *_retval = m_pEncode->NumBytesProcessed();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::DoEncoding(bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::DoEncoding(bool *_retval) {
|
||||
if (_retval && m_pEncode) {
|
||||
bool done = false;
|
||||
while (m_pEncode->DoWork(&done) && !done);
|
||||
bool done = false;
|
||||
while (m_pEncode->DoWork(&done) && !done)
|
||||
;
|
||||
*_retval = done;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::Initialize(nsIFile *inFile, nsIFile *outFile, const char *fileName, const char *mimeType)
|
||||
{
|
||||
NS_IMETHODIMP nsIImportMimeEncodeImpl::Initialize(nsIFile *inFile,
|
||||
nsIFile *outFile,
|
||||
const char *fileName,
|
||||
const char *mimeType) {
|
||||
delete m_pEncode;
|
||||
delete m_pOut;
|
||||
|
||||
|
@ -408,4 +365,3 @@ NS_IMETHODIMP nsIImportMimeEncodeImpl::Initialize(nsIFile *inFile, nsIFile *outF
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,62 +12,61 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIImportMimeEncode.h"
|
||||
|
||||
|
||||
// Content-Type: image/gif; name="blah.xyz"
|
||||
// Content-Transfer-Encoding: base64
|
||||
// Content-Disposition: attachment; filename="blah.xyz"
|
||||
|
||||
class nsImportMimeEncode : public nsImportEncodeScan {
|
||||
public:
|
||||
public:
|
||||
nsImportMimeEncode();
|
||||
~nsImportMimeEncode();
|
||||
|
||||
void EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const char *pFileName, const char *pMimeType);
|
||||
void EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const char *pFileName,
|
||||
const char *pMimeType);
|
||||
|
||||
bool DoWork(bool *pDone);
|
||||
|
||||
long NumBytesProcessed(void) { long val = m_bytesProcessed; m_bytesProcessed = 0; return val;}
|
||||
long NumBytesProcessed(void) {
|
||||
long val = m_bytesProcessed;
|
||||
m_bytesProcessed = 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void CleanUp(void);
|
||||
bool SetUpEncode(void);
|
||||
bool WriteFileName(nsCString& fName, bool wasTrans, const char *pTag);
|
||||
bool TranslateFileName(nsCString& inFile, nsCString& outFile);
|
||||
|
||||
bool WriteFileName(nsCString &fName, bool wasTrans, const char *pTag);
|
||||
bool TranslateFileName(nsCString &inFile, nsCString &outFile);
|
||||
|
||||
virtual bool ScanBuffer(bool *pDone) override;
|
||||
|
||||
protected:
|
||||
nsCString m_fileName;
|
||||
nsCOMPtr<nsIFile> m_pMimeFile;
|
||||
ImportOutFile *m_pOut;
|
||||
nsCString m_mimeType;
|
||||
|
||||
protected:
|
||||
nsCString m_fileName;
|
||||
nsCOMPtr <nsIFile> m_pMimeFile;
|
||||
ImportOutFile * m_pOut;
|
||||
nsCString m_mimeType;
|
||||
int m_state;
|
||||
long m_bytesProcessed;
|
||||
uint8_t *m_pInputBuf;
|
||||
bool m_appleSingle;
|
||||
|
||||
int m_state;
|
||||
long m_bytesProcessed;
|
||||
uint8_t * m_pInputBuf;
|
||||
bool m_appleSingle;
|
||||
|
||||
// Actual encoding variables
|
||||
int m_lineLen;
|
||||
int m_lineLen;
|
||||
};
|
||||
|
||||
|
||||
class nsIImportMimeEncodeImpl : public nsIImportMimeEncode {
|
||||
public:
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIIMPORTMIMEENCODE
|
||||
|
||||
nsIImportMimeEncodeImpl();
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsIImportMimeEncodeImpl();
|
||||
ImportOutFile * m_pOut;
|
||||
nsImportMimeEncode * m_pEncode;
|
||||
ImportOutFile *m_pOut;
|
||||
nsImportMimeEncode *m_pEncode;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsImportMimeEncode_h__ */
|
||||
|
||||
|
|
|
@ -7,21 +7,18 @@
|
|||
#include "nsImportScanFile.h"
|
||||
#include "ImportCharSet.h"
|
||||
|
||||
nsImportScanFile::nsImportScanFile()
|
||||
{
|
||||
nsImportScanFile::nsImportScanFile() {
|
||||
m_allocated = false;
|
||||
m_eof = false;
|
||||
m_pBuf = nullptr;
|
||||
}
|
||||
|
||||
nsImportScanFile::~nsImportScanFile()
|
||||
{
|
||||
if (m_allocated)
|
||||
CleanUpScan();
|
||||
nsImportScanFile::~nsImportScanFile() {
|
||||
if (m_allocated) CleanUpScan();
|
||||
}
|
||||
|
||||
void nsImportScanFile::InitScan(nsIInputStream *pInputStream, uint8_t * pBuf, uint32_t sz)
|
||||
{
|
||||
void nsImportScanFile::InitScan(nsIInputStream *pInputStream, uint8_t *pBuf,
|
||||
uint32_t sz) {
|
||||
m_pInputStream = pInputStream;
|
||||
m_pBuf = pBuf;
|
||||
m_bufSz = sz;
|
||||
|
@ -29,27 +26,26 @@ void nsImportScanFile::InitScan(nsIInputStream *pInputStream, uint8_t * pBuf, ui
|
|||
m_pos = 0;
|
||||
}
|
||||
|
||||
void nsImportScanFile::CleanUpScan(void)
|
||||
{
|
||||
void nsImportScanFile::CleanUpScan(void) {
|
||||
m_pInputStream = nullptr;
|
||||
if (m_allocated) {
|
||||
delete [] m_pBuf;
|
||||
delete[] m_pBuf;
|
||||
m_pBuf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void nsImportScanFile::ShiftBuffer(void)
|
||||
{
|
||||
uint8_t * pTop;
|
||||
uint8_t * pCurrent;
|
||||
void nsImportScanFile::ShiftBuffer(void) {
|
||||
uint8_t *pTop;
|
||||
uint8_t *pCurrent;
|
||||
|
||||
if (m_pos < m_bytesInBuf) {
|
||||
pTop = m_pBuf;
|
||||
pCurrent = pTop + m_pos;
|
||||
uint32_t cnt = m_bytesInBuf - m_pos;
|
||||
uint32_t cnt = m_bytesInBuf - m_pos;
|
||||
while (cnt) {
|
||||
*pTop = *pCurrent;
|
||||
pTop++; pCurrent++;
|
||||
pTop++;
|
||||
pCurrent++;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
@ -58,102 +54,90 @@ void nsImportScanFile::ShiftBuffer(void)
|
|||
m_pos = 0;
|
||||
}
|
||||
|
||||
bool nsImportScanFile::FillBufferFromFile(void)
|
||||
{
|
||||
bool nsImportScanFile::FillBufferFromFile(void) {
|
||||
uint64_t available;
|
||||
nsresult rv = m_pInputStream->Available(&available);
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
|
||||
// Fill up a buffer and scan it
|
||||
ShiftBuffer();
|
||||
|
||||
// Read in some more bytes
|
||||
uint32_t cnt = m_bufSz - m_bytesInBuf;
|
||||
uint32_t cnt = m_bufSz - m_bytesInBuf;
|
||||
// To distinguish from disk errors
|
||||
// Check first for end of file?
|
||||
// Set a done flag if true...
|
||||
uint32_t read;
|
||||
char *pBuf = (char *)m_pBuf;
|
||||
pBuf += m_bytesInBuf;
|
||||
rv = m_pInputStream->Read(pBuf, (int32_t) cnt, &read);
|
||||
rv = m_pInputStream->Read(pBuf, (int32_t)cnt, &read);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return false;
|
||||
if (NS_FAILED(rv)) return false;
|
||||
rv = m_pInputStream->Available(&available);
|
||||
if (NS_FAILED(rv))
|
||||
m_eof = true;
|
||||
if (NS_FAILED(rv)) m_eof = true;
|
||||
|
||||
m_bytesInBuf += cnt;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nsImportScanFile::Scan(bool *pDone)
|
||||
{
|
||||
bool nsImportScanFile::Scan(bool *pDone) {
|
||||
uint64_t available;
|
||||
nsresult rv = m_pInputStream->Available(&available);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
if (m_pos < m_bytesInBuf)
|
||||
ScanBuffer(pDone);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (m_pos < m_bytesInBuf) ScanBuffer(pDone);
|
||||
*pDone = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fill up a buffer and scan it
|
||||
if (!FillBufferFromFile())
|
||||
return false;
|
||||
if (!FillBufferFromFile()) return false;
|
||||
|
||||
return ScanBuffer(pDone);
|
||||
}
|
||||
|
||||
bool nsImportScanFile::ScanBuffer(bool *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool nsImportScanFile::ScanBuffer(bool *) { return true; }
|
||||
|
||||
|
||||
bool nsImportScanFileLines::ScanBuffer(bool *pDone)
|
||||
{
|
||||
bool nsImportScanFileLines::ScanBuffer(bool *pDone) {
|
||||
// m_pos, m_bytesInBuf, m_eof, m_pBuf are relevant
|
||||
|
||||
uint32_t pos = m_pos;
|
||||
uint32_t max = m_bytesInBuf;
|
||||
uint8_t * pChar = m_pBuf + pos;
|
||||
uint32_t startPos;
|
||||
uint32_t pos = m_pos;
|
||||
uint32_t max = m_bytesInBuf;
|
||||
uint8_t *pChar = m_pBuf + pos;
|
||||
uint32_t startPos;
|
||||
|
||||
while (pos < max) {
|
||||
if (m_needEol) {
|
||||
// Find the next eol...
|
||||
while ((pos < max) && (*pChar != ImportCharSet::cCRChar) && (*pChar != ImportCharSet::cLinefeedChar)) {
|
||||
while ((pos < max) && (*pChar != ImportCharSet::cCRChar) &&
|
||||
(*pChar != ImportCharSet::cLinefeedChar)) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
m_pos = pos;
|
||||
if (pos < max)
|
||||
m_needEol = false;
|
||||
if (pos == max) // need more buffer for an end of line
|
||||
if (pos < max) m_needEol = false;
|
||||
if (pos == max) // need more buffer for an end of line
|
||||
break;
|
||||
}
|
||||
// Skip past any eol characters
|
||||
while ((pos < max) && ((*pChar == ImportCharSet::cCRChar) || (*pChar == ImportCharSet::cLinefeedChar))) {
|
||||
while ((pos < max) && ((*pChar == ImportCharSet::cCRChar) ||
|
||||
(*pChar == ImportCharSet::cLinefeedChar))) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
m_pos = pos;
|
||||
if (pos == max)
|
||||
break;
|
||||
if (pos == max) break;
|
||||
// Make sure we can find either the eof or the
|
||||
// next end of line
|
||||
startPos = pos;
|
||||
while ((pos < max) && (*pChar != ImportCharSet::cCRChar) && (*pChar != ImportCharSet::cLinefeedChar)) {
|
||||
while ((pos < max) && (*pChar != ImportCharSet::cCRChar) &&
|
||||
(*pChar != ImportCharSet::cLinefeedChar)) {
|
||||
pos++;
|
||||
pChar++;
|
||||
}
|
||||
|
||||
// Is line too big for our buffer?
|
||||
if ((pos == max) && !m_eof) {
|
||||
if (!m_pos) { // line too big for our buffer
|
||||
if (!m_pos) { // line too big for our buffer
|
||||
m_pos = pos;
|
||||
m_needEol = true;
|
||||
}
|
||||
|
@ -168,4 +152,3 @@ bool nsImportScanFileLines::ScanBuffer(bool *pDone)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,45 +11,46 @@
|
|||
#include "nsIInputStream.h"
|
||||
|
||||
class nsImportScanFile {
|
||||
public:
|
||||
public:
|
||||
nsImportScanFile();
|
||||
virtual ~nsImportScanFile();
|
||||
|
||||
void InitScan(nsIInputStream *pInputStream, uint8_t * pBuf, uint32_t sz);
|
||||
void InitScan(nsIInputStream *pInputStream, uint8_t *pBuf, uint32_t sz);
|
||||
|
||||
void CleanUpScan(void);
|
||||
void CleanUpScan(void);
|
||||
|
||||
virtual bool Scan(bool *pDone);
|
||||
virtual bool Scan(bool *pDone);
|
||||
|
||||
protected:
|
||||
void ShiftBuffer(void);
|
||||
bool FillBufferFromFile(void);
|
||||
virtual bool ScanBuffer(bool *pDone);
|
||||
protected:
|
||||
void ShiftBuffer(void);
|
||||
bool FillBufferFromFile(void);
|
||||
virtual bool ScanBuffer(bool *pDone);
|
||||
|
||||
protected:
|
||||
nsCOMPtr <nsIInputStream> m_pInputStream;
|
||||
uint8_t * m_pBuf;
|
||||
uint32_t m_bufSz;
|
||||
uint32_t m_bytesInBuf;
|
||||
uint32_t m_pos;
|
||||
bool m_eof;
|
||||
bool m_allocated;
|
||||
protected:
|
||||
nsCOMPtr<nsIInputStream> m_pInputStream;
|
||||
uint8_t *m_pBuf;
|
||||
uint32_t m_bufSz;
|
||||
uint32_t m_bytesInBuf;
|
||||
uint32_t m_pos;
|
||||
bool m_eof;
|
||||
bool m_allocated;
|
||||
};
|
||||
|
||||
class nsImportScanFileLines : public nsImportScanFile {
|
||||
public:
|
||||
nsImportScanFileLines() {m_needEol = false;}
|
||||
public:
|
||||
nsImportScanFileLines() { m_needEol = false; }
|
||||
|
||||
void ResetLineScan(void) { m_needEol = false;}
|
||||
void ResetLineScan(void) { m_needEol = false; }
|
||||
|
||||
virtual bool ProcessLine(uint8_t * /* pLine */, uint32_t /* len */, bool * /* pDone */) {return true;}
|
||||
virtual bool ProcessLine(uint8_t * /* pLine */, uint32_t /* len */,
|
||||
bool * /* pDone */) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool ScanBuffer(bool *pDone) override;
|
||||
|
||||
bool m_needEol;
|
||||
protected:
|
||||
virtual bool ScanBuffer(bool *pDone) override;
|
||||
|
||||
bool m_needEol;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsImportScanFile_h__ */
|
||||
|
|
|
@ -30,133 +30,116 @@
|
|||
|
||||
mozilla::LazyLogModule IMPORTLOGMODULE("Import");
|
||||
|
||||
static nsIImportService * gImportService = nullptr;
|
||||
static const char * kWhitespace = "\b\t\r\n ";
|
||||
|
||||
static nsIImportService *gImportService = nullptr;
|
||||
static const char *kWhitespace = "\b\t\r\n ";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
nsImportService::nsImportService() : m_pModules(nullptr)
|
||||
{
|
||||
nsImportService::nsImportService() : m_pModules(nullptr) {
|
||||
IMPORT_LOG0("* nsImport Service Created\n");
|
||||
|
||||
m_didDiscovery = false;
|
||||
|
||||
nsresult rv = nsImportStringBundle::GetStringBundle(IMPORT_MSGS_URL, getter_AddRefs(m_stringBundle));
|
||||
nsresult rv = nsImportStringBundle::GetStringBundle(
|
||||
IMPORT_MSGS_URL, getter_AddRefs(m_stringBundle));
|
||||
if (NS_FAILED(rv))
|
||||
IMPORT_LOG0("Failed to get string bundle for Importing Mail");
|
||||
}
|
||||
|
||||
|
||||
nsImportService::~nsImportService()
|
||||
{
|
||||
nsImportService::~nsImportService() {
|
||||
gImportService = nullptr;
|
||||
|
||||
if (m_pModules != nullptr)
|
||||
delete m_pModules;
|
||||
if (m_pModules != nullptr) delete m_pModules;
|
||||
|
||||
IMPORT_LOG0("* nsImport Service Deleted\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsImportService, nsIImportService)
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportService::DiscoverModules(void)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::DiscoverModules(void) {
|
||||
m_didDiscovery = false;
|
||||
return DoDiscover();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewFieldMap(nsIImportFieldMap **_retval)
|
||||
{
|
||||
return nsImportFieldMap::Create(m_stringBundle, nullptr, NS_GET_IID(nsIImportFieldMap), (void**)_retval);
|
||||
NS_IMETHODIMP nsImportService::CreateNewFieldMap(nsIImportFieldMap **_retval) {
|
||||
return nsImportFieldMap::Create(
|
||||
m_stringBundle, nullptr, NS_GET_IID(nsIImportFieldMap), (void **)_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewMailboxDescriptor(nsIImportMailboxDescriptor **_retval)
|
||||
{
|
||||
return nsImportMailboxDescriptor::Create(nullptr, NS_GET_IID(nsIImportMailboxDescriptor), (void**)_retval);
|
||||
NS_IMETHODIMP nsImportService::CreateNewMailboxDescriptor(
|
||||
nsIImportMailboxDescriptor **_retval) {
|
||||
return nsImportMailboxDescriptor::Create(
|
||||
nullptr, NS_GET_IID(nsIImportMailboxDescriptor), (void **)_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewABDescriptor(nsIImportABDescriptor **_retval)
|
||||
{
|
||||
return nsImportABDescriptor::Create(nullptr, NS_GET_IID(nsIImportABDescriptor), (void**)_retval);
|
||||
NS_IMETHODIMP nsImportService::CreateNewABDescriptor(
|
||||
nsIImportABDescriptor **_retval) {
|
||||
return nsImportABDescriptor::Create(
|
||||
nullptr, NS_GET_IID(nsIImportABDescriptor), (void **)_retval);
|
||||
}
|
||||
|
||||
extern nsresult NS_NewGenericMail(nsIImportGeneric** aImportGeneric);
|
||||
extern nsresult NS_NewGenericMail(nsIImportGeneric **aImportGeneric);
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericMail(nsIImportGeneric **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericMail(
|
||||
nsIImportGeneric **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return NS_NewGenericMail(_retval);
|
||||
}
|
||||
|
||||
extern nsresult NS_NewGenericAddressBooks(nsIImportGeneric** aImportGeneric);
|
||||
extern nsresult NS_NewGenericAddressBooks(nsIImportGeneric **aImportGeneric);
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericAddressBooks(nsIImportGeneric **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericAddressBooks(
|
||||
nsIImportGeneric **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return NS_NewGenericAddressBooks(_retval);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModuleCount(const char *filter, int32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModuleCount(const char *filter,
|
||||
int32_t *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
DoDiscover();
|
||||
|
||||
if (m_pModules != nullptr) {
|
||||
ImportModuleDesc * pDesc;
|
||||
int32_t count = 0;
|
||||
ImportModuleDesc *pDesc;
|
||||
int32_t count = 0;
|
||||
for (int32_t i = 0; i < m_pModules->GetCount(); i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (pDesc->SupportsThings(filter))
|
||||
count++;
|
||||
if (pDesc->SupportsThings(filter)) count++;
|
||||
}
|
||||
*_retval = count;
|
||||
}
|
||||
else
|
||||
} else
|
||||
*_retval = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModuleWithCID(const nsCID& cid, nsIImportModule **ppModule)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModuleWithCID(const nsCID &cid,
|
||||
nsIImportModule **ppModule) {
|
||||
NS_ASSERTION(ppModule != nullptr, "null ptr");
|
||||
if (!ppModule)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!ppModule) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*ppModule = nullptr;
|
||||
nsresult rv = DoDiscover();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (m_pModules == nullptr)
|
||||
return NS_ERROR_FAILURE;
|
||||
int32_t cnt = m_pModules->GetCount();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (m_pModules == nullptr) return NS_ERROR_FAILURE;
|
||||
int32_t cnt = m_pModules->GetCount();
|
||||
ImportModuleDesc *pDesc;
|
||||
for (int32_t i = 0; i < cnt; i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (!pDesc)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!pDesc) return NS_ERROR_FAILURE;
|
||||
if (pDesc->GetCID().Equals(cid)) {
|
||||
pDesc->GetModule(ppModule);
|
||||
|
||||
IMPORT_LOG0("* nsImportService::GetSpecificModule - attempted to load module\n");
|
||||
IMPORT_LOG0(
|
||||
"* nsImportService::GetSpecificModule - attempted to load module\n");
|
||||
|
||||
if (*ppModule == nullptr)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (*ppModule == nullptr) return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -166,25 +149,23 @@ NS_IMETHODIMP nsImportService::GetModuleWithCID(const nsCID& cid, nsIImportModul
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModuleInfo(const char *filter, int32_t index, char16_t **name, char16_t **moduleDescription)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModuleInfo(const char *filter, int32_t index,
|
||||
char16_t **name,
|
||||
char16_t **moduleDescription) {
|
||||
NS_ASSERTION(name != nullptr, "null ptr");
|
||||
NS_ASSERTION(moduleDescription != nullptr, "null ptr");
|
||||
if (!name || !moduleDescription)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!name || !moduleDescription) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*name = nullptr;
|
||||
*moduleDescription = nullptr;
|
||||
|
||||
DoDiscover();
|
||||
if (!m_pModules)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_pModules) return NS_ERROR_FAILURE;
|
||||
|
||||
if ((index < 0) || (index >= m_pModules->GetCount()))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((index < 0) || (index >= m_pModules->GetCount())) return NS_ERROR_FAILURE;
|
||||
|
||||
ImportModuleDesc * pDesc;
|
||||
int32_t count = 0;
|
||||
ImportModuleDesc *pDesc;
|
||||
int32_t count = 0;
|
||||
for (int32_t i = 0; i < m_pModules->GetCount(); i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (pDesc->SupportsThings(filter)) {
|
||||
|
@ -192,8 +173,7 @@ NS_IMETHODIMP nsImportService::GetModuleInfo(const char *filter, int32_t index,
|
|||
*name = NS_xstrdup(pDesc->GetName());
|
||||
*moduleDescription = NS_xstrdup(pDesc->GetDescription());
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
} else
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -201,31 +181,27 @@ NS_IMETHODIMP nsImportService::GetModuleInfo(const char *filter, int32_t index,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModuleName(const char *filter, int32_t index, char16_t **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModuleName(const char *filter, int32_t index,
|
||||
char16_t **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
DoDiscover();
|
||||
if (!m_pModules)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_pModules) return NS_ERROR_FAILURE;
|
||||
|
||||
if ((index < 0) || (index >= m_pModules->GetCount()))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((index < 0) || (index >= m_pModules->GetCount())) return NS_ERROR_FAILURE;
|
||||
|
||||
ImportModuleDesc * pDesc;
|
||||
int32_t count = 0;
|
||||
ImportModuleDesc *pDesc;
|
||||
int32_t count = 0;
|
||||
for (int32_t i = 0; i < m_pModules->GetCount(); i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (pDesc->SupportsThings(filter)) {
|
||||
if (count == index) {
|
||||
*_retval = NS_xstrdup(pDesc->GetName());
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
} else
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -233,32 +209,28 @@ NS_IMETHODIMP nsImportService::GetModuleName(const char *filter, int32_t index,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModuleDescription(const char *filter, int32_t index, char16_t **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModuleDescription(const char *filter,
|
||||
int32_t index,
|
||||
char16_t **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = nullptr;
|
||||
|
||||
DoDiscover();
|
||||
if (!m_pModules)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_pModules) return NS_ERROR_FAILURE;
|
||||
|
||||
if ((index < 0) || (index >= m_pModules->GetCount()))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((index < 0) || (index >= m_pModules->GetCount())) return NS_ERROR_FAILURE;
|
||||
|
||||
ImportModuleDesc * pDesc;
|
||||
int32_t count = 0;
|
||||
ImportModuleDesc *pDesc;
|
||||
int32_t count = 0;
|
||||
for (int32_t i = 0; i < m_pModules->GetCount(); i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (pDesc->SupportsThings(filter)) {
|
||||
if (count == index) {
|
||||
*_retval = NS_xstrdup(pDesc->GetDescription());
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
} else
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -266,19 +238,16 @@ NS_IMETHODIMP nsImportService::GetModuleDescription(const char *filter, int32_t
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
class nsProxySendRunnable : public mozilla::Runnable
|
||||
{
|
||||
public:
|
||||
nsProxySendRunnable(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgCompFields *aMsgFields,
|
||||
const char *attachment1_type,
|
||||
const nsACString &attachment1_body,
|
||||
bool aIsDraft,
|
||||
nsIArray *aLoadedAttachments,
|
||||
nsIArray *aEmbeddedAttachments,
|
||||
nsIMsgSendListener *aListener);
|
||||
class nsProxySendRunnable : public mozilla::Runnable {
|
||||
public:
|
||||
nsProxySendRunnable(nsIMsgIdentity *aIdentity, nsIMsgCompFields *aMsgFields,
|
||||
const char *attachment1_type,
|
||||
const nsACString &attachment1_body, bool aIsDraft,
|
||||
nsIArray *aLoadedAttachments,
|
||||
nsIArray *aEmbeddedAttachments,
|
||||
nsIMsgSendListener *aListener);
|
||||
NS_DECL_NSIRUNNABLE
|
||||
private:
|
||||
private:
|
||||
nsCOMPtr<nsIMsgIdentity> m_identity;
|
||||
nsCOMPtr<nsIMsgCompFields> m_compFields;
|
||||
bool m_isDraft;
|
||||
|
@ -287,108 +256,87 @@ private:
|
|||
nsCOMPtr<nsIArray> m_loadedAttachments;
|
||||
nsCOMPtr<nsIArray> m_embeddedAttachments;
|
||||
nsCOMPtr<nsIMsgSendListener> m_listener;
|
||||
|
||||
};
|
||||
|
||||
nsProxySendRunnable::nsProxySendRunnable(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgCompFields *aMsgFields,
|
||||
const char *aBodyType,
|
||||
const nsACString &aBody,
|
||||
bool aIsDraft,
|
||||
const nsACString &aBody, bool aIsDraft,
|
||||
nsIArray *aLoadedAttachments,
|
||||
nsIArray *aEmbeddedAttachments,
|
||||
nsIMsgSendListener *aListener) :
|
||||
mozilla::Runnable("nsProxySendRunnable"),
|
||||
m_identity(aIdentity), m_compFields(aMsgFields),
|
||||
m_isDraft(aIsDraft), m_bodyType(aBodyType),
|
||||
m_body(aBody), m_loadedAttachments(aLoadedAttachments),
|
||||
m_embeddedAttachments(aEmbeddedAttachments),
|
||||
m_listener(aListener)
|
||||
{
|
||||
}
|
||||
nsIMsgSendListener *aListener)
|
||||
: mozilla::Runnable("nsProxySendRunnable"),
|
||||
m_identity(aIdentity),
|
||||
m_compFields(aMsgFields),
|
||||
m_isDraft(aIsDraft),
|
||||
m_bodyType(aBodyType),
|
||||
m_body(aBody),
|
||||
m_loadedAttachments(aLoadedAttachments),
|
||||
m_embeddedAttachments(aEmbeddedAttachments),
|
||||
m_listener(aListener) {}
|
||||
|
||||
NS_IMETHODIMP nsProxySendRunnable::Run()
|
||||
{
|
||||
NS_IMETHODIMP nsProxySendRunnable::Run() {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgSend> msgSend = do_CreateInstance(NS_MSGSEND_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return msgSend->CreateRFC822Message(m_identity, m_compFields,
|
||||
m_bodyType.get(), m_body,
|
||||
m_isDraft, m_loadedAttachments,
|
||||
m_embeddedAttachments,
|
||||
m_listener);
|
||||
return msgSend->CreateRFC822Message(
|
||||
m_identity, m_compFields, m_bodyType.get(), m_body, m_isDraft,
|
||||
m_loadedAttachments, m_embeddedAttachments, m_listener);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImportService::CreateRFC822Message(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgCompFields *aMsgFields,
|
||||
const char *aBodyType,
|
||||
const nsACString &aBody,
|
||||
bool aIsDraft,
|
||||
const nsACString &aBody, bool aIsDraft,
|
||||
nsIArray *aLoadedAttachments,
|
||||
nsIArray *aEmbeddedAttachments,
|
||||
nsIMsgSendListener *aListener)
|
||||
{
|
||||
RefPtr<nsProxySendRunnable> runnable =
|
||||
new nsProxySendRunnable(aIdentity,
|
||||
aMsgFields,
|
||||
aBodyType,
|
||||
aBody,
|
||||
aIsDraft,
|
||||
aLoadedAttachments,
|
||||
aEmbeddedAttachments,
|
||||
aListener);
|
||||
// invoke the callback
|
||||
return NS_DispatchToMainThread(runnable);
|
||||
nsIMsgSendListener *aListener) {
|
||||
RefPtr<nsProxySendRunnable> runnable = new nsProxySendRunnable(
|
||||
aIdentity, aMsgFields, aBodyType, aBody, aIsDraft, aLoadedAttachments,
|
||||
aEmbeddedAttachments, aListener);
|
||||
// invoke the callback
|
||||
return NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::GetModule(const char *filter, int32_t index, nsIImportModule **_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsImportService::GetModule(const char *filter, int32_t index,
|
||||
nsIImportModule **_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nullptr;
|
||||
|
||||
DoDiscover();
|
||||
if (!m_pModules)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_pModules) return NS_ERROR_FAILURE;
|
||||
|
||||
if ((index < 0) || (index >= m_pModules->GetCount()))
|
||||
return NS_ERROR_FAILURE;
|
||||
if ((index < 0) || (index >= m_pModules->GetCount())) return NS_ERROR_FAILURE;
|
||||
|
||||
ImportModuleDesc * pDesc;
|
||||
int32_t count = 0;
|
||||
ImportModuleDesc *pDesc;
|
||||
int32_t count = 0;
|
||||
for (int32_t i = 0; i < m_pModules->GetCount(); i++) {
|
||||
pDesc = m_pModules->GetModuleDesc(i);
|
||||
if (pDesc->SupportsThings(filter)) {
|
||||
if (count == index) {
|
||||
pDesc->GetModule(_retval);
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (!(*_retval))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!(*_retval)) return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsImportService::DoDiscover(void) {
|
||||
if (m_didDiscovery) return NS_OK;
|
||||
|
||||
nsresult nsImportService::DoDiscover(void)
|
||||
{
|
||||
if (m_didDiscovery)
|
||||
return NS_OK;
|
||||
|
||||
if (m_pModules != nullptr)
|
||||
m_pModules->ClearList();
|
||||
if (m_pModules != nullptr) m_pModules->ClearList();
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsICategoryManager> catMan =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> e;
|
||||
|
@ -397,11 +345,9 @@ nsresult nsImportService::DoDiscover(void)
|
|||
nsCOMPtr<nsISupports> supports;
|
||||
nsCOMPtr<nsISupportsCString> contractid;
|
||||
rv = e->GetNext(getter_AddRefs(supports));
|
||||
while (NS_SUCCEEDED(rv) && supports)
|
||||
{
|
||||
while (NS_SUCCEEDED(rv) && supports) {
|
||||
contractid = do_QueryInterface(supports);
|
||||
if (!contractid)
|
||||
break;
|
||||
if (!contractid) break;
|
||||
|
||||
nsCString contractIdStr;
|
||||
contractid->ToString(getter_Copies(contractIdStr));
|
||||
|
@ -417,32 +363,28 @@ nsresult nsImportService::DoDiscover(void)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsImportService::LoadModuleInfo(const char *pClsId, const char *pSupports)
|
||||
{
|
||||
if (!pClsId || !pSupports)
|
||||
return NS_OK;
|
||||
nsresult nsImportService::LoadModuleInfo(const char *pClsId,
|
||||
const char *pSupports) {
|
||||
if (!pClsId || !pSupports) return NS_OK;
|
||||
|
||||
if (m_pModules == nullptr)
|
||||
m_pModules = new nsImportModuleList();
|
||||
if (m_pModules == nullptr) m_pModules = new nsImportModuleList();
|
||||
|
||||
// load the component and get all of the info we need from it....
|
||||
// then call AddModule
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
|
||||
nsCID clsId;
|
||||
nsCID clsId;
|
||||
clsId.Parse(pClsId);
|
||||
nsCOMPtr<nsIImportModule> module = do_CreateInstance(clsId, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsString theTitle;
|
||||
nsString theDescription;
|
||||
nsString theTitle;
|
||||
nsString theDescription;
|
||||
rv = module->GetName(getter_Copies(theTitle));
|
||||
if (NS_FAILED(rv))
|
||||
theTitle.AssignLiteral("Unknown");
|
||||
if (NS_FAILED(rv)) theTitle.AssignLiteral("Unknown");
|
||||
|
||||
rv = module->GetDescription(getter_Copies(theDescription));
|
||||
if (NS_FAILED(rv))
|
||||
theDescription.AssignLiteral("Unknown description");
|
||||
if (NS_FAILED(rv)) theDescription.AssignLiteral("Unknown description");
|
||||
|
||||
// call the module to get the info we need
|
||||
m_pModules->AddModule(clsId, pSupports, theTitle.get(), theDescription.get());
|
||||
|
@ -451,41 +393,31 @@ nsresult nsImportService::LoadModuleInfo(const char *pClsId, const char *pSuppor
|
|||
}
|
||||
|
||||
// XXX This should return already_AddRefed.
|
||||
void ImportModuleDesc::GetModule(nsIImportModule **_retval)
|
||||
{
|
||||
if (!m_pModule)
|
||||
{
|
||||
nsresult rv;
|
||||
void ImportModuleDesc::GetModule(nsIImportModule **_retval) {
|
||||
if (!m_pModule) {
|
||||
nsresult rv;
|
||||
m_pModule = do_CreateInstance(m_cid, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
m_pModule = nullptr;
|
||||
if (NS_FAILED(rv)) m_pModule = nullptr;
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*_retval = m_pModule);
|
||||
return;
|
||||
}
|
||||
|
||||
void ImportModuleDesc::ReleaseModule(void)
|
||||
{
|
||||
m_pModule = nullptr;
|
||||
}
|
||||
void ImportModuleDesc::ReleaseModule(void) { m_pModule = nullptr; }
|
||||
|
||||
bool ImportModuleDesc::SupportsThings(const char *pThings)
|
||||
{
|
||||
if (!pThings || !*pThings)
|
||||
return true;
|
||||
bool ImportModuleDesc::SupportsThings(const char *pThings) {
|
||||
if (!pThings || !*pThings) return true;
|
||||
|
||||
nsCString thing(pThings);
|
||||
nsCString item;
|
||||
int32_t idx;
|
||||
|
||||
while ((idx = thing.FindChar(',')) != -1)
|
||||
{
|
||||
while ((idx = thing.FindChar(',')) != -1) {
|
||||
item = StringHead(thing, idx);
|
||||
item.Trim(kWhitespace);
|
||||
ToLowerCase(item);
|
||||
if (item.Length() && (m_supports.Find(item) == -1))
|
||||
return false;
|
||||
if (item.Length() && (m_supports.Find(item) == -1)) return false;
|
||||
thing = Substring(thing, idx + 1);
|
||||
}
|
||||
thing.Trim(kWhitespace);
|
||||
|
@ -493,41 +425,35 @@ bool ImportModuleDesc::SupportsThings(const char *pThings)
|
|||
return thing.IsEmpty() || (m_supports.Find(thing) != -1);
|
||||
}
|
||||
|
||||
void nsImportModuleList::ClearList(void)
|
||||
{
|
||||
if (m_pList)
|
||||
{
|
||||
for (int i = 0; i < m_count; i++)
|
||||
{
|
||||
void nsImportModuleList::ClearList(void) {
|
||||
if (m_pList) {
|
||||
for (int i = 0; i < m_count; i++) {
|
||||
delete m_pList[i];
|
||||
m_pList[i] = nullptr;
|
||||
}
|
||||
m_count = 0;
|
||||
delete [] m_pList;
|
||||
delete[] m_pList;
|
||||
m_pList = nullptr;
|
||||
m_alloc = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void nsImportModuleList::AddModule(const nsCID& cid, const char *pSupports, const char16_t *pName, const char16_t *pDesc)
|
||||
{
|
||||
if (!m_pList)
|
||||
{
|
||||
void nsImportModuleList::AddModule(const nsCID &cid, const char *pSupports,
|
||||
const char16_t *pName,
|
||||
const char16_t *pDesc) {
|
||||
if (!m_pList) {
|
||||
m_alloc = 10;
|
||||
m_pList = new ImportModuleDesc *[m_alloc];
|
||||
m_count = 0;
|
||||
memset(m_pList, 0, sizeof(ImportModuleDesc *) * m_alloc);
|
||||
}
|
||||
|
||||
if (m_count == m_alloc)
|
||||
{
|
||||
if (m_count == m_alloc) {
|
||||
ImportModuleDesc **pList = new ImportModuleDesc *[m_alloc + 10];
|
||||
memset(&(pList[m_alloc]), 0, sizeof(ImportModuleDesc *) * 10);
|
||||
memcpy(pList, m_pList, sizeof(ImportModuleDesc *) * m_alloc);
|
||||
for(int i = 0; i < m_count; i++)
|
||||
delete m_pList[i];
|
||||
delete [] m_pList;
|
||||
for (int i = 0; i < m_count; i++) delete m_pList[i];
|
||||
delete[] m_pList;
|
||||
m_pList = pList;
|
||||
m_alloc += 10;
|
||||
}
|
||||
|
@ -540,7 +466,8 @@ void nsImportModuleList::AddModule(const nsCID& cid, const char *pSupports, cons
|
|||
|
||||
m_count++;
|
||||
#ifdef IMPORT_DEBUG
|
||||
IMPORT_LOG3("* nsImportService registered import module: %s, %s, %s\n", NS_LossyConvertUTF16toASCII(pName).get(), NS_LossyConvertUTF16toASCII(pDesc).get(), pSupports);
|
||||
IMPORT_LOG3("* nsImportService registered import module: %s, %s, %s\n",
|
||||
NS_LossyConvertUTF16toASCII(pName).get(),
|
||||
NS_LossyConvertUTF16toASCII(pDesc).get(), pSupports);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -14,48 +14,46 @@
|
|||
|
||||
class nsImportModuleList;
|
||||
|
||||
class nsImportService : public nsIImportService
|
||||
{
|
||||
public:
|
||||
|
||||
class nsImportService : public nsIImportService {
|
||||
public:
|
||||
nsImportService();
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTSERVICE
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsImportService();
|
||||
nsresult LoadModuleInfo(const char*pClsId, const char *pSupports);
|
||||
nsresult LoadModuleInfo(const char *pClsId, const char *pSupports);
|
||||
nsresult DoDiscover(void);
|
||||
|
||||
private:
|
||||
nsImportModuleList * m_pModules;
|
||||
private:
|
||||
nsImportModuleList *m_pModules;
|
||||
bool m_didDiscovery;
|
||||
nsCString m_sysCharset;
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
};
|
||||
|
||||
class ImportModuleDesc {
|
||||
public:
|
||||
ImportModuleDesc() { m_pModule = nullptr;}
|
||||
~ImportModuleDesc() { ReleaseModule(); }
|
||||
public:
|
||||
ImportModuleDesc() { m_pModule = nullptr; }
|
||||
~ImportModuleDesc() { ReleaseModule(); }
|
||||
|
||||
void SetCID(const nsCID& cid) { m_cid = cid;}
|
||||
void SetName(const char16_t *pName) { m_name = pName;}
|
||||
void SetDescription(const char16_t *pDesc) { m_description = pDesc;}
|
||||
void SetSupports(const char *pSupports) { m_supports = pSupports;}
|
||||
void SetCID(const nsCID &cid) { m_cid = cid; }
|
||||
void SetName(const char16_t *pName) { m_name = pName; }
|
||||
void SetDescription(const char16_t *pDesc) { m_description = pDesc; }
|
||||
void SetSupports(const char *pSupports) { m_supports = pSupports; }
|
||||
|
||||
nsCID GetCID(void) { return m_cid;}
|
||||
const char16_t *GetName(void) { return m_name.get();}
|
||||
const char16_t *GetDescription(void) { return m_description.get();}
|
||||
const char * GetSupports(void) { return m_supports.get();}
|
||||
nsCID GetCID(void) { return m_cid; }
|
||||
const char16_t *GetName(void) { return m_name.get(); }
|
||||
const char16_t *GetDescription(void) { return m_description.get(); }
|
||||
const char *GetSupports(void) { return m_supports.get(); }
|
||||
|
||||
void GetModule(nsIImportModule **);
|
||||
void ReleaseModule(void);
|
||||
void GetModule(nsIImportModule **);
|
||||
void ReleaseModule(void);
|
||||
|
||||
bool SupportsThings(const char *pThings);
|
||||
bool SupportsThings(const char *pThings);
|
||||
|
||||
private:
|
||||
private:
|
||||
nsCID m_cid;
|
||||
nsString m_name;
|
||||
nsString m_description;
|
||||
|
@ -64,25 +62,33 @@ private:
|
|||
};
|
||||
|
||||
class nsImportModuleList {
|
||||
public:
|
||||
nsImportModuleList() { m_pList = nullptr; m_alloc = 0; m_count = 0;}
|
||||
public:
|
||||
nsImportModuleList() {
|
||||
m_pList = nullptr;
|
||||
m_alloc = 0;
|
||||
m_count = 0;
|
||||
}
|
||||
~nsImportModuleList() { ClearList(); }
|
||||
|
||||
void AddModule(const nsCID& cid, const char *pSupports, const char16_t *pName, const char16_t *pDesc);
|
||||
void AddModule(const nsCID &cid, const char *pSupports, const char16_t *pName,
|
||||
const char16_t *pDesc);
|
||||
|
||||
void ClearList(void);
|
||||
void ClearList(void);
|
||||
|
||||
int32_t GetCount(void) { return m_count;}
|
||||
int32_t GetCount(void) { return m_count; }
|
||||
|
||||
ImportModuleDesc * GetModuleDesc(int32_t idx)
|
||||
{ if ((idx < 0) || (idx >= m_count)) return nullptr; else return m_pList[idx];}
|
||||
ImportModuleDesc *GetModuleDesc(int32_t idx) {
|
||||
if ((idx < 0) || (idx >= m_count))
|
||||
return nullptr;
|
||||
else
|
||||
return m_pList[idx];
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
ImportModuleDesc ** m_pList;
|
||||
int32_t m_alloc;
|
||||
int32_t m_count;
|
||||
private:
|
||||
private:
|
||||
ImportModuleDesc **m_pList;
|
||||
int32_t m_alloc;
|
||||
int32_t m_count;
|
||||
};
|
||||
|
||||
#endif // nsImportService_h__
|
||||
#endif // nsImportService_h__
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
#include "mozilla/Services.h"
|
||||
|
||||
nsresult nsImportStringBundle::GetStringBundle(const char *aPropertyURL,
|
||||
nsIStringBundle **aBundle)
|
||||
{
|
||||
nsIStringBundle **aBundle) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> sBundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
mozilla::services::GetStringBundleService();
|
||||
NS_ENSURE_TRUE(sBundleService, NS_ERROR_UNEXPECTED);
|
||||
rv = sBundleService->CreateBundle(aPropertyURL, aBundle);
|
||||
|
||||
|
@ -27,20 +26,16 @@ nsresult nsImportStringBundle::GetStringBundle(const char *aPropertyURL,
|
|||
|
||||
void nsImportStringBundle::GetStringByID(int32_t aStringID,
|
||||
nsIStringBundle *aBundle,
|
||||
nsString &aResult)
|
||||
{
|
||||
nsString &aResult) {
|
||||
aResult.Adopt(GetStringByID(aStringID, aBundle));
|
||||
}
|
||||
|
||||
char16_t *nsImportStringBundle::GetStringByID(int32_t aStringID,
|
||||
nsIStringBundle *aBundle)
|
||||
{
|
||||
if (aBundle)
|
||||
{
|
||||
nsIStringBundle *aBundle) {
|
||||
if (aBundle) {
|
||||
nsAutoString str;
|
||||
nsresult rv = aBundle->GetStringFromID(aStringID, str);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return ToNewUnicode(str);
|
||||
if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
|
||||
}
|
||||
|
||||
nsString resultString(NS_LITERAL_STRING("[StringID "));
|
||||
|
@ -52,20 +47,16 @@ char16_t *nsImportStringBundle::GetStringByID(int32_t aStringID,
|
|||
|
||||
void nsImportStringBundle::GetStringByName(const char *aName,
|
||||
nsIStringBundle *aBundle,
|
||||
nsString &aResult)
|
||||
{
|
||||
nsString &aResult) {
|
||||
aResult.Adopt(GetStringByName(aName, aBundle));
|
||||
}
|
||||
|
||||
char16_t *nsImportStringBundle::GetStringByName(const char *aName,
|
||||
nsIStringBundle *aBundle)
|
||||
{
|
||||
if (aBundle)
|
||||
{
|
||||
nsIStringBundle *aBundle) {
|
||||
if (aBundle) {
|
||||
nsAutoString str;
|
||||
nsresult rv = aBundle->GetStringFromName(aName, str);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return ToNewUnicode(str);
|
||||
if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
|
||||
}
|
||||
|
||||
nsString resultString(NS_LITERAL_STRING("[StringName "));
|
||||
|
|
|
@ -9,40 +9,35 @@
|
|||
|
||||
class nsIStringBundle;
|
||||
|
||||
class nsImportStringBundle
|
||||
{
|
||||
public:
|
||||
static char16_t* GetStringByID(int32_t aStringID,
|
||||
nsIStringBundle *aBundle = nullptr);
|
||||
static void GetStringByID(int32_t aStringID,
|
||||
nsIStringBundle *aBundle,
|
||||
class nsImportStringBundle {
|
||||
public:
|
||||
static char16_t *GetStringByID(int32_t aStringID,
|
||||
nsIStringBundle *aBundle = nullptr);
|
||||
static void GetStringByID(int32_t aStringID, nsIStringBundle *aBundle,
|
||||
nsString &aResult);
|
||||
static char16_t* GetStringByName(const char *aName,
|
||||
nsIStringBundle *aBundle = nullptr);
|
||||
static void GetStringByName(const char *aName,
|
||||
nsIStringBundle *aBundle,
|
||||
nsString &aResult);
|
||||
static char16_t *GetStringByName(const char *aName,
|
||||
nsIStringBundle *aBundle = nullptr);
|
||||
static void GetStringByName(const char *aName, nsIStringBundle *aBundle,
|
||||
nsString &aResult);
|
||||
static nsresult GetStringBundle(const char *aPropertyURL,
|
||||
nsIStringBundle **aBundle);
|
||||
};
|
||||
|
||||
#define IMPORT_MSGS_URL "chrome://messenger/locale/importMsgs.properties"
|
||||
#define IMPORT_MSGS_URL "chrome://messenger/locale/importMsgs.properties"
|
||||
|
||||
#define IMPORT_NO_ADDRBOOKS 2000
|
||||
#define IMPORT_ERROR_AB_NOTINITIALIZED 2001
|
||||
#define IMPORT_ERROR_AB_NOTHREAD 2002
|
||||
#define IMPORT_ERROR_GETABOOK 2003
|
||||
#define IMPORT_NO_MAILBOXES 2004
|
||||
#define IMPORT_ERROR_MB_NOTINITIALIZED 2005
|
||||
#define IMPORT_ERROR_MB_NOTHREAD 2006
|
||||
#define IMPORT_ERROR_MB_NOPROXY 2007
|
||||
#define IMPORT_ERROR_MB_FINDCHILD 2008
|
||||
#define IMPORT_ERROR_MB_CREATE 2009
|
||||
#define IMPORT_ERROR_MB_NODESTFOLDER 2010
|
||||
|
||||
#define IMPORT_NO_ADDRBOOKS 2000
|
||||
#define IMPORT_ERROR_AB_NOTINITIALIZED 2001
|
||||
#define IMPORT_ERROR_AB_NOTHREAD 2002
|
||||
#define IMPORT_ERROR_GETABOOK 2003
|
||||
#define IMPORT_NO_MAILBOXES 2004
|
||||
#define IMPORT_ERROR_MB_NOTINITIALIZED 2005
|
||||
#define IMPORT_ERROR_MB_NOTHREAD 2006
|
||||
#define IMPORT_ERROR_MB_NOPROXY 2007
|
||||
#define IMPORT_ERROR_MB_FINDCHILD 2008
|
||||
#define IMPORT_ERROR_MB_CREATE 2009
|
||||
#define IMPORT_ERROR_MB_NODESTFOLDER 2010
|
||||
|
||||
#define IMPORT_FIELD_DESC_START 2100
|
||||
#define IMPORT_FIELD_DESC_END 2136
|
||||
|
||||
#define IMPORT_FIELD_DESC_START 2100
|
||||
#define IMPORT_FIELD_DESC_END 2136
|
||||
|
||||
#endif /* _nsImportStringBundle_H__ */
|
||||
|
|
|
@ -8,106 +8,100 @@
|
|||
|
||||
#include "ImportCharSet.h"
|
||||
|
||||
|
||||
bool nsImportTranslator::ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed)
|
||||
{
|
||||
if (pProcessed)
|
||||
*pProcessed = inLen;
|
||||
bool nsImportTranslator::ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed) {
|
||||
if (pProcessed) *pProcessed = inLen;
|
||||
return (pOutFile->WriteData(pIn, inLen));
|
||||
}
|
||||
|
||||
void CMHTranslator::ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t * pOut)
|
||||
{
|
||||
void CMHTranslator::ConvertBuffer(const uint8_t *pIn, uint32_t inLen,
|
||||
uint8_t *pOut) {
|
||||
while (inLen) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) || ImportCharSet::Is822SpecialChar(*pIn) || ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '*') || (*pIn == '\'') ||
|
||||
(*pIn == '%')) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) ||
|
||||
ImportCharSet::Is822SpecialChar(*pIn) ||
|
||||
ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '*') ||
|
||||
(*pIn == '\'') || (*pIn == '%')) {
|
||||
// needs to be encode as %hex val
|
||||
*pOut = '%'; pOut++;
|
||||
*pOut = '%';
|
||||
pOut++;
|
||||
ImportCharSet::ByteToHex(*pIn, pOut);
|
||||
pOut += 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*pOut = *pIn;
|
||||
pOut++;
|
||||
}
|
||||
pIn++; inLen--;
|
||||
pIn++;
|
||||
inLen--;
|
||||
}
|
||||
*pOut = 0;
|
||||
}
|
||||
|
||||
bool CMHTranslator::ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed)
|
||||
{
|
||||
uint8_t hex[2];
|
||||
bool CMHTranslator::ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed) {
|
||||
uint8_t hex[2];
|
||||
while (inLen) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) || ImportCharSet::Is822SpecialChar(*pIn) || ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '*') || (*pIn == '\'') ||
|
||||
(*pIn == '%')) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) ||
|
||||
ImportCharSet::Is822SpecialChar(*pIn) ||
|
||||
ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '*') ||
|
||||
(*pIn == '\'') || (*pIn == '%')) {
|
||||
// needs to be encode as %hex val
|
||||
if (!pOutFile->WriteByte('%'))
|
||||
return false;
|
||||
if (!pOutFile->WriteByte('%')) return false;
|
||||
ImportCharSet::ByteToHex(*pIn, hex);
|
||||
if (!pOutFile->WriteData(hex, 2))
|
||||
return false;
|
||||
if (!pOutFile->WriteData(hex, 2)) return false;
|
||||
} else {
|
||||
if (!pOutFile->WriteByte(*pIn)) return false;
|
||||
}
|
||||
else {
|
||||
if (!pOutFile->WriteByte(*pIn))
|
||||
return false;
|
||||
}
|
||||
pIn++; inLen--;
|
||||
pIn++;
|
||||
inLen--;
|
||||
}
|
||||
|
||||
if (pProcessed)
|
||||
*pProcessed = inLen;
|
||||
if (pProcessed) *pProcessed = inLen;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool C2047Translator::ConvertToFileQ(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed) {
|
||||
if (!inLen) return true;
|
||||
|
||||
bool C2047Translator::ConvertToFileQ(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed)
|
||||
{
|
||||
if (!inLen)
|
||||
return true;
|
||||
int maxLineLen = 64;
|
||||
int curLineLen = m_startLen;
|
||||
bool startLine = true;
|
||||
|
||||
int maxLineLen = 64;
|
||||
int curLineLen = m_startLen;
|
||||
bool startLine = true;
|
||||
|
||||
uint8_t hex[2];
|
||||
uint8_t hex[2];
|
||||
while (inLen) {
|
||||
if (startLine) {
|
||||
if (!pOutFile->WriteStr(" =?"))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr(m_charset.get()))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr("?q?"))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr(" =?")) return false;
|
||||
if (!pOutFile->WriteStr(m_charset.get())) return false;
|
||||
if (!pOutFile->WriteStr("?q?")) return false;
|
||||
curLineLen += (6 + m_charset.Length());
|
||||
startLine = false;
|
||||
}
|
||||
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) || ImportCharSet::Is822SpecialChar(*pIn) || ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '?') || (*pIn == '=')) {
|
||||
if (!ImportCharSet::IsUSAscii(*pIn) ||
|
||||
ImportCharSet::Is822SpecialChar(*pIn) ||
|
||||
ImportCharSet::Is822CtlChar(*pIn) ||
|
||||
(*pIn == ImportCharSet::cSpaceChar) || (*pIn == '?') || (*pIn == '=')) {
|
||||
// needs to be encode as =hex val
|
||||
if (!pOutFile->WriteByte('='))
|
||||
return false;
|
||||
if (!pOutFile->WriteByte('=')) return false;
|
||||
ImportCharSet::ByteToHex(*pIn, hex);
|
||||
if (!pOutFile->WriteData(hex, 2))
|
||||
return false;
|
||||
if (!pOutFile->WriteData(hex, 2)) return false;
|
||||
curLineLen += 3;
|
||||
}
|
||||
else {
|
||||
if (!pOutFile->WriteByte(*pIn))
|
||||
return false;
|
||||
} else {
|
||||
if (!pOutFile->WriteByte(*pIn)) return false;
|
||||
curLineLen++;
|
||||
}
|
||||
pIn++; inLen--;
|
||||
pIn++;
|
||||
inLen--;
|
||||
if (curLineLen > maxLineLen) {
|
||||
if (!pOutFile->WriteStr("?="))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr("?=")) return false;
|
||||
if (inLen) {
|
||||
if (!pOutFile->WriteStr("\x0D\x0A "))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr("\x0D\x0A ")) return false;
|
||||
}
|
||||
|
||||
startLine = true;
|
||||
|
@ -117,42 +111,40 @@ bool C2047Translator::ConvertToFileQ(const uint8_t * pIn, uint32_t inLen, Import
|
|||
|
||||
if (!startLine) {
|
||||
// end the encoding!
|
||||
if (!pOutFile->WriteStr("?="))
|
||||
return false;
|
||||
if (!pOutFile->WriteStr("?=")) return false;
|
||||
}
|
||||
|
||||
if (pProcessed)
|
||||
*pProcessed = inLen;
|
||||
if (pProcessed) *pProcessed = inLen;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool C2047Translator::ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed)
|
||||
{
|
||||
bool C2047Translator::ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed) {
|
||||
if (m_useQuotedPrintable)
|
||||
return ConvertToFileQ(pIn, inLen, pOutFile, pProcessed);
|
||||
|
||||
if (!inLen)
|
||||
return true;
|
||||
if (!inLen) return true;
|
||||
|
||||
int maxLineLen = 64;
|
||||
int curLineLen = m_startLen;
|
||||
bool startLine = true;
|
||||
int encodeMax;
|
||||
uint8_t * pEncoded = new uint8_t[maxLineLen * 2];
|
||||
int maxLineLen = 64;
|
||||
int curLineLen = m_startLen;
|
||||
bool startLine = true;
|
||||
int encodeMax;
|
||||
uint8_t *pEncoded = new uint8_t[maxLineLen * 2];
|
||||
|
||||
while (inLen) {
|
||||
if (startLine) {
|
||||
if (!pOutFile->WriteStr(" =?")) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
if (!pOutFile->WriteStr(m_charset.get())) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
if (!pOutFile->WriteStr("?b?")) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
curLineLen += (6 + m_charset.Length());
|
||||
|
@ -161,15 +153,15 @@ bool C2047Translator::ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportO
|
|||
encodeMax = maxLineLen - curLineLen;
|
||||
encodeMax *= 3;
|
||||
encodeMax /= 4;
|
||||
if ((uint32_t)encodeMax > inLen)
|
||||
encodeMax = (int)inLen;
|
||||
if ((uint32_t)encodeMax > inLen) encodeMax = (int)inLen;
|
||||
|
||||
// encode the line, end the line
|
||||
// then continue. Update curLineLen, pIn, startLine, and inLen
|
||||
UMimeEncode::ConvertBuffer(pIn, encodeMax, pEncoded, maxLineLen, maxLineLen, "\x0D\x0A");
|
||||
UMimeEncode::ConvertBuffer(pIn, encodeMax, pEncoded, maxLineLen, maxLineLen,
|
||||
"\x0D\x0A");
|
||||
|
||||
if (!pOutFile->WriteStr((const char *)pEncoded)) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -178,28 +170,25 @@ bool C2047Translator::ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportO
|
|||
startLine = true;
|
||||
curLineLen = 0;
|
||||
if (!pOutFile->WriteStr("?=")) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
if (inLen) {
|
||||
if (!pOutFile->WriteStr("\x0D\x0A ")) {
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete [] pEncoded;
|
||||
delete[] pEncoded;
|
||||
|
||||
if (pProcessed)
|
||||
*pProcessed = inLen;
|
||||
if (pProcessed) *pProcessed = inLen;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t UMimeEncode::GetBufferSize(uint32_t inBytes)
|
||||
{
|
||||
uint32_t UMimeEncode::GetBufferSize(uint32_t inBytes) {
|
||||
// it takes 4 base64 bytes to represent 3 regular bytes
|
||||
inBytes += 3;
|
||||
inBytes /= 3;
|
||||
|
@ -213,29 +202,41 @@ uint32_t UMimeEncode::GetBufferSize(uint32_t inBytes)
|
|||
return inBytes;
|
||||
}
|
||||
|
||||
static uint8_t gBase64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static uint8_t gBase64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
uint32_t UMimeEncode::ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t * pOut, uint32_t maxLen, uint32_t firstLineLen, const char * pEolStr)
|
||||
{
|
||||
|
||||
uint32_t pos = 0;
|
||||
uint32_t len = 0;
|
||||
uint32_t lineLen = 0;
|
||||
uint32_t maxLine = firstLineLen;
|
||||
int eolLen = 0;
|
||||
if (pEolStr)
|
||||
eolLen = strlen(pEolStr);
|
||||
uint32_t UMimeEncode::ConvertBuffer(const uint8_t *pIn, uint32_t inLen,
|
||||
uint8_t *pOut, uint32_t maxLen,
|
||||
uint32_t firstLineLen,
|
||||
const char *pEolStr) {
|
||||
uint32_t pos = 0;
|
||||
uint32_t len = 0;
|
||||
uint32_t lineLen = 0;
|
||||
uint32_t maxLine = firstLineLen;
|
||||
int eolLen = 0;
|
||||
if (pEolStr) eolLen = strlen(pEolStr);
|
||||
|
||||
while ((pos + 2) < inLen) {
|
||||
// Encode 3 bytes
|
||||
*pOut = gBase64[*pIn >> 2];
|
||||
pOut++; len++; lineLen++;
|
||||
*pOut = gBase64[(((*pIn) & 0x3)<< 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
|
||||
pIn++; pOut++; len++; lineLen++;
|
||||
*pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >>6)];
|
||||
pIn++; pOut++; len++; lineLen++;
|
||||
pOut++;
|
||||
len++;
|
||||
lineLen++;
|
||||
*pOut = gBase64[(((*pIn) & 0x3) << 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
|
||||
pIn++;
|
||||
pOut++;
|
||||
len++;
|
||||
lineLen++;
|
||||
*pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >> 6)];
|
||||
pIn++;
|
||||
pOut++;
|
||||
len++;
|
||||
lineLen++;
|
||||
*pOut = gBase64[(*pIn) & 0x3F];
|
||||
pIn++; pOut++; len++; lineLen++;
|
||||
pIn++;
|
||||
pOut++;
|
||||
len++;
|
||||
lineLen++;
|
||||
pos += 3;
|
||||
if (lineLen >= maxLine) {
|
||||
lineLen = 0;
|
||||
|
@ -261,32 +262,43 @@ uint32_t UMimeEncode::ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t
|
|||
if (pos < inLen) {
|
||||
// Get the last few bytes!
|
||||
*pOut = gBase64[*pIn >> 2];
|
||||
pOut++; len++;
|
||||
pOut++;
|
||||
len++;
|
||||
pos++;
|
||||
if (pos < inLen) {
|
||||
*pOut = gBase64[(((*pIn) & 0x3)<< 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
|
||||
pIn++; pOut++; pos++; len++;
|
||||
*pOut = gBase64[(((*pIn) & 0x3) << 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
|
||||
pIn++;
|
||||
pOut++;
|
||||
pos++;
|
||||
len++;
|
||||
if (pos < inLen) {
|
||||
// Should be dead code!! (Then why is it here doofus?)
|
||||
*pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >>6)];
|
||||
pIn++; pOut++; len++;
|
||||
*pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >> 6)];
|
||||
pIn++;
|
||||
pOut++;
|
||||
len++;
|
||||
*pOut = gBase64[(*pIn) & 0x3F];
|
||||
pos++; pOut++; len++;
|
||||
}
|
||||
else {
|
||||
pos++;
|
||||
pOut++;
|
||||
len++;
|
||||
} else {
|
||||
*pOut = gBase64[(((*pIn) & 0xF) << 2)];
|
||||
pOut++; len++;
|
||||
pOut++;
|
||||
len++;
|
||||
*pOut = '=';
|
||||
pOut++; len++;
|
||||
pOut++;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*pOut = gBase64[(((*pIn) & 0x3)<< 4)];
|
||||
pOut++; len++;
|
||||
} else {
|
||||
*pOut = gBase64[(((*pIn) & 0x3) << 4)];
|
||||
pOut++;
|
||||
len++;
|
||||
*pOut = '=';
|
||||
pOut++; len++;
|
||||
pOut++;
|
||||
len++;
|
||||
*pOut = '=';
|
||||
pOut++; len++;
|
||||
pOut++;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,53 +14,74 @@
|
|||
class ImportOutFile;
|
||||
|
||||
class UMimeEncode {
|
||||
public:
|
||||
static uint32_t GetBufferSize(uint32_t inByes);
|
||||
static uint32_t ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t *pOut, uint32_t maxLen = 72, uint32_t firstLineLen = 72, const char * pEolStr = nullptr);
|
||||
public:
|
||||
static uint32_t GetBufferSize(uint32_t inByes);
|
||||
static uint32_t ConvertBuffer(const uint8_t *pIn, uint32_t inLen,
|
||||
uint8_t *pOut, uint32_t maxLen = 72,
|
||||
uint32_t firstLineLen = 72,
|
||||
const char *pEolStr = nullptr);
|
||||
};
|
||||
|
||||
|
||||
class nsImportTranslator {
|
||||
public:
|
||||
public:
|
||||
virtual ~nsImportTranslator() {}
|
||||
virtual bool Supports8bitEncoding(void) { return false;}
|
||||
virtual uint32_t GetMaxBufferSize(uint32_t inLen) { return inLen + 1;}
|
||||
virtual void ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t * pOut) { memcpy(pOut, pIn, inLen); pOut[inLen] = 0;}
|
||||
virtual bool ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed = nullptr);
|
||||
virtual bool FinishConvertToFile(ImportOutFile * /* pOutFile */) { return true;}
|
||||
virtual bool Supports8bitEncoding(void) { return false; }
|
||||
virtual uint32_t GetMaxBufferSize(uint32_t inLen) { return inLen + 1; }
|
||||
virtual void ConvertBuffer(const uint8_t *pIn, uint32_t inLen,
|
||||
uint8_t *pOut) {
|
||||
memcpy(pOut, pIn, inLen);
|
||||
pOut[inLen] = 0;
|
||||
}
|
||||
virtual bool ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed = nullptr);
|
||||
virtual bool FinishConvertToFile(ImportOutFile * /* pOutFile */) {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void GetCharset(nsCString& charSet) { charSet = "us-ascii";}
|
||||
virtual void GetLanguage(nsCString& lang) { lang = "en";}
|
||||
virtual void GetEncoding(nsCString& encoding) { encoding.Truncate();}
|
||||
virtual void GetCharset(nsCString &charSet) { charSet = "us-ascii"; }
|
||||
virtual void GetLanguage(nsCString &lang) { lang = "en"; }
|
||||
virtual void GetEncoding(nsCString &encoding) { encoding.Truncate(); }
|
||||
};
|
||||
|
||||
// Specialized encoder, not a valid language translator, used for Mime headers.
|
||||
// rfc2231
|
||||
class CMHTranslator : public nsImportTranslator {
|
||||
public:
|
||||
virtual uint32_t GetMaxBufferSize(uint32_t inLen) override { return (inLen * 3) + 1;}
|
||||
virtual void ConvertBuffer(const uint8_t * pIn, uint32_t inLen, uint8_t * pOut) override;
|
||||
virtual bool ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed = nullptr) override;
|
||||
public:
|
||||
virtual uint32_t GetMaxBufferSize(uint32_t inLen) override {
|
||||
return (inLen * 3) + 1;
|
||||
}
|
||||
virtual void ConvertBuffer(const uint8_t *pIn, uint32_t inLen,
|
||||
uint8_t *pOut) override;
|
||||
virtual bool ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed = nullptr) override;
|
||||
};
|
||||
|
||||
// Specialized encoder, not a valid language translator, used for mail headers
|
||||
// rfc2047
|
||||
class C2047Translator : public nsImportTranslator {
|
||||
public:
|
||||
public:
|
||||
virtual ~C2047Translator() {}
|
||||
|
||||
C2047Translator(const char *pCharset, uint32_t headerLen) { m_charset = pCharset; m_startLen = headerLen; m_useQuotedPrintable = false;}
|
||||
C2047Translator(const char *pCharset, uint32_t headerLen) {
|
||||
m_charset = pCharset;
|
||||
m_startLen = headerLen;
|
||||
m_useQuotedPrintable = false;
|
||||
}
|
||||
|
||||
void SetUseQuotedPrintable(void) { m_useQuotedPrintable = true;}
|
||||
void SetUseQuotedPrintable(void) { m_useQuotedPrintable = true; }
|
||||
|
||||
virtual bool ConvertToFile(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed = nullptr) override;
|
||||
bool ConvertToFileQ(const uint8_t * pIn, uint32_t inLen, ImportOutFile *pOutFile, uint32_t *pProcessed);
|
||||
virtual bool ConvertToFile(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile,
|
||||
uint32_t *pProcessed = nullptr) override;
|
||||
bool ConvertToFileQ(const uint8_t *pIn, uint32_t inLen,
|
||||
ImportOutFile *pOutFile, uint32_t *pProcessed);
|
||||
|
||||
protected:
|
||||
bool m_useQuotedPrintable;
|
||||
nsCString m_charset;
|
||||
uint32_t m_startLen;
|
||||
protected:
|
||||
bool m_useQuotedPrintable;
|
||||
nsCString m_charset;
|
||||
uint32_t m_startLen;
|
||||
};
|
||||
|
||||
#endif /* nsImportTranslator_h__ */
|
||||
|
||||
|
|
|
@ -21,22 +21,18 @@
|
|||
#include "plstr.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
#define kWhitespace " \t\b\r\n"
|
||||
#define kWhitespace " \t\b\r\n"
|
||||
|
||||
nsTextAddress::nsTextAddress()
|
||||
{
|
||||
nsTextAddress::nsTextAddress() {
|
||||
m_LFCount = 0;
|
||||
m_CRCount = 0;
|
||||
}
|
||||
|
||||
nsTextAddress::~nsTextAddress()
|
||||
{
|
||||
}
|
||||
nsTextAddress::~nsTextAddress() {}
|
||||
|
||||
nsresult nsTextAddress::GetUnicharLineStreamForFile(nsIFile *aFile,
|
||||
nsIInputStream *aInputStream,
|
||||
nsIUnicharLineInputStream **aStream)
|
||||
{
|
||||
nsresult nsTextAddress::GetUnicharLineStreamForFile(
|
||||
nsIFile *aFile, nsIInputStream *aInputStream,
|
||||
nsIUnicharLineInputStream **aStream) {
|
||||
nsAutoCString charset;
|
||||
nsresult rv = MsgDetectCharsetFromFile(aFile, charset);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -44,19 +40,20 @@ nsresult nsTextAddress::GetUnicharLineStreamForFile(nsIFile *aFile,
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIConverterInputStream> converterStream =
|
||||
do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
|
||||
do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = converterStream->Init(aInputStream,
|
||||
charset.get(),
|
||||
8192,
|
||||
nsIConverterInputStream::DEFAULT_REPLACEMENT_CHARACTER);
|
||||
rv = converterStream->Init(
|
||||
aInputStream, charset.get(), 8192,
|
||||
nsIConverterInputStream::DEFAULT_REPLACEMENT_CHARACTER);
|
||||
}
|
||||
|
||||
return CallQueryInterface(converterStream, aStream);
|
||||
}
|
||||
|
||||
nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName, nsIFile *pSrc, nsIAddrDatabase *pDb, nsIImportFieldMap *fieldMap, nsString& errors, uint32_t *pProgress)
|
||||
{
|
||||
nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName,
|
||||
nsIFile *pSrc, nsIAddrDatabase *pDb,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsString &errors, uint32_t *pProgress) {
|
||||
// Open the source file for reading, read each line and process it!
|
||||
m_database = pDb;
|
||||
m_fieldMap = fieldMap;
|
||||
|
@ -84,12 +81,14 @@ nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName, nsI
|
|||
|
||||
rv = m_fieldMap->GetSkipFirstRecord(&skipRecord);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error checking to see if we should skip the first record\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Error checking to see if we should skip the first record\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUnicharLineInputStream> lineStream;
|
||||
rv = GetUnicharLineStreamForFile(pSrc, inputStream, getter_AddRefs(lineStream));
|
||||
rv = GetUnicharLineStreamForFile(pSrc, inputStream,
|
||||
getter_AddRefs(lineStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error opening converter stream for importer\n");
|
||||
return rv;
|
||||
|
@ -99,8 +98,7 @@ nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName, nsI
|
|||
nsAutoString line;
|
||||
|
||||
// Skip the first record if the user has requested it.
|
||||
if (skipRecord)
|
||||
rv = ReadRecord(lineStream, line, &more);
|
||||
if (skipRecord) rv = ReadRecord(lineStream, line, &more);
|
||||
|
||||
while (!(*pAbort) && more && NS_SUCCEEDED(rv)) {
|
||||
// Read the line in
|
||||
|
@ -125,7 +123,8 @@ nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName, nsI
|
|||
inputStream->Close();
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error reading the address book - probably incorrect ending\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Error reading the address book - probably incorrect ending\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -133,9 +132,7 @@ nsresult nsTextAddress::ImportAddresses(bool *pAbort, const char16_t *pName, nsI
|
|||
}
|
||||
|
||||
nsresult nsTextAddress::ReadRecord(nsIUnicharLineInputStream *aLineStream,
|
||||
nsAString &aLine,
|
||||
bool *aMore)
|
||||
{
|
||||
nsAString &aLine, bool *aMore) {
|
||||
bool more = true;
|
||||
uint32_t numQuotes = 0;
|
||||
nsresult rv;
|
||||
|
@ -148,13 +145,11 @@ nsresult nsTextAddress::ReadRecord(nsIUnicharLineInputStream *aLineStream,
|
|||
if (!more) {
|
||||
// No more, so we must have an incorrect file.
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Read the line and append it
|
||||
rv = aLineStream->ReadLine(line, &more);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (!aLine.IsEmpty())
|
||||
aLine.AppendLiteral(MSG_LINEBREAK);
|
||||
if (!aLine.IsEmpty()) aLine.AppendLiteral(MSG_LINEBREAK);
|
||||
aLine.Append(line);
|
||||
|
||||
numQuotes += MsgCountChar(line, char16_t('"'));
|
||||
|
@ -167,8 +162,8 @@ nsresult nsTextAddress::ReadRecord(nsIUnicharLineInputStream *aLineStream,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsTextAddress::ReadRecordNumber(nsIFile *aSrc, nsAString &aLine, int32_t rNum)
|
||||
{
|
||||
nsresult nsTextAddress::ReadRecordNumber(nsIFile *aSrc, nsAString &aLine,
|
||||
int32_t rNum) {
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), aSrc);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -187,7 +182,8 @@ nsresult nsTextAddress::ReadRecordNumber(nsIFile *aSrc, nsAString &aLine, int32_
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIUnicharLineInputStream> lineStream;
|
||||
rv = GetUnicharLineStreamForFile(aSrc, inputStream, getter_AddRefs(lineStream));
|
||||
rv = GetUnicharLineStreamForFile(aSrc, inputStream,
|
||||
getter_AddRefs(lineStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error opening converter stream for importer\n");
|
||||
return rv;
|
||||
|
@ -212,146 +208,126 @@ nsresult nsTextAddress::ReadRecordNumber(nsIFile *aSrc, nsAString &aLine, int32_
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
int32_t nsTextAddress::CountFields(const nsAString &aLine, char16_t delim)
|
||||
{
|
||||
int32_t pos = 0;
|
||||
int32_t maxLen = aLine.Length();
|
||||
int32_t count = 0;
|
||||
char16_t tab = char16_t('\t');
|
||||
char16_t doubleQuote = char16_t('"');
|
||||
int32_t nsTextAddress::CountFields(const nsAString &aLine, char16_t delim) {
|
||||
int32_t pos = 0;
|
||||
int32_t maxLen = aLine.Length();
|
||||
int32_t count = 0;
|
||||
char16_t tab = char16_t('\t');
|
||||
char16_t doubleQuote = char16_t('"');
|
||||
|
||||
if (delim == tab)
|
||||
tab = char16_t('\0');
|
||||
if (delim == tab) tab = char16_t('\0');
|
||||
|
||||
while (pos < maxLen) {
|
||||
while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
|
||||
(pos < maxLen)) {
|
||||
pos++;
|
||||
}
|
||||
if ((pos < maxLen) && (aLine[pos] == doubleQuote)) {
|
||||
pos++;
|
||||
while ((pos < maxLen) && (aLine[pos] != doubleQuote)) {
|
||||
pos++;
|
||||
if (((pos + 1) < maxLen) &&
|
||||
(aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
pos += 2;
|
||||
}
|
||||
}
|
||||
if (pos < maxLen)
|
||||
pos++;
|
||||
}
|
||||
while ((pos < maxLen) && (aLine[pos] != delim))
|
||||
pos++;
|
||||
|
||||
count++;
|
||||
while (pos < maxLen) {
|
||||
while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
|
||||
(pos < maxLen)) {
|
||||
pos++;
|
||||
}
|
||||
if ((pos < maxLen) && (aLine[pos] == doubleQuote)) {
|
||||
pos++;
|
||||
while ((pos < maxLen) && (aLine[pos] != doubleQuote)) {
|
||||
pos++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool nsTextAddress::GetField(const nsAString &aLine,
|
||||
int32_t index,
|
||||
nsString &field,
|
||||
char16_t delim)
|
||||
{
|
||||
bool result = false;
|
||||
int32_t pos = 0;
|
||||
int32_t maxLen = aLine.Length();
|
||||
char16_t tab = char16_t('\t');
|
||||
char16_t doubleQuote = char16_t('"');
|
||||
|
||||
field.Truncate();
|
||||
|
||||
if (delim == tab)
|
||||
tab = 0;
|
||||
|
||||
while (index && (pos < maxLen)) {
|
||||
while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
|
||||
(pos < maxLen)) {
|
||||
pos++;
|
||||
if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
pos += 2;
|
||||
}
|
||||
if (pos >= maxLen)
|
||||
break;
|
||||
if (aLine[pos] == doubleQuote) {
|
||||
do {
|
||||
pos++;
|
||||
if (((pos + 1) < maxLen) &&
|
||||
(aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
pos += 2;
|
||||
}
|
||||
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
|
||||
if (pos < maxLen)
|
||||
pos++;
|
||||
}
|
||||
if (pos >= maxLen)
|
||||
break;
|
||||
|
||||
while ((pos < maxLen) && (aLine[pos] != delim))
|
||||
pos++;
|
||||
|
||||
if (pos >= maxLen)
|
||||
break;
|
||||
|
||||
index--;
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (pos >= maxLen)
|
||||
return result;
|
||||
|
||||
result = true;
|
||||
|
||||
while ((pos < maxLen) && ((aLine[pos] == ' ') || (aLine[pos] == tab)))
|
||||
pos++;
|
||||
|
||||
int32_t fLen = 0;
|
||||
int32_t startPos = pos;
|
||||
bool quoted = false;
|
||||
if (aLine[pos] == '"') {
|
||||
startPos++;
|
||||
fLen = -1;
|
||||
do {
|
||||
pos++;
|
||||
fLen++;
|
||||
if (((pos + 1) < maxLen) &&
|
||||
(aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
quoted = true;
|
||||
pos += 2;
|
||||
fLen += 2;
|
||||
}
|
||||
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
|
||||
}
|
||||
else {
|
||||
while ((pos < maxLen) && (aLine[pos] != delim)) {
|
||||
pos++;
|
||||
fLen++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fLen) {
|
||||
return result;
|
||||
}
|
||||
|
||||
field.Append(nsDependentSubstring(aLine, startPos, fLen));
|
||||
field.Trim(kWhitespace);
|
||||
|
||||
if (quoted) {
|
||||
int32_t offset = field.Find("\"\"");
|
||||
while (offset != -1) {
|
||||
field.Cut(offset, 1);
|
||||
offset = MsgFind(field, "\"\"", false, offset + 1);
|
||||
}
|
||||
if (pos < maxLen) pos++;
|
||||
}
|
||||
while ((pos < maxLen) && (aLine[pos] != delim)) pos++;
|
||||
|
||||
return result;
|
||||
count++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc)
|
||||
{
|
||||
bool nsTextAddress::GetField(const nsAString &aLine, int32_t index,
|
||||
nsString &field, char16_t delim) {
|
||||
bool result = false;
|
||||
int32_t pos = 0;
|
||||
int32_t maxLen = aLine.Length();
|
||||
char16_t tab = char16_t('\t');
|
||||
char16_t doubleQuote = char16_t('"');
|
||||
|
||||
field.Truncate();
|
||||
|
||||
if (delim == tab) tab = 0;
|
||||
|
||||
while (index && (pos < maxLen)) {
|
||||
while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
|
||||
(pos < maxLen)) {
|
||||
pos++;
|
||||
}
|
||||
if (pos >= maxLen) break;
|
||||
if (aLine[pos] == doubleQuote) {
|
||||
do {
|
||||
pos++;
|
||||
if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
pos += 2;
|
||||
}
|
||||
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
|
||||
if (pos < maxLen) pos++;
|
||||
}
|
||||
if (pos >= maxLen) break;
|
||||
|
||||
while ((pos < maxLen) && (aLine[pos] != delim)) pos++;
|
||||
|
||||
if (pos >= maxLen) break;
|
||||
|
||||
index--;
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (pos >= maxLen) return result;
|
||||
|
||||
result = true;
|
||||
|
||||
while ((pos < maxLen) && ((aLine[pos] == ' ') || (aLine[pos] == tab))) pos++;
|
||||
|
||||
int32_t fLen = 0;
|
||||
int32_t startPos = pos;
|
||||
bool quoted = false;
|
||||
if (aLine[pos] == '"') {
|
||||
startPos++;
|
||||
fLen = -1;
|
||||
do {
|
||||
pos++;
|
||||
fLen++;
|
||||
if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
|
||||
(aLine[pos + 1] == doubleQuote)) {
|
||||
quoted = true;
|
||||
pos += 2;
|
||||
fLen += 2;
|
||||
}
|
||||
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
|
||||
} else {
|
||||
while ((pos < maxLen) && (aLine[pos] != delim)) {
|
||||
pos++;
|
||||
fLen++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fLen) {
|
||||
return result;
|
||||
}
|
||||
|
||||
field.Append(nsDependentSubstring(aLine, startPos, fLen));
|
||||
field.Trim(kWhitespace);
|
||||
|
||||
if (quoted) {
|
||||
int32_t offset = field.Find("\"\"");
|
||||
while (offset != -1) {
|
||||
field.Cut(offset, 1);
|
||||
offset = MsgFind(field, "\"\"", false, offset + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc) {
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), aSrc);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -368,7 +344,8 @@ nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc)
|
|||
bool more = true;
|
||||
|
||||
nsCOMPtr<nsIUnicharLineInputStream> lineStream;
|
||||
rv = GetUnicharLineStreamForFile(aSrc, inputStream, getter_AddRefs(lineStream));
|
||||
rv = GetUnicharLineStreamForFile(aSrc, inputStream,
|
||||
getter_AddRefs(lineStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error opening converter stream for importer\n");
|
||||
return rv;
|
||||
|
@ -394,7 +371,7 @@ nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc)
|
|||
else
|
||||
m_delim = char16_t(',');
|
||||
|
||||
IMPORT_LOG2( "Tab count = %d, Comma count = %d\n", tabLines, commaLines);
|
||||
IMPORT_LOG2("Tab count = %d, Comma count = %d\n", tabLines, commaLines);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -403,53 +380,48 @@ nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc)
|
|||
This is where the real work happens!
|
||||
Go through the field map and set the data in a new database row
|
||||
*/
|
||||
nsresult nsTextAddress::ProcessLine(const nsAString &aLine, nsString& errors)
|
||||
{
|
||||
if (!m_fieldMap) {
|
||||
IMPORT_LOG0("*** Error, text import needs a field map\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsresult nsTextAddress::ProcessLine(const nsAString &aLine, nsString &errors) {
|
||||
if (!m_fieldMap) {
|
||||
IMPORT_LOG0("*** Error, text import needs a field map\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
|
||||
// Wait until we get our first non-empty field, then create a new row,
|
||||
// fill in the data, then add the row to the database.
|
||||
nsCOMPtr<nsIMdbRow> newRow;
|
||||
nsAutoString fieldVal;
|
||||
int32_t fieldNum;
|
||||
int32_t numFields = 0;
|
||||
bool active;
|
||||
rv = m_fieldMap->GetMapSize(&numFields);
|
||||
for (int32_t i = 0; (i < numFields) && NS_SUCCEEDED(rv); i++) {
|
||||
active = false;
|
||||
rv = m_fieldMap->GetFieldMap(i, &fieldNum);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = m_fieldMap->GetFieldActive(i, &active);
|
||||
if (NS_SUCCEEDED(rv) && active) {
|
||||
if (GetField(aLine, i, fieldVal, m_delim)) {
|
||||
if (!fieldVal.IsEmpty()) {
|
||||
if (!newRow) {
|
||||
rv = m_database->GetNewRow(getter_AddRefs(newRow));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error getting new address database row\n");
|
||||
}
|
||||
}
|
||||
if (newRow) {
|
||||
rv = m_fieldMap->SetFieldValue(m_database, newRow, fieldNum, fieldVal.get());
|
||||
}
|
||||
}
|
||||
// Wait until we get our first non-empty field, then create a new row,
|
||||
// fill in the data, then add the row to the database.
|
||||
nsCOMPtr<nsIMdbRow> newRow;
|
||||
nsAutoString fieldVal;
|
||||
int32_t fieldNum;
|
||||
int32_t numFields = 0;
|
||||
bool active;
|
||||
rv = m_fieldMap->GetMapSize(&numFields);
|
||||
for (int32_t i = 0; (i < numFields) && NS_SUCCEEDED(rv); i++) {
|
||||
active = false;
|
||||
rv = m_fieldMap->GetFieldMap(i, &fieldNum);
|
||||
if (NS_SUCCEEDED(rv)) rv = m_fieldMap->GetFieldActive(i, &active);
|
||||
if (NS_SUCCEEDED(rv) && active) {
|
||||
if (GetField(aLine, i, fieldVal, m_delim)) {
|
||||
if (!fieldVal.IsEmpty()) {
|
||||
if (!newRow) {
|
||||
rv = m_database->GetNewRow(getter_AddRefs(newRow));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error getting new address database row\n");
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else if (active) {
|
||||
IMPORT_LOG1("*** Error getting field map for index %ld\n", (long) i);
|
||||
}
|
||||
if (newRow) {
|
||||
rv = m_fieldMap->SetFieldValue(m_database, newRow, fieldNum,
|
||||
fieldVal.get());
|
||||
}
|
||||
}
|
||||
} else
|
||||
break;
|
||||
} else if (active) {
|
||||
IMPORT_LOG1("*** Error getting field map for index %ld\n", (long)i);
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && newRow)
|
||||
rv = m_database->AddCardRowToDB(newRow);
|
||||
if (NS_SUCCEEDED(rv) && newRow) rv = m_database->AddCardRowToDB(newRow);
|
||||
|
||||
return rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,36 +22,38 @@ class nsIUnicharLineInputStream;
|
|||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsTextAddress {
|
||||
public:
|
||||
public:
|
||||
nsTextAddress();
|
||||
virtual ~nsTextAddress();
|
||||
|
||||
nsresult ImportAddresses(bool *pAbort, const char16_t *pName, nsIFile *pSrc, nsIAddrDatabase *pDb, nsIImportFieldMap *fieldMap, nsString& errors, uint32_t *pProgress);
|
||||
nsresult ImportAddresses(bool *pAbort, const char16_t *pName, nsIFile *pSrc,
|
||||
nsIAddrDatabase *pDb, nsIImportFieldMap *fieldMap,
|
||||
nsString &errors, uint32_t *pProgress);
|
||||
|
||||
nsresult DetermineDelim(nsIFile *pSrc);
|
||||
char16_t GetDelim(void) { return m_delim; }
|
||||
|
||||
static nsresult ReadRecordNumber(nsIFile *pSrc, nsAString &aLine, int32_t rNum);
|
||||
static bool GetField(const nsAString &aLine, int32_t index, nsString &field, char16_t delim);
|
||||
static nsresult ReadRecordNumber(nsIFile *pSrc, nsAString &aLine,
|
||||
int32_t rNum);
|
||||
static bool GetField(const nsAString &aLine, int32_t index, nsString &field,
|
||||
char16_t delim);
|
||||
|
||||
private:
|
||||
private:
|
||||
nsresult ProcessLine(const nsAString &aLine, nsString &errors);
|
||||
|
||||
static int32_t CountFields(const nsAString &aLine, char16_t delim);
|
||||
static nsresult ReadRecord(nsIUnicharLineInputStream *pSrc, nsAString &aLine, bool *aMore);
|
||||
static nsresult GetUnicharLineStreamForFile(nsIFile *aFile,
|
||||
nsIInputStream *aInputStream,
|
||||
nsIUnicharLineInputStream **aStream);
|
||||
static nsresult ReadRecord(nsIUnicharLineInputStream *pSrc, nsAString &aLine,
|
||||
bool *aMore);
|
||||
static nsresult GetUnicharLineStreamForFile(
|
||||
nsIFile *aFile, nsIInputStream *aInputStream,
|
||||
nsIUnicharLineInputStream **aStream);
|
||||
|
||||
char16_t m_delim;
|
||||
int32_t m_LFCount;
|
||||
int32_t m_CRCount;
|
||||
nsCOMPtr<nsIAddrDatabase> m_database;
|
||||
nsCOMPtr<nsIAddrDatabase> m_database;
|
||||
nsCOMPtr<nsIImportFieldMap> m_fieldMap;
|
||||
nsCOMPtr<nsIImportService> m_pService;
|
||||
nsCOMPtr<nsIImportService> m_pService;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsTextAddress_h__ */
|
||||
|
||||
|
|
|
@ -31,34 +31,37 @@
|
|||
#include "nsMsgUtils.h"
|
||||
|
||||
#define TEXT_MSGS_URL "chrome://messenger/locale/textImportMsgs.properties"
|
||||
#define TEXTIMPORT_NAME 2000
|
||||
#define TEXTIMPORT_DESCRIPTION 2001
|
||||
#define TEXTIMPORT_ADDRESS_NAME 2002
|
||||
#define TEXTIMPORT_ADDRESS_SUCCESS 2003
|
||||
#define TEXTIMPORT_ADDRESS_BADPARAM 2004
|
||||
#define TEXTIMPORT_NAME 2000
|
||||
#define TEXTIMPORT_DESCRIPTION 2001
|
||||
#define TEXTIMPORT_ADDRESS_NAME 2002
|
||||
#define TEXTIMPORT_ADDRESS_SUCCESS 2003
|
||||
#define TEXTIMPORT_ADDRESS_BADPARAM 2004
|
||||
#define TEXTIMPORT_ADDRESS_BADSOURCEFILE 2005
|
||||
#define TEXTIMPORT_ADDRESS_CONVERTERROR 2006
|
||||
#define TEXTIMPORT_ADDRESS_CONVERTERROR 2006
|
||||
|
||||
class ImportAddressImpl final : public nsIImportAddressBooks
|
||||
{
|
||||
public:
|
||||
explicit ImportAddressImpl(nsIStringBundle* aStringBundle);
|
||||
class ImportAddressImpl final : public nsIImportAddressBooks {
|
||||
public:
|
||||
explicit ImportAddressImpl(nsIStringBundle *aStringBundle);
|
||||
|
||||
static nsresult Create(nsIImportAddressBooks** aImport,
|
||||
static nsresult Create(nsIImportAddressBooks **aImport,
|
||||
nsIStringBundle *aStringBundle);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
// nsISupports interface
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
// nsIImportAddressBooks interface
|
||||
// nsIImportAddressBooks interface
|
||||
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) override { *_retval = false; return NS_OK;}
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) override {
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAutoFind(char16_t **description, bool *_retval) override;
|
||||
|
||||
NS_IMETHOD GetNeedsFieldMap(nsIFile *location, bool *_retval) override;
|
||||
|
||||
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found, bool *userVerify) override;
|
||||
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found,
|
||||
bool *userVerify) override;
|
||||
|
||||
NS_IMETHOD FindAddressBooks(nsIFile *location, nsIArray **_retval) override;
|
||||
|
||||
|
@ -68,29 +71,29 @@ public:
|
|||
nsIAddrDatabase *destination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t **errorLog,
|
||||
char16_t **successLog,
|
||||
char16_t **errorLog, char16_t **successLog,
|
||||
bool *fatalError) override;
|
||||
|
||||
NS_IMETHOD GetImportProgress(uint32_t *_retval) override;
|
||||
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound, char16_t **pStr) override;
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound,
|
||||
char16_t **pStr) override;
|
||||
|
||||
NS_IMETHOD SetSampleLocation(nsIFile *) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
void ClearSampleFile(void);
|
||||
void SaveFieldMap(nsIImportFieldMap *pMap);
|
||||
|
||||
static void ReportSuccess(nsString& name, nsString *pStream,
|
||||
nsIStringBundle* pBundle);
|
||||
static void SetLogs(nsString& success, nsString& error, char16_t **pError,
|
||||
static void ReportSuccess(nsString &name, nsString *pStream,
|
||||
nsIStringBundle *pBundle);
|
||||
static void SetLogs(nsString &success, nsString &error, char16_t **pError,
|
||||
char16_t **pSuccess);
|
||||
static void ReportError(int32_t errorNum, nsString& name, nsString *pStream,
|
||||
nsIStringBundle* pBundle);
|
||||
static void SanitizeSampleData(nsString& val);
|
||||
static void ReportError(int32_t errorNum, nsString &name, nsString *pStream,
|
||||
nsIStringBundle *pBundle);
|
||||
static void SanitizeSampleData(nsString &val);
|
||||
|
||||
private:
|
||||
private:
|
||||
~ImportAddressImpl() {}
|
||||
nsTextAddress m_text;
|
||||
bool m_haveDelim;
|
||||
|
@ -103,30 +106,24 @@ private:
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsTextImport::nsTextImport()
|
||||
{
|
||||
nsTextImport::nsTextImport() {
|
||||
IMPORT_LOG0("nsTextImport Module Created\n");
|
||||
|
||||
nsImportStringBundle::GetStringBundle(TEXT_MSGS_URL,
|
||||
getter_AddRefs(m_stringBundle));
|
||||
}
|
||||
|
||||
nsTextImport::~nsTextImport()
|
||||
{
|
||||
IMPORT_LOG0("nsTextImport Module Deleted\n");
|
||||
}
|
||||
nsTextImport::~nsTextImport() { IMPORT_LOG0("nsTextImport Module Deleted\n"); }
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsTextImport, nsIImportModule)
|
||||
|
||||
NS_IMETHODIMP nsTextImport::GetName(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsTextImport::GetName(char16_t **name) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
*name = nsImportStringBundle::GetStringByID(TEXTIMPORT_NAME, m_stringBundle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextImport::GetDescription(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsTextImport::GetDescription(char16_t **name) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
*name = nsImportStringBundle::GetStringByID(TEXTIMPORT_DESCRIPTION,
|
||||
m_stringBundle);
|
||||
|
@ -134,25 +131,22 @@ NS_IMETHODIMP nsTextImport::GetDescription(char16_t **name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextImport::GetSupports(char **supports)
|
||||
{
|
||||
NS_IMETHODIMP nsTextImport::GetSupports(char **supports) {
|
||||
NS_ENSURE_ARG_POINTER(supports);
|
||||
*supports = strdup(kTextSupportsString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextImport::GetSupportsUpgrade(bool *pUpgrade)
|
||||
{
|
||||
NS_IMETHODIMP nsTextImport::GetSupportsUpgrade(bool *pUpgrade) {
|
||||
NS_ASSERTION(pUpgrade != nullptr, "null ptr");
|
||||
if (! pUpgrade)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pUpgrade) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*pUpgrade = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface)
|
||||
{
|
||||
NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType,
|
||||
nsISupports **ppInterface) {
|
||||
NS_ENSURE_ARG_POINTER(pImportType);
|
||||
NS_ENSURE_ARG_POINTER(ppInterface);
|
||||
|
||||
|
@ -165,7 +159,8 @@ NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType, nsISuppo
|
|||
nsCOMPtr<nsIImportGeneric> pGeneric;
|
||||
rv = ImportAddressImpl::Create(getter_AddRefs(pAddress), m_stringBundle);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = impSvc->CreateNewGenericAddressBooks(getter_AddRefs(pGeneric));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -182,51 +177,44 @@ NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType, nsISuppo
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport,
|
||||
nsIStringBundle* aStringBundle)
|
||||
{
|
||||
nsresult ImportAddressImpl::Create(nsIImportAddressBooks **aImport,
|
||||
nsIStringBundle *aStringBundle) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new ImportAddressImpl(aStringBundle));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ImportAddressImpl::ImportAddressImpl(nsIStringBundle* aStringBundle) :
|
||||
m_notProxyBundle(aStringBundle)
|
||||
{
|
||||
ImportAddressImpl::ImportAddressImpl(nsIStringBundle *aStringBundle)
|
||||
: m_notProxyBundle(aStringBundle) {
|
||||
m_haveDelim = false;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImportAddressImpl, nsIImportAddressBooks)
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(char16_t **addrDescription, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(char16_t **addrDescription,
|
||||
bool *_retval) {
|
||||
NS_ASSERTION(addrDescription != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (! addrDescription || !_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!addrDescription || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsString str;
|
||||
*_retval = false;
|
||||
|
||||
if (!m_notProxyBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_notProxyBundle) return NS_ERROR_FAILURE;
|
||||
|
||||
nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_NAME, m_notProxyBundle, str);
|
||||
nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_NAME, m_notProxyBundle,
|
||||
str);
|
||||
*addrDescription = ToNewUnicode(str);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetDefaultLocation(nsIFile **ppLoc, bool *found, bool *userVerify)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::GetDefaultLocation(nsIFile **ppLoc,
|
||||
bool *found,
|
||||
bool *userVerify) {
|
||||
NS_ASSERTION(found != nullptr, "null ptr");
|
||||
NS_ASSERTION(ppLoc != nullptr, "null ptr");
|
||||
NS_ASSERTION(userVerify != nullptr, "null ptr");
|
||||
if (! found || !userVerify || !ppLoc)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!found || !userVerify || !ppLoc) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*ppLoc = nullptr;
|
||||
*found = false;
|
||||
|
@ -234,27 +222,22 @@ NS_IMETHODIMP ImportAddressImpl::GetDefaultLocation(nsIFile **ppLoc, bool *found
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsIArray **ppArray)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc,
|
||||
nsIArray **ppArray) {
|
||||
NS_ASSERTION(pLoc != nullptr, "null ptr");
|
||||
NS_ASSERTION(ppArray != nullptr, "null ptr");
|
||||
if (!pLoc || !ppArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pLoc || !ppArray) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
ClearSampleFile();
|
||||
|
||||
*ppArray = nullptr;
|
||||
bool exists = false;
|
||||
nsresult rv = pLoc->Exists(&exists);
|
||||
if (NS_FAILED(rv) || !exists)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !exists) return NS_ERROR_FAILURE;
|
||||
|
||||
bool isFile = false;
|
||||
rv = pLoc->IsFile(&isFile);
|
||||
if (NS_FAILED(rv) || !isFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !isFile) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = m_text.DetermineDelim(pLoc);
|
||||
|
||||
|
@ -288,7 +271,8 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsIArray **ppAr
|
|||
|
||||
nsCOMPtr<nsIImportABDescriptor> desc;
|
||||
|
||||
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Failed to obtain the import service\n");
|
||||
return rv;
|
||||
|
@ -299,7 +283,7 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsIArray **ppAr
|
|||
int64_t sz = 0;
|
||||
pLoc->GetFileSize(&sz);
|
||||
desc->SetPreferredName(name);
|
||||
desc->SetSize((uint32_t) sz);
|
||||
desc->SetSize((uint32_t)sz);
|
||||
desc->SetAbFile(m_fileLoc);
|
||||
nsCOMPtr<nsISupports> pInterface(do_QueryInterface(desc));
|
||||
array->AppendElement(pInterface);
|
||||
|
@ -312,15 +296,13 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsIArray **ppAr
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void ImportAddressImpl::ReportSuccess(nsString& name, nsString *pStream,
|
||||
nsIStringBundle* pBundle)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportAddressImpl::ReportSuccess(nsString &name, nsString *pStream,
|
||||
nsIStringBundle *pBundle) {
|
||||
if (!pStream) return;
|
||||
|
||||
// load the success string
|
||||
char16_t *pFmt =
|
||||
nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_SUCCESS, pBundle);
|
||||
nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_SUCCESS, pBundle);
|
||||
|
||||
nsString pText;
|
||||
nsTextFormatter::ssprintf(pText, pFmt, name.get());
|
||||
|
@ -329,11 +311,10 @@ void ImportAddressImpl::ReportSuccess(nsString& name, nsString *pStream,
|
|||
pStream->Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
void ImportAddressImpl::ReportError(int32_t errorNum, nsString& name,
|
||||
nsString *pStream, nsIStringBundle* pBundle)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportAddressImpl::ReportError(int32_t errorNum, nsString &name,
|
||||
nsString *pStream,
|
||||
nsIStringBundle *pBundle) {
|
||||
if (!pStream) return;
|
||||
|
||||
// load the error string
|
||||
char16_t *pFmt = nsImportStringBundle::GetStringByID(errorNum, pBundle);
|
||||
|
@ -344,24 +325,19 @@ void ImportAddressImpl::ReportError(int32_t errorNum, nsString& name,
|
|||
pStream->Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
void ImportAddressImpl::SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess)
|
||||
{
|
||||
if (pError)
|
||||
*pError = ToNewUnicode(error);
|
||||
if (pSuccess)
|
||||
*pSuccess = ToNewUnicode(success);
|
||||
void ImportAddressImpl::SetLogs(nsString &success, nsString &error,
|
||||
char16_t **pError, char16_t **pSuccess) {
|
||||
if (pError) *pError = ToNewUnicode(error);
|
||||
if (pSuccess) *pSuccess = ToNewUnicode(success);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
|
||||
nsIAddrDatabase *pDestination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t ** pErrorLog,
|
||||
char16_t ** pSuccessLog,
|
||||
bool * fatalError)
|
||||
{
|
||||
char16_t **pErrorLog,
|
||||
char16_t **pSuccessLog, bool *fatalError) {
|
||||
NS_ASSERTION(pSource != nullptr, "null ptr");
|
||||
NS_ASSERTION(pDestination != nullptr, "null ptr");
|
||||
NS_ASSERTION(fatalError != nullptr, "null ptr");
|
||||
|
@ -372,13 +348,11 @@ ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
|
|||
if (!pSource || !pDestination || !fatalError) {
|
||||
IMPORT_LOG0("*** Bad param passed to text address import\n");
|
||||
nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_BADPARAM,
|
||||
m_notProxyBundle,
|
||||
error);
|
||||
m_notProxyBundle, error);
|
||||
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
|
||||
if (fatalError)
|
||||
*fatalError = true;
|
||||
if (fatalError) *fatalError = true;
|
||||
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
@ -400,7 +374,8 @@ ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
|
|||
|
||||
nsCOMPtr<nsIFile> inFile;
|
||||
if (NS_FAILED(pSource->GetAbFile(getter_AddRefs(inFile)))) {
|
||||
ReportError(TEXTIMPORT_ADDRESS_BADSOURCEFILE, name, &error, m_notProxyBundle);
|
||||
ReportError(TEXTIMPORT_ADDRESS_BADSOURCEFILE, name, &error,
|
||||
m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -412,38 +387,41 @@ ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
|
|||
|
||||
bool isLDIF = false;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService(do_QueryInterface(aSupportService, &rv));
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService(
|
||||
do_QueryInterface(aSupportService, &rv));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ldifService->IsLDIFFile(inFile, &isLDIF);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error reading address file\n");
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ldifService->IsLDIFFile(inFile, &isLDIF);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error reading address file\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error, m_notProxyBundle);
|
||||
ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error,
|
||||
m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (isLDIF) {
|
||||
if (ldifService)
|
||||
rv = ldifService->ImportLDIFFile(pDestination, inFile, false, &m_bytesImported);
|
||||
rv = ldifService->ImportLDIFFile(pDestination, inFile, false,
|
||||
&m_bytesImported);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
rv = m_text.ImportAddresses(&addrAbort, name.get(), inFile, pDestination, fieldMap, error, &m_bytesImported);
|
||||
} else {
|
||||
rv = m_text.ImportAddresses(&addrAbort, name.get(), inFile, pDestination,
|
||||
fieldMap, error, &m_bytesImported);
|
||||
SaveFieldMap(fieldMap);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && error.IsEmpty()) {
|
||||
ReportSuccess(name, &success, m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
}
|
||||
else {
|
||||
ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error, m_notProxyBundle);
|
||||
} else {
|
||||
ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error,
|
||||
m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
}
|
||||
|
||||
|
@ -451,17 +429,14 @@ ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetImportProgress(uint32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::GetImportProgress(uint32_t *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = m_bytesImported;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetNeedsFieldMap(nsIFile *aLocation, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::GetNeedsFieldMap(nsIFile *aLocation,
|
||||
bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
|
||||
|
@ -472,28 +447,25 @@ NS_IMETHODIMP ImportAddressImpl::GetNeedsFieldMap(nsIFile *aLocation, bool *_ret
|
|||
nsresult rv = aLocation->Exists(&exists);
|
||||
rv = aLocation->IsFile(&isFile);
|
||||
|
||||
if (!exists || !isFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!exists || !isFile) return NS_ERROR_FAILURE;
|
||||
|
||||
bool isLDIF = false;
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService = do_GetService(NS_ABLDIFSERVICE_CONTRACTID, &rv);
|
||||
bool isLDIF = false;
|
||||
nsCOMPtr<nsIAbLDIFService> ldifService =
|
||||
do_GetService(NS_ABLDIFSERVICE_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = ldifService->IsLDIFFile(aLocation, &isLDIF);
|
||||
if (NS_SUCCEEDED(rv)) rv = ldifService->IsLDIFFile(aLocation, &isLDIF);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error determining if file is of type LDIF\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (isLDIF)
|
||||
*_retval = false;
|
||||
if (isLDIF) *_retval = false;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void ImportAddressImpl::SanitizeSampleData(nsString& val)
|
||||
{
|
||||
void ImportAddressImpl::SanitizeSampleData(nsString &val) {
|
||||
// remove any line-feeds...
|
||||
int32_t offset = val.Find(NS_LITERAL_STRING("\x0D\x0A"));
|
||||
while (offset != -1) {
|
||||
|
@ -512,12 +484,11 @@ void ImportAddressImpl::SanitizeSampleData(nsString& val)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetSampleData(int32_t index, bool *pFound, char16_t **pStr)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::GetSampleData(int32_t index, bool *pFound,
|
||||
char16_t **pStr) {
|
||||
NS_ASSERTION(pFound != nullptr, "null ptr");
|
||||
NS_ASSERTION(pStr != nullptr, "null ptr");
|
||||
if (!pFound || !pStr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pFound || !pStr) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!m_fileLoc) {
|
||||
IMPORT_LOG0("*** Error, called GetSampleData before SetSampleLocation\n");
|
||||
|
@ -552,8 +523,7 @@ NS_IMETHODIMP ImportAddressImpl::GetSampleData(int32_t index, bool *pFound, char
|
|||
nsString field;
|
||||
int32_t fNum = 0;
|
||||
while (nsTextAddress::GetField(line, fNum, field, m_delim)) {
|
||||
if (fNum)
|
||||
str.Append(char16_t('\n'));
|
||||
if (fNum) str.Append(char16_t('\n'));
|
||||
SanitizeSampleData(field);
|
||||
str.Append(field);
|
||||
fNum++;
|
||||
|
@ -564,8 +534,7 @@ NS_IMETHODIMP ImportAddressImpl::GetSampleData(int32_t index, bool *pFound, char
|
|||
*pFound = true;
|
||||
|
||||
/* IMPORT_LOG1("Sample data: %S\n", str.get()); */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*pFound = false;
|
||||
*pStr = NS_xstrdup(&term);
|
||||
}
|
||||
|
@ -573,8 +542,7 @@ NS_IMETHODIMP ImportAddressImpl::GetSampleData(int32_t index, bool *pFound, char
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::SetSampleLocation(nsIFile *pLocation)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::SetSampleLocation(nsIFile *pLocation) {
|
||||
NS_ENSURE_ARG_POINTER(pLocation);
|
||||
|
||||
m_fileLoc = pLocation;
|
||||
|
@ -582,14 +550,12 @@ NS_IMETHODIMP ImportAddressImpl::SetSampleLocation(nsIFile *pLocation)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void ImportAddressImpl::ClearSampleFile(void)
|
||||
{
|
||||
void ImportAddressImpl::ClearSampleFile(void) {
|
||||
m_fileLoc = nullptr;
|
||||
m_haveDelim = false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIImportFieldMap *fieldMap)
|
||||
{
|
||||
NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIImportFieldMap *fieldMap) {
|
||||
// Let's remember the last one the user used!
|
||||
// This should be normal for someone importing multiple times, it's usually
|
||||
// from the same file format.
|
||||
|
@ -607,8 +573,7 @@ NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIImportFieldMap *fieldMap)
|
|||
bool active;
|
||||
long fIndex = 0;
|
||||
while (*pStr) {
|
||||
while (*pStr && (*pStr != '+') && (*pStr != '-'))
|
||||
pStr++;
|
||||
while (*pStr && (*pStr != '+') && (*pStr != '-')) pStr++;
|
||||
if (*pStr == '+')
|
||||
active = true;
|
||||
else if (*pStr == '-')
|
||||
|
@ -616,19 +581,15 @@ NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIImportFieldMap *fieldMap)
|
|||
else
|
||||
break;
|
||||
fNum = 0;
|
||||
while (*pStr && ((*pStr < '0') || (*pStr > '9')))
|
||||
pStr++;
|
||||
if (!(*pStr))
|
||||
break;
|
||||
while (*pStr && ((*pStr < '0') || (*pStr > '9'))) pStr++;
|
||||
if (!(*pStr)) break;
|
||||
while (*pStr && (*pStr >= '0') && (*pStr <= '9')) {
|
||||
fNum *= 10;
|
||||
fNum += (*pStr - '0');
|
||||
pStr++;
|
||||
}
|
||||
while (*pStr && (*pStr != ','))
|
||||
pStr++;
|
||||
if (*pStr == ',')
|
||||
pStr++;
|
||||
while (*pStr && (*pStr != ',')) pStr++;
|
||||
if (*pStr == ',') pStr++;
|
||||
fieldMap->SetFieldMap(-1, fNum);
|
||||
fieldMap->SetFieldActive(fIndex, active);
|
||||
fIndex++;
|
||||
|
@ -643,19 +604,16 @@ NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIImportFieldMap *fieldMap)
|
|||
|
||||
// Now also get the last used skip first record value.
|
||||
bool skipFirstRecord = false;
|
||||
rv = prefs->GetBoolPref("mailnews.import.text.skipfirstrecord", &skipFirstRecord);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
fieldMap->SetSkipFirstRecord(skipFirstRecord);
|
||||
rv = prefs->GetBoolPref("mailnews.import.text.skipfirstrecord",
|
||||
&skipFirstRecord);
|
||||
if (NS_SUCCEEDED(rv)) fieldMap->SetSkipFirstRecord(skipFirstRecord);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void ImportAddressImpl::SaveFieldMap(nsIImportFieldMap *pMap)
|
||||
{
|
||||
if (!pMap)
|
||||
return;
|
||||
void ImportAddressImpl::SaveFieldMap(nsIImportFieldMap *pMap) {
|
||||
if (!pMap) return;
|
||||
|
||||
int size;
|
||||
int index;
|
||||
|
|
|
@ -11,16 +11,17 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
#define NS_TEXTIMPORT_CID \
|
||||
{ /* A5991D01-ADA7-11d3-A9C2-00A0CC26DA63 */ \
|
||||
0xa5991d01, 0xada7, 0x11d3, \
|
||||
{0xa9, 0xc2, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 }}
|
||||
#define NS_TEXTIMPORT_CID \
|
||||
{ /* A5991D01-ADA7-11d3-A9C2-00A0CC26DA63 */ \
|
||||
0xa5991d01, 0xada7, 0x11d3, { \
|
||||
0xa9, 0xc2, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define kTextSupportsString NS_IMPORT_ADDRESS_STR
|
||||
|
||||
class nsTextImport : public nsIImportModule
|
||||
{
|
||||
public:
|
||||
class nsTextImport : public nsIImportModule {
|
||||
public:
|
||||
nsTextImport();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -31,9 +32,9 @@ public:
|
|||
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual ~nsTextImport();
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
};
|
||||
|
||||
#endif /* nsTextImport_h___ */
|
||||
|
|
|
@ -18,22 +18,14 @@
|
|||
#include "msgCore.h"
|
||||
#include "nsMsgUtils.h"
|
||||
|
||||
nsVCardAddress::nsVCardAddress()
|
||||
{
|
||||
}
|
||||
nsVCardAddress::nsVCardAddress() {}
|
||||
|
||||
nsVCardAddress::~nsVCardAddress()
|
||||
{
|
||||
}
|
||||
nsVCardAddress::~nsVCardAddress() {}
|
||||
|
||||
nsresult nsVCardAddress::ImportAddresses(
|
||||
bool *pAbort,
|
||||
const char16_t *pName,
|
||||
nsIFile *pSrc,
|
||||
nsIAddrDatabase *pDb,
|
||||
nsString& errors,
|
||||
uint32_t *pProgress)
|
||||
{
|
||||
nsresult nsVCardAddress::ImportAddresses(bool *pAbort, const char16_t *pName,
|
||||
nsIFile *pSrc, nsIAddrDatabase *pDb,
|
||||
nsString &errors,
|
||||
uint32_t *pProgress) {
|
||||
// Open the source file for reading, read each line and process it!
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), pSrc);
|
||||
|
@ -68,7 +60,8 @@ nsresult nsVCardAddress::ImportAddresses(
|
|||
if (NS_SUCCEEDED(rv) && !record.IsEmpty()) {
|
||||
// Parse the vCard and build an nsIAbCard from it
|
||||
nsCOMPtr<nsIAbCard> cardFromVCard;
|
||||
rv = ab->EscapedVCardToAbCard(record.get(), getter_AddRefs(cardFromVCard));
|
||||
rv =
|
||||
ab->EscapedVCardToAbCard(record.get(), getter_AddRefs(cardFromVCard));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = pDb->CreateNewCardAndAddToDB(cardFromVCard, false, nullptr);
|
||||
|
@ -89,16 +82,16 @@ nsresult nsVCardAddress::ImportAddresses(
|
|||
inputStream->Close();
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Error reading the address book - probably incorrect ending\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Error reading the address book - probably incorrect ending\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return pDb->Commit(nsAddrDBCommitType::kLargeCommit);
|
||||
}
|
||||
|
||||
nsresult nsVCardAddress::ReadRecord(
|
||||
nsILineInputStream *aLineStream, nsCString &aRecord, bool *aMore)
|
||||
{
|
||||
nsresult nsVCardAddress::ReadRecord(nsILineInputStream *aLineStream,
|
||||
nsCString &aRecord, bool *aMore) {
|
||||
bool more = true;
|
||||
nsresult rv;
|
||||
nsCString line;
|
||||
|
@ -108,14 +101,13 @@ nsresult nsVCardAddress::ReadRecord(
|
|||
// remove the empty lines.
|
||||
do {
|
||||
rv = aLineStream->ReadLine(line, aMore);
|
||||
}
|
||||
while (line.IsEmpty() && *aMore);
|
||||
if (!*aMore)
|
||||
return rv;
|
||||
} while (line.IsEmpty() && *aMore);
|
||||
if (!*aMore) return rv;
|
||||
|
||||
// read BEGIN:VCARD
|
||||
if (!line.LowerCaseEqualsLiteral("begin:vcard")) {
|
||||
IMPORT_LOG0("*** Expected case-insensitive BEGIN:VCARD at start of vCard\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Expected case-insensitive BEGIN:VCARD at start of vCard\n");
|
||||
rv = NS_ERROR_FAILURE;
|
||||
*aMore = more;
|
||||
return rv;
|
||||
|
@ -125,7 +117,8 @@ nsresult nsVCardAddress::ReadRecord(
|
|||
// read until END:VCARD
|
||||
do {
|
||||
if (!more) {
|
||||
IMPORT_LOG0("*** Expected case-insensitive END:VCARD at start of vCard\n");
|
||||
IMPORT_LOG0(
|
||||
"*** Expected case-insensitive END:VCARD at start of vCard\n");
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -12,22 +12,17 @@ class nsIFile;
|
|||
class nsILineInputStream;
|
||||
|
||||
class nsVCardAddress {
|
||||
public:
|
||||
public:
|
||||
nsVCardAddress();
|
||||
virtual ~nsVCardAddress();
|
||||
|
||||
nsresult ImportAddresses(
|
||||
bool *pAbort,
|
||||
const char16_t *pName,
|
||||
nsIFile *pSrc,
|
||||
nsIAddrDatabase *pDb,
|
||||
nsString& errors,
|
||||
uint32_t *pProgress);
|
||||
nsresult ImportAddresses(bool *pAbort, const char16_t *pName, nsIFile *pSrc,
|
||||
nsIAddrDatabase *pDb, nsString &errors,
|
||||
uint32_t *pProgress);
|
||||
|
||||
private:
|
||||
static nsresult ReadRecord(
|
||||
nsILineInputStream *aLineStream, nsCString &aRecord, bool *aMore);
|
||||
private:
|
||||
static nsresult ReadRecord(nsILineInputStream *aLineStream,
|
||||
nsCString &aRecord, bool *aMore);
|
||||
};
|
||||
|
||||
#endif /* nsVCardAddress_h__ */
|
||||
|
||||
|
|
|
@ -24,13 +24,12 @@
|
|||
#include "nsVCardAddress.h"
|
||||
#include "nsVCardImport.h"
|
||||
|
||||
class ImportVCardAddressImpl : public nsIImportAddressBooks
|
||||
{
|
||||
public:
|
||||
explicit ImportVCardAddressImpl(nsIStringBundle* aStringBundle);
|
||||
class ImportVCardAddressImpl : public nsIImportAddressBooks {
|
||||
public:
|
||||
explicit ImportVCardAddressImpl(nsIStringBundle *aStringBundle);
|
||||
|
||||
static nsresult Create(
|
||||
nsIImportAddressBooks** aImport, nsIStringBundle* aStringBundle);
|
||||
static nsresult Create(nsIImportAddressBooks **aImport,
|
||||
nsIStringBundle *aStringBundle);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
@ -39,104 +38,100 @@ public:
|
|||
|
||||
// TODO: support multiple vCard files in future - shouldn't be too hard,
|
||||
// since you just import each file in turn.
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) override
|
||||
{ *_retval = false; return NS_OK;}
|
||||
NS_IMETHOD GetSupportsMultiple(bool *_retval) override {
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAutoFind(char16_t **description, bool *_retval) override;
|
||||
|
||||
NS_IMETHOD GetNeedsFieldMap(nsIFile *location, bool *_retval) override
|
||||
{ *_retval = false; return NS_OK;}
|
||||
NS_IMETHOD GetNeedsFieldMap(nsIFile *location, bool *_retval) override {
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetDefaultLocation(
|
||||
nsIFile **location, bool *found, bool *userVerify) override;
|
||||
NS_IMETHOD GetDefaultLocation(nsIFile **location, bool *found,
|
||||
bool *userVerify) override;
|
||||
|
||||
NS_IMETHOD FindAddressBooks(nsIFile *location, nsIArray **_retval) override;
|
||||
|
||||
NS_IMETHOD InitFieldMap(nsIImportFieldMap *fieldMap) override
|
||||
{ return NS_ERROR_FAILURE;}
|
||||
NS_IMETHOD InitFieldMap(nsIImportFieldMap *fieldMap) override {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHOD ImportAddressBook(nsIImportABDescriptor *source,
|
||||
nsIAddrDatabase *destination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t **errorLog,
|
||||
char16_t **successLog,
|
||||
char16_t **errorLog, char16_t **successLog,
|
||||
bool *fatalError) override;
|
||||
|
||||
NS_IMETHOD GetImportProgress(uint32_t *_retval) override;
|
||||
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound, char16_t **pStr) override
|
||||
{ return NS_ERROR_FAILURE;}
|
||||
NS_IMETHOD GetSampleData(int32_t index, bool *pFound,
|
||||
char16_t **pStr) override {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHOD SetSampleLocation(nsIFile *) override
|
||||
{ return NS_ERROR_FAILURE; }
|
||||
NS_IMETHOD SetSampleLocation(nsIFile *) override { return NS_ERROR_FAILURE; }
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~ImportVCardAddressImpl();
|
||||
static void ReportSuccess(
|
||||
nsString& name, nsString *pStream, nsIStringBundle* pBundle);
|
||||
static void SetLogs(
|
||||
nsString& success, nsString& error,
|
||||
char16_t **pError, char16_t **pSuccess);
|
||||
static void ReportError(
|
||||
const char *errorName, nsString& name, nsString *pStream,
|
||||
nsIStringBundle* pBundle);
|
||||
static void ReportSuccess(nsString &name, nsString *pStream,
|
||||
nsIStringBundle *pBundle);
|
||||
static void SetLogs(nsString &success, nsString &error, char16_t **pError,
|
||||
char16_t **pSuccess);
|
||||
static void ReportError(const char *errorName, nsString &name,
|
||||
nsString *pStream, nsIStringBundle *pBundle);
|
||||
|
||||
private:
|
||||
private:
|
||||
nsVCardAddress m_vCard;
|
||||
nsCOMPtr<nsIFile> m_fileLoc;
|
||||
uint32_t m_bytesImported;
|
||||
nsCOMPtr<nsIStringBundle> m_notProxyBundle;
|
||||
};
|
||||
|
||||
nsVCardImport::nsVCardImport()
|
||||
{
|
||||
nsImportStringBundle::GetStringBundle(
|
||||
VCARDIMPORT_MSGS_URL, getter_AddRefs(m_stringBundle));
|
||||
nsVCardImport::nsVCardImport() {
|
||||
nsImportStringBundle::GetStringBundle(VCARDIMPORT_MSGS_URL,
|
||||
getter_AddRefs(m_stringBundle));
|
||||
|
||||
IMPORT_LOG0("nsVCardImport Module Created\n");
|
||||
}
|
||||
|
||||
nsVCardImport::~nsVCardImport()
|
||||
{
|
||||
nsVCardImport::~nsVCardImport() {
|
||||
IMPORT_LOG0("nsVCardImport Module Deleted\n");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsVCardImport, nsIImportModule)
|
||||
|
||||
NS_IMETHODIMP nsVCardImport::GetName(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsVCardImport::GetName(char16_t **name) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
*name = nsImportStringBundle::GetStringByName(
|
||||
"vCardImportName", m_stringBundle);
|
||||
*name =
|
||||
nsImportStringBundle::GetStringByName("vCardImportName", m_stringBundle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsVCardImport::GetDescription(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsVCardImport::GetDescription(char16_t **name) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
*name = nsImportStringBundle::GetStringByName(
|
||||
"vCardImportDescription", m_stringBundle);
|
||||
*name = nsImportStringBundle::GetStringByName("vCardImportDescription",
|
||||
m_stringBundle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsVCardImport::GetSupports(char **supports)
|
||||
{
|
||||
NS_IMETHODIMP nsVCardImport::GetSupports(char **supports) {
|
||||
NS_ENSURE_ARG_POINTER(supports);
|
||||
*supports = strdup(NS_IMPORT_ADDRESS_STR);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsVCardImport::GetSupportsUpgrade(bool *pUpgrade)
|
||||
{
|
||||
NS_IMETHODIMP nsVCardImport::GetSupportsUpgrade(bool *pUpgrade) {
|
||||
NS_ENSURE_ARG_POINTER(pUpgrade);
|
||||
*pUpgrade = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsVCardImport::GetImportInterface(
|
||||
const char *pImportType, nsISupports **ppInterface)
|
||||
{
|
||||
NS_IMETHODIMP nsVCardImport::GetImportInterface(const char *pImportType,
|
||||
nsISupports **ppInterface) {
|
||||
NS_ENSURE_ARG_POINTER(pImportType);
|
||||
NS_ENSURE_ARG_POINTER(ppInterface);
|
||||
*ppInterface = nullptr;
|
||||
|
@ -145,7 +140,8 @@ NS_IMETHODIMP nsVCardImport::GetImportInterface(
|
|||
// create the nsIImportMail interface and return it!
|
||||
nsCOMPtr<nsIImportAddressBooks> pAddress;
|
||||
nsCOMPtr<nsIImportGeneric> pGeneric;
|
||||
rv = ImportVCardAddressImpl::Create(getter_AddRefs(pAddress), m_stringBundle);
|
||||
rv = ImportVCardAddressImpl::Create(getter_AddRefs(pAddress),
|
||||
m_stringBundle);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
|
@ -163,45 +159,39 @@ NS_IMETHODIMP nsVCardImport::GetImportInterface(
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsresult ImportVCardAddressImpl::Create(
|
||||
nsIImportAddressBooks** aImport, nsIStringBundle* aStringBundle)
|
||||
{
|
||||
nsresult ImportVCardAddressImpl::Create(nsIImportAddressBooks **aImport,
|
||||
nsIStringBundle *aStringBundle) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new ImportVCardAddressImpl(aStringBundle));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ImportVCardAddressImpl::ImportVCardAddressImpl(
|
||||
nsIStringBundle* aStringBundle) : m_notProxyBundle(aStringBundle)
|
||||
{
|
||||
}
|
||||
ImportVCardAddressImpl::ImportVCardAddressImpl(nsIStringBundle *aStringBundle)
|
||||
: m_notProxyBundle(aStringBundle) {}
|
||||
|
||||
ImportVCardAddressImpl::~ImportVCardAddressImpl()
|
||||
{
|
||||
}
|
||||
ImportVCardAddressImpl::~ImportVCardAddressImpl() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImportVCardAddressImpl, nsIImportAddressBooks)
|
||||
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetAutoFind(
|
||||
char16_t **addrDescription, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetAutoFind(char16_t **addrDescription,
|
||||
bool *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(addrDescription);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
nsString str;
|
||||
*_retval = false;
|
||||
|
||||
if (!m_notProxyBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_notProxyBundle) return NS_ERROR_FAILURE;
|
||||
|
||||
nsImportStringBundle::GetStringByName("vCardImportAddressName", m_notProxyBundle, str);
|
||||
nsImportStringBundle::GetStringByName("vCardImportAddressName",
|
||||
m_notProxyBundle, str);
|
||||
*addrDescription = ToNewUnicode(str);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetDefaultLocation(
|
||||
nsIFile **ppLoc, bool *found, bool *userVerify)
|
||||
{
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetDefaultLocation(nsIFile **ppLoc,
|
||||
bool *found,
|
||||
bool *userVerify) {
|
||||
NS_ENSURE_ARG_POINTER(found);
|
||||
NS_ENSURE_ARG_POINTER(ppLoc);
|
||||
NS_ENSURE_ARG_POINTER(userVerify);
|
||||
|
@ -212,22 +202,19 @@ NS_IMETHODIMP ImportVCardAddressImpl::GetDefaultLocation(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks(
|
||||
nsIFile *pLoc, nsIArray **ppArray)
|
||||
{
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks(nsIFile *pLoc,
|
||||
nsIArray **ppArray) {
|
||||
NS_ENSURE_ARG_POINTER(pLoc);
|
||||
NS_ENSURE_ARG_POINTER(ppArray);
|
||||
|
||||
*ppArray = nullptr;
|
||||
bool exists = false;
|
||||
nsresult rv = pLoc->Exists(&exists);
|
||||
if (NS_FAILED(rv) || !exists)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !exists) return NS_ERROR_FAILURE;
|
||||
|
||||
bool isFile = false;
|
||||
rv = pLoc->IsFile(&isFile);
|
||||
if (NS_FAILED(rv) || !isFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !isFile) return NS_ERROR_FAILURE;
|
||||
|
||||
m_fileLoc = pLoc;
|
||||
|
||||
|
@ -250,7 +237,7 @@ NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks(
|
|||
name.SetLength(idx);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIImportABDescriptor> desc;
|
||||
nsCOMPtr<nsIImportABDescriptor> desc;
|
||||
nsCOMPtr<nsIImportService> impSvc(
|
||||
do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -263,7 +250,7 @@ NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks(
|
|||
int64_t sz = 0;
|
||||
pLoc->GetFileSize(&sz);
|
||||
desc->SetPreferredName(name);
|
||||
desc->SetSize((uint32_t) sz);
|
||||
desc->SetSize((uint32_t)sz);
|
||||
desc->SetAbFile(m_fileLoc);
|
||||
nsCOMPtr<nsISupports> pInterface(do_QueryInterface(desc, &rv));
|
||||
array->AppendElement(pInterface);
|
||||
|
@ -278,11 +265,9 @@ NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void ImportVCardAddressImpl::ReportSuccess(
|
||||
nsString& name, nsString *pStream, nsIStringBundle* pBundle)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportVCardAddressImpl::ReportSuccess(nsString &name, nsString *pStream,
|
||||
nsIStringBundle *pBundle) {
|
||||
if (!pStream) return;
|
||||
|
||||
// load the success string
|
||||
char16_t *pFmt = nsImportStringBundle::GetStringByName(
|
||||
|
@ -295,12 +280,10 @@ void ImportVCardAddressImpl::ReportSuccess(
|
|||
pStream->Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
void ImportVCardAddressImpl::ReportError(
|
||||
const char *errorName, nsString& name, nsString *pStream,
|
||||
nsIStringBundle* pBundle)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportVCardAddressImpl::ReportError(const char *errorName, nsString &name,
|
||||
nsString *pStream,
|
||||
nsIStringBundle *pBundle) {
|
||||
if (!pStream) return;
|
||||
|
||||
// load the error string
|
||||
char16_t *pFmt = nsImportStringBundle::GetStringByName(errorName, pBundle);
|
||||
|
@ -311,31 +294,21 @@ void ImportVCardAddressImpl::ReportError(
|
|||
pStream->Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
void ImportVCardAddressImpl::SetLogs(
|
||||
nsString& success, nsString& error,
|
||||
char16_t **pError, char16_t **pSuccess)
|
||||
{
|
||||
if (pError)
|
||||
*pError = ToNewUnicode(error);
|
||||
if (pSuccess)
|
||||
*pSuccess = ToNewUnicode(success);
|
||||
void ImportVCardAddressImpl::SetLogs(nsString &success, nsString &error,
|
||||
char16_t **pError, char16_t **pSuccess) {
|
||||
if (pError) *pError = ToNewUnicode(error);
|
||||
if (pSuccess) *pSuccess = ToNewUnicode(success);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::ImportAddressBook(
|
||||
nsIImportABDescriptor *pSource,
|
||||
nsIAddrDatabase *pDestination,
|
||||
nsIImportFieldMap *fieldMap,
|
||||
nsISupports *aSupportService,
|
||||
char16_t ** pErrorLog,
|
||||
char16_t ** pSuccessLog,
|
||||
bool * fatalError)
|
||||
{
|
||||
nsIImportABDescriptor *pSource, nsIAddrDatabase *pDestination,
|
||||
nsIImportFieldMap *fieldMap, nsISupports *aSupportService,
|
||||
char16_t **pErrorLog, char16_t **pSuccessLog, bool *fatalError) {
|
||||
NS_ENSURE_ARG_POINTER(pSource);
|
||||
NS_ENSURE_ARG_POINTER(pDestination);
|
||||
NS_ENSURE_ARG_POINTER(fatalError);
|
||||
|
||||
if (!m_notProxyBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!m_notProxyBundle) return NS_ERROR_FAILURE;
|
||||
|
||||
m_bytesImported = 0;
|
||||
nsString success, error;
|
||||
|
@ -354,7 +327,8 @@ NS_IMETHODIMP ImportVCardAddressImpl::ImportAddressBook(
|
|||
|
||||
nsCOMPtr<nsIFile> inFile;
|
||||
if (NS_FAILED(pSource->GetAbFile(getter_AddRefs(inFile)))) {
|
||||
ReportError("vCardImportAddressBadSourceFile", name, &error, m_notProxyBundle);
|
||||
ReportError("vCardImportAddressBadSourceFile", name, &error,
|
||||
m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -364,15 +338,15 @@ NS_IMETHODIMP ImportVCardAddressImpl::ImportAddressBook(
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv = m_vCard.ImportAddresses(
|
||||
&addrAbort, name.get(), inFile, pDestination, error, &m_bytesImported);
|
||||
nsresult rv = m_vCard.ImportAddresses(&addrAbort, name.get(), inFile,
|
||||
pDestination, error, &m_bytesImported);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && error.IsEmpty()) {
|
||||
ReportSuccess(name, &success, m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
}
|
||||
else {
|
||||
ReportError("vCardImportAddressConvertError", name, &error, m_notProxyBundle);
|
||||
} else {
|
||||
ReportError("vCardImportAddressConvertError", name, &error,
|
||||
m_notProxyBundle);
|
||||
SetLogs(success, error, pErrorLog, pSuccessLog);
|
||||
}
|
||||
|
||||
|
@ -380,8 +354,7 @@ NS_IMETHODIMP ImportVCardAddressImpl::ImportAddressBook(
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetImportProgress(uint32_t *_retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportVCardAddressImpl::GetImportProgress(uint32_t *_retval) {
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = m_bytesImported;
|
||||
return NS_OK;
|
||||
|
|
|
@ -9,17 +9,18 @@
|
|||
#include "nsIStringBundle.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_VCARDIMPORT_CID \
|
||||
{ /* 0EB034A3-964A-4E2F-92EBCC55D9AE9DD2 */ \
|
||||
0x0eb034a3, 0x964a, 0x4e2f, \
|
||||
{0x92, 0xeb, 0xcc, 0x55, 0xd9, 0xae, 0x9d, 0xd2}}
|
||||
#define NS_VCARDIMPORT_CID \
|
||||
{ /* 0EB034A3-964A-4E2F-92EBCC55D9AE9DD2 */ \
|
||||
0x0eb034a3, 0x964a, 0x4e2f, { \
|
||||
0x92, 0xeb, 0xcc, 0x55, 0xd9, 0xae, 0x9d, 0xd2 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define VCARDIMPORT_MSGS_URL "chrome://messenger/locale/vCardImportMsgs.properties"
|
||||
|
||||
class nsVCardImport : public nsIImportModule
|
||||
{
|
||||
public:
|
||||
#define VCARDIMPORT_MSGS_URL \
|
||||
"chrome://messenger/locale/vCardImportMsgs.properties"
|
||||
|
||||
class nsVCardImport : public nsIImportModule {
|
||||
public:
|
||||
nsVCardImport();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -30,7 +31,7 @@ public:
|
|||
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual ~nsVCardImport();
|
||||
nsCOMPtr<nsIStringBundle> m_stringBundle;
|
||||
};
|
||||
|
|
|
@ -21,69 +21,65 @@
|
|||
|
||||
#include "ImportDebug.h"
|
||||
|
||||
class ImportWMMailImpl : public nsIImportMail
|
||||
{
|
||||
public:
|
||||
class ImportWMMailImpl : public nsIImportMail {
|
||||
public:
|
||||
ImportWMMailImpl();
|
||||
|
||||
static nsresult Create(nsIImportMail** aImport);
|
||||
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);
|
||||
/* 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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
static void SetLogs(nsString &success, nsString &error, char16_t **pError,
|
||||
char16_t **pSuccess);
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~ImportWMMailImpl();
|
||||
};
|
||||
|
||||
nsWMImport::nsWMImport()
|
||||
{
|
||||
nsWMImport::nsWMImport() {
|
||||
IMPORT_LOG0("nsWMImport Module Created\n");
|
||||
nsWMStringBundle::GetStringBundle();
|
||||
}
|
||||
|
||||
nsWMImport::~nsWMImport()
|
||||
{
|
||||
IMPORT_LOG0("nsWMImport Module Deleted\n");
|
||||
}
|
||||
nsWMImport::~nsWMImport() { IMPORT_LOG0("nsWMImport Module Deleted\n"); }
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsWMImport, nsIImportModule)
|
||||
|
||||
NS_IMETHODIMP nsWMImport::GetName(char16_t **name)
|
||||
{
|
||||
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;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWMImport::GetDescription(char16_t **name)
|
||||
{
|
||||
NS_IMETHODIMP nsWMImport::GetDescription(char16_t **name) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
|
||||
// nsString desc = "Windows Live Mail mail and address books";
|
||||
|
@ -92,29 +88,24 @@ NS_IMETHODIMP nsWMImport::GetDescription(char16_t **name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWMImport::GetSupports(char **supports)
|
||||
{
|
||||
NS_IMETHODIMP nsWMImport::GetSupports(char **supports) {
|
||||
NS_ASSERTION(supports != nullptr, "null ptr");
|
||||
if (! supports)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!supports) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*supports = strdup(kWMSupportsString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWMImport::GetSupportsUpgrade(bool *pUpgrade)
|
||||
{
|
||||
NS_IMETHODIMP nsWMImport::GetSupportsUpgrade(bool *pUpgrade) {
|
||||
NS_ASSERTION(pUpgrade != nullptr, "null ptr");
|
||||
if (! pUpgrade)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!pUpgrade) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*pUpgrade = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWMImport::GetImportInterface(const char *pImportType,
|
||||
nsISupports **ppInterface)
|
||||
{
|
||||
nsISupports **ppInterface) {
|
||||
NS_ENSURE_ARG_POINTER(pImportType);
|
||||
NS_ENSURE_ARG_POINTER(ppInterface);
|
||||
|
||||
|
@ -135,50 +126,40 @@ NS_IMETHODIMP nsWMImport::GetImportInterface(const char *pImportType,
|
|||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
nsresult ImportWMMailImpl::Create(nsIImportMail** aImport)
|
||||
{
|
||||
nsresult ImportWMMailImpl::Create(nsIImportMail **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new ImportWMMailImpl());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ImportWMMailImpl::ImportWMMailImpl()
|
||||
{
|
||||
}
|
||||
ImportWMMailImpl::ImportWMMailImpl() {}
|
||||
|
||||
ImportWMMailImpl::~ImportWMMailImpl()
|
||||
{
|
||||
}
|
||||
ImportWMMailImpl::~ImportWMMailImpl() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImportWMMailImpl, nsIImportMail)
|
||||
|
||||
NS_IMETHODIMP ImportWMMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval)
|
||||
{
|
||||
NS_IMETHODIMP ImportWMMailImpl::TranslateFolderName(
|
||||
const nsAString &aFolderName, nsAString &_retval) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportWMMailImpl::GetDefaultLocation(nsIFile **ppLoc, bool *found,
|
||||
bool *userVerify)
|
||||
{
|
||||
bool *userVerify) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportWMMailImpl::FindMailboxes(nsIFile *pLoc,
|
||||
nsIArray **ppArray)
|
||||
{
|
||||
nsIArray **ppArray) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void ImportWMMailImpl::AddLinebreak(nsString *pStream)
|
||||
{
|
||||
if (pStream)
|
||||
pStream->Append(char16_t('\n'));
|
||||
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;
|
||||
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);
|
||||
nsString pText;
|
||||
|
@ -188,10 +169,9 @@ void ImportWMMailImpl::ReportSuccess(nsString& name, int32_t count, nsString *pS
|
|||
AddLinebreak(pStream);
|
||||
}
|
||||
|
||||
void ImportWMMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return;
|
||||
void ImportWMMailImpl::ReportError(int32_t errorNum, nsString &name,
|
||||
nsString *pStream) {
|
||||
if (!pStream) return;
|
||||
// load the error string
|
||||
char16_t *pFmt = nsWMStringBundle::GetStringByID(errorNum);
|
||||
nsString pText;
|
||||
|
@ -201,25 +181,18 @@ void ImportWMMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *p
|
|||
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);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
NS_IMETHODIMP ImportWMMailImpl::GetImportProgress(uint32_t *pDoneSoFar) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@
|
|||
#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}}
|
||||
#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:
|
||||
|
||||
class nsWMImport : public nsIImportModule {
|
||||
public:
|
||||
nsWMImport();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
NS_DECL_NSIIMPORTMODULE
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual ~nsWMImport();
|
||||
};
|
||||
|
||||
|
|
|
@ -37,85 +37,73 @@
|
|||
#include "nsWMUtils.h"
|
||||
|
||||
class WMSettings {
|
||||
public:
|
||||
public:
|
||||
static bool DoImport(nsIMsgAccount **ppAccount);
|
||||
static bool DoIMAPServer(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
static bool DoPOP3Server(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
static bool DoNNTPServer(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount);
|
||||
static void SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
|
||||
mozilla::dom::Document *xmlDoc, nsAutoString &userName,
|
||||
int32_t authMethodIncoming, bool isNNTP);
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
nsAutoString &userName, int32_t authMethodIncoming,
|
||||
bool isNNTP);
|
||||
static void SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *id,
|
||||
nsAutoString& inUserName, int32_t authMethodIncoming);
|
||||
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
|
||||
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)
|
||||
{
|
||||
nsresult nsWMSettings::Create(nsIImportSettings **aImport) {
|
||||
NS_ENSURE_ARG_POINTER(aImport);
|
||||
NS_ADDREF(*aImport = new nsWMSettings());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsWMSettings::nsWMSettings()
|
||||
{
|
||||
}
|
||||
nsWMSettings::nsWMSettings() {}
|
||||
|
||||
nsWMSettings::~nsWMSettings()
|
||||
{
|
||||
}
|
||||
nsWMSettings::~nsWMSettings() {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsWMSettings, nsIImportSettings)
|
||||
|
||||
NS_IMETHODIMP nsWMSettings::AutoLocate(char16_t **description,
|
||||
nsIFile **location, bool *_retval)
|
||||
{
|
||||
nsIFile **location, bool *_retval) {
|
||||
NS_ASSERTION(description != nullptr, "null ptr");
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
if (!description || !_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!description || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*description = nsWMStringBundle::GetStringByID(WMIMPORT_NAME);
|
||||
*_retval = false;
|
||||
|
||||
if (location)
|
||||
*location = nullptr;
|
||||
if (location) *location = nullptr;
|
||||
nsCOMPtr<nsIWindowsRegKey> key;
|
||||
if (NS_SUCCEEDED(nsWMUtils::FindWMKey(getter_AddRefs(key))))
|
||||
*_retval = true;
|
||||
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::SetLocation(nsIFile *location) { return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP nsWMSettings::Import(nsIMsgAccount **localMailAccount,
|
||||
bool *_retval)
|
||||
{
|
||||
bool *_retval) {
|
||||
NS_ASSERTION(_retval != nullptr, "null ptr");
|
||||
|
||||
if (WMSettings::DoImport(localMailAccount)) {
|
||||
*_retval = true;
|
||||
IMPORT_LOG0("Settings import appears successful\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*_retval = false;
|
||||
IMPORT_LOG0("Settings import returned FALSE\n");
|
||||
}
|
||||
|
@ -123,8 +111,7 @@ NS_IMETHODIMP nsWMSettings::Import(nsIMsgAccount **localMailAccount,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
|
||||
{
|
||||
bool WMSettings::DoImport(nsIMsgAccount **ppAccount) {
|
||||
// do the windows registry stuff first
|
||||
nsCOMPtr<nsIWindowsRegKey> key;
|
||||
if (NS_FAILED(nsWMUtils::FindWMKey(getter_AddRefs(key)))) {
|
||||
|
@ -142,21 +129,25 @@ bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
|
|||
nsIWindowsRegKey::ACCESS_QUERY_VALUE,
|
||||
getter_AddRefs(subKey)))) {
|
||||
uint32_t dwordResult = -1;
|
||||
rv = subKey->ReadIntValue(NS_LITERAL_STRING("Poll For Mail"), &dwordResult); // reg_dword
|
||||
rv = subKey->ReadIntValue(NS_LITERAL_STRING("Poll For Mail"),
|
||||
&dwordResult); // reg_dword
|
||||
subKey->Close();
|
||||
if (NS_SUCCEEDED(rv) && dwordResult != -1){
|
||||
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
|
||||
// (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);
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0("*** Failed to create an account manager!\n");
|
||||
return false;
|
||||
|
@ -173,26 +164,20 @@ bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
|
|||
int accounts = 0;
|
||||
nsCOMPtr<mozilla::dom::Document> xmlDoc;
|
||||
|
||||
for (int32_t i = fileArray.Count() - 1 ; i >= 0; i--){
|
||||
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 (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 (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 (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, "POP3_Server", value)))
|
||||
if (DoPOP3Server(accMgr, xmlDoc, value, getter_AddRefs(anAccount)))
|
||||
accounts++;
|
||||
|
||||
|
@ -200,8 +185,7 @@ bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
|
|||
nsString name;
|
||||
// Is this the default account?
|
||||
fileArray[i]->GetLeafName(name);
|
||||
if (defMailAcct.Equals(name))
|
||||
accMgr->SetDefaultAccount(anAccount);
|
||||
if (defMailAcct.Equals(name)) accMgr->SetDefaultAccount(anAccount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,68 +197,56 @@ bool WMSettings::DoImport(nsIMsgAccount **ppAccount)
|
|||
}
|
||||
|
||||
bool WMSettings::DoIMAPServer(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount)
|
||||
{
|
||||
int32_t authMethod; // Secure Password Authentication (SPA)
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount) {
|
||||
int32_t authMethod; // Secure Password Authentication (SPA)
|
||||
nsresult errorCode;
|
||||
if (ppAccount)
|
||||
*ppAccount = nullptr;
|
||||
if (ppAccount) *ppAccount = nullptr;
|
||||
|
||||
nsAutoString userName, value;
|
||||
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"IMAP_User_Name",
|
||||
userName)))
|
||||
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));
|
||||
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));
|
||||
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){
|
||||
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))) {
|
||||
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 (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))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "IMAP_Use_Sicily", value))) {
|
||||
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure :
|
||||
nsMsgAuthMethod::passwordCleartext;
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure
|
||||
: nsMsgAuthMethod::passwordCleartext;
|
||||
in->SetAuthMethod(authMethod);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"IMAP_Port",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, "IMAP_Port", value))) {
|
||||
in->SetPort(value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"Account_Name",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "Account_Name", value))) {
|
||||
rv = in->SetPrettyName(value);
|
||||
}
|
||||
in->SetDoBiff(checkNewMail);
|
||||
|
@ -289,126 +261,112 @@ bool WMSettings::DoIMAPServer(nsIMsgAccountManager *pMgr,
|
|||
if (NS_SUCCEEDED(rv) && account) {
|
||||
rv = account->SetIncomingServer(in);
|
||||
|
||||
IMPORT_LOG0("Created an account and set the IMAP server "
|
||||
"as the incoming server\n");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (NS_SUCCEEDED(rv) && in) {
|
||||
} 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");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WMSettings::DoPOP3Server(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount)
|
||||
{
|
||||
int32_t authMethod; // Secure Password Authentication (SPA)
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount) {
|
||||
int32_t authMethod; // Secure Password Authentication (SPA)
|
||||
nsresult errorCode;
|
||||
if (ppAccount)
|
||||
*ppAccount = nullptr;
|
||||
if (ppAccount) *ppAccount = nullptr;
|
||||
|
||||
nsAutoString userName, value;
|
||||
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"POP3_User_Name",
|
||||
userName)))
|
||||
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));
|
||||
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));
|
||||
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){
|
||||
if (!pop3Server) {
|
||||
IMPORT_LOG1("*** Failed to create nsIPop3IncomingServer for %S!\n",
|
||||
serverName.get());
|
||||
serverName.get());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"POP3_Secure_Connection",
|
||||
value)) &&
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(
|
||||
xmlDoc, "POP3_Secure_Connection", value)) &&
|
||||
value.ToInteger(&errorCode, 16)) {
|
||||
in->SetSocketType(nsMsgSocketType::SSL);
|
||||
in->SetSocketType(nsMsgSocketType::SSL);
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"POP3_Use_Sicily",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "POP3_Use_Sicily", value))) {
|
||||
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure :
|
||||
nsMsgAuthMethod::passwordCleartext;
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure
|
||||
: nsMsgAuthMethod::passwordCleartext;
|
||||
in->SetAuthMethod(authMethod);
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"POP3_Port",
|
||||
value))) {
|
||||
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 (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
|
||||
// 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",
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, "Leave_Mail_On_Server",
|
||||
value))) {
|
||||
pop3Server->SetLeaveMessagesOnServer((bool)value.ToInteger(&errorCode, 16));
|
||||
pop3Server->SetLeaveMessagesOnServer(
|
||||
(bool)value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"Remove_When_Deleted",
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, "Remove_When_Deleted",
|
||||
value))) {
|
||||
pop3Server->SetDeleteMailLeftOnServer((bool)value.ToInteger(&errorCode, 16));
|
||||
pop3Server->SetDeleteMailLeftOnServer(
|
||||
(bool)value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"Remove_When_Expired",
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, "Remove_When_Expired",
|
||||
value))) {
|
||||
pop3Server->SetDeleteByAgeFromServer((bool)value.ToInteger(&errorCode, 16));
|
||||
pop3Server->SetDeleteByAgeFromServer(
|
||||
(bool)value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"Expire_Days",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "Expire_Days", value))) {
|
||||
pop3Server->SetNumDaysToLeaveOnServer(value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"Account_Name",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "Account_Name", value))) {
|
||||
rv = in->SetPrettyName(value);
|
||||
}
|
||||
|
||||
|
@ -449,48 +407,44 @@ bool WMSettings::DoPOP3Server(nsIMsgAccountManager *pMgr,
|
|||
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");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (NS_SUCCEEDED(rv) && in) {
|
||||
} 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;
|
||||
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");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WMSettings::DoNNTPServer(nsIMsgAccountManager *pMgr,
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString& serverName,
|
||||
nsIMsgAccount **ppAccount)
|
||||
{
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
const nsString &serverName,
|
||||
nsIMsgAccount **ppAccount) {
|
||||
int32_t authMethod;
|
||||
nsresult errorCode;
|
||||
if (ppAccount)
|
||||
*ppAccount = nullptr;
|
||||
if (ppAccount) *ppAccount = nullptr;
|
||||
|
||||
nsAutoString userName, value;
|
||||
// this only exists if NNTP server requires it or not, anonymous login
|
||||
|
@ -500,22 +454,19 @@ bool WMSettings::DoNNTPServer(nsIMsgAccountManager *pMgr,
|
|||
// 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));
|
||||
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));
|
||||
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());
|
||||
serverName.get());
|
||||
return false;
|
||||
}
|
||||
if (!userName.IsEmpty()) { // if username req'd then auth req'd
|
||||
|
@ -524,24 +475,20 @@ bool WMSettings::DoNNTPServer(nsIMsgAccountManager *pMgr,
|
|||
}
|
||||
|
||||
nsAutoString value;
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"NNTP_Port",
|
||||
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))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "Account_Name", value))) {
|
||||
in->SetPrettyName(value);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"NNTP_Use_Sicily",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "NNTP_Use_Sicily", value))) {
|
||||
bool secAuth = (bool)value.ToInteger(&errorCode, 16);
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure :
|
||||
nsMsgAuthMethod::passwordCleartext;
|
||||
authMethod = secAuth ? nsMsgAuthMethod::secure
|
||||
: nsMsgAuthMethod::passwordCleartext;
|
||||
in->SetAuthMethod(authMethod);
|
||||
}
|
||||
|
||||
|
@ -554,41 +501,39 @@ bool WMSettings::DoNNTPServer(nsIMsgAccountManager *pMgr,
|
|||
if (NS_SUCCEEDED(rv) && account) {
|
||||
rv = account->SetIncomingServer(in);
|
||||
|
||||
IMPORT_LOG0("Created an account and set the NNTP server "
|
||||
"as the incoming server\n");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (NS_SUCCEEDED(rv) && in) {
|
||||
} 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");
|
||||
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);
|
||||
if (ppAccount) account.forget(ppAccount);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
void WMSettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
|
||||
mozilla::dom::Document *xmlDoc, nsAutoString &inUserName,
|
||||
int32_t authMethodIncoming, bool isNNTP)
|
||||
{
|
||||
mozilla::dom::Document *xmlDoc,
|
||||
nsAutoString &inUserName,
|
||||
int32_t authMethodIncoming, bool isNNTP) {
|
||||
// Get the relevant information for an identity
|
||||
nsresult rv;
|
||||
nsAutoString value;
|
||||
|
@ -597,37 +542,32 @@ void WMSettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
|
|||
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))) {
|
||||
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))) {
|
||||
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))) {
|
||||
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))) {
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc,
|
||||
isNNTP ? "NNTP_Reply_To_Email_Address"
|
||||
: "SMTP_Reply_To_Email_Address",
|
||||
value))) {
|
||||
id->SetReplyTo(NS_ConvertUTF16toUTF8(value));
|
||||
}
|
||||
|
||||
|
@ -640,14 +580,13 @@ void WMSettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc,
|
|||
SetSmtpServer(xmlDoc, id, inUserName, authMethodIncoming);
|
||||
}
|
||||
|
||||
void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *id,
|
||||
nsAutoString& inUserName, int32_t authMethodIncoming)
|
||||
{
|
||||
void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc,
|
||||
nsIMsgIdentity *id, nsAutoString &inUserName,
|
||||
int32_t authMethodIncoming) {
|
||||
nsresult errorCode;
|
||||
|
||||
// set the id.smtpserver accordingly
|
||||
if (!id)
|
||||
return;
|
||||
if (!id) return;
|
||||
nsCString smtpServerKey, userName;
|
||||
nsAutoString value, smtpName;
|
||||
if (NS_FAILED(nsWMUtils::GetValueForTag(xmlDoc, "SMTP_Server", smtpName)))
|
||||
|
@ -656,32 +595,30 @@ void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *i
|
|||
// 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);
|
||||
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))) {
|
||||
case 1:
|
||||
case 3:
|
||||
if (NS_SUCCEEDED(
|
||||
nsWMUtils::GetValueForTag(xmlDoc, "SMTP_User_Name", value))) {
|
||||
CopyUTF16toUTF8(value, userName);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
CopyUTF16toUTF8(inUserName, userName);
|
||||
}
|
||||
break;
|
||||
case 2 :
|
||||
case 2:
|
||||
CopyUTF16toUTF8(inUserName, userName);
|
||||
break;
|
||||
default :
|
||||
break; // initial userName == ""
|
||||
default:
|
||||
break; // initial userName == ""
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISmtpService>
|
||||
smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &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
|
||||
|
@ -694,21 +631,19 @@ void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *i
|
|||
extgServer->GetKey(getter_Copies(smtpServerKey));
|
||||
id->SetSmtpServerKey(smtpServerKey);
|
||||
|
||||
IMPORT_LOG1("SMTP server already exists: %s\n", NS_ConvertUTF16toUTF8(smtpName).get());
|
||||
}
|
||||
else {
|
||||
IMPORT_LOG1("SMTP server already exists: %s\n",
|
||||
NS_ConvertUTF16toUTF8(smtpName).get());
|
||||
} 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_Port", value))) {
|
||||
smtpServer->SetPort(value.ToInteger(&errorCode, 16));
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc,
|
||||
"SMTP_Secure_Connection",
|
||||
value))) {
|
||||
if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(
|
||||
xmlDoc, "SMTP_Secure_Connection", value))) {
|
||||
if (value.ToInteger(&errorCode, 16) == 1)
|
||||
smtpServer->SetSocketType(nsMsgSocketType::SSL);
|
||||
else
|
||||
|
@ -716,13 +651,14 @@ void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *i
|
|||
}
|
||||
smtpServer->SetUsername(userName);
|
||||
switch (useSicily) {
|
||||
case 1 :
|
||||
case 1:
|
||||
smtpServer->SetAuthMethod(nsMsgAuthMethod::secure);
|
||||
break;
|
||||
case 2 : // requires SMTP authentication to use the incoming server settings
|
||||
case 2: // requires SMTP authentication to use the incoming server
|
||||
// settings
|
||||
smtpServer->SetAuthMethod(authMethodIncoming);
|
||||
break;
|
||||
case 3 :
|
||||
case 3:
|
||||
smtpServer->SetAuthMethod(nsMsgAuthMethod::passwordCleartext);
|
||||
break;
|
||||
default:
|
||||
|
@ -734,7 +670,8 @@ void WMSettings::SetSmtpServer(mozilla::dom::Document *xmlDoc, nsIMsgIdentity *i
|
|||
smtpServer->GetKey(getter_Copies(smtpServerKey));
|
||||
id->SetSmtpServerKey(smtpServerKey);
|
||||
|
||||
IMPORT_LOG1("Created new SMTP server: %s\n", NS_ConvertUTF16toUTF8(smtpName).get());
|
||||
IMPORT_LOG1("Created new SMTP server: %s\n",
|
||||
NS_ConvertUTF16toUTF8(smtpName).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
#include "nsIImportSettings.h"
|
||||
|
||||
class nsWMSettings : public nsIImportSettings {
|
||||
public:
|
||||
public:
|
||||
nsWMSettings();
|
||||
static nsresult Create(nsIImportSettings** aImport);
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMPORTSETTINGS
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual ~nsWMSettings();
|
||||
};
|
||||
|
||||
|
|
|
@ -11,40 +11,34 @@
|
|||
#include "nsWMStringBundle.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#define WM_MSGS_URL "chrome://messenger/locale/wmImportMsgs.properties"
|
||||
#define WM_MSGS_URL "chrome://messenger/locale/wmImportMsgs.properties"
|
||||
|
||||
nsCOMPtr<nsIStringBundle> nsWMStringBundle::m_pBundle = nullptr;
|
||||
|
||||
void nsWMStringBundle::GetStringBundle(void)
|
||||
{
|
||||
if (m_pBundle)
|
||||
return;
|
||||
void nsWMStringBundle::GetStringBundle(void) {
|
||||
if (m_pBundle) return;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> sBundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
mozilla::services::GetStringBundleService();
|
||||
if (sBundleService) {
|
||||
sBundleService->CreateBundle(WM_MSGS_URL, getter_AddRefs(m_pBundle));
|
||||
}
|
||||
}
|
||||
|
||||
void nsWMStringBundle::GetStringByID(int32_t stringID, nsString& result)
|
||||
{
|
||||
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)
|
||||
GetStringBundle();
|
||||
char16_t *nsWMStringBundle::GetStringByID(int32_t stringID) {
|
||||
if (!m_pBundle) GetStringBundle();
|
||||
|
||||
if (m_pBundle) {
|
||||
nsAutoString str;
|
||||
nsresult rv = m_pBundle->GetStringFromID(stringID, str);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return ToNewUnicode(str);
|
||||
if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
|
||||
}
|
||||
|
||||
nsString resultString;
|
||||
|
@ -55,7 +49,4 @@ char16_t *nsWMStringBundle::GetStringByID(int32_t stringID)
|
|||
return ToNewUnicode(resultString);
|
||||
}
|
||||
|
||||
void nsWMStringBundle::Cleanup(void)
|
||||
{
|
||||
m_pBundle = nullptr;
|
||||
}
|
||||
void nsWMStringBundle::Cleanup(void) { m_pBundle = nullptr; }
|
||||
|
|
|
@ -10,29 +10,27 @@
|
|||
class nsIStringBundle;
|
||||
|
||||
class nsWMStringBundle {
|
||||
public:
|
||||
static char16_t * GetStringByID(int32_t stringID);
|
||||
static void GetStringByID(int32_t stringID, nsString& result);
|
||||
static void GetStringBundle(void);
|
||||
static void FreeString(char16_t *pStr) { free(pStr);}
|
||||
static void Cleanup(void);
|
||||
public:
|
||||
static char16_t* GetStringByID(int32_t stringID);
|
||||
static void GetStringByID(int32_t stringID, nsString& result);
|
||||
static void GetStringBundle(void);
|
||||
static void FreeString(char16_t* pStr) { free(pStr); }
|
||||
static void Cleanup(void);
|
||||
|
||||
private:
|
||||
private:
|
||||
static nsCOMPtr<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
|
||||
#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__ */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* 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/. */
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -20,12 +20,10 @@
|
|||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/DOMParser.h"
|
||||
|
||||
nsresult
|
||||
nsWMUtils::FindWMKey(nsIWindowsRegKey **aKey)
|
||||
{
|
||||
nsresult nsWMUtils::FindWMKey(nsIWindowsRegKey **aKey) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIWindowsRegKey> key =
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = key->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||
|
@ -43,35 +41,36 @@ nsWMUtils::FindWMKey(nsIWindowsRegKey **aKey)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWMUtils::GetRootFolder(nsIFile **aRootFolder)
|
||||
{
|
||||
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
|
||||
// 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);
|
||||
uint32_t size =
|
||||
::ExpandEnvironmentStringsW((LPCWSTR)storeRoot.get(), nullptr, 0);
|
||||
nsString expandedStoreRoot;
|
||||
expandedStoreRoot.SetLength(size - 1);
|
||||
if (expandedStoreRoot.Length() != size - 1)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (expandedStoreRoot.Length() != size - 1) return NS_ERROR_FAILURE;
|
||||
::ExpandEnvironmentStringsW((LPCWSTR)storeRoot.get(),
|
||||
(LPWSTR)expandedStoreRoot.BeginWriting(),
|
||||
size);
|
||||
(LPWSTR)expandedStoreRoot.BeginWriting(), size);
|
||||
storeRoot = expandedStoreRoot;
|
||||
|
||||
nsCOMPtr<nsIFile> rootFolder(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIFile> rootFolder(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = rootFolder->InitWithPath(storeRoot);
|
||||
|
@ -82,9 +81,7 @@ nsWMUtils::GetRootFolder(nsIFile **aRootFolder)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWMUtils::GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray)
|
||||
{
|
||||
nsresult nsWMUtils::GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray) {
|
||||
nsCOMPtr<nsIFile> rootFolder;
|
||||
|
||||
nsresult rv = GetRootFolder(getter_AddRefs(rootFolder));
|
||||
|
@ -93,14 +90,11 @@ nsWMUtils::GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray)
|
|||
return GetOEAccountFilesInFolder(rootFolder, aFileArray);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWMUtils::GetOEAccountFilesInFolder(nsIFile *aFolder,
|
||||
nsCOMArray<nsIFile> &aFileArray)
|
||||
{
|
||||
nsresult nsWMUtils::GetOEAccountFilesInFolder(nsIFile *aFolder,
|
||||
nsCOMArray<nsIFile> &aFileArray) {
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
nsresult rv = aFolder->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
if (NS_FAILED(rv) || !entries)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || !entries) return NS_ERROR_FAILURE;
|
||||
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
|
||||
|
@ -114,8 +108,7 @@ nsWMUtils::GetOEAccountFilesInFolder(nsIFile *aFolder,
|
|||
|
||||
if (isDirectory) {
|
||||
GetOEAccountFilesInFolder(file, aFileArray);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
nsString name;
|
||||
rv = file->GetLeafName(name);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -126,43 +119,37 @@ nsWMUtils::GetOEAccountFilesInFolder(nsIFile *aFolder,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWMUtils::MakeXMLdoc(mozilla::dom::Document **aXmlDoc,
|
||||
nsIFile *aFile)
|
||||
{
|
||||
nsresult nsWMUtils::MakeXMLdoc(mozilla::dom::Document **aXmlDoc,
|
||||
nsIFile *aFile) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileInputStream> stream =
|
||||
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
|
||||
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = stream->Init(aFile, PR_RDONLY, -1, 0);
|
||||
mozilla::ErrorResult rv2;
|
||||
RefPtr<mozilla::dom::DOMParser> parser = mozilla::dom::DOMParser::CreateWithoutGlobal(rv2);
|
||||
RefPtr<mozilla::dom::DOMParser> parser =
|
||||
mozilla::dom::DOMParser::CreateWithoutGlobal(rv2);
|
||||
if (rv2.Failed()) {
|
||||
return rv2.StealNSResult();
|
||||
}
|
||||
int64_t filesize;
|
||||
aFile->GetFileSize(&filesize);
|
||||
nsCOMPtr<mozilla::dom::Document> xmldoc =
|
||||
parser->ParseFromStream(stream, EmptyString(), int32_t(filesize),
|
||||
mozilla::dom::SupportedType::Application_xml, rv2);
|
||||
nsCOMPtr<mozilla::dom::Document> xmldoc = parser->ParseFromStream(
|
||||
stream, EmptyString(), int32_t(filesize),
|
||||
mozilla::dom::SupportedType::Application_xml, rv2);
|
||||
xmldoc.forget(aXmlDoc);
|
||||
return rv2.StealNSResult();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWMUtils::GetValueForTag(mozilla::dom::Document *aXmlDoc,
|
||||
const char *aTagName,
|
||||
nsAString &aValue)
|
||||
{
|
||||
nsresult nsWMUtils::GetValueForTag(mozilla::dom::Document *aXmlDoc,
|
||||
const char *aTagName, nsAString &aValue) {
|
||||
nsAutoString tagName;
|
||||
tagName.AssignASCII(aTagName);
|
||||
nsCOMPtr<nsINodeList> list = aXmlDoc->GetElementsByTagName(tagName);
|
||||
nsCOMPtr<nsINode> node = list->Item(0);
|
||||
if (!node)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!node) return NS_ERROR_FAILURE;
|
||||
mozilla::ErrorResult rv2;
|
||||
node->GetTextContent(aValue, rv2);
|
||||
return rv2.StealNSResult();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* 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/. */
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsWMUtils_h___
|
||||
#define nsWMUtils_h___
|
||||
|
@ -9,7 +9,7 @@
|
|||
#include "nsIWindowsRegKey.h"
|
||||
|
||||
class nsWMUtils {
|
||||
public:
|
||||
public:
|
||||
static nsresult FindWMKey(nsIWindowsRegKey **aKey);
|
||||
static nsresult GetRootFolder(nsIFile **aRootFolder);
|
||||
static nsresult GetOEAccountFiles(nsCOMArray<nsIFile> &aFileArray);
|
||||
|
@ -17,8 +17,7 @@ public:
|
|||
nsCOMArray<nsIFile> &aFileArray);
|
||||
static nsresult MakeXMLdoc(mozilla::dom::Document **aXmlDoc, nsIFile *aFile);
|
||||
static nsresult GetValueForTag(mozilla::dom::Document *aXmlDoc,
|
||||
const char *aTagName,
|
||||
nsAString &aValue);
|
||||
const char *aTagName, nsAString &aValue);
|
||||
};
|
||||
|
||||
#endif /* nsWMUtils_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче