Mise en place autoconfig Thunderbird pour auf.org.
[progfou.git] / thunderbird / autoconfig / autoconfig-mail
CommitLineData
3deec619
P
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# https://developer.mozilla.org/fr/docs/Mozilla/Thunderbird/Autoconfiguration
4from sys import stdout
5import psycopg2
6import psycopg2.extras
7import cgi
8import cgitb
9cgitb.enable(display=0, logdir="/tmp")
10
11DSN = 'host=db-srv.auf user=XXX password=XXX dbname=AUF'
12
13info = {
14 'login_local': '%EMAILADDRESS%',
15 'serveur_bal': "imap.refer.org",
16 'domaine': "refer.org",
17 'shortname': 'REFER',
18 'name': 'REFER',
19}
20
21form = cgi.FieldStorage()
22if form:
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,))
28 res = cur.fetchall()
29 if res:
30 row = res[0]
31 if row['login_local']:
32 info['login_local'] = row['login_local']
33 else:
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'
40
41data = """<?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>
49 <port>993</port>
50 <socketType>SSL</socketType>
51 <authentication>password-cleartext</authentication>
52 <username>%(login_local)s</username>
53 </incomingServer>
54 <outgoingServer type="smtp">
55 <hostname>%(serveur_bal)s</hostname>
56 <port>587</port>
57 <socketType>STARTTLS</socketType>
58 <authentication>password-cleartext</authentication>
59 <username>%(login_local)s</username>
60 </outgoingServer>
61 </emailProvider>
62</clientConfig>""" % info
63
64headers = dict()
65headers['Content-Type'] = 'text/xml; charset=utf-8'
66headers['Vary'] = 'Content-Encoding'
67headers['Content-Length'] = len(data)
68
69# envoi de la réponse
70headers = ''.join(map(lambda x: "%s: %s\r\n" % (x, headers[x]), headers))
71stdout.write(headers + "\r\n")
72if data:
73 stdout.write(data)
74