PRBool nsMapiHook::VerifyUserName(const nsString& aUsername, nsCString& aIdKey) { nsresult rv; if (aUsername.IsEmpty()) return PR_FALSE; nsCOMPtr<nsIMsgAccountManager> accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv)); if (NS_FAILED(rv)) return PR_FALSE; nsCOMPtr<nsISupportsArray> identities; rv = accountManager->GetAllIdentities(getter_AddRefs(identities)); if (NS_FAILED(rv)) return PR_FALSE; PRUint32 numIndentities; identities->Count(&numIndentities); for (PRUint32 i = 0; i < numIndentities; i++) { // convert supports->Identity nsCOMPtr<nsISupports> thisSupports; rv = identities->GetElementAt(i, getter_AddRefs(thisSupports)); if (NS_FAILED(rv)) continue; nsCOMPtr<nsIMsgIdentity> thisIdentity(do_QueryInterface(thisSupports, &rv)); if (NS_SUCCEEDED(rv) && thisIdentity) { nsCString email; rv = thisIdentity->GetEmail(email); if (NS_FAILED(rv)) continue; // get the username from the email and compare with the username PRInt32 index = email.FindChar('@'); if (index != -1) email.SetLength(index); if (aUsername.Equals(NS_ConvertASCIItoUTF16(email))) return NS_SUCCEEDED(thisIdentity->GetKey(aIdKey)); } } return PR_FALSE; }
NS_IMETHODIMP nsSpamSettings::Initialize(nsIMsgIncomingServer *aServer) { NS_ENSURE_ARG_POINTER(aServer); nsresult rv; PRInt32 spamLevel; rv = aServer->GetIntValue("spamLevel", &spamLevel); NS_ENSURE_SUCCESS(rv, rv); rv = SetLevel(spamLevel); NS_ENSURE_SUCCESS(rv, rv); bool moveOnSpam; rv = aServer->GetBoolValue("moveOnSpam", &moveOnSpam); NS_ENSURE_SUCCESS(rv, rv); rv = SetMoveOnSpam(moveOnSpam); NS_ENSURE_SUCCESS(rv, rv); PRInt32 moveTargetMode; rv = aServer->GetIntValue("moveTargetMode", &moveTargetMode); NS_ENSURE_SUCCESS(rv, rv); rv = SetMoveTargetMode(moveTargetMode); NS_ENSURE_SUCCESS(rv, rv); nsCString spamActionTargetAccount; rv = aServer->GetCharValue("spamActionTargetAccount", spamActionTargetAccount); NS_ENSURE_SUCCESS(rv, rv); rv = SetActionTargetAccount(spamActionTargetAccount.get()); NS_ENSURE_SUCCESS(rv, rv); nsCString spamActionTargetFolder; rv = aServer->GetCharValue("spamActionTargetFolder", spamActionTargetFolder); NS_ENSURE_SUCCESS(rv, rv); rv = SetActionTargetFolder(spamActionTargetFolder.get()); NS_ENSURE_SUCCESS(rv, rv); bool useWhiteList; rv = aServer->GetBoolValue("useWhiteList", &useWhiteList); NS_ENSURE_SUCCESS(rv, rv); rv = SetUseWhiteList(useWhiteList); NS_ENSURE_SUCCESS(rv, rv); nsCString whiteListAbURI; rv = aServer->GetCharValue("whiteListAbURI", whiteListAbURI); NS_ENSURE_SUCCESS(rv, rv); rv = SetWhiteListAbURI(whiteListAbURI.get()); NS_ENSURE_SUCCESS(rv, rv); bool purgeSpam; rv = aServer->GetBoolValue("purgeSpam", &purgeSpam); NS_ENSURE_SUCCESS(rv, rv); rv = SetPurge(purgeSpam); NS_ENSURE_SUCCESS(rv, rv); PRInt32 purgeSpamInterval; rv = aServer->GetIntValue("purgeSpamInterval", &purgeSpamInterval); NS_ENSURE_SUCCESS(rv, rv); rv = SetPurgeInterval(purgeSpamInterval); NS_ENSURE_SUCCESS(rv, rv); bool useServerFilter; rv = aServer->GetBoolValue("useServerFilter", &useServerFilter); NS_ENSURE_SUCCESS(rv, rv); rv = SetUseServerFilter(useServerFilter); NS_ENSURE_SUCCESS(rv, rv); nsCString serverFilterName; rv = aServer->GetCharValue("serverFilterName", serverFilterName); if (NS_SUCCEEDED(rv)) SetServerFilterName(serverFilterName); PRInt32 serverFilterTrustFlags = 0; rv = aServer->GetIntValue("serverFilterTrustFlags", &serverFilterTrustFlags); NS_ENSURE_SUCCESS(rv, rv); rv = SetServerFilterTrustFlags(serverFilterTrustFlags); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (prefBranch) prefBranch->GetCharPref("mail.trusteddomains", getter_Copies(mTrustedMailDomains)); mWhiteListDirArray.Clear(); if (!mWhiteListAbURI.IsEmpty()) { nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsTArray<nsCString> whiteListArray; ParseString(mWhiteListAbURI, ' ', whiteListArray); for (PRUint32 index = 0; index < whiteListArray.Length(); index++) { nsCOMPtr<nsIAbDirectory> directory; rv = abManager->GetDirectory(whiteListArray[index], getter_AddRefs(directory)); NS_ENSURE_SUCCESS(rv, rv); if (directory) mWhiteListDirArray.AppendObject(directory); } } // the next two preferences affect whether we try to whitelist our own // address or domain. Spammers send emails with spoofed from address matching // either the email address of the recipient, or the recipient's domain, // hoping to get whitelisted. // // The terms to describe this get wrapped up in chains of negatives. A full // definition of the boolean inhibitWhiteListingIdentityUser is "Suppress address // book whitelisting if the sender matches an identity's email address" rv = aServer->GetBoolValue("inhibitWhiteListingIdentityUser", &mInhibitWhiteListingIdentityUser); NS_ENSURE_SUCCESS(rv, rv); rv = aServer->GetBoolValue("inhibitWhiteListingIdentityDomain", &mInhibitWhiteListingIdentityDomain); NS_ENSURE_SUCCESS(rv, rv); // collect lists of identity users if needed if (mInhibitWhiteListingIdentityDomain || mInhibitWhiteListingIdentityUser) { nsCOMPtr<nsIMsgAccountManager> accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIMsgAccount> account; rv = accountManager->FindAccountForServer(aServer, getter_AddRefs(account)); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString accountKey; if (account) account->GetKey(accountKey); // Loop through all accounts, adding emails from this account, as well as // from any accounts that defer to this account. mEmails.Clear(); nsCOMPtr<nsISupportsArray> accounts; rv = accountManager->GetAccounts(getter_AddRefs(accounts)); NS_ENSURE_SUCCESS(rv, rv); PRUint32 accountCount = 0; if (account && accounts) // no sense scanning accounts if we've nothing to match accounts->Count(&accountCount); for (PRUint32 i = 0; i < accountCount; i++) { nsCOMPtr<nsIMsgAccount> loopAccount(do_QueryElementAt(accounts, i)); if (!loopAccount) continue; nsCAutoString loopAccountKey; loopAccount->GetKey(loopAccountKey); nsCOMPtr<nsIMsgIncomingServer> loopServer; loopAccount->GetIncomingServer(getter_AddRefs(loopServer)); nsCAutoString deferredToAccountKey; if (loopServer) loopServer->GetCharValue("deferred_to_account", deferredToAccountKey); // Add the emails for any account that defers to this one, or for the // account itself. if (accountKey.Equals(deferredToAccountKey) || accountKey.Equals(loopAccountKey)) { nsCOMPtr<nsISupportsArray> identities; loopAccount->GetIdentities(getter_AddRefs(identities)); if (!identities) continue; PRUint32 identityCount = 0; identities->Count(&identityCount); for (PRUint32 j = 0; j < identityCount; ++j) { nsCOMPtr<nsIMsgIdentity> identity(do_QueryElementAt(identities, j)); if (!identity) continue; nsCAutoString email; identity->GetEmail(email); if (!email.IsEmpty()) mEmails.AppendElement(email); } } } } return UpdateJunkFolderState(); }