SF.net SVN: tmda: [2146] trunk/tmda/bin/tmda-pending
[email protected] Fri, 23 Feb 2007 11:05:08 -0800
| Newsgroups | gmane.mail.spam.tmda.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 2146
http://svn.sourceforge.net/tmda/?rev=2146&view=rev
Author: jasonrm
Date: 2007-02-23 11:05:07 -0800 (Fri, 23 Feb 2007)
Log Message:
-----------
New features from Lloyd Zusman:
He explains:
I'm using TMDA with the Courier MTA, and all my users get virtual email
directories as implemented in the Courier manner. On my system, all of
these are subdirectories which live under /var/vmail, and all are owned
by uid=vmail and gid=vmail. The .tmda and Maildir directories live in
this subdirectory. For example, for the virtual email address
"[email protected]", we have the following items:
/var/vmail/[email protected] - the top-level email directory
/var/vmail/[email protected]/.tmda - the associated tmda home
/var/vmail/[email protected]/Maildir - the associated Maildir
I can make use of the --vhost-script option for tmda-filter and
tmda-ofmipd to cause each of these programs to set HOME to the
appropriate virtual directory, but I am unable to perform the
corresponding function with tmda-pending, which lacks the --vhost-script
option.
Furthermore, the method in http://wiki.tmda.net/VirtualDomainsHowto for
using tmda-pending with virtual domains does not work for my Courier
virtual email setup ... tmda-pending still can't find the pending
directory.
Up until now, I have always manually hacked the TMDA source code to
allow my users to utilize tmda-pending with their Courier virtual mail
directories. However, I'm getting tired of having to reinstall this
hack every time I upgrade TMDA.
Therefore, I have implemented a patch for tmda-pending which also gives
it a --vhost-script option. It works the same as it does for
tmda-filter and tmda-ofmipd. The script specified by this option will
be passed the user name and the domain name as determined with the
following algorithm (which makes use of two other new options:
--vhost-user and --vhost-domain) ...
user name: if the --vhost-user option is set, use it
else if the USER environment variable is set,
use it
else if the LOGNAME environment variable is set,
use it
else ERROR
domain name: if the --vhost-domain option is set, use it
else if socket.gethostbyaddr(socket.gethostname())[0]
succeeds, use this value
else ERROR
Modified Paths:
--------------
trunk/tmda/bin/tmda-pending
Modified: trunk/tmda/bin/tmda-pending
===================================================================
--- trunk/tmda/bin/tmda-pending 2007-02-23 18:48:52 UTC (rev 2145)
+++ trunk/tmda/bin/tmda-pending 2007-02-23 19:05:07 UTC (rev 2146)
@@ -24,6 +24,7 @@
import os
import sys
+import socket
try:
import paths
@@ -71,6 +72,9 @@
(get a summary listing of all pending messages)
$ tmda-pending -T -b
+ (same as above, but use /usr/local/bin/vhome as the vhome-script)
+ $ tmda-pending -T -b --vhome-script=/usr/local/bin/vhome
+
(interactively operate on just these messages)
$ tmda-pending 1012182077.5803 1012939546.7870
@@ -100,6 +104,33 @@
msggroup = OptionGroup(parser, "Messages")
# general
+gengroup.add_option("--vhome-script",
+ metavar="SCRIPT", dest="vhomescript",
+ help= \
+"""Full pathname of SCRIPT that prints a virtual email user's home
+directory on standard output. tmda-pending will read that path and
+set $HOME to that path so that '~' expansion works properly for
+virtual users. The script takes two arguments, the user name and
+the domain, on its command line. This option is for use with the
+VPopMail and VMailMgr add-ons to qmail and with other systems that
+manage virtual email addresses. The user name is obtained from the
+USER and LOGNAME environment variables, in that order, or by the
+value of the '--vhome-user' option, if defined. The domain name is
+obtained by the '--vhome-domain' option, if defined, and if not,
+an attempt to figure it out automatically.""")
+
+gengroup.add_option("--vhome-user",
+ metavar="USER", dest="vhomeuser",
+ help= \
+"""The user name to optionally pass to the program specified
+in the '--vhome-script' option, above.""")
+
+gengroup.add_option("--vhome-domain",
+ metavar="DOMAIN", dest="vhomedomain",
+ help= \
+"""The domain name to optionally pass to the program specified
+in the '--vhome-script' option, above.""")
+
gengroup.add_option("-c", "--config-file",
metavar="FILE", dest="config_file",
help= \
@@ -229,6 +260,44 @@
else:
threshold = None
+if opts.vhomescript:
+ """Set $HOME to the recipient's (virtual user) home directory."""
+ user = None
+ if opts.vhomeuser:
+ user = opts.vhomeuser
+ else:
+ try:
+ user = os.environ['USER']
+ except:
+ try:
+ user = os.environ['LOGNAME']
+ except:
+ user = None
+ domain = None
+ if opts.vhomedomain:
+ domain = opts.vhomedomain
+ else:
+ try:
+ domain = socket.gethostbyaddr(socket.gethostname())[0]
+ except:
+ domain = None
+ message = ''
+ if user is None:
+ message += ' USER'
+ if domain is None:
+ message += ' DOMAIN'
+ if message != '':
+ sys.stdout.write('missing:%s\n' % message)
+ sys.exit(1)
+ cmd = "%s '%s' '%s'" % ( opts.vhomescript, user, domain )
+ fpin = os.popen(cmd)
+ vuserhomedir = fpin.read().strip()
+ if fpin.close() is None:
+ os.environ['HOME'] = vuserhomedir
+ os.chdir(vuserhomedir)
+ else:
+ sys.stdout.write('invocation failed: %s\n' % ( cmd, ))
+ sys.exit(1)
from TMDA import Pending
from TMDA import Errors
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.