Revision eef0f61d
Added by Thomas Noël (congés → 24 novembre) over 12 years ago
| calebasse/facturation/transmission_utils.py | ||
|---|---|---|
| 5 | 5 |
import re |
| 6 | 6 |
import base64 |
| 7 | 7 |
from datetime import datetime |
| 8 |
import zlib |
|
| 8 |
import gzip |
|
| 9 |
import StringIO |
|
| 9 | 10 |
|
| 10 | 11 |
import ldap |
| 11 | 12 |
from M2Crypto import X509, SSL, Rand, SMIME, BIO |
| 12 | 13 |
|
| 13 | 14 |
MODE_TEST = False |
| 14 | 15 |
MODE_COMPRESS = True |
| 16 |
MODE_ENCRYPT = True |
|
| 15 | 17 |
|
| 16 | 18 |
LDAP_HOST = 'ldap://annuaire.gip-cps.fr' |
| 17 | 19 |
|
| ... | ... | |
| 91 | 93 |
def mime(message): |
| 92 | 94 |
# compress |
| 93 | 95 |
if MODE_COMPRESS: |
| 94 |
zmessage = zlib.compress(message) |
|
| 96 |
sio = StringIO.StringIO() |
|
| 97 |
gzf = gzip.GzipFile(fileobj=sio, mode='wb', filename='B2.gz') |
|
| 98 |
gzf.write(message) |
|
| 99 |
gzf.close() |
|
| 100 |
zmessage = sio.getvalue() |
|
| 101 |
sio.close() |
|
| 95 | 102 |
else: |
| 96 | 103 |
zmessage = message |
| 97 | 104 |
if MODE_TEST: |
| ... | ... | |
| 103 | 110 |
return "Content-Type: application/EDI-consent\n" + \ |
| 104 | 111 |
"Content-Transfer-Encoding: base64\n" + \ |
| 105 | 112 |
"Content-Description: " + content_description + "\n" + \ |
| 106 |
"\n" + base64.encodestring(zmessage).rstrip()
|
|
| 113 |
"\n" + base64.encodestring(zmessage) |
|
| 107 | 114 |
|
| 108 | 115 |
def smime(message, x509): |
| 109 | 116 |
""" |
| ... | ... | |
| 147 | 154 |
'Mime-Version': '1.0', |
| 148 | 155 |
'Content-Type': 'multipart/mixed; boundary="%s"' % delimiter, |
| 149 | 156 |
} |
| 150 |
smime_part = smime(mime(b2), get_certificate(large_regime, dest_organism)) |
|
| 157 |
mime_part = mime(b2) |
|
| 158 |
if MODE_ENCRYPT: |
|
| 159 |
mime_part = smime(mime(b2), get_certificate(large_regime, dest_organism)) |
|
| 151 | 160 |
|
| 152 | 161 |
filename = b2_filename + '-mail' |
| 153 | 162 |
fd = open(filename, 'w') |
| ... | ... | |
| 155 | 164 |
fd.write('%s: %s\n' % (k,v))
|
| 156 | 165 |
fd.write('\n')
|
| 157 | 166 |
fd.write('--%s\n' % delimiter)
|
| 158 |
fd.write(smime_part)
|
|
| 159 |
fd.write('--%s\n' % delimiter)
|
|
| 167 |
fd.write(mime_part) |
|
| 168 |
fd.write('--%s--\n' % delimiter)
|
|
| 160 | 169 |
fd.close() |
| 161 | 170 |
return filename |
| 162 | 171 |
|
Also available in: Unified diff
facturation/transmission: fixes...
- add MODE_ENCRYPT flag
- use gzip instead of zlib.compress
- add the last MIME delimiter ('--' at the end)