fix 352184 mark messages from trusted domains as non-junk, sr=mscott
git-svn-id: svn://10.0.0.236/trunk@209894 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
66630cf5f8
commit
a407a883e3
@ -177,47 +177,7 @@ nsresult nsMsgContentPolicy::IsTrustedDomain(nsIURI * aContentLocation, PRBool *
|
||||
aContentLocation->GetHost(host);
|
||||
|
||||
if (!mTrustedMailDomains.IsEmpty())
|
||||
{
|
||||
const char *domain, *domainEnd, *end;
|
||||
PRUint32 hostLen, domainLen;
|
||||
|
||||
domain = mTrustedMailDomains.BeginReading();
|
||||
domainEnd = mTrustedMailDomains.EndReading();
|
||||
nsACString::const_iterator hostStart;
|
||||
|
||||
host.BeginReading(hostStart);
|
||||
hostLen = host.Length();
|
||||
|
||||
do {
|
||||
// skip any whitespace
|
||||
while (*domain == ' ' || *domain == '\t')
|
||||
++domain;
|
||||
|
||||
// find end of this domain in the string
|
||||
end = strchr(domain, ',');
|
||||
if (!end)
|
||||
end = domainEnd;
|
||||
|
||||
// to see if the hostname is in the domain, check if the domain
|
||||
// matches the end of the hostname.
|
||||
domainLen = end - domain;
|
||||
if (domainLen && hostLen >= domainLen) {
|
||||
const char *hostTail = hostStart.get() + hostLen - domainLen;
|
||||
if (PL_strncasecmp(domain, hostTail, domainLen) == 0)
|
||||
{
|
||||
// now, make sure either that the hostname is a direct match or
|
||||
// that the hostname begins with a dot.
|
||||
if (hostLen == domainLen || *hostTail == '.' || *(hostTail - 1) == '.')
|
||||
{
|
||||
*aTrustedDomain = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
domain = end + 1;
|
||||
} while (*end);
|
||||
}
|
||||
*aTrustedDomain = MsgHostDomainIsTrusted(host, mTrustedMailDomains);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1957,12 +1957,21 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgWindow *aMsgWindow, PRBool *aFiltersRun)
|
||||
|
||||
whiteListDirectory = do_QueryInterface(resource, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
headerParser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// if we can't get the db, we probably want to continue firing spam filters.
|
||||
}
|
||||
|
||||
nsXPIDLCString trustedMailDomains;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (prefBranch)
|
||||
prefBranch->GetCharPref("mail.trusteddomains", getter_Copies(trustedMailDomains));
|
||||
|
||||
if (whiteListDirectory || !trustedMailDomains.IsEmpty())
|
||||
{
|
||||
headerParser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// build up list of keys to classify
|
||||
//
|
||||
nsXPIDLCString uri;
|
||||
@ -1977,7 +1986,28 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgWindow *aMsgWindow, PRBool *aFiltersRun)
|
||||
rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(msgHdr));
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
continue;
|
||||
|
||||
nsXPIDLCString author;
|
||||
nsXPIDLCString authorEmailAddress;
|
||||
if (whiteListDirectory || !trustedMailDomains.IsEmpty())
|
||||
{
|
||||
msgHdr->GetAuthor(getter_Copies(author));
|
||||
rv = headerParser->ExtractHeaderAddressMailboxes(nsnull, author.get(), getter_Copies(authorEmailAddress));
|
||||
}
|
||||
|
||||
if (!trustedMailDomains.IsEmpty())
|
||||
{
|
||||
nsCAutoString domain;
|
||||
PRInt32 atPos = authorEmailAddress.FindChar('@');
|
||||
if (atPos >= 0)
|
||||
authorEmailAddress.Right(domain, authorEmailAddress.Length() - atPos - 1);
|
||||
if (!domain.IsEmpty() && MsgHostDomainIsTrusted(domain, trustedMailDomains))
|
||||
{
|
||||
// mark this msg as non-junk, because we whitelisted it.
|
||||
mDatabase->SetStringProperty(msgKey, "junkscore", "0");
|
||||
mDatabase->SetStringProperty(msgKey, "junkscoreorigin", "plugin");
|
||||
continue; // skip this msg since it's in the white list
|
||||
}
|
||||
}
|
||||
msgHdr->GetStringProperty("junkscore", getter_Copies(junkScore));
|
||||
if (!junkScore.IsEmpty()) // ignore already scored messages.
|
||||
continue;
|
||||
@ -1987,12 +2017,8 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgWindow *aMsgWindow, PRBool *aFiltersRun)
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool cardExists = PR_FALSE;
|
||||
nsXPIDLCString author;
|
||||
nsXPIDLCString authorEmailAddress;
|
||||
msgHdr->GetAuthor(getter_Copies(author));
|
||||
rv = headerParser->ExtractHeaderAddressMailboxes(nsnull, author.get(), getter_Copies(authorEmailAddress));
|
||||
// don't want to abort the rest of the scoring.
|
||||
if (NS_SUCCEEDED(rv))
|
||||
if (!authorEmailAddress.IsEmpty())
|
||||
rv = whiteListDirectory->HasCardForEmailAddress(authorEmailAddress, &cardExists);
|
||||
if (NS_SUCCEEDED(rv) && cardExists)
|
||||
{
|
||||
|
||||
@ -1256,3 +1256,47 @@ PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, nsACStrin
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains)
|
||||
{
|
||||
const char *domain, *domainEnd, *end;
|
||||
PRUint32 hostLen, domainLen;
|
||||
PRBool domainIsTrusted = PR_FALSE;
|
||||
|
||||
domain = trustedMailDomains.BeginReading();
|
||||
domainEnd = trustedMailDomains.EndReading();
|
||||
nsACString::const_iterator hostStart;
|
||||
|
||||
host.BeginReading(hostStart);
|
||||
hostLen = host.Length();
|
||||
|
||||
do {
|
||||
// skip any whitespace
|
||||
while (*domain == ' ' || *domain == '\t')
|
||||
++domain;
|
||||
|
||||
// find end of this domain in the string
|
||||
end = strchr(domain, ',');
|
||||
if (!end)
|
||||
end = domainEnd;
|
||||
|
||||
// to see if the hostname is in the domain, check if the domain
|
||||
// matches the end of the hostname.
|
||||
domainLen = end - domain;
|
||||
if (domainLen && hostLen >= domainLen) {
|
||||
const char *hostTail = hostStart.get() + hostLen - domainLen;
|
||||
if (PL_strncasecmp(domain, hostTail, domainLen) == 0)
|
||||
{
|
||||
// now, make sure either that the hostname is a direct match or
|
||||
// that the hostname begins with a dot.
|
||||
if (hostLen == domainLen || *hostTail == '.' || *(hostTail - 1) == '.')
|
||||
{
|
||||
domainIsTrusted = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
domain = end + 1;
|
||||
} while (*end);
|
||||
return domainIsTrusted;
|
||||
}
|
||||
|
||||
@ -164,5 +164,7 @@ NS_MSG_BASE PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keyword
|
||||
nsACString::const_iterator &start,
|
||||
nsACString::const_iterator &end);
|
||||
|
||||
NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user