Skip to content

MIMEText __init__ does not support Charset instance #60528

Closed

Description

@claudep
mannequin
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']

    Activity

    1. claudep commented on Oct 25, 2012

      claudepmannequin
      MannequinAuthor

      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?

    2. bitdancer commented on Oct 25, 2012

      @bitdancer
      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.

    3. claudep commented on Oct 25, 2012

      claudepmannequin
      MannequinAuthor

      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_.

    4. berkerpeksag commented on Sep 26, 2014

      @berkerpeksag
      Member

      Here's an updated patch.

    5. added
      type-featureA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or error
      on Sep 26, 2014
    6. bitdancer commented on Sep 26, 2014

      @bitdancer
      Member

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

    7. python-dev commented on Sep 26, 2014

      python-devmannequin
      Mannequin

      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

    8. berkerpeksag commented on Sep 26, 2014

      @berkerpeksag
      Member

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

    9. self-assigned this
      on Sep 26, 2014
    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions