Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

#8252 closed enhancement (fixed)

Allow 8bit emails from trac

Reported by: petr.hroudny@… Owned by: rblank
Priority: normal Milestone: 0.11.5
Component: general Version: none
Severity: normal Keywords:
Cc: petr.hroudny@…
Release Notes:
API Changes:

Description

#1754 introduced new config option

[notification]
mime_encoding = base64 | qp | none

in order to avoid unnecessary base64 encoding in emails from trac. However, it's still not possible to have trac output plain 8bit emails, since "none" only works with pure ASCII.

It's perfectly valid to generate 8-bit UTF-8 emails today, when the following MIME headers are used:

Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: 8bit

An example MUAs doing that are Thunderbird, Mutt, …

Thus another option for 8bit notifications is needed and I'd even say it should be the default these days.

The following addition into /trunk/trac/notification.py should do it:

297	        elif pref == '8bit':
298	            self._charset.header_encoding = SHORTEST
299	            self._charset.body_encoding = None
300	            self._charset.output_charset = 'utf-8'
301	            self._charset.input_codec = 'utf-8'
302	            self._charset.output_codec = 'utf-8'

Attachments (1)

8252-8bit-body-encoding-r8165.patch (4.4 KB) - added by rblank 5 years ago.
Patch against 0.11-stable using either 7bit or 8bit body encoding when mime_encoding = none.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 5 years ago by rblank

  • Milestone set to 0.11.5
  • Owner set to rblank

comment:2 follow-up: Changed 5 years ago by petr.hroudny@…

There is actually a major difference between Trac and Python. Option "none" in Python means no special encoding should be used and 8bit body is allowed, while in Trac this option only allows 7-bit ASCII messages.

Thus is might be perhaps better to redefine what "none" does in Trac and sync it with Python. The following lines need to be changed:

287	        from email.Charset import Charset, QP, BASE64, SHORTEST

303	        elif pref == 'none':
304	            self._charset.header_encoding = SHORTEST
305	            self._charset.body_encoding = None
306                 self._charset.output_charset = 'utf-8'
307	            self._charset.input_codec = 'utf-8'
308	            self._chaset.output_codec = 'utf-8'

And the following lines need to be removed:

459	        # sanity check
460	        if not self._charset.body_encoding:
461	            try:
462	                dummy = body.encode('ascii')
463	            except UnicodeDecodeError:
464	                raise TracError(_("Ticket contains non-ASCII chars. " \
465	                                  "Please change encoding setting"))

After the above changes, the option "none" could be used to send out properly formatted 8bit utf-8 emails.

Changed 5 years ago by rblank

Patch against 0.11-stable using either 7bit or 8bit body encoding when mime_encoding = none.

comment:3 in reply to: ↑ 2 Changed 5 years ago by rblank

Replying to petr.hroudny@…:

Thus is might be perhaps better to redefine what "none" does in Trac and sync it with Python.

This makes a lot of sense to me. Throwing an error when an e-mail requires 8bit encoding (which is quite often, as the ellipsis is used to obfuscate e-mail addresses) and [notification] mime_encoding = none is not very user friendly.

The patch above implements the suggestion, together with a test case.

Manu, could you please comment on the patch? Thanks!

comment:4 Changed 5 years ago by rblank

  • Resolution set to fixed
  • Status changed from new to closed

Patch applied in [8218].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed The owner will remain rblank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from rblank to the specified user.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.