asp.net - spamassassin check score C# code -


is there way check score in asp.net application? class or similar .net? how other spam filters out there. --edited looking way check spam score of email messages in c#.

here super simplified "just check score" code connecting running spam assassin email check c# wrote http://elasticemail.com. setup sa run on server , set access permissions.

then can use code call it:

public class simplespamassassin {     public class ruleresult     {         public double score = 0;         public string rule = "";         public string description = "";          public ruleresult() { }         public ruleresult(string line)         {             score = double.parse(line.substring(0, line.indexof(" ")).trim());             line = line.substring(line.indexof(" ") + 1);             rule = line.substring(0, 23).trim();             description = line.substring(23).trim();         }     }     public static list<ruleresult> getreport(string serverip, string message)      {         string command = "report";          stringbuilder sb = new stringbuilder();         sb.appendformat("{0} spamc/1.2\r\n", command);         sb.appendformat("content-length: {0}\r\n\r\n", message.length);         sb.appendformat(message);          byte[] messagebuffer = encoding.ascii.getbytes(sb.tostring());          using (socket spamassassinsocket = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp))         {             spamassassinsocket.connect(serverip, 783);             spamassassinsocket.send(messagebuffer);             spamassassinsocket.shutdown(socketshutdown.send);              int received;             string receivedmessage = string.empty;                         {                 byte[] receivebuffer = new byte[1024];                 received = spamassassinsocket.receive(receivebuffer);                 receivedmessage += encoding.ascii.getstring(receivebuffer, 0, received);             }             while (received > 0);              spamassassinsocket.shutdown(socketshutdown.both);              return parseresponse(receivedmessage);         }      }      private static list<ruleresult> parseresponse(string receivedmessage)     {         //merge line endings         receivedmessage = receivedmessage.replace("\r\n", "\n");         receivedmessage = receivedmessage.replace("\r", "\n");         string[] lines = receivedmessage.split('\n');          list<ruleresult> results = new list<ruleresult>();         bool inreport = false;         foreach (string line in lines)         {             if (inreport)             {                 try                 {                     results.add(new ruleresult(line.trim()));                 }                 catch                 {                     //past end of report                 }             }              if (line.startswith("---"))                 inreport = true;         }          return results;     }  } 

usage quite easy:

list<ruleresult> spamcheckresult = simplespamassassin.getreport(ip of sa server, full email including headers); 

it return list of spam check rules hit , resulting score impact.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -