summaryrefslogtreecommitdiff
path: root/modules/aliases.py
blob: 700c062b22057217fd35a8f2a247b9dbcee7ab1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# This is mailman's interface to the alias database.

# TODO:

# Write a wrapper program w/ root uid that allows the mailman user
# only to update the alias database.

import string
_file = open('/etc/aliases', 'r')
_lines = _file.readlines()
aliases = {}
_cur_line  = None

def _AddAlias(line):
  line = string.strip(line)
  if not line:
    return
  colon_index = string.find(line, ":")
  if colon_index < 1:
    raise "SyntaxError", "Malformed /etc/aliases file"
  alias = string.lower(string.strip(line[:colon_index]))
  rest = string.split(line[colon_index+1:], ",")
  rest = map(string.strip, rest)
  aliases[alias] = rest

for _line in _lines:
  if _line[0] == '#':
    continue
  if _line[0] == ' ' or _line[0] == '\t':
    _cur_line = _cur_line + _line
    continue
  if _cur_line:
    _AddAlias(_cur_line)
  _cur_line = _line
  
def GetAlias(str):
  str = string.lower(str)
  if not aliases.has_key(str):
    raise KeyError, "No such alias"
  return aliases[str]