Index: pykota/trunk/bin/pkusers
===================================================================
--- pykota/trunk/bin/pkusers (revision 2829)
+++ pykota/trunk/bin/pkusers (revision 2937)
@@ -54,5 +54,10 @@
                        
   -d | --delete        Deletes users from the quota storage.
-  
+
+  -e | --email addr    Sets the email address for the users.
+                       If the addr parameter begins with @, then
+                       the username is prepended to addr to form
+                       a valid email address.
+
   -D | --description d Adds a textual description to users or groups.
                        
@@ -154,4 +159,8 @@
   cost of each print job will be multiplied by zero before charging
   his account.
+
+  $ pkusers --email @example.com
+
+  This will set the email address for each user to username@example.com
 """)
         
@@ -165,6 +174,10 @@
             entry.setLimitBy(limitby)
         if not groups :
-            if email :
-                entry.Email = email
+            if email is not None :      # we allow "" to empty the field
+                if email.startswith("@") :
+                    email = "%s%s" % (entry.Name, email)
+                if email and email.count('@') != 1 :
+                    raise PyKotaCommandLineError, _("Invalid email address %s") % email
+                entry.setEmail(email)
             if overcharge is not None : # NB : 0 is allowed !     
                 entry.setOverChargeFactor(overcharge)
@@ -279,9 +292,12 @@
             description = options["description"]
             if description :
-                description = options["description"].strip()
+                description = description.strip()
                 
             comment = options["comment"]
             if comment :
-                comment = options["comment"].strip()
+                comment = comment.strip()
+            email = options["email"]    
+            if email :
+                email = email.strip()
             skipexisting = options["skipexisting"]    
             groups = options["groups"]
@@ -294,12 +310,10 @@
                     percent.setSize(len(names))
                     for ename in names :
-                        email = None
+                        useremail = None
                         if not groups :
                             splitname = ename.split('/', 1)     # username/email
                             if len(splitname) == 1 :
                                 splitname.append("")
-                            (ename, email) = splitname
-                            if email and (email.count('@') != 1) :
-                                raise PyKotaCommandLineError, _("Invalid email address %s") % email
+                            (ename, useremail) = splitname
                         if self.isValidName(ename) :
                             reject = 0
@@ -326,5 +340,5 @@
                                                      description, overcharge,\
                                                      balance, balancevalue, \
-                                                     comment, email)
+                                                     comment, useremail or email)
                                 oldentry = getattr(self.storage, "add%s" % suffix)(entry)
                                 if oldentry is not None :
@@ -340,5 +354,5 @@
                                                      description, overcharge,\
                                                      balance, balancevalue, \
-                                                     comment, email)
+                                                     comment, useremail or email)
                                         oldentry.save()
                                         if not groups :
@@ -359,5 +373,5 @@
                             self.modifyEntry(entry, groups, limitby, description, \
                                              overcharge, balance, balancevalue, \
-                                             comment)
+                                             comment, email)
                             self.manageUsersGroups(usersgroups, entry, remove)                
                         entry.save()    
@@ -378,8 +392,8 @@
                      "comment" : "", \
                    }
-        short_options = "hvaD:dgl:rso:i:b:C:L"
+        short_options = "hvaD:dgl:rso:i:b:C:Le:"
         long_options = ["help", "version", "add", "description=", \
                         "delete", "groups", "list", "remove", \
-                        "skipexisting", "overcharge=", \
+                        "skipexisting", "overcharge=", "email=", \
                         "ingroups=", "limitby=", "balance=", "comment=", \
                        ]
@@ -408,4 +422,5 @@
         options["overcharge"] = options["o"] or options["overcharge"]
         options["comment"] = options["C"] or options["comment"] or defaults["comment"]
+        options["email"] = options["e"] or options["email"]
         
         if options["help"] :
@@ -413,7 +428,7 @@
         elif options["version"] :
             manager.display_version_and_quit()
-        elif (options["delete"] and (options["add"] or options["remove"] or options["description"])) \
+        elif (options["delete"] and (options["add"] or options["remove"] or options["description"] or options["email"])) \
            or (options["skipexisting"] and not options["add"]) \
-           or (options["list"] and (options["add"] or options["delete"] or options["remove"] or options["description"])) \
+           or (options["list"] and (options["add"] or options["delete"] or options["remove"] or options["description"] or options["email"])) \
            or (options["groups"] and (options["balance"] or options["ingroups"] or options["overcharge"])) :
             raise PyKotaCommandLineError, _("incompatible options, see help.")
