|
|
Changing Mailman Python Scripts for Virtual Host Support
|
Tuesday, 22 September 09, 12:49 pm
compton
|
Mailman is a tried-and-tested Open Source mailing list manager. It's robust and reasonably efficient when running, however it organises lists internally by their local name only. In other words, you can't have one list called maillist@domain.org on the same server as another list called maillist@somewhereelse.com on the same machine, unless you have a separate mailman installation for each domain.
Many production environments do appear to use the separate installation per domain approach, however with 8 'queue runner' processes running per installation, it would not require many domains before mailman starts gobbling unacceptable levels of resources.
One solution is to internally combine the domain name and the list name selected by the user. This would mean that each list would appear to the user as listname@domain.com, but internally would be listname-domain.com@domain.com.
In order to pull this off transparently, the following needs to be accomplished:
email aliases: The address {listname}@mydomain.com needs to be aliased to {listname}-{domain}@mydomain.com so that incoming mail for the list is delivered correctly
mailing list archives: Some public web address such as www.domain.com/mailarchive/{listname} should be redirected to www.domain.com/pipermail/{listname}-{domain}
list creation: a mechanism that prevents lists being created with a hyphen in the name (or whatever other character is used as a separator)
Outgoing email messages: need to be changed so that email addresses and listnames in them appear in the 'friendly' format
There's a good synopsis of the basics of Python syntax at this site, which is quite suitable for experienced programmers wanting a quick overview, despite its name. IBM also provide a good primer.
Like in C, strings are really just character arrays. Thus you can refer to a single character of a string using array notation, such as somestring[5]. Python adds to this standard array notation with the concept of slicing, where two indicies are supplied, separated by a colon. This creates a new array consisting of the elements between the two indicies. When dealing with strings, the slice is the Python way of specifying substrings e.g. somestring[5:8].
Python does use a lot of syntax that's quite different to other programming languages such as C++ or Java. For instance, to indicate that a class is derived from another class, we simply add the name of the base class in parenthesis after the name of the derived class. The derived class can override member functions of the base class.
One thing in Python which we need to get our head round for these virtual domain script changes is the Python dictionary type: UserDict. This is really just a class wrapper for the built-in dictionary type, allowing classes to inherit from it to override or add methods and data attributes. (In Python, class member variables are known as data attributes.) Use of this UserDict wrapper class has been largely obviated in newer versions of Python by the ability to inherit directly from the built-in dictionary type using the keyword dict as the class name; however the mailman scripts use the older syntax.
The dictionary type is in effect an associative array, i.e. a list of name-value pairs. The UserDict class defines a single data attribute (cunningly called 'data'), which is underlying dictionary data structure of the class.
Here's the standard Python way to use a dictionary to replace tokens in a string of text:
template_string = 'foo %(sometoken)s bar %(sometoken)s baz' message = template_string % {'sometoken': variable}
This is exactly what the SafeDict.interpolate() method does:
def interpolate(self, template): return template % self |
|
|
Leave Comment
|
|
|
compton
1:22 pm, Tuesday, 22 September 09
|
|
|
compton
2:23 pm, Thursday, 15 October 09
|
|
|
compton
2:12 pm, Wednesday, 28 October 09
|
|
|
compton
1:49 pm, Wednesday, 18 November 09
|
|
|
|
|
Leave Comment
|
|