comparison mercurial/mail.py @ 30072:87b8e40eb812

mail: handle renamed email.Header We are still using email.Header which was renamed to email.header back in Python 2.5. References: https://hg.python.org/cpython/file/2.4/Lib/email and https://hg.python.org/cpython/file/2.5/Lib/email
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 07 Oct 2016 17:30:11 +0200
parents 63a3749147af
children 040f23ed6963
comparison
equal deleted inserted replaced
30071:2def3d55b1b9 30072:87b8e40eb812
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import, print_function 8 from __future__ import absolute_import, print_function
9 9
10 import email 10 import email
11 import email.header
11 import os 12 import os
12 import quopri 13 import quopri
13 import smtplib 14 import smtplib
14 import socket 15 import socket
15 import sys 16 import sys
21 error, 22 error,
22 sslutil, 23 sslutil,
23 util, 24 util,
24 ) 25 )
25 26
26 _oldheaderinit = email.Header.Header.__init__ 27 _oldheaderinit = email.header.Header.__init__
27 def _unifiedheaderinit(self, *args, **kw): 28 def _unifiedheaderinit(self, *args, **kw):
28 """ 29 """
29 Python 2.7 introduces a backwards incompatible change 30 Python 2.7 introduces a backwards incompatible change
30 (Python issue1974, r70772) in email.Generator.Generator code: 31 (Python issue1974, r70772) in email.Generator.Generator code:
31 pre-2.7 code passed "continuation_ws='\t'" to the Header 32 pre-2.7 code passed "continuation_ws='\t'" to the Header
277 def headencode(ui, s, charsets=None, display=False): 278 def headencode(ui, s, charsets=None, display=False):
278 '''Returns RFC-2047 compliant header from given string.''' 279 '''Returns RFC-2047 compliant header from given string.'''
279 if not display: 280 if not display:
280 # split into words? 281 # split into words?
281 s, cs = _encode(ui, s, charsets) 282 s, cs = _encode(ui, s, charsets)
282 return str(email.Header.Header(s, cs)) 283 return str(email.header.Header(s, cs))
283 return s 284 return s
284 285
285 def _addressencode(ui, name, addr, charsets=None): 286 def _addressencode(ui, name, addr, charsets=None):
286 name = headencode(ui, name, charsets) 287 name = headencode(ui, name, charsets)
287 try: 288 try:
328 return mimetextqp(s, 'plain', cs) 329 return mimetextqp(s, 'plain', cs)
329 330
330 def headdecode(s): 331 def headdecode(s):
331 '''Decodes RFC-2047 header''' 332 '''Decodes RFC-2047 header'''
332 uparts = [] 333 uparts = []
333 for part, charset in email.Header.decode_header(s): 334 for part, charset in email.header.decode_header(s):
334 if charset is not None: 335 if charset is not None:
335 try: 336 try:
336 uparts.append(part.decode(charset)) 337 uparts.append(part.decode(charset))
337 continue 338 continue
338 except UnicodeDecodeError: 339 except UnicodeDecodeError: