diff --git a/trac/notification.py b/trac/notification.py
|
a
|
b
|
|
| 79 | 79 | """Comma-separated list of domains that should be considered as |
| 80 | 80 | valid for email addresses (such as localdomain)""") |
| 81 | 81 | |
| 82 | | mime_encoding = Option('notification', 'mime_encoding', 'base64', |
| | 82 | mime_encoding = Option('notification', 'mime_encoding', 'none', |
| 83 | 83 | """Specifies the MIME encoding scheme for emails. |
| 84 | 84 | |
| 85 | 85 | Valid options are 'base64' for Base64 encoding, 'qp' for |
| 86 | | Quoted-Printable, and 'none' for no encoding. Note that the no encoding |
| 87 | | means that non-ASCII characters in text are going to cause problems |
| 88 | | with notifications (''since 0.10'').""") |
| | 86 | Quoted-Printable, and 'none' for no encoding, in which case mails will |
| | 87 | be sent as 7bit if the content is all ASCII, or 8bit otherwise. |
| | 88 | (''since 0.10'')""") |
| 89 | 89 | |
| 90 | 90 | use_public_cc = BoolOption('notification', 'use_public_cc', 'false', |
| 91 | 91 | """Recipients can see email addresses of other CC'ed recipients. |
| … |
… |
|
| 196 | 196 | self.email_map[username] = email |
| 197 | 197 | |
| 198 | 198 | def _init_pref_encoding(self): |
| 199 | | from email.Charset import Charset, QP, BASE64 |
| | 199 | from email.Charset import Charset, QP, BASE64, SHORTEST |
| 200 | 200 | self._charset = Charset() |
| 201 | 201 | self._charset.input_charset = 'utf-8' |
| | 202 | self._charset.output_charset = 'utf-8' |
| | 203 | self._charset.input_codec = 'utf-8' |
| | 204 | self._charset.output_codec = 'utf-8' |
| 202 | 205 | pref = self.env.config.get('notification', 'mime_encoding').lower() |
| 203 | 206 | if pref == 'base64': |
| 204 | 207 | self._charset.header_encoding = BASE64 |
| 205 | 208 | self._charset.body_encoding = BASE64 |
| 206 | | self._charset.output_charset = 'utf-8' |
| 207 | | self._charset.input_codec = 'utf-8' |
| 208 | | self._charset.output_codec = 'utf-8' |
| 209 | 209 | elif pref in ['qp', 'quoted-printable']: |
| 210 | 210 | self._charset.header_encoding = QP |
| 211 | 211 | self._charset.body_encoding = QP |
| 212 | | self._charset.output_charset = 'utf-8' |
| 213 | | self._charset.input_codec = 'utf-8' |
| 214 | | self._charset.output_codec = 'utf-8' |
| 215 | 212 | elif pref == 'none': |
| 216 | | self._charset.header_encoding = None |
| | 213 | self._charset.header_encoding = SHORTEST |
| 217 | 214 | self._charset.body_encoding = None |
| 218 | | self._charset.input_codec = None |
| 219 | | self._charset.output_charset = 'ascii' |
| 220 | 215 | else: |
| 221 | 216 | raise TracError(_('Invalid email encoding setting: %s' % pref)) |
| 222 | 217 | |
| … |
… |
|
| 388 | 383 | if pcc: |
| 389 | 384 | headers['Cc'] = ', '.join(pcc) |
| 390 | 385 | headers['Date'] = formatdate() |
| 391 | | # sanity check |
| 392 | | if not self._charset.body_encoding: |
| 393 | | try: |
| 394 | | dummy = body.encode('ascii') |
| 395 | | except UnicodeDecodeError: |
| 396 | | raise TracError(_("Ticket contains non-ASCII chars. " \ |
| 397 | | "Please change encoding setting")) |
| 398 | 386 | msg = MIMEText(body, 'plain') |
| 399 | 387 | # Message class computes the wrong type from MIMEText constructor, |
| 400 | 388 | # which does not take a Charset object as initializer. Reset the |
diff --git a/trac/ticket/tests/notification.py b/trac/ticket/tests/notification.py
|
a
|
b
|
|
| 411 | 411 | self._validate_mimebody((quopri, 'quoted-printable', 'utf-8'), |
| 412 | 412 | ticket, True) |
| 413 | 413 | |
| 414 | | def test_mimebody_none(self): |
| 415 | | """MIME None/ascii encoding""" |
| | 414 | def test_mimebody_none_7bit(self): |
| | 415 | """MIME None encoding resulting in 7bit""" |
| 416 | 416 | self.env.config.set('notification','mime_encoding', 'none') |
| 417 | 417 | ticket = Ticket(self.env) |
| 418 | 418 | ticket['reporter'] = 'joe.user' |
| 419 | 419 | ticket['summary'] = u'This is a summary' |
| 420 | 420 | ticket.insert() |
| 421 | | self._validate_mimebody((None, '7bit', 'ascii'), \ |
| | 421 | self._validate_mimebody((None, '7bit', 'utf-8'), \ |
| | 422 | ticket, True) |
| | 423 | |
| | 424 | def test_mimebody_none_8bit(self): |
| | 425 | """MIME None encoding resulting in 8bit""" |
| | 426 | self.env.config.set('notification','mime_encoding', 'none') |
| | 427 | ticket = Ticket(self.env) |
| | 428 | ticket['reporter'] = 'joe.user' |
| | 429 | ticket['summary'] = u'This is a summary for Jöe Usèr' |
| | 430 | ticket.insert() |
| | 431 | self._validate_mimebody((None, '8bit', 'utf-8'), \ |
| 422 | 432 | ticket, True) |
| 423 | 433 | |
| 424 | 434 | def test_md5_digest(self): |