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

MIMEText __init__ does not support Charset instance #60528

Closed
claudep mannequin opened this issue Oct 25, 2012 · 7 comments
Closed

MIMEText __init__ does not support Charset instance #60528

claudep mannequin opened this issue Oct 25, 2012 · 7 comments
Assignees
Labels
topic-email type-feature A feature request or enhancement

Comments

@claudep
Copy link
Mannequin

claudep mannequin commented Oct 25, 2012

BPO 16324
Nosy @warsaw, @bitdancer, @berkerpeksag
Files
  • issue16324-1.diff: Allow Charset to be passed to MIMEText
  • issue16324_v2.diff
  • 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 = 'https://github.com/berkerpeksag'
    closed_at = <Date 2014-09-26.21:58:57.085>
    created_at = <Date 2012-10-25.15:49:32.881>
    labels = ['type-feature', 'expert-email']
    title = 'MIMEText __init__ does not support Charset instance'
    updated_at = <Date 2014-09-26.21:58:57.084>
    user = 'https://bugs.python.org/claudep'

    bugs.python.org fields:

    activity = <Date 2014-09-26.21:58:57.084>
    actor = 'berker.peksag'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2014-09-26.21:58:57.085>
    closer = 'berker.peksag'
    components = ['email']
    creation = <Date 2012-10-25.15:49:32.881>
    creator = 'claudep'
    dependencies = []
    files = ['27726', '36737']
    hgrepos = []
    issue_num = 16324
    keywords = ['patch']
    message_count = 7.0
    messages = ['173764', '173793', '173794', '227615', '227617', '227660', '227661']
    nosy_count = 5.0
    nosy_names = ['barry', 'r.david.murray', 'python-dev', 'berker.peksag', 'claudep']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16324'
    versions = ['Python 3.5']

    @claudep
    Copy link
    Mannequin Author

    claudep mannequin commented Oct 25, 2012

    When initializing a MIMEText instance, it might be desirable to set the _charset parameter to a real Charset instance, not only a charset identifier (for example to pass a Charset with customized body_encoding). Unfortunately, this is failing:

    File ".../django/core/mail/message.py", line 128, in __init__
    MIMEText.__init__(self, text, subtype, charset)
    File "/usr/lib/python3.2/email/mime/text.py", line 29, in __init__
    **{'charset': _charset})
    File "/usr/lib/python3.2/email/mime/base.py", line 25, in __init__
    self.add_header('Content-Type', ctype, **_params)
    File "/usr/lib/python3.2/email/message.py", line 475, in add_header
    parts.append(_formatparam(k.replace('_', '-'), v))
    File "/usr/lib/python3.2/email/message.py", line 67, in _formatparam
    if value is not None and len(value) > 0:
    TypeError: object of type 'Charset' has no len()

    It is possible to later call set_charset, but the payload is already encoded (and 'Content-Transfer-Encoding' is set).
    Did I miss anything?

    @claudep claudep mannequin added type-bug An unexpected behavior, bug, or error topic-email labels Oct 25, 2012
    @bitdancer
    Copy link
    Member

    I don't think you missed anything. It doesn't look like this has ever worked, but you'd certainly think it would. The documentation doesn't claim anything about it one way or another. That probably means we should treat it as an enhancement rather than a bug fix, but I'm open to argument on that.

    @claudep
    Copy link
    Mannequin Author

    claudep mannequin commented Oct 25, 2012

    It's fine for me to consider it as an enhancement. The fix might be as simple as replacing **{'charset': _charset} by **{'charset': str(charset)} in MIMEText __init_.

    @berkerpeksag
    Copy link
    Member

    Here's an updated patch.

    @berkerpeksag berkerpeksag added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Sep 26, 2014
    @bitdancer
    Copy link
    Member

    The updated patch looks good to me. Go ahead and commit it.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 26, 2014

    New changeset d43d4d4ebf2c by Berker Peksag in branch 'default':
    Issue bpo-16324: _charset parameter of MIMEText now also accepts email.charset.Charset instances.
    https://hg.python.org/cpython/rev/d43d4d4ebf2c

    @berkerpeksag
    Copy link
    Member

    Thanks for the patch, Claude and thanks for the review, David!

    @berkerpeksag berkerpeksag self-assigned this Sep 26, 2014
    @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
    topic-email type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants