Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv10998

Modified Files:
      Tag: CORESVR
        XMLRPCPlugin.py 
Log Message:
We scored our first (fake) form submission today.  Yay!


Index: XMLRPCPlugin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Attic/XMLRPCPlugin.py,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -d -r1.1.2.7 -r1.1.2.8
*** XMLRPCPlugin.py     6 Jun 2007 03:37:37 -0000       1.1.2.7
--- XMLRPCPlugin.py     6 Jun 2007 22:24:17 -0000       1.1.2.8
***************
*** 76,83 ****
              raise xmlrpclib.Fault(404, '"%s" is not supported' % method)
  
!     def score(self, form_dict, extra_tokens):
          """Score a dictionary + extra tokens."""
!         mime_message = form_to_mime(form_dict, extra_tokens)
!         return self.score_mime(mime_message)
  
      def score_mime(self, msg_text, encoding):
--- 76,84 ----
              raise xmlrpclib.Fault(404, '"%s" is not supported' % method)
  
!     def score(self, form_dict, extra_tokens, attachments):
          """Score a dictionary + extra tokens."""
!         mime_message = form_to_mime(form_dict, extra_tokens, attachments)
!         mime_message = unicode(mime_message).encode("utf-8")
!         return self.score_mime(mime_message, "utf-8")
  
      def score_mime(self, msg_text, encoding):
***************
*** 100,104 ****
          # XXX Maybe from here on down...
  
!         prob = self.state.bayes.spamprob(tokens, evidence=False)
          self.state.record_classification(msg.GetClassification(), prob)
  
--- 101,107 ----
          # XXX Maybe from here on down...
  
!         prob, clues = self.state.bayes.spamprob(tokens, evidence=True)
!         msg.addSBHeaders(prob, clues)
! 
          self.state.record_classification(msg.GetClassification(), prob)
  
***************
*** 112,140 ****
          return prob
  
! def form_to_mime(form, mime_type, extra_tokens):
      """Encode submission form bits as a MIME message.
  
      form - a dictionary of key/value pairs representing the form's contents
      extra_tokens - a sequence of synthetic tokens generated by the caller.
!     For example, if you include a honeypot hidden field in your form, you
!     might generate a synthetic token which tells if it was filled in or not.
!     You might also generate tokens which indicate how long a submitting
!     username has existed or how many successful posts that username has
!     submitted.
      """
      msg = Message.Message()
      msg.set_type("multipart/digest")
      main = Message.Message()
      main.set_payload(" ".join(["%s:%s" % (k, v) for (k, v) in form.items()]))
      msg.attach(main)
!     for msg_type, content in attachments:
          attachment = Message.Message()
!         attachment.set_type(msg_type)
!         attachment.set_payload(content)
          msg.attach(attachment)
!     if extra_tokens:
!         extra = Message.Message()
!         extra.set_payload(" ".join(extra_tokens))
!         msg.attach(extra)
      return msg
  
--- 115,160 ----
          return prob
  
! def form_to_mime(form, extra_tokens, attachments):
      """Encode submission form bits as a MIME message.
  
      form - a dictionary of key/value pairs representing the form's contents
      extra_tokens - a sequence of synthetic tokens generated by the caller.
!       For example, if you include a honeypot hidden field in your form, you
!       might generate a synthetic token which tells if it was filled in or not.
!       You might also generate tokens which indicate how long a submitting
!       username has existed or how many successful posts that username has
!       submitted.
!     attachments - list of dictionaries describing an attachment.
!       The 'payload' key is required.  If there is no 'content-type' key
!       'application/octet-stream' is assumed.  If 'content-transfer-encoding'
!       is given it will be added to the headers of the attachment.  Note that
!       the keys are case-sensitive and must be lower case.
      """
      msg = Message.Message()
      msg.set_type("multipart/digest")
+     msg.add_header("Subject", "Form submission")
+ 
      main = Message.Message()
      main.set_payload(" ".join(["%s:%s" % (k, v) for (k, v) in form.items()]))
      msg.attach(main)
! 
!     # Always add the extra tokens payload so we can reliably reverse the
!     # conversion.
!     extra = Message.Message()
!     extra.set_type("text/plain")
!     extra.set_payload("\n".join(extra_tokens))
!     msg.attach(extra)
! 
!     # Any further payloads are for the attachments.
!     for content in attachments:
!         mime_type = content.get("content-type") or "application/octet-stream"
          attachment = Message.Message()
!         if "content-transfer-encoding" in content:
!             attachment.add_header("Content-Transfer-Encoding",
!                                   content["content-transfer-encoding"])
!         attachment.set_type(mime_type)
!         attachment.set_payload(content["payload"])
          msg.attach(attachment)
! 
      return msg
  

_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to