summaryrefslogtreecommitdiffstats
path: root/fooconf-postfix-mailbox-map
blob: 03a862824fef7a3e67be8a71d29544aacd71cc1f (plain)
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
#!/usr/bin/env python
# Hey Emacs, this is -*-python-*- code!

from fooconflib import *

def generatePostfixMailboxMapFragment(ctx = FooConfContext()):
    cursor = ctx.db.cursor()
    cursor.execute("SELECT DISTINCT local, domain, recipient, account.name AS name " +
                   "FROM mail_alias, domain, account, mailbox " +
                   "WHERE mail_alias.domain = domain.name " +
                   "AND domain.owner = account.id " +
                   "AND mailbox.owner = account.id " +
                   "AND mailbox.enabled = \"t\" " +
                   "AND account.enabled = \"t\" " +
                   "AND type=\"mailbox\"")

    while 1:
        row = cursor.fetchone()
        if row is None: break

        print "%s@%s %s" % (row["local"], row["domain"], ctx.makeHomeDir(row["name"])+"/mail/"+row["recipient"])

if __name__ == "__main__":
    generatePostfixMailboxMapFragment()