[issue14062] UTF-8 Email Subject problem

2012-03-14 Thread Michal Sladek

Michal Sladek mic...@sladkovi.eu added the comment:

Changing code to:
encodedSubject = '=?utf-8?b?{0}?='.format(base64Subject)
still works properly with smtp.seznam.cz server

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14062
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14062] UTF-8 Email Subject problem

2012-03-13 Thread Michal Sladek

Michal Sladek mic...@sladkovi.eu added the comment:

I tested the code again. Using Gmail SMTP server produces correct results, 
using server smtp.seznam.cz leads to a problem (I should mention here, that 
Seznam is the largest free mail provider in the Czech Republic). Here are the 
differences on receiving side.

GMAIL:

Return-Path: mic...@sladkovi.eu
Received: from mail-bk0-f45.google.com (mail-bk0-f45.google.com [209.85.214.45])
by mx4.volny.cz (Postfix) with ESMTP id 0A3E12E086B
for msla...@volny.cz; Tue, 13 Mar 2012 17:58:03 +0100 (CET)
Received: by bkcjg9 with SMTP id jg9so842625bkc.18
for msla...@volny.cz; Tue, 13 Mar 2012 09:58:03 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=google.com; s=20120113;
h=message-id:date:content-type:mime-version:from:to:subject
 :x-gm-message-state;
bh=Sdb8G6CtN+pEzPJHxwbwCprTgWPJUrR3jiU+qeK1WAs=;
b=X88feHvtpL6zBXYNYSjgUQ+1WirGmU8B69k+4fGlAge6F5+pYd6SzuJ6ExdBsp+brw
 1QuCne97OdVnYoFmg86ZviFz3m6Cn6N8hgPNa2H7hCPQD4O+cjJQQzze4xXYqgPJQs+D
 ke4ISEmxL9UFJUvkTyFhrCDefSxQMY+TnnLwWQR+PCD/uB0FgR2UgBjEx9K7EUKQi6W0
 78+EZYO3cd+SuuadOUvIpe2cj0576ahcP40dGN0kIe+P4NX5Ij7D2cCa/bWiwFdDRUI4
 v8UxJcnbTuOCQFtlItxCAxU9IzZWGekWtpJVnRDBGG63iGXHoTDzp+4+d1FRBGsDQ2pD
 l5tg==
Received: by 10.204.150.73 with SMTP id x9mr6371797bkv.7.1331657883687;
Tue, 13 Mar 2012 09:58:03 -0700 (PDT)
Received: from dvr.ph.sladkovi.eu (ip-84-42-150-218.net.upcbroadband.cz. 
[84.42.150.218])
by mx.google.com with ESMTPS id u14sm2783344bkp.2.2012.03.13.09.58.02
(version=SSLv3 cipher=OTHER);
Tue, 13 Mar 2012 09:58:02 -0700 (PDT)
Message-ID: 4f5f7c9a.0e70cc0a.12f5.7...@mx.google.com
Date: Tue, 13 Mar 2012 09:58:02 -0700 (PDT)
Content-Type: multipart/mixed; boundary1165280172==
MIME-Version: 1.0
From: mic...@sladkovi.eu
To: msla...@volny.cz
Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=
X-Gm-Message-State: 
ALoCoQmf6k2GVVKdm0ZNbvSyPpZ0Gl1yv/BDc3h3zrh34hWWp3wa/fSBXbWT9FANzBLd5k1qUnEP
X-DKIM-Status: neutral
X-Virus: no (m2.volny.internal - Tue, 13 Mar 2012 17:58:05 +0100 (CET))
X-Spam: no (m2.volny.internal - Tue, 13 Mar 2012 17:58:07 +0100 (CET))
X-Received-Date: Tue, 13 Mar 2012 17:58:08 +0100 (CET)

--===1165280172==
Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Content-Transfer-Encoding: base64

w7pwxJtsIMSPw6FiZWxza8OpIMOzZHk=

--===1165280172==--

--

SEZNAM:

Return-Path: michal.sla...@seznam.cz
Received: from smtp2.seznam.cz (smtp2.seznam.cz [77.75.76.43])
by mx4.volny.cz (Postfix) with ESMTP id 542A32E0868
for msla...@volny.cz; Tue, 13 Mar 2012 18:00:05 +0100 (CET)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=seznam.cz;

h=Received:Content-Type:MIME-Version:From:To:Subject:--===1097187749==:MIME-Version:Content-Transfer-Encoding:X-Smtpd:X-Seznam-User:X-Session:X-Country:X-Virus-Info:X-Seznam-SPF:X-Seznam-DomainKeys;
b=bfwTOSoFJU7vGbB7VvXNIQzhbsj+pDPhwr72BX1aVWAicyK0Cix3evz6c3+srYBba
lHDeYd74ZXW5553N6ocfy68pRxpI6K5dKfvcKKLgUN7+N/iQOUtj09D4wN81cjPt7qQ
uH5rjcdsDsbZV31EsxyS1P/rn6F7bYOxrpPeHAk=
Received: from dvr.ph.sladkovi.eu (ip-84-42-150-218.net.upcbroadband.cz 
[84.42.150.218])by email-relay1.ng.seznam.cz (Seznam SMTPD 
1.2.15-6@18976) with ESMTP;  Tue, 13 Mar 2012 17:59:32 +0100 (CET)  
Content-Type: multipart/mixed; boundary1097187749==
MIME-Version: 1.0
From: michal.sla...@seznam.cz
To: msla...@volny.cz
Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?= 
X-DKIM-Status: fail
X-Virus: no (m2.volny.internal - Tue, 13 Mar 2012 18:00:06 +0100 (CET))
X-Spam: no (m2.volny.internal - Tue, 13 Mar 2012 18:00:08 +0100 (CET))
X-Received-Date: Tue, 13 Mar 2012 18:00:08 +0100 (CET)

--===1097187749==:Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Content-Transfer-Encoding: base64
X-Smtpd: 1.2.15-6@18976
X-Seznam-User: michal.sla...@seznam.cz
X-Session: 5
X-Country: CZ
X-Virus-Info:clean
X-Seznam-SPF:neutral
X-Seznam-DomainKeys:unknown

w7pwxJtsIMSPw6FiZWxza8OpIMOzZHk=

--===1097187749==--

--

As you can see, Seznam is adding a lot of headers into mail's body. Anyway, 
making utf-8 subject manually like this:

base64Subject = base64.b64encode(subject.encode('utf-8')).decode()
encodedSubject = '=?UTF-8?B?{0}?='.format(base64Subject)
message.add_header('Subject',encodedSubject)

works correctly for both SMTP servers. So there must be a difference...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14062
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options

[issue14062] UTF-8 Email Subject problem

2012-02-20 Thread Michal Sladek

New submission from Michal Sladek mic...@sladkovi.eu:

Hello!

I think there is a problem when adding UTF-8 subject to email message. I wrote 
following function (its code is based on examples I found in offical docs) 
which should send an email with UTF-8 subject, UTF-8 plain text body and 
attached file when all arguments are given. 
fromAddr - address of sender
toAddr - address of recipient
subject - subject
body - text of email body
attachment - full path to file we want to attach

Here is the code:

def sendMail (fromAddr, toAddr, subject, body = '', attachment = ''):
message = email.mime.multipart.MIMEMultipart()
message.add_header('From',fromAddr)
message.add_header('To',toAddr)

message['Subject'] = email.header.Header(subject,'utf-8')

if (body != ''):
msgPart = email.mime.text.MIMEText(body,'plain','utf-8')
message.attach(msgPart)
if (attachment != ''):
if os.path.exists(attachment) == True:
filename = attachment.rpartition(os.sep)[2]
fp = open(attachment,'rb')
msgPart = email.mime.base.MIMEBase('application','octet-stream')
msgPart.set_payload(fp.read())
fp.close()
email.encoders.encode_base64(msgPart)

msgPart.add_header('Content-Disposition','attachment',filename=filename)
message.attach(msgPart)
if smtpPort == 25:
smtpCon = smtplib.SMTP(smtpSrv,smtpPort)
else:
smtpCon = smtplib.SMTP_SSL(smtpSrv,smtpPort)
if (smtpUser != '') and (smtpPass != ''):
smtpCon.login(smtpUser,smtpPass)
smtpCon.send_message(message,mail_options=['UTF8SMTP','8BITMIME'])
smtpCon.quit()

Running the function with following arguments:

sendMail('rzro...@seznam.cz','msla...@volny.cz','žluťoučký kůň','úpěl ďábelské 
ódy')

produces following output on receiving side:

Return-Path: rzro...@seznam.cz
Received: from smtp2.seznam.cz (smtp2.seznam.cz [77.75.76.43])
by mx1.volny.cz (Postfix) with ESMTP id DD6BB2E09CD
for msla...@volny.cz; Mon, 20 Feb 2012 08:34:38 +0100 (CET)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=seznam.cz;

h=Received:Content-Type:MIME-Version:From:To:Subject:--===1029508565==:MIME-Version:Content-Transfer-Encoding:X-Smtpd:X-Seznam-User:X-Session:X-Country:X-Virus-Info:X-Seznam-SPF:X-Seznam-DomainKeys;
b=cdU1VSRTCDf0x2CeBNbLJxYSOhSy7r9lNp+1s7+bed6AGBI48vufe3q7f8JFxlfTc
ulZIDptWi6PMvlZYCBkh1uzTKcihZR7MCoxgW0PJLO1LX5elTJsZ/GTc5oe/GZXkTPT
qwj1EQIlVn0dpZtt4jIzfC2RrO2IRieR2rozeQM=
Received: from dvr.ph.sladkovi.eu (ip-84-42-150-218.net.upcbroadband.cz 
[84.42.150.218])by email-relay2.ng.seznam.cz (Seznam SMTPD 
1.2.15-6@18976) with ESMTP;  Mon, 20 Feb 2012 08:34:35 +0100 (CET)  
Content-Type: multipart/mixed; boundary1029508565==
MIME-Version: 1.0
From: rzro...@seznam.cz
To: msla...@volny.cz
Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?= 
X-DKIM-Status: fail
X-Virus: no (m2.volny.internal - Mon, 20 Feb 2012 08:34:40 +0100 (CET))
X-Spam: no (m2.volny.internal - Mon, 20 Feb 2012 08:34:41 +0100 (CET))
X-Received-Date: Mon, 20 Feb 2012 08:34:42 +0100 (CET)

--===1029508565==:Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Content-Transfer-Encoding: base64
X-Smtpd: 1.2.15-6@18976
X-Seznam-User: rzro...@seznam.cz
X-Session: 11
X-Country: CZ
X-Virus-Info:clean
X-Seznam-SPF:neutral
X-Seznam-DomainKeys:unknown

w7pwxJtsIMSPw6FiZWxza8OpIMOzZHk=

--===1029508565==--

Although no attachment argument was given, the client says that message has an 
attachment of unknown type and that message does not contain any text at all. 
See that message part header :Content-Type: text/plain; charset=utf-8 is part 
of the message part boundary instead of beeing inside of the message part.

When I change the code of function to generate the subject manually and add it 
via add_header like this:

def sendMail (fromAddr, toAddr, subject, body = '', attachment = ''):
message = email.mime.multipart.MIMEMultipart()
message.add_header('From',fromAddr)
message.add_header('To',toAddr)

base64Subject = base64.b64encode(subject.encode('utf-8')).decode()
encodedSubject = '=?UTF-8?B?{0}?='.format(base64Subject)
message.add_header('Subject',encodedSubject)

if (body != ''):
msgPart = email.mime.text.MIMEText(body,'plain','utf-8')
message.attach(msgPart)
if (attachment != ''):
if os.path.exists(attachment) == True:
filename = attachment.rpartition(os.sep)[2]
fp = open(attachment,'rb')
msgPart = email.mime.base.MIMEBase('application','octet-stream')
msgPart.set_payload(fp.read())
fp.close()
email.encoders.encode_base64(msgPart)

msgPart.add_header('Content-Disposition','attachment',filename=filename)
message.attach(msgPart)
if smtpPort == 25:
smtpCon = smtplib.SMTP

[issue14047] UTF-8 Email Header

2012-02-20 Thread Michal Sladek

Michal Sladek mic...@sladkovi.eu added the comment:

Hello Martin!

Thanks for your kind words and for giving me hints how to fill the bug
report properly. I hope this time it will be accepted (ID 14062).

Best regards

Michal

Dne 19. února 2012 19:59 Martin v. Löwis rep...@bugs.python.org napsal(a):

 Martin v. Löwis mar...@v.loewis.de added the comment:

 Michal, it's your wording of your report, and also some of the contents that 
 caused Eric's reaction. When you conclude with Am I doing something wrong?, 
 then your message is *not* a bug report, but a question for help (namely, you 
 are asking somebody to find out whether you did something wrong).

 Please structure bug reports as follows:
 1. this is what I did
 2. this is what happened
 3. this is what I expected to happen instead

 Your report gives hints at 1, but neither discusses 2 or 3. I.e. you say what 
 code you write, but you did not say (AFAICT) what parameters you passed to 
 the function. And you did not say what happened when you passed the 
 parameters.

 This is important information, as the first step of us is to reproduce the 
 bug report, i.e. try out all your steps and see whether the same happens also 
 when we do it (which often enough is not the case).

 Since this bug report is already filled with unrelated meta-discussion, 
 please submit a new bug report in the style I explain above.

 --
 nosy: +loewis

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue14047
 ___

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14047
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14047] UTF-8 Email Header

2012-02-19 Thread Michal Sladek

Michal Sladek mic...@sladkovi.eu added the comment:

Hello Eric!

I believe that there is a bug which prevents adding UTF-8 encoded
suject to multipart message properly. But because I am not a
programmer, I admin I might be wrong. So if you are a programmer and
you don't see any obvious mistake in my example code, open that bug
report again. Because in my opinion that code should work properly and
it does not.

Best regards

Michal

Dne 19. února 2012 9:31 Éric Araujo rep...@bugs.python.org napsal(a):

 Éric Araujo mer...@netwok.org added the comment:

 Hello Michal.  This bug tracker is used to collect bug reports and feature 
 requests, not for general support.  Please use the python-list mailing list, 
 also known as the comp.lang.python newgroup, or #python on IRC (Freenode), or 
 Stack Overflow, or any other discussion venue.  If you do find that the 
 Python docs are erroneous, misleading or incomplete, then feel free to say so 
 and we’ll reopen this report to see how we can improve the docs.  Cheers!

 --
 nosy: +eric.araujo
 resolution:  - invalid
 stage:  - committed/rejected
 status: open - closed
 type: behavior -

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue14047
 ___

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14047
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14047] UTF-8 Email Header

2012-02-19 Thread Michal Sladek

Michal Sladek mic...@sladkovi.eu added the comment:

I guess you don't understand me.

My script works properly. I don't need any help with it. OK? I have
found a workaround and I am happy with it for now. But I think, there
is a problem in current version of Python language.

Now, what should I do to report the bug with adding UTF-8 encoded
header? I described the problem, I submitted the example code. How can
I draw developers attention to the problem when you close the bug?

Dne 19. února 2012 9:52 Éric Araujo rep...@bugs.python.org napsal(a):

 Éric Araujo mer...@netwok.org added the comment:

 Sorry, I cannot right now take the time to go through the doc and your code.  
 Please use any of the friendly venues I listed in my previous message to get 
 help on your code.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue14047
 ___

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14047
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14047] UTF-8 Email Header

2012-02-17 Thread Michal Sladek

New submission from Michal Sladek mic...@sladkovi.eu:

Hello!

I am not a programmer so I appologize if I just don't understand the docs 
properly. I need to wirte a function which sends emails with utf-8 encoded 
subject and body. I tried something like this:

def sendMail (fromAddr, toAddr, subject, body = '', attachment = ''):
message = email.mime.multipart.MIMEMultipart()
message.add_header('From',fromAddr)
message.add_header('To',toAddr)
message['Subject'] = email.header.Header(subject,'utf-8')
if (body != ''):
msgPart = email.mime.text.MIMEText(body,'plain','utf-8')
message.attach(msgPart)
if (attachment != ''):
if os.path.exists(attachment) == True:
filename = attachment.rpartition(os.sep)[2]
fp = open(attachment,'rb')
msgPart = email.mime.base.MIMEBase('application','octet-stream')
msgPart.set_payload(fp.read())
fp.close()
email.encoders.encode_base64(msgPart)

msgPart.add_header('Content-Disposition','attachment',filename=filename)
message.attach(msgPart)
if smtpPort == 25:
smtpCon = smtplib.SMTP(smtpSrv,smtpPort)
else:
smtpCon = smtplib.SMTP_SSL(smtpSrv,smtpPort)
if (smtpUser != '') and (smtpPass != ''):
smtpCon.login(smtpUser,smtpPass)
smtpCon.send_message(message,mail_options=['UTF8SMTP','8BITMIME'])
logger.info (_('Sent mail to: {0} with subject: 
{1}').format(toAddr,subject))
smtpCon.quit()

I realized that adding email subject this way somehow brokes the message, so 
that the plain text body of the message is not visible on receiving side. I had 
to chnage the code like this:

base64Subject = base64.b64encode(subject.encode('utf-8')).decode()
encodedSubject = '=?UTF-8?B?{0}?='.format(base64Subject)
message.add_header('Subject',encodedSubject)

Am I doing something wrong?

--
messages: 153634
nosy: msladek
priority: normal
severity: normal
status: open
title: UTF-8 Email Header
type: behavior
versions: Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14047
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com