2 # -*- coding: utf-8 -*-
3 # https://developer.mozilla.org/fr/docs/Mozilla/Thunderbird/Autoconfiguration
9 cgitb.enable(display=0, logdir="/tmp")
11 DSN = 'host=db-srv.auf user=XXX password=XXX dbname=AUF'
14 'login_local': '%EMAILADDRESS%',
15 'serveur_bal': "imap.refer.org",
16 'domaine': "refer.org",
21 form = cgi.FieldStorage()
23 email = form.getvalue('emailaddress')
24 cnx = psycopg2.connect(DSN)
25 cur = cnx.cursor(cursor_factory=psycopg2.extras.DictCursor)
26 cur.execute("""SELECT login_local,serveur_bal,pays """
27 """FROM "Authentification".annuaire WHERE courriel=%s""", (email,))
31 if row['login_local']:
32 info['login_local'] = row['login_local']
34 info['login_local'] = '%EMAILADDRESS%'
35 info['serveur_bal'] = row['serveur_bal']
36 #info['domaine'] = row['pays'] + ".auf.org"
37 info['domaine'] = "auf.org"
38 info['shortname'] = 'AUF'
39 info['name'] = 'Agence universitaire de la Francophonie'
41 data = """<?xml version="1.0" encoding="utf-8"?>
42 <clientConfig version="1.1">
43 <emailProvider id="auf.org">
44 <domain>%(domaine)s</domain>
45 <displayName>%(name)s</displayName>
46 <displayShortName>%(shortname)s</displayShortName>
47 <incomingServer type="imap">
48 <hostname>%(serveur_bal)s</hostname>
50 <socketType>SSL</socketType>
51 <authentication>password-cleartext</authentication>
52 <username>%(login_local)s</username>
54 <outgoingServer type="smtp">
55 <hostname>%(serveur_bal)s</hostname>
57 <socketType>STARTTLS</socketType>
58 <authentication>password-cleartext</authentication>
59 <username>%(login_local)s</username>
62 </clientConfig>""" % info
65 headers['Content-Type'] = 'text/xml; charset=utf-8'
66 headers['Vary'] = 'Content-Encoding'
67 headers['Content-Length'] = len(data)
70 headers = ''.join(map(lambda x: "%s: %s\r\n" % (x, headers[x]), headers))
71 stdout.write(headers + "\r\n")