Code

extended date syntax to make range searches even more useful
[roundup.git] / roundup / mailgw.py
index c7a8b68f75913961e1619c1391b437b4faa38492..66102ebee56a4ffbaed38b8f50e99b20a0857d19 100644 (file)
@@ -73,15 +73,14 @@ are calling the create() method to create a new node). If an auditor raises
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
-$Id: mailgw.py,v 1.112 2003-03-24 02:51:21 richard Exp $
+$Id: mailgw.py,v 1.116 2003-04-17 06:51:44 richard Exp $
 '''
 
 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
 import time, random, sys
 import traceback, MimeWriter, rfc822
 '''
 
 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
 import time, random, sys
 import traceback, MimeWriter, rfc822
-import hyperdb, date, password
 
 
-import rfc2822
+from roundup import hyperdb, date, password, rfc2822
 
 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
 
 
 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
 
@@ -219,7 +218,7 @@ class MailGW:
     def do_apop(self, server, user='', password=''):
         ''' Do authentication POP
         '''
     def do_apop(self, server, user='', password=''):
         ''' Do authentication POP
         '''
-        self.do_pop(server, user, password, apop=1):
+        self.do_pop(server, user, password, apop=1)
 
     def do_pop(self, server, user='', password='', apop=0):
         '''Read a series of messages from the specified POP server.
 
     def do_pop(self, server, user='', password='', apop=0):
         '''Read a series of messages from the specified POP server.
@@ -807,6 +806,7 @@ not find a text/plain part to use.
         # parse the body of the message, stripping out bits as appropriate
         summary, content = parseContent(content, keep_citations, 
             keep_body)
         # parse the body of the message, stripping out bits as appropriate
         summary, content = parseContent(content, keep_citations, 
             keep_body)
+        content = content.strip()
 
         # 
         # handle the attachments
 
         # 
         # handle the attachments
@@ -1024,8 +1024,26 @@ def uidFromAddress(db, address, create=1, **user_props):
 
     # couldn't match address or username, so create a new user
     if create:
 
     # couldn't match address or username, so create a new user
     if create:
-        return db.user.create(username=address, address=address,
+        # generate a username
+        if '@' in address:
+            username = address.split('@')[0]
+        else:
+            username = address
+        trying = username
+        n = 0
+        while 1:
+            try:
+                # does this username exist already?
+                db.user.lookup(trying)
+            except KeyError:
+                break
+            n += 1
+            trying = username + str(n)
+
+        # create!
+        return db.user.create(username=trying, address=address,
             realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
             realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
+            password=password.Password(password.generatePassword()),
             **user_props)
     else:
         return 0
             **user_props)
     else:
         return 0