void nsImportGenericAddressBooks::GetDefaultFieldMap(void) { if (!m_pInterface || !m_pLocation) return; NS_IF_RELEASE(m_pFieldMap); 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(&m_pFieldMap); if (NS_FAILED(rv)) return; 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_FAILED(rv)) { IMPORT_LOG0("*** Error: Unable to initialize field map\n"); NS_IF_RELEASE(m_pFieldMap); } }
NS_IMETHODIMP nsAppleMailImportModule::GetImportInterface(const char *aImportType, nsISupports **aInterface) { NS_ENSURE_ARG_POINTER(aImportType); NS_ENSURE_ARG_POINTER(aInterface); *aInterface = nsnull; nsresult rv = NS_ERROR_NOT_AVAILABLE; if (!strcmp(aImportType, "mail")) { nsCOMPtr<nsIImportMail> mail(do_CreateInstance(NS_APPLEMAILIMPL_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIImportGeneric> generic; rv = impSvc->CreateNewGenericMail(getter_AddRefs(generic)); if (NS_SUCCEEDED(rv)) { nsAutoString name; rv = mBundle->GetStringFromID(APPLEMAILIMPORT_NAME, getter_Copies(name)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsString> nameString(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); nameString->SetData(name); generic->SetData("name", nameString); generic->SetData("mailInterface", mail); rv = CallQueryInterface(generic, aInterface); } } } } return rv; }
NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface) { NS_ENSURE_ARG_POINTER(pImportType); NS_ENSURE_ARG_POINTER(ppInterface); *ppInterface = nsnull; nsresult rv; if (!strcmp(pImportType, "addressbook")) { // create the nsIImportMail interface and return it! nsIImportAddressBooks * pAddress = nsnull; nsIImportGeneric * pGeneric = nsnull; rv = ImportAddressImpl::Create(&pAddress, m_stringBundle); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = impSvc->CreateNewGenericAddressBooks(&pGeneric); if (NS_SUCCEEDED(rv)) { pGeneric->SetData("addressInterface", pAddress); rv = pGeneric->QueryInterface(kISupportsIID, (void **)ppInterface); } } } NS_IF_RELEASE(pAddress); NS_IF_RELEASE(pGeneric); return rv; } return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHODIMP ImportOEAddressImpl::FindAddressBooks(nsIFile *location, nsISupportsArray **_retval) { NS_PRECONDITION(_retval != nsnull, "null ptr"); if (!_retval) return NS_ERROR_NULL_POINTER; nsresult rv = NS_NewISupportsArray(_retval); if (NS_FAILED(rv)) return rv; // Make sure we can load up the windows address book... rv = NS_ERROR_FAILURE; if (m_pWab) delete m_pWab; nsCOMPtr<nsIFile> currentProcessDir; rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(currentProcessDir)); bool equals = false; currentProcessDir->Equals(location, &equals); // If the location is not a fake, use it. if (location && !equals) { nsCOMPtr<nsIFile> localFile = do_QueryInterface(location, &rv); NS_ENSURE_SUCCESS(rv, rv); m_pWab = new CWAB(localFile); } else { m_pWab = new CWAB(nsnull); } nsIImportABDescriptor * pID; nsISupports * pInterface; nsString str; str.Append(nsOEStringBundle::GetStringByID(OEIMPORT_DEFAULT_NAME)); if (m_pWab->Loaded()) { // create a new nsIImportABDescriptor and add it to the array nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = impSvc->CreateNewABDescriptor(&pID); if (NS_SUCCEEDED(rv)) { pID->SetIdentifier(0x4F453334); pID->SetRef(1); pID->SetSize(100); pID->SetPreferredName(str); rv = pID->QueryInterface(kISupportsIID, (void **) &pInterface); (*_retval)->AppendElement(pInterface); pInterface->Release(); pID->Release(); } } } if (NS_FAILED(rv)) { delete m_pWab; m_pWab = nsnull; } return NS_OK; }
nsresult nsComm4xMail::FindMailboxes(nsIFile *pRoot, nsISupportsArray **ppArray) { nsresult rv = NS_NewISupportsArray(ppArray); if (NS_FAILED(rv)) { IMPORT_LOG0("FAILED to allocate the nsISupportsArray\n"); return rv; } nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; m_depth = 0; return (ScanMailDir(pRoot, *ppArray, impSvc)); }
nsresult nsEudoraWin32::FindMailboxes( nsIFile *pRoot, nsISupportsArray **ppArray) { nsresult rv = NS_NewISupportsArray( ppArray); if (NS_FAILED( rv)) { IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n"); return( rv); } nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED( rv)) return( rv); m_depth = 0; m_mailImportLocation = do_QueryInterface(pRoot); return( ScanMailDir( pRoot, *ppArray, impSvc)); }
NS_IMETHODIMP ImportOEAddressImpl::FindAddressBooks(nsIFile *location, nsISupportsArray **_retval) { NS_PRECONDITION(_retval != nsnull, "null ptr"); if (!_retval) return NS_ERROR_NULL_POINTER; nsresult rv = NS_NewISupportsArray(_retval); if (NS_FAILED(rv)) return rv; // Make sure we can load up the windows address book... rv = NS_ERROR_FAILURE; if (m_pWab) delete m_pWab; m_pWab = new CWAB(nsnull); nsIImportABDescriptor * pID; nsISupports * pInterface; nsString str; str.Append(nsOEStringBundle::GetStringByID(OEIMPORT_DEFAULT_NAME)); if (m_pWab->Loaded()) { // create a new nsIImportABDescriptor and add it to the array nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = impSvc->CreateNewABDescriptor(&pID); if (NS_SUCCEEDED(rv)) { pID->SetIdentifier(0x4F453334); pID->SetRef(1); pID->SetSize(100); pID->SetPreferredName(str); rv = pID->QueryInterface(kISupportsIID, (void **) &pInterface); (*_retval)->AppendElement(pInterface); pInterface->Release(); pID->Release(); } } } if (NS_FAILED(rv)) { delete m_pWab; m_pWab = nsnull; } return NS_OK; }
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsISupportsArray **ppArray) { NS_PRECONDITION(pLoc != nsnull, "null ptr"); NS_PRECONDITION(ppArray != nsnull, "null ptr"); if (!pLoc || !ppArray) return NS_ERROR_NULL_POINTER; ClearSampleFile(); *ppArray = nsnull; bool exists = false; nsresult rv = pLoc->Exists(&exists); 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; rv = m_text.DetermineDelim(pLoc); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Error determining delimitter\n"); return rv; } m_haveDelim = true; m_delim = m_text.GetDelim(); m_fileLoc = do_QueryInterface(pLoc); /* Build an address book descriptor based on the file passed in! */ nsCOMPtr<nsISupportsArray> array; rv = NS_NewISupportsArray(getter_AddRefs(array)); if (NS_FAILED(rv)) { IMPORT_LOG0("FAILED to allocate the nsISupportsArray\n"); return rv; } nsString name; m_fileLoc->GetLeafName(name); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed getting leaf name of file\n"); return rv; } PRInt32 idx = name.RFindChar('.'); if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) { name.SetLength(idx); } nsCOMPtr<nsIImportABDescriptor> desc; nsISupports * pInterface; nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to obtain the import service\n"); return rv; } rv = impSvc->CreateNewABDescriptor(getter_AddRefs(desc)); if (NS_SUCCEEDED(rv)) { PRInt64 sz = 0; pLoc->GetFileSize(&sz); desc->SetPreferredName(name); desc->SetSize((PRUint32) sz); desc->SetAbFile(m_fileLoc); rv = desc->QueryInterface(kISupportsIID, (void **) &pInterface); array->AppendElement(pInterface); pInterface->Release(); } if (NS_FAILED(rv)) { IMPORT_LOG0("*** Error creating address book descriptor for text import\n"); } else { rv = array->QueryInterface(NS_GET_IID(nsISupportsArray), (void **) ppArray); } return rv; }
nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, const PRUnichar *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; if (pCount) *pCount = 0; else pCount = &dummyCount; CMapiFolder *pFolder; if (id > 0) { int32_t idx = (int32_t) id; idx--; while (idx >= 0) { pFolder = m_addressList.GetItem(idx); if (pFolder->IsStore()) { OpenMessageStore(pFolder); break; } idx--; } } pFolder = m_addressList.GetItem(id); OpenMessageStore(pFolder); if (!m_lpMdb) { IMPORT_LOG1("*** Unable to obtain mapi message store for address book: %S\n", pName); return NS_ERROR_FAILURE; } if (pFolder->IsStore()) return NS_OK; nsresult rv; nsCOMPtr<nsIImportFieldMap> pFieldMap; 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()); BOOL done = FALSE; ULONG cbEid; LPENTRYID lpEid; ULONG oType; LPMESSAGE lpMsg; nsCString type; LPSPropValue pVal; nsString subject; while (!done) { (*pCount)++; if (!contents.GetNext(&cbEid, &lpEid, &oType, &done)) { IMPORT_LOG1("*** Error iterating address book: %S\n", pName); return NS_ERROR_FAILURE; } if (pTotal && (*pTotal == 0)) *pTotal = contents.GetCount(); if (!done && (oType == MAPI_MESSAGE)) { if (!m_mapi.OpenMdbEntry(m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName); return NS_ERROR_FAILURE; } // Get the PR_MESSAGE_CLASS attribute, // ensure that it is IPM.Contact pVal = m_mapi.GetMapiProperty(lpMsg, PR_MESSAGE_CLASS); if (pVal) { type.Truncate(); m_mapi.GetStringFromProp(pVal, type); if (type.EqualsLiteral("IPM.Contact")) { // 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); 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 // never releases it but that doesn't seem right to me! if (newRow) { if (BuildCard(subject.get(), pDb, newRow, lpMsg, pFieldMap)) { pDb->AddCardRowToDB(newRow); } } } 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); CreateList(subject.get(), pDb, lpMsg, pFieldMap); } } lpMsg->Release(); } } rv = pDb->Commit(nsAddrDBCommitType::kLargeCommit); return rv; }
void nsOEScanBoxes::BuildMailboxList( MailboxEntry *pBox, nsIFile * root, PRInt32 depth, nsISupportsArray *pArray) { if (pBox == nsnull) { if (m_pFirst != nsnull) { pBox = m_pFirst; IMPORT_LOG0( "Assigning start of mailbox list to m_pFirst\n"); } else { if (m_entryArray.Count() > 0) { pBox = (MailboxEntry *) m_entryArray.ElementAt( 0); IMPORT_LOG0( "Assigning start of mailbox list to entry at index 0\n"); } } if (pBox == nsnull) { IMPORT_LOG0( "ERROR ASSIGNING STARTING MAILBOX\n"); } } nsresult rv; nsCOMPtr <nsILocalFile> file; MailboxEntry * pChild; nsIImportMailboxDescriptor * pID; nsISupports * pInterface; PRInt64 size; nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED( rv)) return; while (pBox) { rv = impSvc->CreateNewMailboxDescriptor( &pID); if (NS_SUCCEEDED( rv)) { pID->SetDepth( depth); pID->SetIdentifier( pBox->index); pID->SetDisplayName( (PRUnichar *)pBox->mailName.get()); if (!pBox->fileName.IsEmpty()) { pID->GetFile( getter_AddRefs(file)); nsCOMPtr <nsILocalFile> localRoot = do_QueryInterface(root); file->InitWithFile(localRoot); file->AppendNative( pBox->fileName); size = 0; file->GetFileSize( &size); pID->SetSize( size); } rv = pID->QueryInterface( kISupportsIID, (void **) &pInterface); pArray->AppendElement( pInterface); pInterface->Release(); pID->Release(); } if (pBox->child) { pChild = GetIndexEntry( pBox->child); if (pChild != nsnull) BuildMailboxList( pChild, root, depth + 1, pArray); } if (pBox->sibling != -1) { pBox = GetIndexEntry( pBox->sibling); } else pBox = nsnull; } }
nsresult nsEudoraWin32::FindAddressBooks( nsIFile *pRoot, nsISupportsArray **ppArray) { nsresult rv; nsCOMPtr<nsILocalFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalFile> localRoot = do_QueryInterface(pRoot); rv = file->InitWithFile( localRoot); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewISupportsArray( ppArray); if (NS_FAILED( rv)) { IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n"); return( rv); } nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED( rv)) return( rv); m_addressImportFolder = pRoot; nsString displayName; nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_NICKNAMES_NAME, displayName); // First off, get the default nndbase.txt, then scan the default nicknames subdir, // then look in the .ini file for additional directories to scan for address books! PRBool exists = PR_FALSE; PRBool isFile = PR_FALSE; rv = file->AppendNative(NS_LITERAL_CSTRING("nndbase.txt")); PRBool checkedBoth = PR_FALSE; do { if (NS_SUCCEEDED(rv)) rv = file->Exists(&exists); if (NS_SUCCEEDED(rv) && exists) rv = file->IsFile(&isFile); // Stop if we already checked the second default name possibility or // if we found the default address book name. if (checkedBoth || (exists && isFile)) break; // Check for alternate file extension ".nnt" which Windows Eudora uses as an option // to hide from simple minded viruses that scan ".txt" files for addresses. rv = file->SetNativeLeafName(NS_LITERAL_CSTRING("nndbase.nnt")); checkedBoth = PR_TRUE; } while (NS_SUCCEEDED(rv)); if (exists && isFile) { if (NS_FAILED( rv = FoundAddressBook( file, displayName.get(), *ppArray, impSvc))) return( rv); } // Try the default directory rv = rv = file->InitWithFile( localRoot); if (NS_FAILED( rv)) return( rv); rv = file->AppendNative(NS_LITERAL_CSTRING("Nickname")); PRBool isDir = PR_FALSE; exists = PR_FALSE; if (NS_SUCCEEDED( rv)) rv = file->Exists( &exists); if (NS_SUCCEEDED( rv) && exists) rv = file->IsDirectory( &isDir); if (exists && isDir) { if (NS_FAILED( rv = ScanAddressDir(file, *ppArray, impSvc))) return( rv); } // Try the ini file to find other directories! rv = rv = file->InitWithFile( localRoot); if (NS_FAILED( rv)) return( rv); rv = file->AppendNative(NS_LITERAL_CSTRING("eudora.ini")); exists = PR_FALSE; isFile = PR_FALSE; if (NS_SUCCEEDED( rv)) rv = file->Exists( &exists); if (NS_SUCCEEDED( rv) && exists) rv = file->IsFile( &isFile); if (!isFile || !exists) { rv = file->InitWithFile( localRoot); if (NS_FAILED( rv)) return( NS_OK); if (!FindMimeIniFile(file)) return( NS_OK); } nsCString fileName; file->GetNativePath(fileName); // This is the supposed ini file name! // Get the extra directories for nicknames and parse it for valid nickname directories // to look into... char *pBuffer = new char[2048]; DWORD len = ::GetPrivateProfileString( "Settings", "ExtraNicknameDirs", "", pBuffer, 2048, fileName.get()); if (len == 2047) { // If the value is really that large then don't bother! delete [] pBuffer; return( NS_OK); } nsCString dirs(pBuffer); delete [] pBuffer; dirs.Trim( kWhitespace); PRInt32 idx = 0; nsCString currentDir; while ((idx = dirs.FindChar( ';')) != -1) { dirs.Left( currentDir, idx); currentDir.Trim( kWhitespace); if (!currentDir.IsEmpty()) { rv = file->InitWithNativePath(currentDir); exists = PR_FALSE; isDir = PR_FALSE; if (NS_SUCCEEDED( rv)) rv = file->Exists( &exists); if (NS_SUCCEEDED( rv) && exists) rv = file->IsDirectory( &isDir); if (exists && isDir) { if (NS_FAILED( rv = ScanAddressDir(file, *ppArray, impSvc))) return( rv); } } dirs.Right( currentDir, dirs.Length() - idx - 1); dirs = currentDir; dirs.Trim( kWhitespace); } if (!dirs.IsEmpty()) { rv = file->InitWithNativePath(dirs); exists = PR_FALSE; isDir = PR_FALSE; if (NS_SUCCEEDED( rv)) rv = file->Exists( &exists); if (NS_SUCCEEDED( rv) && exists) rv = file->IsDirectory( &isDir); if (exists && isDir) { if (NS_FAILED( rv = ScanAddressDir(file, *ppArray, impSvc))) return( rv); } } return( NS_OK); }
nsresult nsOutlookMail::GetAddressBooks(nsISupportsArray **pArray) { if (!m_haveMapi) { IMPORT_LOG0("GetAddressBooks called before Mapi is initialized\n"); return NS_ERROR_FAILURE; } nsresult rv = NS_NewISupportsArray(pArray); if (NS_FAILED(rv)) { IMPORT_LOG0("FAILED to allocate the nsISupportsArray for the address book list\n"); 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); int i = 0; CMapiFolder *pFolder; if (m_storeList.GetSize() > 1) { while ((pFolder = m_storeList.GetItem(i))) { CMapiFolder *pItem = new CMapiFolder(pFolder); pItem->SetDepth(1); m_addressList.AddItem(pItem); if (!m_mapi.GetStoreAddressFolders(pItem->GetCBEntryID(), pItem->GetEntryID(), m_addressList)) { IMPORT_LOG1("GetStoreAddressFolders for index %d failed.\n", i); } i++; } } else { if ((pFolder = m_storeList.GetItem(i))) { if (!m_mapi.GetStoreAddressFolders(pFolder->GetCBEntryID(), pFolder->GetEntryID(), m_addressList)) { IMPORT_LOG1("GetStoreFolders for index %d failed.\n", i); } } } // Create the mailbox descriptors for the list of folders nsIImportABDescriptor * pID; nsISupports * pInterface; nsString name; nsString list; for (i = 0; i < m_addressList.GetSize(); i++) { pFolder = m_addressList.GetItem(i); if (!pFolder->IsStore()) { rv = impSvc->CreateNewABDescriptor(&pID); if (NS_SUCCEEDED(rv)) { pID->SetIdentifier(i); pFolder->GetDisplayName(name); MakeAddressBookNameUnique(name, list); pID->SetPreferredName(name); pID->SetSize(100); rv = pID->QueryInterface(kISupportsIID, (void **) &pInterface); (*pArray)->AppendElement(pInterface); pInterface->Release(); pID->Release(); } } } return NS_OK; }
NS_IMETHODIMP nsOutlookImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface) { NS_PRECONDITION(pImportType != nsnull, "null ptr"); if (! pImportType) return NS_ERROR_NULL_POINTER; NS_PRECONDITION(ppInterface != nsnull, "null ptr"); if (! ppInterface) return NS_ERROR_NULL_POINTER; *ppInterface = nsnull; nsresult rv; if (!strcmp(pImportType, "mail")) { // create the nsIImportMail interface and return it! nsIImportMail * pMail = nsnull; nsIImportGeneric *pGeneric = nsnull; rv = ImportOutlookMailImpl::Create(&pMail); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = impSvc->CreateNewGenericMail(&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)); if (NS_SUCCEEDED(rv)) { nameString->SetData(name); pGeneric->SetData("name", nameString); rv = pGeneric->QueryInterface(kISupportsIID, (void **)ppInterface); } } } } NS_IF_RELEASE(pMail); NS_IF_RELEASE(pGeneric); return rv; } if (!strcmp(pImportType, "addressbook")) { // create the nsIImportAddressBook interface and return it! nsIImportAddressBooks * pAddress = nsnull; nsIImportGeneric * pGeneric = nsnull; rv = ImportOutlookAddressImpl::Create(&pAddress); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = impSvc->CreateNewGenericAddressBooks(&pGeneric); if (NS_SUCCEEDED(rv)) { pGeneric->SetData("addressInterface", pAddress); rv = pGeneric->QueryInterface(kISupportsIID, (void **)ppInterface); } } } NS_IF_RELEASE(pAddress); NS_IF_RELEASE(pGeneric); return rv; } if (!strcmp(pImportType, "settings")) { nsIImportSettings *pSettings = nsnull; rv = nsOutlookSettings::Create(&pSettings); if (NS_SUCCEEDED(rv)) pSettings->QueryInterface(kISupportsIID, (void **)ppInterface); NS_IF_RELEASE(pSettings); return rv; } return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks( nsIFile *pLoc, nsISupportsArray **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; bool isFile = false; rv = pLoc->IsFile(&isFile); if (NS_FAILED(rv) || !isFile) return NS_ERROR_FAILURE; m_fileLoc = do_QueryInterface(pLoc); /* Build an address book descriptor based on the file passed in! */ nsCOMPtr<nsISupportsArray> array; rv = NS_NewISupportsArray(getter_AddRefs(array)); if (NS_FAILED(rv)) { IMPORT_LOG0("FAILED to allocate the nsISupportsArray\n"); return rv; } nsString name; m_fileLoc->GetLeafName(name); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed getting leaf name of file\n"); return rv; } int32_t idx = name.RFindChar('.'); if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) { name.SetLength(idx); } nsCOMPtr<nsIImportABDescriptor> desc; nsCOMPtr<nsIImportService> impSvc( do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to obtain the import service\n"); return rv; } rv = impSvc->CreateNewABDescriptor(getter_AddRefs(desc)); if (NS_SUCCEEDED(rv)) { int64_t sz = 0; pLoc->GetFileSize(&sz); desc->SetPreferredName(name); desc->SetSize((uint32_t) sz); desc->SetAbFile(m_fileLoc); nsCOMPtr<nsISupports> pInterface(do_QueryInterface(desc, &rv)); array->AppendElement(pInterface); } if (NS_FAILED(rv)) { IMPORT_LOG0( "*** Error creating address book descriptor for vCard import\n"); } else { array.swap(*ppArray); } return rv; }
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *pLoc, nsISupportsArray **ppArray) { NS_PRECONDITION(pLoc != nsnull, "null ptr"); NS_PRECONDITION(ppArray != nsnull, "null ptr"); if (!pLoc || !ppArray) return NS_ERROR_NULL_POINTER; ClearSampleFile(); *ppArray = nsnull; PRBool exists = PR_FALSE; nsresult rv = pLoc->Exists( &exists); if (NS_FAILED( rv) || !exists) return( NS_ERROR_FAILURE); PRBool isFile = PR_FALSE; rv = pLoc->IsFile( &isFile); if (NS_FAILED( rv) || !isFile) return( NS_ERROR_FAILURE); rv = m_text.DetermineDelim( pLoc); if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Error determining delimitter\n"); return( rv); } m_haveDelim = PR_TRUE; m_delim = m_text.GetDelim(); m_fileLoc = pLoc; NS_ADDREF( m_fileLoc); /* Build an address book descriptor based on the file passed in! */ nsCOMPtr<nsISupportsArray> array; rv = NS_NewISupportsArray( getter_AddRefs( array)); if (NS_FAILED( rv)) { IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n"); return( 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); } nsXPIDLCString pName; rv = pLoc->GetLeafName(getter_Copies(pName)); if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Failed getting leaf name of file\n"); return( rv); } // for get unicode leafname. If it uses nsILocalFile interface, // these codes do not need due to nsILocalFile->GetUnicodeLeafName() nsString name; rv = impSvc->SystemStringToUnicode((const char*) pName, name); if (NS_FAILED(rv)) name.AssignWithConversion((const char*) pName); PRInt32 idx = name.RFindChar( '.'); if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) { nsString t; name.Left( t, idx); name = t; } nsCOMPtr<nsIImportABDescriptor> desc; nsISupports * pInterface; rv = impSvc->CreateNewABDescriptor( getter_AddRefs( desc)); if (NS_SUCCEEDED( rv)) { PRUint32 sz = 0; pLoc->GetFileSize( &sz); desc->SetPreferredName( name.get()); desc->SetSize( sz); nsIFileSpec *pSpec = nsnull; desc->GetFileSpec( &pSpec); if (pSpec) { pSpec->FromFileSpec( pLoc); NS_RELEASE( pSpec); } rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface); array->AppendElement( pInterface); pInterface->Release(); } if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Error creating address book descriptor for text import\n"); } else { rv = array->QueryInterface( NS_GET_IID(nsISupportsArray), (void **) ppArray); } return( rv); }
bool nsOEAddressIterator::BuildCard(const char16_t * pName, nsIMdbRow *newRow, LPMAILUSER pUser) { nsString lastName; nsString firstName; nsString eMail; nsString nickName; nsString middleName; PRTime birthDay = 0; LPSPropValue pProp = m_pWab->GetUserProperty(pUser, PR_EMAIL_ADDRESS); if (pProp) { m_pWab->GetValueString(pProp, eMail); SanitizeValue(eMail); m_pWab->FreeProperty(pProp); } pProp = m_pWab->GetUserProperty(pUser, PR_GIVEN_NAME); if (pProp) { m_pWab->GetValueString(pProp, firstName); SanitizeValue(firstName); m_pWab->FreeProperty(pProp); } pProp = m_pWab->GetUserProperty(pUser, PR_SURNAME); if (pProp) { m_pWab->GetValueString(pProp, lastName); SanitizeValue(lastName); m_pWab->FreeProperty(pProp); } pProp = m_pWab->GetUserProperty(pUser, PR_MIDDLE_NAME); if (pProp) { m_pWab->GetValueString(pProp, middleName); SanitizeValue(middleName); m_pWab->FreeProperty(pProp); } pProp = m_pWab->GetUserProperty(pUser, PR_NICKNAME); if (pProp) { m_pWab->GetValueString(pProp, nickName); SanitizeValue(nickName); m_pWab->FreeProperty(pProp); } // The idea here is that firstName and lastName cannot both be empty! if (firstName.IsEmpty() && lastName.IsEmpty()) firstName = pName; nsString displayName; pProp = m_pWab->GetUserProperty(pUser, PR_DISPLAY_NAME); if (pProp) { m_pWab->GetValueString(pProp, displayName); SanitizeValue(displayName); m_pWab->FreeProperty(pProp); } if (displayName.IsEmpty()) { if (firstName.IsEmpty()) displayName = pName; else { displayName = firstName; if (!middleName.IsEmpty()) { displayName.Append(char16_t(' ')); displayName.Append(middleName); } if (!lastName.IsEmpty()) { displayName.Append(char16_t(' ')); displayName.Append(lastName); } } } pProp = m_pWab->GetUserProperty(pUser, PR_BIRTHDAY); if (pProp) { m_pWab->GetValueTime(pProp, birthDay); m_pWab->FreeProperty(pProp); } // We now have the required fields // write them out followed by any optional fields! if (!displayName.IsEmpty()) m_database->AddDisplayName(newRow, NS_ConvertUTF16toUTF8(displayName).get()); if (!firstName.IsEmpty()) m_database->AddFirstName(newRow, NS_ConvertUTF16toUTF8(firstName).get()); if (!lastName.IsEmpty()) m_database->AddLastName(newRow, NS_ConvertUTF16toUTF8(lastName).get()); if (!nickName.IsEmpty()) m_database->AddNickName(newRow, NS_ConvertUTF16toUTF8(nickName).get()); if (!eMail.IsEmpty()) m_database->AddPrimaryEmail(newRow, NS_ConvertUTF16toUTF8(eMail).get()); if (birthDay) SetBirthDay(newRow, birthDay); // Do all of the extra fields! nsString value; nsString line2; nsresult rv; // Create a field map nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { nsIImportFieldMap * pFieldMap = nullptr; rv = impSvc->CreateNewFieldMap(&pFieldMap); if (NS_SUCCEEDED(rv) && pFieldMap) { int max = sizeof(gMapiFields) / sizeof(MAPIFields); for (int i = 0; i < max; i++) { pProp = m_pWab->GetUserProperty(pUser, gMapiFields[i].mapiTag); if (pProp) { m_pWab->GetValueString(pProp, value); m_pWab->FreeProperty(pProp); if (!value.IsEmpty()) { if (gMapiFields[i].multiLine == kNoMultiLine) { SanitizeValue(value); pFieldMap->SetFieldValue(m_database, newRow, gMapiFields[i].mozField, value.get()); } else if (gMapiFields[i].multiLine == kIsMultiLine) { pFieldMap->SetFieldValue(m_database, newRow, gMapiFields[i].mozField, value.get()); } else { line2.Truncate(); SplitString(value, line2); if (!value.IsEmpty()) pFieldMap->SetFieldValue(m_database, newRow, gMapiFields[i].mozField, value.get()); if (!line2.IsEmpty()) pFieldMap->SetFieldValue(m_database, newRow, gMapiFields[i].multiLine, line2.get()); } } } } // call fieldMap SetFieldValue based on the table of fields NS_RELEASE(pFieldMap); } } return true; }
NS_IMETHODIMP ImportAddressImpl::GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr) { NS_PRECONDITION(pFound != nsnull, "null ptr"); NS_PRECONDITION(pStr != nsnull, "null ptr"); if (!pFound || !pStr) return( NS_ERROR_NULL_POINTER); if (!m_fileLoc) { IMPORT_LOG0( "*** Error, called GetSampleData before SetSampleLocation\n"); return( NS_ERROR_FAILURE); } nsresult rv; *pStr = nsnull; PRBool open = PR_FALSE; PRUnichar term = 0; if (!m_haveDelim) { rv = m_fileLoc->IsStreamOpen( &open); if (open) { m_fileLoc->CloseStream(); open = PR_FALSE; } rv = m_text.DetermineDelim( m_fileLoc); if (NS_FAILED( rv)) return( rv); m_haveDelim = PR_TRUE; m_delim = m_text.GetDelim(); } else { rv = m_fileLoc->IsStreamOpen( &open); } if (!open) { rv = m_fileLoc->OpenStreamForReading(); if (NS_FAILED( rv)) { *pFound = PR_FALSE; *pStr = nsCRT::strdup( &term); return( NS_OK); } } PRInt32 lineLen; PRInt32 bufSz = 10240; char *pLine = new char[bufSz]; nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); rv = nsTextAddress::ReadRecordNumber( m_fileLoc, pLine, bufSz, m_delim, &lineLen, index); if (NS_SUCCEEDED( rv)) { nsString str; nsCString field; nsString uField; PRInt32 fNum = 0; while (nsTextAddress::GetField( pLine, lineLen, fNum, field, m_delim)) { if (fNum) str.AppendLiteral("\n"); SanitizeSampleData( field); if (impSvc) impSvc->SystemStringToUnicode( field.get(), uField); else uField.AssignWithConversion( field.get()); str.Append( uField); fNum++; field.Truncate(); } *pStr = nsCRT::strdup( str.get()); *pFound = PR_TRUE; /* IMPORT_LOG1( "Sample data: %S\n", str.get()); */ } else { *pFound = PR_FALSE; *pStr = nsCRT::strdup( &term); } delete [] pLine; return( NS_OK); }