diff roundup/mailgw.py @ 1592:4074e2336eed

fixes to unit tests for recent changes
author Richard Jones <richard@users.sourceforge.net>
date Thu, 17 Apr 2003 06:51:44 +0000
parents 21312a7564fd
children f2bdf6b07c2a
line wrap: on
line diff
--- a/roundup/mailgw.py	Thu Apr 17 03:38:00 2003 +0000
+++ b/roundup/mailgw.py	Thu Apr 17 06:51:44 2003 +0000
@@ -73,7 +73,7 @@
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
-$Id: mailgw.py,v 1.115 2003-04-17 03:37:59 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
@@ -1024,7 +1024,24 @@
 
     # 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,
             password=password.Password(password.generatePassword()),
             **user_props)

Roundup Issue Tracker: http://roundup-tracker.org/