reading sendmail alaises

A Meowbot meowbot at meowing.net
Thu Jan 31 18:29:28 EST 2002


David Bear <iddwb at moroni.pp.asu.edu> wrote:

> I would like a quick way to resolve sendmail aliases.  I've thought
> about reading and parsing /etc/aliases myself but thats too much
> work.  Is there some module/interface to sendmail that would allow
> something like
>
> realaddress = sendmail.resolve-alias(name)
>
> Even though I could build a dictionary from aliases, the file may
> actually be in db format -- so I'm looking for a 'sendmail' way of
> grabbing them.

The anydbm module will let you access aliases.db in dictionary form.
The keys and values in aliaases.db are null terminated, so you'll need
to account for that.

>>> import anydbm
>>> aliases = anydbm.open("/etc/mail/aliases.db")
>>> aliases["nobody\0"]
'root\x00'

You would still have to find and parse sendmail.cf to learn the
location of aliases and aliases.db...

Or, if that's still too fiddly for you, you could spawn out to the
praliases program.



More information about the Python-list mailing list