/// <summary> /// Checks with AKISMET. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="postMessage">The post message.</param> /// <param name="ipAddress">The IP Address.</param> /// <param name="result">The result.</param> /// <returns> /// Returns if the Content or the User was flagged as Spam, or not /// </returns> private static bool CheckWithAkismet( [NotNull] string userName, [NotNull] string postMessage, [NotNull] string ipAddress, out string result) { try { var service = new AkismetSpamClient(BoardContext.Current.Get <BoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); return (service.CheckCommentForSpam( new Comment(IPAddress.Parse(ipAddress), BoardContext.Current.Get <HttpRequestBase>().UserAgent) { Content = postMessage, Author = userName, }, out result)); } catch (Exception ex) { BoardContext.Current.Get <ILogger>().Error(ex, "Error while Checking for Spam via BlogSpam"); result = string.Empty; return(false); } }
/// <summary> /// Report Message as Spam /// </summary> /// <param name="comment"> /// The comment. /// </param> private void ReportSpam(string comment) { if (this.Get <YafBoardSettings>().SpamServiceType.Equals(1)) { string message = BlogSpamNet.ClassifyComment(comment, true); this.PageContext.AddLoadMessage(message); } try { if (this.Get <YafBoardSettings>().SpamServiceType.Equals(2) && !string.IsNullOrEmpty(this.Get <YafBoardSettings>().AkismetApiKey)) { var service = new AkismetSpamClient(this.Get <YafBoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); service.SubmitSpam(new Comment(null, string.Empty) { Content = comment }); this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED")); } } catch (Exception) { this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED_FAILED")); } }
/// <summary> /// Report Message as Spam /// </summary> /// <param name="comment"> /// The comment. /// </param> private void ReportSpam(string comment) { if (this.Get <YafBoardSettings>().SpamServiceType.Equals(1)) { string message = BlogSpamNet.ClassifyComment(comment, true); this.PageContext.AddLoadMessage(message); } try { if (!this.Get <YafBoardSettings>().SpamServiceType.Equals(2) || string.IsNullOrEmpty(this.Get <YafBoardSettings>().AkismetApiKey)) { return; } var service = new AkismetSpamClient(this.Get <YafBoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); service.SubmitSpam(new Comment(null, string.Empty) { Content = comment }); this.Logger.Log( this.PageContext.PageUserID, "Spam Message Reported", "Message '{0}' was Reported to Akismet.com by {1}".FormatWith( comment, this.Get <YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName), EventLogTypes.SpamMessageReported); this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED")); } catch (Exception) { this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED_FAILED")); } }
/// <summary> /// Report Message as Spam /// </summary> /// <param name="comment"> /// The comment. /// </param> private void ReportSpam(string comment) { if (this.Get<YafBoardSettings>().SpamServiceType.Equals(1)) { string message = BlogSpamNet.ClassifyComment(comment, true); this.PageContext.AddLoadMessage(message); } try { if (!this.Get<YafBoardSettings>().SpamServiceType.Equals(2) || string.IsNullOrEmpty(this.Get<YafBoardSettings>().AkismetApiKey)) { return; } var service = new AkismetSpamClient(this.Get<YafBoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); service.SubmitSpam(new Comment(null, string.Empty) { Content = comment }); this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED")); } catch (Exception) { this.PageContext.AddLoadMessage(this.GetText("MODERATE_DEFAULT", "SPAM_REPORTED_FAILED")); } }
/// <summary> /// Checks with AKISMET. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="postMessage">The post message.</param> /// <param name="ipAddress">The IP Address.</param> /// <param name="result">The result.</param> /// <returns> /// Returns if the Content or the User was flagged as Spam, or not /// </returns> private bool CheckWithAkismet( [NotNull] string userName, [NotNull] string postMessage, [NotNull] string ipAddress, out string result) { try { var service = new AkismetSpamClient(YafContext.Current.Get<YafBoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); return service.CheckCommentForSpam( new Comment(IPAddress.Parse(ipAddress), YafContext.Current.Get<HttpRequestBase>().UserAgent) { Content = postMessage, Author = userName, }, out result); } catch (Exception ex) { YafContext.Current.Get<ILogger>().Error(ex, "Error while Checking for Spam via BlogSpam"); result = string.Empty; return false; } }
public void Akismet_Spam_Client_Verify_Key_Test() { var service = new AkismetSpamClient("XXXX", new Uri("http://www.google.com")); Assert.AreEqual(false, service.VerifyApiKey(), "The Verify of the API Key should be false"); }
/// <summary> /// Check a Post for SPAM against the BlogSpam.NET API or Akismet Service /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="postSubject">The post subject.</param> /// <param name="postMessage">The post message.</param> /// <returns> /// Returns if Post is SPAM or not /// </returns> public static bool IsPostSpam([NotNull]string userName, [NotNull]string postSubject, [NotNull]string postMessage) { if (YafContext.Current.Get<YafBoardSettings>().SpamServiceType.Equals(0)) { return false; } string ipAdress = YafContext.Current.Get<HttpRequestBase>().GetUserRealIPAddress(); if (ipAdress.Equals("::1")) { ipAdress = "127.0.0.1"; } string whiteList = string.Empty; if (ipAdress.Equals("127.0.0.1")) { whiteList = "whitelist=127.0.0.1"; } // Use BlogSpam.NET API if (YafContext.Current.Get<YafBoardSettings>().SpamServiceType.Equals(1)) { try { return BlogSpamNet.CommentIsSpam( new BlogSpamComment { comment = postMessage, ip = ipAdress, agent = YafContext.Current.Get<HttpRequestBase>().UserAgent, name = userName, options = whiteList, }, true); } catch (Exception) { return false; } } // Use Akismet API if (YafContext.Current.Get<YafBoardSettings>().SpamServiceType.Equals(2) && !string.IsNullOrEmpty(YafContext.Current.Get<YafBoardSettings>().AkismetApiKey)) { try { var service = new AkismetSpamClient(YafContext.Current.Get<YafBoardSettings>().AkismetApiKey, new Uri(BaseUrlBuilder.BaseUrl)); return service.CheckCommentForSpam( new Comment(IPAddress.Parse(ipAdress), YafContext.Current.Get<HttpRequestBase>().UserAgent) { Content = postMessage, Author = userName, }); } catch (Exception) { return false; } } return false; }
public void Akismet_Spam_Client_Verify_Key_Test() { var service = new AkismetSpamClient("XXXX", new Uri("http://www.google.com")); Assert.AreEqual(false, service.VerifyApiKey(), "The Verify of the API Key should be false"); }