Issue 118791

Summary: XMailMessage attachment unusable if file name (ReadableName) contains non-ASCII characters
Product: App Dev Reporter: DonJaime <donjaime>
Component: apiAssignee: Ariel Constenla-Haile <arielch>
Status: CLOSED FIXED QA Contact:
Severity: Normal    
Priority: P5 (lowest) CC: arielch, issues
Version: 3.3.0 or older (OOo)   
Target Milestone: ---   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Attachments:
Description Flags
Test file sends two messages, one with attachment "Confirmation", one with attachment "Bestätigung"
none
mailmerge.py with some fixes
none
Localized mail attachments readable name UTF-8 encoded - Mutt client - Linux
none
Localized mail attachments readable name UTF-8 encoded - Thunderbird client - WinXP none

Description DonJaime 2012-01-16 07:32:13 UTC
Created attachment 77134 [details]
Test file sends two messages, one with attachment "Confirmation", one with attachment "Bestätigung"

If XMailServer is used to send an XMailMessage with an attachment whose ReadableName contains non-ASCII character, the attachment header is garbled and the attachment cannot be extracted. For example: if the attachment name is "Bestätigung", the Content-Disposition header is rendered as:

Content-Disposition: =?utf-8?q?attachment=3B_filename=3D=22Best=C3=A4tigung?=
	=?utf-8?q?=22?=

while with file name "Confirmation", the header is:

Content-Disposition: attachment; filename="Confirmation"

Presumably the problem is something simple like "encode(foo & bar)" instead of "foo & encode(bar)"
Comment 1 Ariel Constenla-Haile 2012-01-16 12:19:29 UTC
According to http://docs.python.org/library/email.message.html?highlight=add_header#email.message.Message.add_header

For each item in the keyword argument dictionary _params, the key is taken as the parameter name, with underscores converted to dashes (since dashes are illegal in Python identifiers). Normally, the parameter will be added as key="value" unless the value is None, in which case only the key will be added. If the value contains non-ASCII characters, it must be specified as a three tuple in the format (CHARSET, LANGUAGE, VALUE), where CHARSET is a string naming the charset to be used to encode the value, LANGUAGE can usually be set to None or the empty string (see RFC 2231 for other possibilities), and VALUE is the string value containing non-ASCII code points.

An example with non-ASCII characters:

msg.add_header('Content-Disposition', 'attachment',
               filename=('iso-8859-1', '', 'Fußballer.ppt'))

Which produces

Content-Disposition: attachment; filename*="iso-8859-1''Fu%DFballer.ppt"
Comment 2 Ariel Constenla-Haile 2012-01-16 12:21:18 UTC
Created attachment 77136 [details]
mailmerge.py with some fixes
Comment 3 Ariel Constenla-Haile 2012-01-16 12:26:52 UTC
@DonJaime: please replace 

${ROOT_INST_DIR}/openoffice.org/basis3.${MINOR}/program/mailmerge.py

with the one attached in this bug (first back-up the original one).

The fix to this issue is encoding the ReadableName to utf-8:

msgattachment.add_header(\
'Content-Disposition', \
'attachment', \
filename=('utf-8','',attachment.ReadableName.encode('utf-8')))
Comment 4 DonJaime 2012-01-16 13:55:09 UTC
Replaced as instructed. I had to edit line 46 to dbg = False because the ascii codec was choking on line 128, and when that was fixed I got:

An exception occurred 
Type: com.sun.star.uno.RuntimeException
Message: <type 'exceptions.RuntimeError'>: No SSL support included in this Python, traceback follows
  C:\Program Files\OpenOffice.org 3\Basis\program\python-core-2.6.1\lib\smtplib.py:615 in function starttls() [raise RuntimeError("No SSL support included in this Python")]
  C:\Program Files\OpenOffice.org 3\Basis\program\mailmerge.py:88 in function connect() [self.server.starttls()]
.

So I used ConnectionType Insecure and then it worked.
Comment 5 Ariel Constenla-Haile 2012-01-17 02:29:18 UTC
Fixed in revision 1232130
Comment 6 Ariel Constenla-Haile 2012-01-17 02:36:07 UTC
(In reply to comment #4)
> Replaced as instructed. I had to edit line 46 to dbg = False because the ascii
> codec was choking on line 128, and when that was fixed I got:
> 
> An exception occurred 
> Type: com.sun.star.uno.RuntimeException
> Message: <type 'exceptions.RuntimeError'>: No SSL support included in this
> Python, traceback follows
>   C:\Program Files\OpenOffice.org
> 3\Basis\program\python-core-2.6.1\lib\smtplib.py:615 in function starttls()
> [raise RuntimeError("No SSL support included in this Python")]
>   C:\Program Files\OpenOffice.org 3\Basis\program\mailmerge.py:88 in function
> connect() [self.server.starttls()]
> .
> 
> So I used ConnectionType Insecure and then it worked.

yes, this was bug 118787 that made you use insecure connection when specifying "SSL". It compared"Ssl" != "SSL" in a case sensitive way; as these string are not equal, it used an insecure connection.

This seem to have worked for you (your smtp server seems to use insecure connection), but didn't work with Gmail's smtp server for example.
Comment 7 Ariel Constenla-Haile 2012-01-25 11:23:48 UTC
Revision 118791
Encode ReadableName in UTF-8 only when necessary
Comment 8 Ariel Constenla-Haile 2012-01-25 11:25:21 UTC
Created attachment 77165 [details]
Localized mail attachments readable name UTF-8 encoded - Mutt client - Linux
Comment 9 Ariel Constenla-Haile 2012-01-25 11:25:56 UTC
Created attachment 77166 [details]
Localized mail attachments readable name UTF-8 encoded - Thunderbird client - WinXP
Comment 10 Ariel Constenla-Haile 2012-01-25 11:44:39 UTC
(In reply to comment #7)
> Revision 118791
> Encode ReadableName in UTF-8 only when necessary

I meant revision 1235677