# HG changeset patch # User Pascal Volk # Date 1219697154 0 # Node ID 995d538a6eb50113192949d11e5c552bf0303150 # Parent 5506433db9a3dcc9b247476650021ad9c7240064 * 'VirtualMailManager/Account.py' - Implemented Account.__aliaseCount() - Modified Account.delete() so that aliases (with an identical destination address) will be no longer deleted implicitly. * 'VirtualMailManager/VirtualMailManager.py: userDelete()' * 'vmm: user_delete()/usage()' - Added new parameter 'delalias' * 'man/de/man1/vmm.1' * 'man/man1/vmm.1' - updated * 'po/de.po' * 'po/vmm.pot' - updated diff -r 5506433db9a3 -r 995d538a6eb5 VirtualMailManager/Account.py --- a/VirtualMailManager/Account.py Mon Aug 25 14:49:43 2008 +0000 +++ b/VirtualMailManager/Account.py Mon Aug 25 20:45:54 2008 +0000 @@ -109,6 +109,15 @@ self._dbh.commit() dbc.close() + def __aliaseCount(self): + dbc = self._dbh.cursor() + q = "SELECT COUNT(destination) FROM alias WHERE destination = '%s'"\ + %self._addr + dbc.execute(q) + a_count = dbc.fetchone()[0] + dbc.close() + return a_count + def setPassword(self, password): self._passwd = password @@ -193,9 +202,12 @@ tid=info['transport']).getTransport() return info - def delete(self): - if self._uid > 0: - dbc = self._dbh.cursor() + def delete(self, delalias): + if self._uid < 1: + raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, + ERR.NO_SUCH_ACCOUNT) + dbc = self._dbh.cursor() + if delalias == 'delalias': dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", self._gid, self._localpart) u_rc = dbc.rowcount @@ -204,11 +216,19 @@ dbc.execute("DELETE FROM alias WHERE destination = %s", self._addr) if u_rc > 0 or dbc.rowcount > 0: self._dbh.commit() - dbc.close() - else: - raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, - ERR.NO_SUCH_ACCOUNT) - + else: # check first for aliases + a_count = self.__aliaseCount() + if a_count == 0: + dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", + self._gid, self._localpart) + if dbc.rowcount > 0: + self._dbh.commit() + else: + dbc.close() + raise AccE( + _(u"There are %(count)d aliases with the destination address\ + »%(address)s«.") %{'count': a_count, 'address': self._addr}, ERR.ALIAS_PRESENT) + dbc.close() def getAccountByID(uid, dbh): try: diff -r 5506433db9a3 -r 995d538a6eb5 VirtualMailManager/VirtualMailManager.py --- a/VirtualMailManager/VirtualMailManager.py Mon Aug 25 14:49:43 2008 +0000 +++ b/VirtualMailManager/VirtualMailManager.py Mon Aug 25 20:45:54 2008 +0000 @@ -571,11 +571,14 @@ alias = self.__getAlias(aliasaddress, targetaddress) alias.save() - def userDelete(self, emailaddress): + def userDelete(self, emailaddress, force=None): + if force not in [None, 'delalias']: + raise VMMException(_(u"Invalid argument: »%s«") % force, + ERR.INVALID_AGUMENT) acc = self.__getAccount(emailaddress) uid = acc.getUID() gid = acc.getGID() - acc.delete() + acc.delete(force) if self.__Cfg.getboolean('maildir', 'delete'): try: self.__userDirDelete(acc.getDir('domain'), uid, gid) diff -r 5506433db9a3 -r 995d538a6eb5 man/de/man1/vmm.1 --- a/man/de/man1/vmm.1 Mon Aug 25 14:49:43 2008 +0000 +++ b/man/de/man1/vmm.1 Mon Aug 25 20:45:54 2008 +0000 @@ -1,5 +1,5 @@ .\" $Id$ -.TH "VMM" "1" "24. Aug 2008" "Pascal Volk" +.TH "VMM" "1" "25. Aug 2008" "Pascal Volk" .SH NAME vmm \- Programm für die Kommandozeile, um E-Mail-Domains, -Konten und -Aliase zu verwalten. @@ -307,6 +307,7 @@ \fBvmm u0 b.user@example.com imap\fP \fBvmm userdisable c.user@example.com\fP .fi +.PP .TP \fBuserenable\fP (\fBu1\fP) \fIAdresse\fP [ \fIService\fP ] Um den Zugriff auf bestimmte oder alle gesperrten Service zu gewähren, wird @@ -317,10 +318,16 @@ für das Konto mit der angegebenen \fIAdresse\fP aktiviert. .br Andernfalls wird nur der Zugriff auf den angegeben \fIService\fP gestattet. +.PP .TP -\fBuserdelete\fP (\fBud\fP) \fIAdresse\fP +\fBuserdelete\fP (\fBud\fP) \fIAdresse\fP [ \fIdelalias\fP ] Verwenden Sie diesen Unterbefehl um, das Konto mit der angegebenen \fIAdresse\fP zu löschen. +.br +Sollte es einen oder mehrere Aliase geben, deren Zieladresse mit der des Kontos +identisch ist, wird \fBvmm\fP die Ausführung des Befehls mit einer +entsprechenden Fehlermeldung beenden. Um dieses zu umgehen, kann das optionale +Schlüsselwort '\fIdelalias\fP' angegebenen werden. .\" .SS ALIAS UNTERBEFEHLE .TP @@ -352,8 +359,8 @@ \fBaliasdelete\fP (\fBad\fP) \fIAlias\fP [ \fIZiel\fP ] Verwenden Sie diesen Unterbefehl um den angegebenen \fIAlias\fP zu löschen. .br -Wurde die optionale Ziel-Adresse \fIZiel\fP angegeben, so wird nur diese -Ziel-Adresse vom angegebenen \fIAlias\fP entfernt. +Wurde die optionale Zieladresse \fIZiel\fP angegeben, so wird nur diese +Zieladresse vom angegebenen \fIAlias\fP entfernt. .PP .nf Beispiel: diff -r 5506433db9a3 -r 995d538a6eb5 man/man1/vmm.1 --- a/man/man1/vmm.1 Mon Aug 25 14:49:43 2008 +0000 +++ b/man/man1/vmm.1 Mon Aug 25 20:45:54 2008 +0000 @@ -1,5 +1,5 @@ .\" $Id$ -.TH "VMM" "1" "24. Aug 2008" "Pascal Volk" +.TH "VMM" "1" "25. Aug 2008" "Pascal Volk" .SH NAME vmm \- command line tool to manage email domains/accounts/aliases .SH SYNOPSIS @@ -289,16 +289,21 @@ \fBvmm userdisable c.user@example.com\fP .fi .TP -\fBuserenable\fP (\fBu1\fP) \fIaddress\fP [ \fIservicel\fP ] +\fBuserenable\fP (\fBu1\fP) \fIaddress\fP [ \fIservice\fP ] To allow access to one or all restricted services use this subcommand. .br If neither a \fIservice\fP nor the keyword '\fIall\fP' is given all services (\fIsmtp\fP, \fIpop3\fP, \fIimap\fP, and \fImanagesieve\fP) will be enabled for the account with the specified \fIaddress\fP. Otherwise only the specified \fIservice\fP will be enabled. +.PP .TP -\fBuserdelete\fP (\fBud\fP) \fIaddress\fP +\fBuserdelete\fP (\fBud\fP) \fIaddress\fP [ \fIdelalias\fP ] Use this subcommand to delete the account with the given \fIaddress\fP. +.br +If there are one or more aliases with an identical destination address, +\fBvmm\fP will abort the requested operation and show an error message. To +prevent this, specify the optional keyword '\fIdelalias\fP'. .\" .SS ALIAS SUBCOMMANDS .TP diff -r 5506433db9a3 -r 995d538a6eb5 po/de.po --- a/po/de.po Mon Aug 25 14:49:43 2008 +0000 +++ b/po/de.po Mon Aug 25 20:45:54 2008 +0000 @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: vmm 0.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-08-24 04:32+0200\n" -"PO-Revision-Date: 2008-08-24 04:42+0200\n" +"POT-Creation-Date: 2008-08-25 20:03+0200\n" +"PO-Revision-Date: 2008-08-25 22:31+0200\n" "Last-Translator: Pascal Volk \n" "Language-Team: German\n" "MIME-Version: 1.0\n" @@ -32,34 +32,39 @@ msgid "Unknown service »%s«." msgstr "Unbekannter Service »%s«." -#: VirtualMailManager/Account.py:93 VirtualMailManager/Account.py:150 -#: VirtualMailManager/Account.py:177 VirtualMailManager/Account.py:205 +#: VirtualMailManager/Account.py:93 VirtualMailManager/Account.py:157 +#: VirtualMailManager/Account.py:184 VirtualMailManager/Account.py:205 #, python-format msgid "The account »%s« doesn't exists." msgstr "Der Account »%s« existiert nicht." -#: VirtualMailManager/Account.py:145 +#: VirtualMailManager/Account.py:152 #, python-format msgid "The account »%s« already exists." msgstr "Der Account »%s« existiert bereits." -#: VirtualMailManager/Account.py:185 +#: VirtualMailManager/Account.py:192 msgid "enabled" msgstr "aktiviert" -#: VirtualMailManager/Account.py:187 +#: VirtualMailManager/Account.py:194 msgid "disabled" msgstr "deaktiviert" -#: VirtualMailManager/Account.py:213 +#: VirtualMailManager/Account.py:228 +#, python-format +msgid "There are %(count)d aliases with the destination address »%(address)s«." +msgstr "Es gibt %(count)d Alias(e) mit der Zieladresse »%(address)s«." + +#: VirtualMailManager/Account.py:236 msgid "uid must be an int/long." msgstr "Die UID muss eine Ganzzahl sein." -#: VirtualMailManager/Account.py:215 +#: VirtualMailManager/Account.py:238 msgid "uid must be greater than 0." msgstr "Die UID muss größer als 0 sein." -#: VirtualMailManager/Account.py:223 +#: VirtualMailManager/Account.py:246 #, python-format msgid "There is no account with the UID »%d«." msgstr "Es existiert kein Account mit der UID »%d«." @@ -327,6 +332,7 @@ #: VirtualMailManager/VirtualMailManager.py:466 #: VirtualMailManager/VirtualMailManager.py:485 +#: VirtualMailManager/VirtualMailManager.py:576 #, python-format msgid "Invalid argument: »%s«" msgstr "Ungültiges Argument: »%s«" @@ -346,7 +352,7 @@ msgid "The pattern »%s« contains invalid characters." msgstr "Das Muster »%s« enthält ungültige Zeichen." -#: VirtualMailManager/VirtualMailManager.py:585 +#: VirtualMailManager/VirtualMailManager.py:588 #, python-format msgid "" "The account has been successfully deleted from the database.\n" @@ -359,7 +365,7 @@ " »%(directory)s«\n" " Grund: %(raeson)s" -#: VirtualMailManager/VirtualMailManager.py:617 +#: VirtualMailManager/VirtualMailManager.py:620 msgid "Account doesn't exists" msgstr "Der Account existiert nicht" @@ -374,48 +380,48 @@ " kurz lang\n" " Unterbefehl Objekt args (* = optional)\n" -#: vmm:76 vmm:87 vmm:431 +#: vmm:75 vmm:86 vmm:432 msgid "Error" msgstr "Fehler" -#: vmm:109 +#: vmm:108 msgid "information" msgstr "Informationen" -#: vmm:119 +#: vmm:118 msgid "Available" msgstr "Verfügbare" -#: vmm:122 vmm:215 vmm:219 +#: vmm:121 vmm:214 vmm:218 msgid "alias domains" msgstr "Alias-Domains" -#: vmm:132 vmm:143 vmm:161 +#: vmm:131 vmm:142 vmm:160 msgid "\tNone" msgstr "\tKeine" -#: vmm:136 +#: vmm:135 msgid "Alias information" msgstr "Alias Informationen" -#: vmm:138 +#: vmm:137 #, python-format msgid "\tMail for %s will be redirected to:" msgstr "\tE-Mails für %s werden weitergeleitet an:" -#: vmm:156 +#: vmm:155 msgid "Available domains" msgstr "Verfügbare Domains" -#: vmm:158 +#: vmm:157 msgid "Matching domains" msgstr "Übereinstimmende Domains" -#: vmm:172 +#: vmm:171 msgid "Alias domain information" msgstr "Alias-Domain Informationen" -#: vmm:178 +#: vmm:177 #, python-format msgid "" "\tThe alias domain %(alias)s belongs to:\n" @@ -424,94 +430,94 @@ "\tDie Alias-Domain %(alias)s gehört zu:\n" "\t * %(domain)s" -#: vmm:189 vmm:197 vmm:205 +#: vmm:188 vmm:196 vmm:204 msgid "Missing domain name." msgstr "Kein Domain-Name angegeben." -#: vmm:207 vmm:211 +#: vmm:206 vmm:210 msgid "Domain" msgstr "Domain" -#: vmm:213 vmm:220 +#: vmm:212 vmm:219 msgid "accounts" msgstr "Accounts" -#: vmm:217 vmm:221 +#: vmm:216 vmm:220 msgid "aliases" msgstr "Aliase" -#: vmm:225 +#: vmm:224 msgid "Missing domain name and new transport." msgstr "Domain-Name und neuer Transport fehlen." -#: vmm:227 +#: vmm:226 msgid "Missing new transport." msgstr "Neuer Transport fehlt." -#: vmm:236 +#: vmm:235 msgid "Missing alias domain name and target domain name." msgstr "Domain-Namen für Alias- und Ziel-Domain fehlen." -#: vmm:238 +#: vmm:237 msgid "Missing target domain name." msgstr "Keine Ziel-Domain angegeben." -#: vmm:244 vmm:250 +#: vmm:243 vmm:249 msgid "Missing alias domain name." msgstr "Keine Alias-Domain angegeben." -#: vmm:256 vmm:265 vmm:271 vmm:295 vmm:303 vmm:311 +#: vmm:255 vmm:264 vmm:272 vmm:296 vmm:304 vmm:312 msgid "Missing e-mail address." msgstr "E-Mail-Adresse fehlt." -#: vmm:279 +#: vmm:280 msgid "Missing e-mail address and users name." msgstr "E-Mail-Adresse und der Name des Benutzers fehlen." -#: vmm:281 +#: vmm:282 msgid "Missing users name." msgstr "Name des Benutzers fehlt." -#: vmm:287 +#: vmm:288 msgid "Missing e-mail address and transport." msgstr "E-Mail-Adresse und Transport fehlen." -#: vmm:289 +#: vmm:290 msgid "Missing transport." msgstr "Transport fehlt." -#: vmm:320 +#: vmm:321 msgid "Missing alias address and destination." msgstr "Alias- und Ziel-Adresse fehlen." -#: vmm:326 vmm:332 +#: vmm:327 vmm:333 msgid "Missing alias address" msgstr "Alias-Adresse fehlt." -#: vmm:340 +#: vmm:341 msgid "Missing userid" msgstr "Keine UID angegeben." -#: vmm:353 +#: vmm:354 msgid "Warnings:" msgstr "Warnungen:" -#: vmm:358 +#: vmm:359 msgid "version" msgstr "Version" -#: vmm:359 +#: vmm:360 msgid "from" msgstr "vom" -#: vmm:361 +#: vmm:362 msgid "on" msgstr "auf" -#: vmm:426 +#: vmm:427 msgid "Unknown subcommand" msgstr "Unbekannter Unterbefehl" -#: vmm:429 +#: vmm:430 msgid "Ouch" msgstr "Autsch" diff -r 5506433db9a3 -r 995d538a6eb5 po/vmm.pot --- a/po/vmm.pot Mon Aug 25 14:49:43 2008 +0000 +++ b/po/vmm.pot Mon Aug 25 20:45:54 2008 +0000 @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: vmm 0.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-08-24 04:32+0200\n" +"POT-Creation-Date: 2008-08-25 20:03+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -33,34 +33,39 @@ msgid "Unknown service »%s«." msgstr "" -#: VirtualMailManager/Account.py:93 VirtualMailManager/Account.py:150 -#: VirtualMailManager/Account.py:177 VirtualMailManager/Account.py:205 +#: VirtualMailManager/Account.py:93 VirtualMailManager/Account.py:157 +#: VirtualMailManager/Account.py:184 VirtualMailManager/Account.py:205 #, python-format msgid "The account »%s« doesn't exists." msgstr "" -#: VirtualMailManager/Account.py:145 +#: VirtualMailManager/Account.py:152 #, python-format msgid "The account »%s« already exists." msgstr "" -#: VirtualMailManager/Account.py:185 +#: VirtualMailManager/Account.py:192 msgid "enabled" msgstr "" -#: VirtualMailManager/Account.py:187 +#: VirtualMailManager/Account.py:194 msgid "disabled" msgstr "" -#: VirtualMailManager/Account.py:213 +#: VirtualMailManager/Account.py:228 +#, python-format +msgid "There are %(count)d aliases with the destination address »%(address)s«." +msgstr "" + +#: VirtualMailManager/Account.py:236 msgid "uid must be an int/long." msgstr "" -#: VirtualMailManager/Account.py:215 +#: VirtualMailManager/Account.py:238 msgid "uid must be greater than 0." msgstr "" -#: VirtualMailManager/Account.py:223 +#: VirtualMailManager/Account.py:246 #, python-format msgid "There is no account with the UID »%d«." msgstr "" @@ -316,6 +321,7 @@ #: VirtualMailManager/VirtualMailManager.py:466 #: VirtualMailManager/VirtualMailManager.py:485 +#: VirtualMailManager/VirtualMailManager.py:576 #, python-format msgid "Invalid argument: »%s«" msgstr "" @@ -332,7 +338,7 @@ msgid "The pattern »%s« contains invalid characters." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:585 +#: VirtualMailManager/VirtualMailManager.py:588 #, python-format msgid "" "The account has been successfully deleted from the database.\n" @@ -341,7 +347,7 @@ " Reason: %(raeson)s" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:617 +#: VirtualMailManager/VirtualMailManager.py:620 msgid "Account doesn't exists" msgstr "" @@ -353,142 +359,142 @@ " subcommand object args (* = optional)\n" msgstr "" -#: vmm:76 vmm:87 vmm:431 +#: vmm:75 vmm:86 vmm:432 msgid "Error" msgstr "" -#: vmm:109 +#: vmm:108 msgid "information" msgstr "" -#: vmm:119 +#: vmm:118 msgid "Available" msgstr "" -#: vmm:122 vmm:215 vmm:219 +#: vmm:121 vmm:214 vmm:218 msgid "alias domains" msgstr "" -#: vmm:132 vmm:143 vmm:161 +#: vmm:131 vmm:142 vmm:160 msgid "\tNone" msgstr "" -#: vmm:136 +#: vmm:135 msgid "Alias information" msgstr "" -#: vmm:138 +#: vmm:137 #, python-format msgid "\tMail for %s will be redirected to:" msgstr "" -#: vmm:156 +#: vmm:155 msgid "Available domains" msgstr "" -#: vmm:158 +#: vmm:157 msgid "Matching domains" msgstr "" -#: vmm:172 +#: vmm:171 msgid "Alias domain information" msgstr "" -#: vmm:178 +#: vmm:177 #, python-format msgid "" "\tThe alias domain %(alias)s belongs to:\n" "\t * %(domain)s" msgstr "" -#: vmm:189 vmm:197 vmm:205 +#: vmm:188 vmm:196 vmm:204 msgid "Missing domain name." msgstr "" -#: vmm:207 vmm:211 +#: vmm:206 vmm:210 msgid "Domain" msgstr "" -#: vmm:213 vmm:220 +#: vmm:212 vmm:219 msgid "accounts" msgstr "" -#: vmm:217 vmm:221 +#: vmm:216 vmm:220 msgid "aliases" msgstr "" -#: vmm:225 +#: vmm:224 msgid "Missing domain name and new transport." msgstr "" -#: vmm:227 +#: vmm:226 msgid "Missing new transport." msgstr "" -#: vmm:236 +#: vmm:235 msgid "Missing alias domain name and target domain name." msgstr "" -#: vmm:238 +#: vmm:237 msgid "Missing target domain name." msgstr "" -#: vmm:244 vmm:250 +#: vmm:243 vmm:249 msgid "Missing alias domain name." msgstr "" -#: vmm:256 vmm:265 vmm:271 vmm:295 vmm:303 vmm:311 +#: vmm:255 vmm:264 vmm:272 vmm:296 vmm:304 vmm:312 msgid "Missing e-mail address." msgstr "" -#: vmm:279 +#: vmm:280 msgid "Missing e-mail address and users name." msgstr "" -#: vmm:281 +#: vmm:282 msgid "Missing users name." msgstr "" -#: vmm:287 +#: vmm:288 msgid "Missing e-mail address and transport." msgstr "" -#: vmm:289 +#: vmm:290 msgid "Missing transport." msgstr "" -#: vmm:320 +#: vmm:321 msgid "Missing alias address and destination." msgstr "" -#: vmm:326 vmm:332 +#: vmm:327 vmm:333 msgid "Missing alias address" msgstr "" -#: vmm:340 +#: vmm:341 msgid "Missing userid" msgstr "" -#: vmm:353 +#: vmm:354 msgid "Warnings:" msgstr "" -#: vmm:358 +#: vmm:359 msgid "version" msgstr "" -#: vmm:359 +#: vmm:360 msgid "from" msgstr "" -#: vmm:361 +#: vmm:362 msgid "on" msgstr "" -#: vmm:426 +#: vmm:427 msgid "Unknown subcommand" msgstr "" -#: vmm:429 +#: vmm:430 msgid "Ouch" msgstr "" diff -r 5506433db9a3 -r 995d538a6eb5 vmm --- a/vmm Mon Aug 25 14:49:43 2008 +0000 +++ b/vmm Mon Aug 25 20:45:54 2008 +0000 @@ -58,7 +58,7 @@ ut usertransport user@domain.tld transport u0 userdisable user@domain.tld service* u1 userenable user@domain.tld service* - ud userdelete user@domain.tld + ud userdelete user@domain.tld delalias* aa aliasadd alias@domain.tld user@domain.tld ai aliasinfo alias@domain.tld ad aliasdelete alias@domain.tld user@domain.tld* @@ -262,8 +262,10 @@ def user_delete(): if argc < 3: usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) + elif argc < 4: + vmm.userDelete(argv[2].lower()) else: - vmm.userDelete(argv[2].lower()) + vmm.userDelete(argv[2].lower(), argv[3].lower()) def user_info(): if argc < 3: