private NameValueCollection PrepareFormFieldsFrom(SpamCheckContent checkContent) { NameValueCollection formFields = new NameValueCollection { { "blog", _settings.RootUrl } }; if (checkContent.Extra.Count > 0) { foreach (string key in checkContent.Extra) { formFields.Add(key.UrlEncode(), checkContent.Extra[key].UrlEncode()); } } Action <string, string> addIfSpecified = (key, value) => { if (!string.IsNullOrEmpty(value)) { formFields.Add(key.UrlEncode(), value.UrlEncode()); } }; addIfSpecified("user_ip", checkContent.UserIPAddress); addIfSpecified("user_agent", checkContent.UserAgent); addIfSpecified("comment_author", checkContent.UserName); addIfSpecified("comment_content", checkContent.Content); addIfSpecified("referer", checkContent.UrlReferer); addIfSpecified("permalink", checkContent.Url); addIfSpecified("comment_type", checkContent.ContentType); return(formFields); }
public void MarkAsFalsePositive(SpamCheckContent checkContent) { Check.Argument.IsNotNull(checkContent, "checkContent"); EnsureValidApiKey(); _httpForm.PostAsync(_falsePositiveUrl, PrepareFormFieldsFrom(checkContent)); }
public void MarkAsSpam(SpamCheckContent checkContent) { Check.Argument.IsNotNull(checkContent, "checkContent"); EnsureValidApiKey(); _httpForm.PostAsync(new HttpFormPostRequest { Url = _submitUrl, FormFields = PrepareFormFieldsFrom(checkContent) }); }
public override bool IsSpam(SpamCheckContent spamCheckContent) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); bool isSpam = IsComment(spamCheckContent) ? IsSpamComment(spamCheckContent) : IsSpamStory(spamCheckContent); if ((!isSpam) && (NextHandler != null)) { isSpam = NextHandler.IsSpam(spamCheckContent); } return(isSpam); }
public override bool IsSpam(SpamCheckContent spamCheckContent) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); EnsureValidApiKey(); string response = _httpForm.Post(_checkUrl, PrepareFormFieldsFrom(spamCheckContent)); bool isSpam = ToBool(response); // This protection does not think it is spam so forward it to next handler (If there is any) if ((!isSpam) && (NextHandler != null)) { isSpam = NextHandler.IsSpam(spamCheckContent); } return(isSpam); }
public override bool IsSpam(SpamCheckContent spamCheckContent) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); EnsureValidApiKey(); string response = _httpForm.Post(_checkUrl, PrepareFormFields(spamCheckContent)); bool isSpam = IsMatch(response, "spam", "true"); if ((!isSpam) && (NextHandler != null)) { isSpam = NextHandler.IsSpam(spamCheckContent); } return(isSpam); }
private bool IsSpamStory(SpamCheckContent spamCheckContent) { //First run it over the story description int total = CalculateTotal(spamCheckContent.Content, _storyLocalCalculators); //If it is small then run it over story url if (total <= _storyThreshold) { string response = _httpForm.Get(spamCheckContent.Url); if (!string.IsNullOrEmpty(response)) { total += CalculateTotal(response, _storyRemoteCalculators); } } return(total > _storyThreshold); }
public override void IsSpam(SpamCheckContent spamCheckContent, Action <string, bool> callback) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); Check.Argument.IsNotNull(callback, "callback"); EnsureValidApiKey(); _httpForm.PostAsync( new HttpFormPostRequest { Url = _checkUrl, FormFields = PrepareFormFieldsFrom(spamCheckContent), }, httpResponse => { bool isSpam = ToBool(httpResponse.Response); // This protection does not think it is spam so forward it to next handler (If there is any) if ((!isSpam) && (NextHandler != null)) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(_name, isSpam); } }, e => { // When exception occurs try next handler if (NextHandler != null) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(_name, false); } }); }
private NameValueCollection PrepareFormFields(SpamCheckContent spamCheckContent) { NameValueCollection formFields = new NameValueCollection(); Action <string, string> addIfSpecified = (key, value) => { if (!string.IsNullOrEmpty(value)) { formFields.Add(key, value); } }; addIfSpecified("owner-url", _settings.RootUrl); addIfSpecified("user-ip", spamCheckContent.UserIPAddress); addIfSpecified("article-date", SystemTime.Now().ToString("yyyy/MM/dd", Constants.CurrentCulture)); addIfSpecified("comment-author", spamCheckContent.UserName); addIfSpecified("comment-type", (string.Compare(spamCheckContent.ContentType, "comment", StringComparison.OrdinalIgnoreCase) == 0) ? "comment" : "other"); addIfSpecified("comment-spamCheckContent", spamCheckContent.Content); addIfSpecified("permalink", spamCheckContent.Url); addIfSpecified("referrer", spamCheckContent.UrlReferer); return(formFields); }
public override void IsSpam(SpamCheckContent spamCheckContent, Action <string, bool> callback) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); Check.Argument.IsNotNull(callback, "callback"); EnsureValidApiKey(); _httpForm.PostAsync( _checkUrl, PrepareFormFields(spamCheckContent), response => { bool isSpam = IsMatch(response, "spam", "true"); // Defensio does not think it is spam so forward it to next handler (If there is any) if ((!isSpam) && (NextHandler != null)) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(Source, isSpam); } }, e => { // When exception occurs try next handler if (NextHandler != null) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(Source, false); } }); }
public override void IsSpam(SpamCheckContent spamCheckContent, Action <string, bool> callback) { Check.Argument.IsNotNull(spamCheckContent, "spamCheckContent"); Check.Argument.IsNotNull(callback, "callback"); if (IsComment(spamCheckContent)) { if (IsSpamComment(spamCheckContent)) { callback(Source, true); } else if (NextHandler != null) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(Source, false); } } else { //First run it over the story description int total = CalculateTotal(spamCheckContent.Content, _storyLocalCalculators); if (total > _storyThreshold) { callback(Source, true); } else { _httpForm.GetAsync( new HttpFormGetRequest { Url = spamCheckContent.Url }, httpResponse => { if (!string.IsNullOrEmpty(httpResponse.Response)) { total += CalculateTotal(httpResponse.Response, _storyRemoteCalculators); } if (total > _storyThreshold) { callback(Source, true); } else if (NextHandler != null) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(Source, false); } }, e => { // When exception occurs try next handler if (NextHandler != null) { NextHandler.IsSpam(spamCheckContent, callback); } else { callback(Source, false); } } ); } } }
private bool IsComment(SpamCheckContent conent) { return(conent.Url.StartsWith(_settings.RootUrl, StringComparison.OrdinalIgnoreCase)); }
private bool IsSpamComment(SpamCheckContent spamCheckContent) { int total = CalculateTotal(spamCheckContent.Content, _commentCalculators); return(total > _commentThreshold); }
public abstract void IsSpam(SpamCheckContent spamCheckContent, Action <string, bool> callback);
public abstract bool IsSpam(SpamCheckContent spamCheckContent);