autoconfig-mail : ajout d'une exception pour le Canada
[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',
c5cbe432 19}
3deec619
P
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]
c5cbe432 31 if row['login_local']:
3deec619
P
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
c5cbe432
P
41info['serveur_envoi'] = info['serveur_bal']
42
43# Gestion des exceptions
44
45# France
fb42639a
P
46if info['serveur_bal'] == 'mail.fr.auf.org':
47 if row['login_local']:
48 info['login_local'] = row['login_local']
49 else:
50 info['login_local'] = email.partition('@')[0]
51
c5cbe432
P
52# Canada
53if info['serveur_bal'] == 'mail.ca.auf.org':
54 info['serveur_bal'] = 'imap.ca.auf.org'
55if info['serveur_bal'] == 'imap.ca.auf.org':
56 info['serveur_envoi'] = 'smtp-sortant.ca.auf.org'
57
fb42639a 58# préparation de la réponse XML
3deec619 59data = """<?xml version="1.0" encoding="utf-8"?>
c5cbe432 60<clientConfig version="1.1">
3deec619
P
61 <emailProvider id="auf.org">
62 <domain>%(domaine)s</domain>
63 <displayName>%(name)s</displayName>
64 <displayShortName>%(shortname)s</displayShortName>
65 <incomingServer type="imap">
66 <hostname>%(serveur_bal)s</hostname>
67 <port>993</port>
68 <socketType>SSL</socketType>
69 <authentication>password-cleartext</authentication>
70 <username>%(login_local)s</username>
71 </incomingServer>
72 <outgoingServer type="smtp">
c5cbe432 73 <hostname>%(serveur_envoi)s</hostname>
3deec619
P
74 <port>587</port>
75 <socketType>STARTTLS</socketType>
76 <authentication>password-cleartext</authentication>
77 <username>%(login_local)s</username>
78 </outgoingServer>
79 </emailProvider>
80</clientConfig>""" % info
81
fb42639a 82# préparation des en-têtes de la réponse
3deec619
P
83headers = dict()
84headers['Content-Type'] = 'text/xml; charset=utf-8'
3deec619 85headers['Content-Length'] = len(data)
fb42639a
P
86headers['Pragma'] = 'no-cache'
87#headers['Vary'] = 'Content-Encoding'
3deec619
P
88
89# envoi de la réponse
90headers = ''.join(map(lambda x: "%s: %s\r\n" % (x, headers[x]), headers))
91stdout.write(headers + "\r\n")
92if data:
93 stdout.write(data)
94