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

smtplib.send_message mishandles 8BITMIME RFC 6152 #76995

Open
segevfiner mannequin opened this issue Feb 10, 2018 · 7 comments
Open

smtplib.send_message mishandles 8BITMIME RFC 6152 #76995

segevfiner mannequin opened this issue Feb 10, 2018 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@segevfiner
Copy link
Mannequin

segevfiner mannequin commented Feb 10, 2018

BPO 32814
Nosy @warsaw, @bitdancer, @scorphus, @segevfiner
PRs
  • bpo-32814: Handle 8BITMIME availabilty in smtplib.SMTP.send_message #8303
  • 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 = None
    created_at = <Date 2018-02-10.10:46:21.137>
    labels = ['3.7', '3.8', 'type-bug', 'library', 'expert-email']
    title = 'smtplib.send_message mishandles 8BITMIME RFC 6152'
    updated_at = <Date 2018-07-28.18:03:39.192>
    user = 'https://github.com/segevfiner'

    bugs.python.org fields:

    activity = <Date 2018-07-28.18:03:39.192>
    actor = 'Segev Finer'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'email']
    creation = <Date 2018-02-10.10:46:21.137>
    creator = 'Segev Finer'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32814
    keywords = ['patch']
    message_count = 7.0
    messages = ['311947', '311960', '322428', '322438', '322442', '322543', '322582']
    nosy_count = 4.0
    nosy_names = ['barry', 'r.david.murray', 'scorphus', 'Segev Finer']
    pr_nums = ['8303']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32814'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @segevfiner
    Copy link
    Mannequin Author

    segevfiner mannequin commented Feb 10, 2018

    According to https://tools.ietf.org/html/rfc6152 you should only send an 8bit email body when the server advertises 8BITMIME in the EHLO, and you should declare it with BODY=8BITMIME in the MAIL command.

    The default cte_type is 8bit for the new default email policy which is what will be used by smtplib.send_message when it calls BytesGenerator.flatten, but it will not set BODY=8BITMIME even if the message has any 8-bit characters. It will only set BODY=8BITMIME if the message uses any utf-8 mail/from addresses. This means that a message with ASCII addresses and an 8-bit utf-8 body will be sent without BODY=8BITMIME (I think that's actually quite common).

    What should be done is checking if the server advertises 8BITMIME, and if it doesn't use cte_type=7bit; if it does we should set BODY=8BITMIME if the policy is using cte_type=8bit.

    I don't know whether any real email server chokes on this. But it's best to follow the RFC, I think.

    @segevfiner segevfiner mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error labels Feb 10, 2018
    @bitdancer
    Copy link
    Member

    I agree. I'll be happy to review a patch proposal. Not sure how I overlooked this when I implemented send_message, but that was early enough in my reading of all the RFC that I may have just missed that detail :(

    @bitdancer
    Copy link
    Member

    OK, the bpo-32663 test fix I mentioned in the review is merged.

    @segevfiner
    Copy link
    Mannequin Author

    segevfiner mannequin commented Jul 26, 2018

    OK, the bpo-32663 test fix I mentioned in the review is merged.

    Yeah. I already merged it in.

    @segevfiner
    Copy link
    Mannequin Author

    segevfiner mannequin commented Jul 26, 2018

    Merged into the PR that is.

    @scorphus
    Copy link
    Mannequin

    scorphus mannequin commented Jul 28, 2018

    This is just to note that I'm investigating this as part of the CPython sprint in EuroPython.

    @segevfiner
    Copy link
    Mannequin Author

    segevfiner mannequin commented Jul 28, 2018

    @scorphus Note that I made a PR for this: PR 8303

    @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
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant