[Spambayes-checkins] spambayes pop3proxy.py,1.83,1.84

Richie Hindle richiehindle at users.sourceforge.net
Wed Jul 2 12:42:35 EDT 2003


Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv9471

Modified Files:
	pop3proxy.py 
Log Message:
Fixed a bug whereby long attachments would be broken by the POP3
proxy.

For messages that take a long time to download, the proxy starts 
to forward them after 30 seconds, regardless of whether it's seen the
whole message.  It classifies the message using however much of the
message it's seen so far.  It's done this since the early days, but in the
intervening time someone (whose anonimiTy I MuST hONour hEre)
has changed it to parse the message and then use the stringified
version of the parsed message to forward to the client.  The problem is
that the parser will 'fix' a partial message by appending a closing
boundary separator - this separator can then end up embedded in the
middle of a long attachment.

We still parse the message and add the Spambayes headers to the
parsed message, but we now take just the headers from the parsed
message and add the (possible partial) body ourselves.

This edit simplifies Scott Schlesier's trailing dot fix, because we no
longer need to cope with added boundary separators.


Index: pop3proxy.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/pop3proxy.py,v
retrieving revision 1.83
retrieving revision 1.84
diff -C2 -d -r1.83 -r1.84
*** pop3proxy.py	2 Jul 2003 02:14:31 -0000	1.83
--- pop3proxy.py	2 Jul 2003 18:42:33 -0000	1.84
***************
*** 420,424 ****
          if re.search(r'\n\r?\n', response):
              # Remove the trailing .\r\n before passing to the email parser.
!             if response[-3:] == '.\r\n':
                  response = response[:-3]
  
--- 420,426 ----
          if re.search(r'\n\r?\n', response):
              # Remove the trailing .\r\n before passing to the email parser.
!             # Thanks to Scott Schlesier for this fix.
!             terminatingDotPresent = (response[-4:] == '\n.\r\n')
!             if terminatingDotPresent:
                  response = response[:-3]
  
***************
*** 453,458 ****
                          state.unknownCorpus.addMessage(message)
  
!                 # We'll return the message with the header added.
!                 messageText = msg.as_string()
  
              except:
--- 455,472 ----
                          state.unknownCorpus.addMessage(message)
  
!                 # We'll return the message with the headers added.  We take
!                 # all the headers from the SBHeaderMessage, but take the body
!                 # directly from the POP3 conversation, because the
!                 # SBHeaderMessage might have "fixed" a partial message by
!                 # appending a closing boundary separator.  Remember we can
!                 # be dealing with partial message here because of the timeout
!                 # code in onServerLine.
!                 headers = []
!                 for name, value in msg.items():
!                     enc = Header(value, header_name=name, continuation_ws='\t')
!                     header = "%s: %s" % (name, str(enc))
!                     headers.append(re.sub(r'\r?\n', '\r\n', header))
!                 body = re.split(r'\n\r?\n', messageText, 1)[1]
!                 messageText = "\r\n".join(headers) + "\r\n\r\n" + body
  
              except:
***************
*** 471,492 ****
                                           continuation_ws='\t')
  
!                 # Insert the header, fixing up the fact that email.Header
!                 # splits the lines using \n rather than \r\n (and being
!                 # paranoid about that possibly changing in the future).
                  headers, body = re.split(r'\n\r?\n', messageText, 1)
!                 fixed = str(header).replace('\r\n', '\n').replace('\n', '\r\n')
!                 headers += "\n%s: %s\r\n\r\n" % (headerName, fixed)
                  messageText = headers + body
  
!             # Restore the +OK and the full POP3 \r\n.\r\n terminator.  We
!             # need to make sure the first \r\n is there as well as the
!             # trailing .\r\n because the email parser can fix broken messages
!             # by adding a trailing boundary without a \r\n.  Thanks to Scott
!             # Schlesier for this fix.
              retval = ok + "\n" + messageText
!             if retval[-2:] == '\r\n':
                  retval += '.\r\n'
-             else:
-                 retval += '\r\n.\r\n'
              return retval
  
--- 485,499 ----
                                           continuation_ws='\t')
  
!                 # Insert the header, converting email.Header's '\n' line
!                 # breaks to POP3's '\r\n'.
                  headers, body = re.split(r'\n\r?\n', messageText, 1)
!                 header = re.sub(r'\r?\n', '\r\n', str(header))
!                 headers += "\n%s: %s\r\n\r\n" % (headerName, header)
                  messageText = headers + body
  
!             # Restore the +OK and the POP3 .\r\n terminator if there was one.
              retval = ok + "\n" + messageText
!             if terminatingDotPresent:
                  retval += '.\r\n'
              return retval
  





More information about the Spambayes-checkins mailing list