NS_IMETHODIMP ImportOEMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource, nsIMsgFolder *dstFolder, PRUnichar **pErrorLog, PRUnichar **pSuccessLog, bool *fatalError) { NS_ENSURE_ARG_POINTER(pSource); NS_ENSURE_ARG_POINTER(dstFolder); NS_ENSURE_ARG_POINTER(fatalError); nsString success; nsString error; bool abort = false; nsString name; nsString pName; if (NS_SUCCEEDED(pSource->GetDisplayName(getter_Copies(pName)))) name = pName; PRUint32 mailSize = 0; pSource->GetSize(&mailSize); if (mailSize == 0) { ReportSuccess(name, 0, &success); SetLogs(success, error, pErrorLog, pSuccessLog); return NS_OK; } nsCOMPtr <nsIFile> inFile; if (NS_FAILED(pSource->GetFile(getter_AddRefs(inFile)))) { ReportError(OEIMPORT_MAILBOX_BADSOURCEFILE, name, &error); SetLogs(success, error, pErrorLog, pSuccessLog); return NS_ERROR_FAILURE; } nsCString pPath; inFile->GetNativePath(pPath); IMPORT_LOG1("Importing Outlook Express mailbox: %s\n", pPath.get()); m_bytesDone = 0; PRUint32 msgCount = 0; nsresult rv; if (nsOE5File::IsLocalMailFile(inFile)) { IMPORT_LOG1("Importing OE5 mailbox: %s!\n", NS_LossyConvertUTF16toASCII(name.get())); rv = nsOE5File::ImportMailbox( &m_bytesDone, &abort, name, inFile, dstFolder, &msgCount); } else { if (CImportMailbox::ImportMailbox( &m_bytesDone, &abort, name, inFile, dstFolder, &msgCount)) rv = NS_OK; else rv = NS_ERROR_FAILURE; } if (NS_SUCCEEDED(rv)) ReportSuccess(name, msgCount, &success); else ReportError(OEIMPORT_MAILBOX_CONVERTERROR, name, &error); SetLogs(success, error, pErrorLog, pSuccessLog); return rv; }
void nsOutlookMail::DumpAttachments( void) { #ifdef IMPORT_DEBUG PRInt32 count = 0; count = m_attachments.Count(); if (!count) { IMPORT_LOG0( "*** No Attachments\n"); return; } IMPORT_LOG1( "#%d attachments\n", (int) count); OutlookAttachment * pAttach; for (PRInt32 i = 0; i < count; i++) { IMPORT_LOG1( "\tAttachment #%d ---------------\n", (int) i); pAttach = (OutlookAttachment *) m_attachments.ElementAt( i); if (pAttach->mimeType) IMPORT_LOG1( "\t\tMime type: %s\n", pAttach->mimeType); if (pAttach->description) IMPORT_LOG1( "\t\tDescription: %s\n", pAttach->description); if (pAttach->pAttachment) { nsCString path; pAttach->pAttachment->GetNativePath( path); IMPORT_LOG1( "\t\tFile: %s\n", path.get()); } } #endif }
void nsEudoraWin32::SetSmtpServer( nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, const char *pServer, const char *pUser) { nsresult rv; nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && smtpService) { nsCOMPtr<nsISmtpServer> foundServer; rv = smtpService->FindServer( pUser, pServer, getter_AddRefs( foundServer)); if (NS_SUCCEEDED( rv) && foundServer) { IMPORT_LOG1( "SMTP server already exists: %s\n", pServer); return; } nsCOMPtr<nsISmtpServer> smtpServer; rv = smtpService->CreateSmtpServer( getter_AddRefs( smtpServer)); if (NS_SUCCEEDED( rv) && smtpServer) { smtpServer->SetHostname( pServer); if (pUser) smtpServer->SetUsername( pUser); IMPORT_LOG1( "Created new SMTP server: %s\n", pServer); } } }
void DumpAliasArray( nsVoidArray& a) { CAliasEntry *pEntry; CAliasData *pData; PRInt32 cnt = a.Count(); IMPORT_LOG1( "Alias list size: %ld\n", cnt); for (PRInt32 i = 0; i < cnt; i++) { pEntry = (CAliasEntry *)a.ElementAt( i); IMPORT_LOG1( "\tAlias: %s\n", pEntry->m_name.get()); if (pEntry->m_list.Count() > 1) { IMPORT_LOG1( "\tList count #%ld\n", pEntry->m_list.Count()); for (PRInt32 j = 0; j < pEntry->m_list.Count(); j++) { pData = (CAliasData *) pEntry->m_list.ElementAt( j); IMPORT_LOG0( "\t\t--------\n"); IMPORT_LOG1( "\t\temail: %s\n", pData->m_email.get()); IMPORT_LOG1( "\t\trealName: %s\n", pData->m_realName.get()); IMPORT_LOG1( "\t\tnickName: %s\n", pData->m_nickName.get()); } } else if (pEntry->m_list.Count()) { pData = (CAliasData *) pEntry->m_list.ElementAt( 0); IMPORT_LOG1( "\t\temail: %s\n", pData->m_email.get()); IMPORT_LOG1( "\t\trealName: %s\n", pData->m_realName.get()); IMPORT_LOG1( "\t\tnickName: %s\n", pData->m_nickName.get()); } } }
void WMSettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, nsIDOMDocument *xmlDoc, nsAutoString &inUserName, int32_t authMethodIncoming, bool isNNTP) { // Get the relevant information for an identity // BUG 470587. Don't set this: id->SetIdentityName(fullName); nsresult rv; nsAutoString value; nsCOMPtr<nsIMsgIdentity> id; rv = pMgr->CreateIdentity(getter_AddRefs(id)); if (id) { IMPORT_LOG0("Created identity and added to the account\n"); if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, isNNTP ? "NNTP_Display_Name" : "SMTP_Display_Name", value))) { id->SetFullName(value); IMPORT_LOG1("\tname: %S\n", value.get()); } if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, isNNTP ? "NNTP_Organization_Name" : "SMTP_Organization_Name", value))) { id->SetOrganization(value); } if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, isNNTP ? "NNTP_Email_Address" : "SMTP_Email_Address", value))) { id->SetEmail(NS_ConvertUTF16toUTF8(value)); IMPORT_LOG1("\temail: %S\n", value.get()); } if (NS_SUCCEEDED(nsWMUtils::GetValueForTag(xmlDoc, isNNTP ? "NNTP_Reply_To_Email_Address" : "SMTP_Reply_To_Email_Address", value))) { id->SetReplyTo(NS_ConvertUTF16toUTF8(value)); } // Windows users are used to top style quoting. id->SetReplyOnTop(isNNTP ? 0 : 1); pAcc->AddIdentity(id); } if (!isNNTP) // NNTP does not use SMTP in OE or TB SetSmtpServer(xmlDoc, id, inUserName, authMethodIncoming); }
void OESettings::SetIdentities(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, HKEY hKey, char *pIncomgUserName, PRInt32 authMethodIncoming, bool isNNTP) { // Get the relevant information for an identity char *pSmtpServer = (char *)nsOERegUtil::GetValueBytes(hKey, "SMTP Server"); char *pName = (char *)nsOERegUtil::GetValueBytes(hKey, isNNTP ? "NNTP Display Name" : "SMTP Display Name"); char *pEmail = (char *)nsOERegUtil::GetValueBytes(hKey, isNNTP ? "NNTP Email Address" : "SMTP Email Address"); char *pReply = (char *)nsOERegUtil::GetValueBytes(hKey, isNNTP ? "NNTP Reply To Email Address" : "SMTP Reply To Email Address"); char *pOrgName = (char *)nsOERegUtil::GetValueBytes(hKey, isNNTP ? "NNTP Organization Name" : "SMTP Organization Name"); nsresult rv; nsCOMPtr<nsIMsgIdentity> id; rv = pMgr->CreateIdentity(getter_AddRefs(id)); if (id) { nsAutoString fullName, organization; rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), nsCString(pName), fullName); if (NS_SUCCEEDED(rv)) id->SetFullName(fullName); // BUG 470587. Don't set this: id->SetIdentityName(fullName); rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), nsCString(pOrgName), organization); if (NS_SUCCEEDED(rv)) id->SetOrganization(organization); id->SetEmail(nsCString(pEmail)); if (pReply) id->SetReplyTo(nsCString(pReply)); // Outlook Express users are used to top style quoting. id->SetReplyOnTop(isNNTP ? 0 : 1); pAcc->AddIdentity(id); IMPORT_LOG0("Created identity and added to the account\n"); IMPORT_LOG1("\tname: %s\n", pName); IMPORT_LOG1("\temail: %s\n", pEmail); } if (!isNNTP) // NNTP does not use SMTP in OE or TB SetSmtpServer(pSmtpServer, hKey, id, pIncomgUserName, authMethodIncoming); nsOERegUtil::FreeValueBytes((BYTE *)pName); nsOERegUtil::FreeValueBytes((BYTE *)pSmtpServer); nsOERegUtil::FreeValueBytes((BYTE *)pEmail); nsOERegUtil::FreeValueBytes((BYTE *)pReply); }
PRBool nsOEScanBoxes::Find50Mail( nsIFile *pWhere) { nsresult rv; PRBool success = PR_FALSE; HKEY sKey; nsCOMPtr <nsILocalFile> localWhere = do_QueryInterface(pWhere); if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Identities", 0, KEY_QUERY_VALUE, &sKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes( sKey, "Default User ID"); ::RegCloseKey( sKey); if (pBytes) { nsCString key( "Identities\\"); key += (const char *)pBytes; nsOERegUtil::FreeValueBytes( pBytes); key += "\\Software\\Microsoft\\Outlook Express\\5.0"; if (::RegOpenKeyEx( HKEY_CURRENT_USER, key.get(), 0, KEY_QUERY_VALUE, &sKey) == ERROR_SUCCESS) { pBytes = nsOERegUtil::GetValueBytes( sKey, "Store Root"); if (pBytes) { localWhere->InitWithNativePath(nsDependentCString((const char *)pBytes)); IMPORT_LOG1( "Setting native path: %s\n", pBytes); nsOERegUtil::FreeValueBytes( pBytes); PRBool isDir = PR_FALSE; rv = pWhere->IsDirectory( &isDir); if (isDir && NS_SUCCEEDED( rv)) success = PR_TRUE; } ::RegCloseKey( sKey); } } } return( success); }
nsresult nsOEAddressIterator::EnumUser(const char16_t * pName, LPENTRYID pEid, ULONG cbEid) { IMPORT_LOG1("User: %S\n", pName); nsresult rv = NS_OK; if (m_database) { LPMAILUSER pUser = m_pWab->GetUser(cbEid, pEid); if (pUser) { // Get a new row from the database! nsCOMPtr <nsIMdbRow> newRow; rv = m_database->GetNewRow(getter_AddRefs(newRow)); NS_ENSURE_SUCCESS(rv, rv); if (newRow && BuildCard(pName, newRow, pUser)) { rv = m_database->AddCardRowToDB(newRow); NS_ENSURE_SUCCESS(rv, rv); IMPORT_LOG0("* Added entry to address book database\n"); nsString eMail; LPSPropValue pProp = m_pWab->GetUserProperty(pUser, PR_EMAIL_ADDRESS); if (pProp) { m_pWab->GetValueString(pProp, eMail); SanitizeValue(eMail); m_pWab->FreeProperty(pProp); m_listRows.Put(eMail, newRow); } } m_pWab->ReleaseUser(pUser); } } return rv; }
PRBool CImportMailbox::GetIndexFile( nsIFileSpec* file) { char *pLeaf = nsnull; if (NS_FAILED( file->GetLeafName( &pLeaf))) return( PR_FALSE); PRInt32 len = strlen( pLeaf); if (len < 5) { nsCRT::free( pLeaf); return( PR_FALSE); } pLeaf[len - 1] = 'x'; pLeaf[len - 2] = 'd'; pLeaf[len - 3] = 'i'; IMPORT_LOG1( "Looking for index leaf name: %s\n", pLeaf); nsresult rv; rv = file->SetLeafName( pLeaf); nsCRT::free( pLeaf); PRBool isFile = PR_FALSE; PRBool exists = PR_FALSE; if (NS_SUCCEEDED( rv)) rv = file->IsFile( &isFile); if (NS_SUCCEEDED( rv)) rv = file->Exists( &exists); if (isFile && exists) return( PR_TRUE); else return( PR_FALSE); }
void nsOutlookMail::BuildAttachments( CMapiMessage& msg, int count) { EmptyAttachments(); if (count) { nsresult rv; nsCOMPtr <nsILocalFile> pFile; for (int i = 0; i < count; i++) { if (!msg.GetAttachmentInfo( i)) { IMPORT_LOG1( "*** Error getting attachment info for #%d\n", i); } pFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED( rv) || !pFile) { IMPORT_LOG0( "*** Error creating file spec for attachment\n"); } else { if (msg.GetAttachFileLoc( pFile)) { PRBool isFile = PR_FALSE; PRBool exists = PR_FALSE; pFile->Exists( &exists); pFile->IsFile( &isFile); if (!exists || !isFile) { IMPORT_LOG0( "Attachment file does not exist\n"); } else { // We have a file spec, now get the other info OutlookAttachment *a = new OutlookAttachment; a->mimeType = strdup( msg.GetMimeType()); // Init description here so that we cacn tell // if defaul tattacchment is needed later. a->description = nsnull; const char *fileName = msg.GetFileName(); if (fileName && fileName[0]) { // Convert description to unicode. nsAutoString description; rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), nsDependentCString(fileName), description); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to convert system string to unicode"); if (NS_SUCCEEDED(rv)) a->description = ToNewUTF8String(description); } // If no description use "Attachment i" format. if (!a->description) { nsCAutoString str("Attachment "); str.AppendInt( (PRInt32) i); a->description = ToNewCString( str); } a->pAttachment = pFile; m_attachments.AppendElement( a); } } } } } }
PRBool nsOEScanBoxes::GetMailboxes( nsIFile *pWhere, nsISupportsArray **pArray) { nsCString path; pWhere->GetNativePath(path); if (!path.IsEmpty()) { IMPORT_LOG1( "Looking for mail in: %s\n", path.get()); } else { pWhere->GetNativeLeafName(path); if (!path.IsEmpty()) IMPORT_LOG1( "Looking for mail in: %s\n", path.get()); else IMPORT_LOG0( "Unable to get info about where to look for mail\n"); } nsCOMPtr <nsIFile> location; pWhere->Clone(getter_AddRefs(location)); // 1. Look for 5.0 folders.dbx // 2. Look for 3.x & 4.x folders.nch // 3. Look for 5.0 *.dbx mailboxes // 4. Look for 3.x & 4.x *.mbx mailboxes PRBool result; location->AppendNative(NS_LITERAL_CSTRING("folders.dbx")); if (Find50MailBoxes(location)) { result = GetMailboxList( location, pArray); } else { // 2. Look for 4.x mailboxes location->AppendNative(NS_LITERAL_CSTRING("folders.nch")); if (FindMailBoxes(location)) { result = GetMailboxList( location, pArray); } else { // 3 & 4, look for the specific mailbox files. pWhere->Clone(getter_AddRefs(location)); ScanMailboxDir( location); result = GetMailboxList( location, pArray); } } return( result); }
PRBool CImportMailbox::ImportMailbox( PRUint32 *pDone, PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRUint32 *pCount) { PRBool done = PR_FALSE; nsIFileSpec *idxFile; if (NS_FAILED( NS_NewFileSpec( &idxFile))) { IMPORT_LOG0( "New file spec failed!\n"); return( PR_FALSE); } idxFile->FromFileSpec( inFile); if (GetIndexFile( idxFile)) { IMPORT_LOG1( "Using index file for: %S\n", name.get()); CIndexScanner *pIdxScanner = new CIndexScanner( name, idxFile, inFile, outFile); if (pIdxScanner->Initialize()) { if (pIdxScanner->DoWork( pAbort, pDone, pCount)) { done = PR_TRUE; } else { IMPORT_LOG0( "CIndexScanner::DoWork() failed\n"); } } else { IMPORT_LOG0( "CIndexScanner::Initialize() failed\n"); } delete pIdxScanner; } idxFile->Release(); if (done) return( done); /* something went wrong with the index file, just scan the mailbox file itself. */ CMbxScanner *pMbx = new CMbxScanner( name, inFile, outFile); if (pMbx->Initialize()) { if (pMbx->DoWork( pAbort, pDone, pCount)) { done = PR_TRUE; } else { IMPORT_LOG0( "CMbxScanner::DoWork() failed\n"); } } else { IMPORT_LOG0( "CMbxScanner::Initialize() failed\n"); } delete pMbx; return( done); }
nsresult OutlookSettings::SetSmtpServer(nsIMsgAccountManager *aMgr, nsIMsgAccount *aAcc, nsIMsgIdentity *aId, const nsString &aServer, const nsString &aUser) { nsresult rv; nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString nativeUserName; NS_CopyUnicodeToNative(aUser, nativeUserName); nsCAutoString nativeServerName; NS_CopyUnicodeToNative(aServer, nativeServerName); nsCOMPtr<nsISmtpServer> foundServer; 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()); return rv; } nsCOMPtr<nsISmtpServer> smtpServer; rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer)); NS_ENSURE_SUCCESS(rv, rv); smtpServer->SetHostname(nativeServerName); if (!aUser.IsEmpty()) smtpServer->SetUsername(nativeUserName); if (aId) SetSmtpServerKey(aId, smtpServer); // TODO SSL, auth method IMPORT_LOG1("Ceated new SMTP server: %s\n", nativeServerName.get()); return NS_OK; }
PRBool nsEudoraWin32::BuildIMAPAccount( nsIMsgAccountManager *accMgr, const char *pSection, const char *pIni, nsIMsgAccount **ppAccount) { char valBuff[kIniValueSize]; nsCString serverName; nsCString userName; GetServerAndUserName( pSection, pIni, serverName, userName, valBuff); if (serverName.IsEmpty() || userName.IsEmpty()) return( PR_FALSE); PRBool result = PR_FALSE; nsCOMPtr<nsIMsgIncomingServer> in; nsresult rv = accMgr->FindServer( userName, serverName, NS_LITERAL_CSTRING("imap"), getter_AddRefs(in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? rv = accMgr->CreateIncomingServer( userName, serverName, NS_LITERAL_CSTRING("imap"), getter_AddRefs(in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType(NS_LITERAL_CSTRING("imap")); // rv = in->SetHostName( serverName); // rv = in->SetUsername( userName); IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", serverName.get(), userName.get()); nsString prettyName; GetAccountName( pSection, prettyName); IMPORT_LOG1( "\tSet pretty name to: %S\n", prettyName.get()); rv = in->SetPrettyName(prettyName); // We have a server, create an account. nsCOMPtr<nsIMsgAccount> account; rv = accMgr->CreateAccount( getter_AddRefs( account)); if (NS_SUCCEEDED( rv) && account) { rv = account->SetIncomingServer(in); IMPORT_LOG0( "Created an account and set the IMAP server as the incoming server\n"); // Fiddle with the identities SetIdentities(accMgr, account, pSection, pIni, userName.get(), serverName.get(), valBuff); result = PR_TRUE; if (ppAccount) account->QueryInterface( NS_GET_IID(nsIMsgAccount), (void **)ppAccount); } } } else result = PR_TRUE; return( result); }
void nsEudoraWin32::SetIdentities(nsIMsgAccountManager *accMgr, nsIMsgAccount *acc, const char *pSection, const char *pIniFile, const char *userName, const char *serverName, char *pBuff) { nsCAutoString realName; nsCAutoString email; nsCAutoString server; DWORD valSize; nsresult rv; valSize = ::GetPrivateProfileString( pSection, "RealName", "", pBuff, kIniValueSize, pIniFile); if (valSize) realName = pBuff; valSize = ::GetPrivateProfileString( pSection, "SMTPServer", "", pBuff, kIniValueSize, pIniFile); if (valSize) server = pBuff; valSize = ::GetPrivateProfileString( pSection, "ReturnAddress", "", pBuff, kIniValueSize, pIniFile); if (valSize) email = pBuff; nsCOMPtr<nsIMsgIdentity> id; rv = accMgr->CreateIdentity( getter_AddRefs( id)); if (id) { nsAutoString fullName; fullName.Assign(NS_ConvertASCIItoUTF16(realName)); id->SetFullName(fullName); id->SetIdentityName(fullName); if (email.IsEmpty()) { email = userName; email += "@"; email += serverName; } id->SetEmail(email); acc->AddIdentity( id); IMPORT_LOG0( "Created identity and added to the account\n"); IMPORT_LOG1( "\tname: %s\n", realName.get()); IMPORT_LOG1( "\temail: %s\n", email.get()); } SetSmtpServer( accMgr, acc, server.get(), userName); }
void DUMP_FILENAME(nsIFile *pFile, bool endLine) { nsCString pPath; if (pFile) pFile->GetNativePath(pPath); if (!pPath.IsEmpty()) IMPORT_LOG1("%s", pPath.get()); else IMPORT_LOG0("Unknown"); if (endLine) IMPORT_LOG0("\n"); }
nsresult nsEudoraWin32::FoundMailbox( nsIFile *mailFile, const char *pName, nsISupportsArray *pArray, nsIImportService *pImport) { nsString displayName; nsCOMPtr<nsIImportMailboxDescriptor> desc; nsISupports * pInterface; NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); #ifdef IMPORT_DEBUG nsCAutoString path; mailFile->GetNativePath(path); if (!path.IsEmpty()) IMPORT_LOG2( "Found eudora mailbox, %s: %s\n", path.get(), pName); else IMPORT_LOG1( "Found eudora mailbox, %s\n", pName); IMPORT_LOG1( "\tm_depth = %d\n", (int)m_depth); #endif nsresult rv = pImport->CreateNewMailboxDescriptor( getter_AddRefs( desc)); if (NS_SUCCEEDED( rv)) { PRInt64 sz = 0; mailFile->GetFileSize( &sz); desc->SetDisplayName( displayName.get()); desc->SetDepth( m_depth); desc->SetSize( sz); nsCOMPtr <nsILocalFile> pFile = nsnull; desc->GetFile(getter_AddRefs(pFile)); if (pFile) { nsCOMPtr <nsILocalFile> localMailFile = do_QueryInterface(mailFile); pFile->InitWithFile( localMailFile); } rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface); pArray->AppendElement( pInterface); pInterface->Release(); } return( NS_OK); }
void OutlookSettings::SetSmtpServer(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, char *pServer, const nsCString& user) { nsresult rv; nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && smtpService) { nsCOMPtr<nsISmtpServer> foundServer; rv = smtpService->FindServer(user.get(), pServer, getter_AddRefs(foundServer)); if (NS_SUCCEEDED(rv) && foundServer) { IMPORT_LOG1("SMTP server already exists: %s\n", pServer); return; } nsCOMPtr<nsISmtpServer> smtpServer; rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer)); if (NS_SUCCEEDED(rv) && smtpServer) { smtpServer->SetHostname(nsDependentCString(pServer)); if (!user.IsEmpty()) smtpServer->SetUsername(user); // TODO SSL, auth method IMPORT_LOG1("Ceated new SMTP server: %s\n", pServer); } } }
PRBool CMbxScanner::WriteMailItem( PRUint32 flags, PRUint32 offset, PRUint32 size, PRUint32 *pTotalMsgSize) { PRUint32 values[kNumMbxLongsToRead]; PRInt32 cnt = kNumMbxLongsToRead * sizeof( PRUint32); nsresult rv; PRBool failed = PR_FALSE; PRInt32 cntRead; PRInt8 * pChar = (PRInt8 *) values; rv = m_mbxFile->Seek( offset); m_mbxFile->Failed( &failed); if (NS_FAILED( rv) || failed) { IMPORT_LOG1( "Mbx seek error: 0x%lx\n", offset); return( PR_FALSE); } rv = m_mbxFile->Read( (char **) &pChar, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) { IMPORT_LOG1( "Mbx read error at: 0x%lx\n", offset); return( PR_FALSE); } if (values[0] != 0x7F007F00) { IMPORT_LOG2( "Mbx tag field doesn't match: 0x%lx, at offset: 0x%lx\n", values[0], offset); return( PR_FALSE); } if (size && (values[2] != size)) { IMPORT_LOG3( "Mbx size doesn't match idx, mbx: %ld, idx: %ld, at offset: 0x%lx\n", values[2], size, offset); return( PR_FALSE); } if (pTotalMsgSize != nsnull) *pTotalMsgSize = values[2]; // everything looks kosher... // the actual message text follows and is values[3] bytes long... return( CopyMbxFileBytes(flags, values[3])); }
/* 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 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()); } } } 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); return rv; }
PRBool CIndexScanner::ValidateIdxFile( void) { PRInt8 id[4]; PRInt32 cnt = 4; nsresult rv; PRInt32 cntRead; PRInt8 * pReadTo; pReadTo = id; rv = m_idxFile->Read( (char **) &pReadTo, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); if ((id[0] != 'J') || (id[1] != 'M') || (id[2] != 'F') || (id[3] != '9')) return( PR_FALSE); cnt = 4; PRUint32 subId; pReadTo = (PRInt8 *) &subId; rv = m_idxFile->Read( (char **) &pReadTo, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); if (subId != 0x00010004) { IMPORT_LOG1( "Idx file subid doesn't match: 0x%lx\n", subId); return( PR_FALSE); } pReadTo = (PRInt8 *) &m_numMessages; rv = m_idxFile->Read( (char **) &pReadTo, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); IMPORT_LOG1( "Idx file num messages: %ld\n", m_numMessages); m_didBytes += 80; m_idxOffset = 80; return( PR_TRUE); }
PRBool CIndexScanner::GetMailItem( PRUint32 *pFlags, PRUint32 *pOffset, PRUint32 *pSize) { PRUint32 values[kNumIdxLongsToRead]; PRInt32 cnt = kNumIdxLongsToRead * sizeof( PRUint32); PRInt8 * pReadTo = (PRInt8 *) values; PRInt32 cntRead; nsresult rv; rv = m_idxFile->Seek( m_idxOffset); if (NS_FAILED( rv)) return( PR_FALSE); rv = m_idxFile->Read( (char **) &pReadTo, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); if (values[3] != m_idxOffset) { IMPORT_LOG2( "Self pointer invalid: m_idxOffset=0x%lx, self=0x%lx\n", m_idxOffset, values[3]); return( PR_FALSE); } // So... what do we have here??? #ifdef DEBUG_SUBJECT_AND_FLAGS IMPORT_LOG2( "Number: %ld, msg offset: 0x%lx, ", values[2], values[5]); IMPORT_LOG2( "msg length: %ld, Flags: 0x%lx\n", values[6], values[0]); m_idxFile->seek( m_idxOffset + 212); PRUint32 subSz = 0; cnt = 4; pReadTo = (PRInt8 *) &subSz; m_idxFile->Read( (char **) &pReadTo, cnt, &cntRead); if ((subSz >= 0) && (subSz < 1024)) { char *pSub = new char[subSz + 1]; m_idxFile->Read( &pSub, subSz, &cntRead); pSub[subSz] = 0; IMPORT_LOG1( " Subject: %s\n", pSub); delete [] pSub; } #endif m_idxOffset += values[4]; m_didBytes += values[4]; *pFlags = values[0]; *pOffset = values[5]; *pSize = values[6]; return( PR_TRUE); }
bool nsEudoraMailbox::AddAttachment(nsCString& fileName) { IMPORT_LOG1("Found attachment: %s\n", fileName.get()); nsresult rv; nsCOMPtr <nsIFile> pFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) return false; nsCString mimeType; nsCString attachmentName; if (NS_FAILED(GetAttachmentInfo(fileName.get(), pFile, mimeType, attachmentName))) return false; ImportAttachment *a = new ImportAttachment; a->mimeType = ToNewCString(mimeType); a->description = !attachmentName.IsEmpty() ? ToNewCString(attachmentName) : strdup("Attached File"); a->pAttachment = pFile; m_attachments.AppendElement(a); return true; }
nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsString& name, nsIFile *inFile, nsIFile *pDestination, PRUint32 *pCount) { nsresult rv; PRInt32 msgCount = 0; if (pCount) *pCount = 0; nsCOMPtr <nsIInputStream> inputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), inFile); if (NS_FAILED( rv)) return( rv); nsCOMPtr <nsIOutputStream> outputStream; rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), pDestination, -1, 0600); if (NS_FAILED( rv)) return( rv); PRUint32 * pIndex; PRUint32 indexSize; if (!ReadIndex( inputStream, &pIndex, &indexSize)) { IMPORT_LOG1( "No messages found in mailbox: %S\n", name.get()); return( NS_OK); } char * pBuffer = new char[kMailboxBufferSize]; if (!(*pAbort)) ConvertIndex( inputStream, pBuffer, pIndex, indexSize); PRUint32 block[4]; PRInt32 sepLen = (PRInt32) strlen( m_pFromLineSep); PRUint32 written; /* Each block is: marker - matches file offset block length text length in block pointer to next block. (0 if end) Each message is made up of a linked list of block data. So what we do for each message is: 1. Read the first block data. 2. Write out the From message separator if the message doesn't already start with one. 3. If the block of data doesn't end with CRLF then a line is broken into two blocks, so save the incomplete line for later process when we read the next block. Then write out the block excluding the partial line at the end of the block (if exists). 4. If there's next block of data then read next data block. Otherwise we're done. If we found a partial line in step #3 then find the rest of the line from the current block and write out this line separately. 5. Reset some of the control variables and repeat step #3. */ PRUint32 didBytes = 0; PRUint32 next, size; char *pStart, *pEnd, *partialLineStart; nsCAutoString partialLine, tempLine; rv = NS_OK; for (PRUint32 i = 0; (i < indexSize) && !(*pAbort); i++) { if (! pIndex[i]) continue; if (ReadBytes( inputStream, block, pIndex[i], 16) && (block[0] == pIndex[i]) && (block[2] < kMailboxBufferSize) && (ReadBytes( inputStream, pBuffer, kDontSeek, block[2]))) { // block[2] contains the chars in the buffer (ie, buf content size). // block[3] contains offset to the next block of data (0 means no more data). size = block[2]; pStart = pBuffer; pEnd = pStart + size; // write out the from separator. if (IsFromLine( pBuffer, size)) { char *pChar = pStart; while ((pChar < pEnd) && (*pChar != '\r') && (*(pChar+1) != '\n')) pChar++; if (pChar < pEnd) { // Get the "From " line so write it out. rv = outputStream->Write(pStart, pChar-pStart+2, &written); NS_ENSURE_SUCCESS(rv,rv); // Now buffer starts from the 2nd line. pStart = pChar + 2; } } else { // Write out the default from line since there is none in the msg. rv = outputStream->Write( m_pFromLineSep, sepLen, &written); // FIXME: Do I need to check the return value of written??? if (NS_FAILED( rv)) break; } char statusLine[50]; PRUint32 msgFlags = 0; // need to convert from OE flags to mozilla flags PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF); rv = outputStream->Write(statusLine, strlen(statusLine), &written); NS_ENSURE_SUCCESS(rv,rv); PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF0000); rv = outputStream->Write(statusLine, strlen(statusLine), &written); NS_ENSURE_SUCCESS(rv,rv); do { partialLine.Truncate(); partialLineStart = pEnd; // If the buffer doesn't end with CRLF then a line is broken into two blocks, // so save the incomplete line for later process when we read the next block. if ( (size > 1) && !(*(pEnd - 2) == '\r' && *(pEnd - 1) == '\n') ) { partialLineStart -= 2; while ((partialLineStart >= pStart) && (*partialLineStart != '\r') && (*(partialLineStart+1) != '\n')) partialLineStart--; if (partialLineStart != (pEnd - 2)) partialLineStart += 2; // skip over CRLF if we find them. partialLine.Assign(partialLineStart, pEnd - partialLineStart); } // Now process the block of data which ends with CRLF. rv = EscapeFromSpaceLine(outputStream, pStart, partialLineStart); if (NS_FAILED(rv)) break; didBytes += block[2]; next = block[3]; if (! next) { // OK, we're done so flush out the partial line if it's not empty. if (partialLine.Length()) rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length())); } else if (ReadBytes(inputStream, block, next, 16) && (block[0] == next) && (block[2] < kMailboxBufferSize) && (ReadBytes(inputStream, pBuffer, kDontSeek, block[2]))) { // See if we have a partial line from previous block. If so then build a complete // line (ie, take the remaining chars from this block) and process this line. Need // to adjust where data start and size in this case. size = block[2]; pStart = pBuffer; pEnd = pStart + size; if (partialLine.Length()) { while ((pStart < pEnd) && (*pStart != '\r') && (*(pStart+1) != '\n')) pStart++; if (pStart < pEnd) // if we found a CRLF .. pStart += 2; // .. then copy that too. tempLine.Assign(pBuffer, pStart - pBuffer); partialLine.Append(tempLine); rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length())); if (NS_FAILED(rv)) break; // Adjust where data start and size (since some of the data has been processed). size -= (pStart - pBuffer); } } else { IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]); rv = outputStream->Write( "\x0D\x0A", 2, &written); next = 0; } } while (next); // Always end a msg with CRLF. This will make sure that OE msgs without body is // correctly recognized as msgs. Otherwise, we'll end up with the following in // the msg folder where the 2nd msg starts right after the headers of the 1st msg: // // From - Jan 1965 00:00:00 <<<--- 1st msg starts here // Subject: Test msg // . . . (more headers) // To: <*****@*****.**> // From - Jan 1965 00:00:00 <<<--- 2nd msg starts here // Subject: How are you // . . .(more headers) // // In this case, the 1st msg is not recognized as a msg (it's skipped) // when you open the folder. rv = outputStream->Write( "\x0D\x0A", 2, &written); if (NS_FAILED(rv)) break; msgCount++; if (pCount) *pCount = msgCount; if (pBytesDone) *pBytesDone = didBytes; } else { // Error reading message, should this be logged??? IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]); *pAbort = PR_TRUE; } } delete [] pBuffer; if (NS_FAILED(rv)) *pAbort = PR_TRUE; return( rv); }
void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr, nsIMsgAccount *aAcc, nsIWindowsRegKey *aKey) { // Get the relevant information for an identity nsAutoString name; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Display Name"), name); nsAutoString server; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Server"), server); nsAutoString email; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Email Address"), email); nsAutoString reply; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Reply To Email Address"), reply); nsAutoString userName; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP User Name"), userName); nsAutoString orgName; aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Organization Name"), orgName); nsresult rv; 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. rv = aMgr->CreateIdentity(getter_AddRefs(id)); if (id) { id->SetFullName(name); id->SetIdentityName(name); id->SetOrganization(orgName); nsCAutoString nativeEmail; NS_CopyUnicodeToNative(email, nativeEmail); id->SetEmail(nativeEmail); if (!reply.IsEmpty()) { nsCAutoString nativeReply; NS_CopyUnicodeToNative(reply, nativeReply); id->SetReplyTo(nativeReply); } aAcc->AddIdentity(id); nsCAutoString nativeName; NS_CopyUnicodeToNative(name, nativeName); IMPORT_LOG0("Created identity and added to the account\n"); IMPORT_LOG1("\tname: %s\n", nativeName.get()); IMPORT_LOG1("\temail: %s\n", nativeEmail.get()); } } if (userName.IsEmpty()) { nsCOMPtr<nsIMsgIncomingServer> incomingServer; rv = aAcc->GetIncomingServer(getter_AddRefs(incomingServer)); if (NS_SUCCEEDED(rv) && incomingServer) { nsCAutoString nativeUserName; rv = incomingServer->GetUsername(nativeUserName); NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get UserName from incomingServer"); NS_CopyNativeToUnicode(nativeUserName, userName); } } SetSmtpServer(aMgr, aAcc, id, server, userName); }
bool OutlookSettings::DoImport(nsIMsgAccount **aAccount) { nsCOMPtr<nsIWindowsRegKey> key; nsresult rv = OutlookSettings::FindAccountsKey(getter_AddRefs(key)); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Error finding Outlook registry account keys\n"); return false; } nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create a account manager!\n"); return false; } nsAutoString defMailName; rv = GetDefaultMailAccountName(defMailName); PRUint32 childCount; key->GetChildCount(&childCount); PRUint32 accounts = 0; PRUint32 popCount = 0; for (PRUint32 i = 0; i < childCount; i++) { nsAutoString keyName; key->GetChildName(i, keyName); nsCOMPtr<nsIWindowsRegKey> subKey; rv = key->OpenChild(keyName, nsIWindowsRegKey::ACCESS_QUERY_VALUE, getter_AddRefs(subKey)); if (NS_FAILED(rv)) continue; // Get the values for this account. nsCAutoString nativeKeyName; NS_CopyUnicodeToNative(keyName, nativeKeyName); IMPORT_LOG1("Opened Outlook account: %s\n", nativeKeyName.get()); nsCOMPtr<nsIMsgAccount> account; nsAutoString value; rv = subKey->ReadStringValue(NS_LITERAL_STRING("IMAP Server"), value); if (NS_SUCCEEDED(rv) && DoIMAPServer(accMgr, subKey, value, getter_AddRefs(account))) accounts++; rv = subKey->ReadStringValue(NS_LITERAL_STRING("POP3 Server"), value); if (NS_SUCCEEDED(rv) && DoPOP3Server(accMgr, subKey, value, getter_AddRefs(account))) { popCount++; accounts++; if (aAccount && account) { // If we created a mail account, get rid of it since // we have 2 POP accounts! if (popCount > 1) NS_RELEASE(*aAccount); else NS_ADDREF(*aAccount = account); } } // Is this the default account? if (account && keyName.Equals(defMailName)) accMgr->SetDefaultAccount(account); } // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return accounts != 0; }
// Creates a folder in Local Folders with the module name + mail // for e.g: Outlook Mail bool nsImportGenericMail::CreateFolder(nsIMsgFolder **ppFolder) { nsresult rv; *ppFolder = nullptr; nsCOMPtr<nsIStringBundle> bundle; nsCOMPtr<nsIStringBundleService> bundleService = mozilla::services::GetStringBundleService(); if (!bundleService) return false; rv = bundleService->CreateBundle(IMPORT_MSGS_URL, getter_AddRefs(bundle)); if (NS_FAILED(rv)) return false; nsString folderName; if (!m_pName.IsEmpty()) { const PRUnichar *moduleName[] = { m_pName.get() }; rv = bundle->FormatStringFromName(NS_LITERAL_STRING("ImportModuleFolderName").get(), moduleName, 1, getter_Copies(folderName)); } else { rv = bundle->GetStringFromName(NS_LITERAL_STRING("DefaultFolderName").get(), getter_Copies(folderName)); } if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to get Folder Name!\n"); return false; } nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create account manager!\n"); return false; } nsCOMPtr <nsIMsgIncomingServer> server; rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); // if Local Folders does not exist already, create it if (NS_FAILED(rv) || !server) { rv = accMgr->CreateLocalMailAccount(); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create Local Folders!\n"); return false; } rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); } if (NS_SUCCEEDED(rv) && server) { nsCOMPtr <nsIMsgFolder> localRootFolder; rv = server->GetRootMsgFolder(getter_AddRefs(localRootFolder)); if (localRootFolder) { // we need to call GetSubFolders() so that the folders get initialized // if they are not initialized yet. nsCOMPtr<nsISimpleEnumerator> aEnumerator; rv = localRootFolder->GetSubFolders(getter_AddRefs(aEnumerator)); if (NS_SUCCEEDED(rv)) { // check if the folder name we picked already exists. bool exists = false; rv = localRootFolder->ContainsChildNamed(folderName, &exists); if (exists) { nsString name; localRootFolder->GenerateUniqueSubfolderName(folderName, nullptr, name); if (!name.IsEmpty()) folderName.Assign(name); else { IMPORT_LOG0("*** Failed to find a unique folder name!\n"); return false; } } IMPORT_LOG1("Creating folder for importing mail: '%s'\n", NS_ConvertUTF16toUTF8(folderName).get()); // Bug 564162 identifies a dataloss design flaw. // A working Thunderbird client can have mail in Local Folders and a // subsequent import 'Everything' will trigger a migration which // overwrites existing mailboxes with the imported mailboxes. rv = localRootFolder->CreateSubfolder(folderName, nullptr); if (NS_SUCCEEDED(rv)) { rv = localRootFolder->GetChildNamed(folderName, ppFolder); if (*ppFolder) { IMPORT_LOG1("Folder '%s' created successfully\n", NS_ConvertUTF16toUTF8(folderName).get()); return true; } } } } // if localRootFolder } // if server IMPORT_LOG0("****** FAILED TO CREATE FOLDER FOR IMPORT\n"); return false; }
static void ImportMailThread(void *stuff) { ImportThreadData *pData = (ImportThreadData *)stuff; IMPORT_LOG0("ImportMailThread: Starting..."); nsresult rv = NS_OK; nsCOMPtr<nsIMsgFolder> destRoot(pData->destRoot); uint32_t count = 0; rv = pData->boxes->Count(&count); uint32_t i; bool import; uint32_t size; uint32_t depth = 1; uint32_t newDepth; nsString lastName; PRUnichar * pName; nsCOMPtr<nsIMsgFolder> curFolder(destRoot); nsCOMPtr<nsIMsgFolder> newFolder; nsCOMPtr<nsIMsgFolder> subFolder; nsCOMPtr<nsISimpleEnumerator> enumerator; bool exists; nsString success; nsString error; // GetSubFolders() will initialize folders if they are not already initialized. ProxyGetSubFolders(curFolder, getter_AddRefs(enumerator)); IMPORT_LOG1("ImportMailThread: Total number of folders to import = %d.", count); // Note that the front-end js script only displays one import result string so // we combine both good and bad import status into one string (in var 'success'). for (i = 0; (i < count) && !(pData->abort); i++) { nsCOMPtr<nsIImportMailboxDescriptor> box = do_QueryElementAt(pData->boxes, i); if (box) { pData->currentMailbox = i; import = false; size = 0; rv = box->GetImport(&import); if (import) rv = box->GetSize(&size); rv = box->GetDepth(&newDepth); if (newDepth > depth) { // OK, we are going to add a subfolder under the last/previous folder we processed, so // find this folder (stored in 'lastName') who is going to be the new parent folder. IMPORT_LOG1("ImportMailThread: Processing child folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get()); rv = ProxyGetChildNamed(curFolder, lastName, getter_AddRefs(subFolder)); if (NS_FAILED(rv)) { IMPORT_LOG1("*** ImportMailThread: Failed to get the interface for child folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get()); nsImportGenericMail::ReportError(IMPORT_ERROR_MB_FINDCHILD, lastName.get(), &error, pData->stringBundle); pData->fatalError = true; break; } curFolder = subFolder; // Make sure this new parent folder obj has the correct subfolder list so far. rv = ProxyGetSubFolders(curFolder, getter_AddRefs(enumerator)); } else if (newDepth < depth) { rv = NS_OK; while ((newDepth < depth) && NS_SUCCEEDED(rv)) { rv = curFolder->GetParent(getter_AddRefs(curFolder)); if (NS_FAILED(rv)) { IMPORT_LOG1("*** ImportMailThread: Failed to get the interface for parent folder '%s'.", lastName.get()); nsImportGenericMail::ReportError(IMPORT_ERROR_MB_FINDCHILD, lastName.get(), &error, pData->stringBundle); pData->fatalError = true; break; } depth--; } if (NS_FAILED(rv)) { IMPORT_LOG1("*** ImportMailThread: Failed to get the proxy interface for parent folder '%s'.", lastName.get()); nsImportStringBundle::GetStringByID(IMPORT_ERROR_MB_NOPROXY, pData->stringBundle, error); pData->fatalError = true; break; } } depth = newDepth; pName = nullptr; box->GetDisplayName(&pName); if (pName) { lastName = pName; NS_Free(pName); } else lastName.AssignLiteral("Unknown!"); // translate the folder name if we are doing migration, but // only for special folders which are at the root level if (pData->performingMigration && depth == 1) pData->mailImport->TranslateFolderName(lastName, lastName); exists = false; rv = ProxyContainsChildNamed(curFolder, lastName, &exists); // If we are performing profile migration (as opposed to importing) then we are starting // with empty local folders. In that case, always choose to over-write the existing local folder // with this name. Don't create a unique subfolder name. Otherwise you end up with "Inbox, Inbox0" // or "Unsent Folders, UnsentFolders0" if (exists && !pData->performingMigration) { nsString subName; ProxyGenerateUniqueSubfolderName(curFolder, lastName, nullptr, subName); if (!subName.IsEmpty()) lastName.Assign(subName); } IMPORT_LOG1("ImportMailThread: Creating new import folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get()); ProxyCreateSubfolder(curFolder, lastName); // this may fail if the folder already exists..that's ok rv = ProxyGetChildNamed(curFolder, lastName, getter_AddRefs(newFolder)); if (NS_FAILED(rv)) { IMPORT_LOG1("*** ImportMailThread: Failed to locate subfolder '%s' after it's been created.", lastName.get()); nsImportGenericMail::ReportError(IMPORT_ERROR_MB_CREATE, lastName.get(), &error, pData->stringBundle); } if (size && import && newFolder && NS_SUCCEEDED(rv)) { bool fatalError = false; pData->currentSize = size; PRUnichar *pSuccess = nullptr; PRUnichar *pError = nullptr; rv = pData->mailImport->ImportMailbox(box, newFolder, &pError, &pSuccess, &fatalError); if (pError) { error.Append(pError); NS_Free(pError); } if (pSuccess) { success.Append(pSuccess); NS_Free(pSuccess); } pData->currentSize = 0; pData->currentTotal += size; // commit to the db synchronously, but using a proxy since it doesn't like being used // elsewhere than from the main thread. // OK, we've copied the actual folder/file over if the folder size is not 0 // (ie, the msg summary is no longer valid) so close the msg database so that // when the folder is reopened the folder db can be reconstructed (which // validates msg summary and forces folder to be reparsed). rv = ProxyForceDBClosed(newFolder); fatalError = NS_FAILED(rv); if (fatalError) { IMPORT_LOG1("*** ImportMailThread: ImportMailbox returned fatalError, mailbox #%d\n", (int) i); pData->fatalError = true; break; } } } } // Now save the new acct info to pref file. nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_SUCCEEDED(rv) && accMgr) { rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); } nsImportGenericMail::SetLogs(success, error, pData->successLog, pData->errorLog); if (pData->abort || pData->fatalError) { IMPORT_LOG0("*** ImportMailThread: Abort or fatalError flag was set\n"); if (pData->ownsDestRoot) { IMPORT_LOG0("Calling destRoot->RecursiveDelete\n"); destRoot->RecursiveDelete(true, nullptr); } else { // FIXME: just delete the stuff we created? } } IMPORT_LOG1("Import mailbox thread done: %d\n", (int) pData->currentTotal); pData->ThreadDelete(); }
void OESettings::SetSmtpServer(char *pSmtpServer, HKEY hKey, nsIMsgIdentity *id, char *pIncomgUserName, PRInt32 authMethodIncoming) { // set the id.smtpserver accordingly // first we have to calculate the smtp user name which is based on sicily if (!hKey || !id || !pIncomgUserName || !pSmtpServer) return; nsCString smtpServerKey, userName; BYTE *pBytes; // smtp user name depends on sicily which may or not exist PRInt32 useSicily = 0; if (pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP Use Sicily")){ useSicily = *(PRInt32 *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); } switch (useSicily) { case 1 : case 3 : // has to go in whether empty or no // shouldn't be empty but better safe than sorry if (pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP User Name")){ userName = (char *)pBytes; // this may be empty; shouldn't be non-existent nsOERegUtil::FreeValueBytes(pBytes); } break; case 2 : userName = pIncomgUserName; break; default : break; // initial userName == "" } nsresult rv; nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv) && smtpService) { nsCOMPtr<nsISmtpServer> foundServer; // don't try to make another server // regardless if username doesn't match rv = smtpService->FindServer(userName.get(), pSmtpServer, getter_AddRefs(foundServer)); if (NS_SUCCEEDED(rv) && foundServer) { // set our account keyed to this smptserver key foundServer->GetKey(getter_Copies(smtpServerKey)); id->SetSmtpServerKey(smtpServerKey); IMPORT_LOG1("SMTP server already exists: %s\n", pSmtpServer); } else { nsCOMPtr<nsISmtpServer> smtpServer; PRInt32 port; rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer)); if (NS_SUCCEEDED(rv) && smtpServer) { pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP Port"); if (pBytes) { smtpServer->SetPort(*(PRInt32 *) pBytes); port = *(PRInt32 *) pBytes; nsOERegUtil::FreeValueBytes(pBytes); } pBytes = nsOERegUtil::GetValueBytes(hKey,"SMTP Secure Connection"); if (pBytes) { if (*(PRInt32 *)pBytes == 1) { // Outlook Express does not support STARTTLS without KB933612 fix. if (IsKB933612Applied() && port != 465) smtpServer->SetSocketType(nsMsgSocketType::alwaysSTARTTLS); else smtpServer->SetSocketType(nsMsgSocketType::SSL); } else { smtpServer->SetSocketType(nsMsgSocketType::plain); } nsOERegUtil::FreeValueBytes(pBytes); } smtpServer->SetUsername(userName); switch (useSicily) { case 1 : smtpServer->SetAuthMethod(nsMsgAuthMethod::secure); break; case 2 : // requires SMTP authentication to use the incoming server settings smtpServer->SetAuthMethod(authMethodIncoming); break; case 3 : smtpServer->SetAuthMethod(nsMsgAuthMethod::passwordCleartext); break; default: smtpServer->SetAuthMethod(nsMsgAuthMethod::none); } smtpServer->SetHostname(nsDependentCString(pSmtpServer)); smtpServer->GetKey(getter_Copies(smtpServerKey)); id->SetSmtpServerKey(smtpServerKey); IMPORT_LOG1("Created new SMTP server: %s\n", pSmtpServer); } } } }
bool OESettings::DoImport(nsIMsgAccount **ppAccount) { HKEY hKey = FindAccountsKey(); if (hKey == nsnull) { IMPORT_LOG0("*** Error finding Outlook Express registry account keys\n"); return false; } nsresult rv; nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create a account manager!\n"); ::RegCloseKey(hKey); return false; } HKEY subKey; nsCString defMailName; // OE has default mail account here when it has been // set up by transfer or has multiple identities // look below for orig code that looked in new OE installs if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Identities", 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default User ID"); ::RegCloseKey(subKey); if (pBytes) { nsCString key("Identities\\"); key += (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); key += "\\Software\\Microsoft\\Internet Account Manager"; if (::RegOpenKeyEx(HKEY_CURRENT_USER, key.get(), 0, KEY_QUERY_VALUE , &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default Mail Account"); ::RegCloseKey(subKey); if (pBytes) { defMailName = (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); } } } } // else it must be here in original install location from orig code if (defMailName.IsEmpty()) { if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Outlook Express", 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default Mail Account"); ::RegCloseKey(subKey); if (pBytes) { defMailName = (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); } } } // else defmailname will be "". No big deal. // 'poll for messages' setting in OE is a global setting // in OE options general tab and in following global OE // registry location. // for all accounts poll interval is a 32 bit value, 0 for // "don't poll", else milliseconds HKEY subSubKey; subKey = Find50Key(); if (!subKey) subKey = Find40Key(); // above key not critical checkNewMailTime = 30; checkNewMail = false; if (subKey){ if (::RegOpenKeyEx(subKey, "Mail", 0, KEY_QUERY_VALUE, &subSubKey) == ERROR_SUCCESS) { ::RegCloseKey(subKey); BYTE * pBytes = nsOERegUtil::GetValueBytes(subSubKey, "Poll For Mail"); ::RegCloseKey(subSubKey); if (pBytes) { if (*(PRInt32 *)pBytes != -1){ checkNewMail = true; checkNewMailTime = *(PRInt32 *)pBytes / 60000; } nsOERegUtil::FreeValueBytes(pBytes); } } } // Iterate the accounts looking for POP3 & IMAP accounts... // Ignore LDAP for now! DWORD index = 0; DWORD numChars; TCHAR keyName[256]; LONG result = ERROR_SUCCESS; BYTE * pBytes; int accounts = 0; nsCString keyComp; while (result == ERROR_SUCCESS) { numChars = 256; result = ::RegEnumKeyEx(hKey, index, keyName, &numChars, NULL, NULL, NULL, NULL); index++; if (result == ERROR_SUCCESS) { if (::RegOpenKeyEx(hKey, keyName, 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { // Get the values for this account. IMPORT_LOG1("Opened Outlook Express account: %s\n", (char *)keyName); nsIMsgAccount *anAccount = nsnull; pBytes = nsOERegUtil::GetValueBytes(subKey, "IMAP Server"); if (pBytes) { if (DoIMAPServer(accMgr, subKey, (char *)pBytes, &anAccount)) accounts++; nsOERegUtil::FreeValueBytes(pBytes); } pBytes = nsOERegUtil::GetValueBytes(subKey, "NNTP Server"); if (pBytes) { if (DoNNTPServer(accMgr, subKey, (char *)pBytes, &anAccount)) accounts++; nsOERegUtil::FreeValueBytes(pBytes); } pBytes = nsOERegUtil::GetValueBytes(subKey, "POP3 Server"); if (pBytes) { if (DoPOP3Server(accMgr, subKey, (char *)pBytes, &anAccount)) { accounts++; } nsOERegUtil::FreeValueBytes(pBytes); } if (anAccount) { // Is this the default account? keyComp = keyName; if (keyComp.Equals(defMailName)) { accMgr->SetDefaultAccount(anAccount); } NS_RELEASE(anAccount); } ::RegCloseKey(subKey); } } } ::RegCloseKey(hKey); // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return accounts != 0; }