Comment Spam and Blacklisting
Eric's “Killing Comment Spam“ post and Luke Hutteman's comment sparked a little adventure for me. Of course, it's not complete or very functional. It's more of a motivation piece to get something started. I might have to jump into the .Text source to see about implementing some sort of plugin. I know .Text (Community Server :: Blogs) is provider based so it might be fairly easy to implement this into the Comment Provider... if there is such a beast. Here's a little bit of test code that grabs the MT-BlackList from the Comment Spam ClearingHouse.
namespace BlackList
{
class Check
{
public static void Main(string[] args)
{
ArrayList expressions = new ArrayList();
expressions = BuildBlackList();
if ( expressions.Count > 0 )
{
foreach (string expression in expressions)
{
try
{
Regex pattern = new Regex(expression,
RegexOptions.Multiline|RegexOptions.IgnoreCase);
if (pattern.IsMatch("01-logo.com"))
Console.WriteLine("Found A Match");
pattern = null;
}
catch {}
}
}
Console.ReadLine();
}
private static ArrayList BuildBlackList()
{
// In reality this file would be local and downloaded once a
// day. Or, if we were in a web environment we could cache it.
// But, hey, its just a demo to spark some thought.
//
string url = "http://www.jayallen.org/comment_spam/blacklist.txt";
ArrayList expressions = new ArrayList();
WebResponse response = null;
try
{
WebRequest request = WebRequest.Create(url);
if (request != null)
{
response = request.GetResponse();
using (StreamReader sr =
new StreamReader(response.GetResponseStream()))
{
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.Substring(0,1) != "#" )
expressions.Add(line);
}
}
}
}
catch(Exception)
{
throw;
}
return expressions;
}
}
}