Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8 Email Header #58255

Closed
msladek mannequin opened this issue Feb 18, 2012 · 8 comments
Closed

UTF-8 Email Header #58255

msladek mannequin opened this issue Feb 18, 2012 · 8 comments

Comments

@msladek
Copy link
Mannequin

msladek mannequin commented Feb 18, 2012

BPO 14047
Nosy @loewis, @merwok

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-02-19.08:31:41.114>
created_at = <Date 2012-02-18.07:23:28.166>
labels = ['invalid']
title = 'UTF-8 Email Header'
updated_at = <Date 2012-02-20.23:58:32.791>
user = 'https://bugs.python.org/msladek'

bugs.python.org fields:

activity = <Date 2012-02-20.23:58:32.791>
actor = 'eric.araujo'
assignee = 'none'
closed = True
closed_date = <Date 2012-02-19.08:31:41.114>
closer = 'eric.araujo'
components = []
creation = <Date 2012-02-18.07:23:28.166>
creator = 'msladek'
dependencies = []
files = []
hgrepos = []
issue_num = 14047
keywords = []
message_count = 8.0
messages = ['153634', '153672', '153675', '153676', '153679', '153717', '153767', '153819']
nosy_count = 3.0
nosy_names = ['loewis', 'eric.araujo', 'msladek']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue14047'
versions = ['Python 3.2']

@msladek
Copy link
Mannequin Author

msladek mannequin commented Feb 18, 2012

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?

@msladek msladek mannequin added the type-bug An unexpected behavior, bug, or error label Feb 18, 2012
@merwok
Copy link
Member

merwok commented Feb 19, 2012

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!

@merwok merwok closed this as completed Feb 19, 2012
@merwok merwok added invalid and removed type-bug An unexpected behavior, bug, or error labels Feb 19, 2012
@msladek
Copy link
Mannequin Author

msladek mannequin commented Feb 19, 2012

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 <report@bugs.python.org> napsal(a):

Éric Araujo <merwok@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 <report@bugs.python.org>
<http://bugs.python.org/issue14047\>


@merwok
Copy link
Member

merwok commented Feb 19, 2012

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.

@msladek
Copy link
Mannequin Author

msladek mannequin commented Feb 19, 2012

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 <report@bugs.python.org> napsal(a):

Éric Araujo <merwok@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 <report@bugs.python.org>
<http://bugs.python.org/issue14047\>


@loewis
Copy link
Mannequin

loewis mannequin commented Feb 19, 2012

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.

@msladek
Copy link
Mannequin Author

msladek mannequin commented Feb 20, 2012

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 <report@bugs.python.org> napsal(a):

Martin v. Löwis <martin@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 <report@bugs.python.org>
<http://bugs.python.org/issue14047\>


@merwok
Copy link
Member

merwok commented Feb 20, 2012

I had written a message which read much like Martin’s and wanted to reopen this report, but apparently my flaky connection did not let it go through and now it’s lost. My apologies for not understanding your report for what it was, and thanks for persevering.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant