Skip to content

email.Header encode() unicode P2.6 #42687

Closed

Description

@xnovakj
mannequin
BPO 1379416
Nosy @warsaw, @ezio-melotti, @bitdancer
Files
  • header_encode_test.diff
  • header_charset_fix.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/bitdancer'
    closed_at = <Date 2010-12-27.19:18:53.320>
    created_at = <Date 2005-12-13.11:09:30.000>
    labels = ['type-bug', 'library']
    title = 'email.Header encode() unicode P2.6'
    updated_at = <Date 2010-12-27.19:18:53.318>
    user = 'https://bugs.python.org/xnovakj'

    bugs.python.org fields:

    activity = <Date 2010-12-27.19:18:53.318>
    actor = 'r.david.murray'
    assignee = 'r.david.murray'
    closed = True
    closed_date = <Date 2010-12-27.19:18:53.320>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2005-12-13.11:09:30.000>
    creator = 'xnovakj'
    dependencies = []
    files = ['18652', '18653']
    hgrepos = []
    issue_num = 1379416
    keywords = ['patch']
    message_count = 6.0
    messages = ['27063', '84003', '97359', '114997', '115009', '124724']
    nosy_count = 5.0
    nosy_names = ['barry', 'exarkun', 'xnovakj', 'ezio.melotti', 'r.david.murray']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1379416'
    versions = ['Python 2.7']

    Activity

    1. xnovakj commented on Dec 13, 2005

      xnovakjmannequin
      MannequinAuthor

      Python: 2.4
      Module: email.Header
      Method: encode()
      In some cases returns unicode (example on line 5)

      1>> from email.Header import Header

      2>> Header(unicode('abcá','iso-8859-2'),'utf-8').encode()
      '=?utf-8?b?YWJjw6E=?='

      3>> Header('abc','utf-8').encode()
      '=?utf-8?q?abc?='

      4>> Header(u'abc','utf-8').encode()
      'abc' ???

      5>> Header('abc','iso-8859-2').encode()
      u'=?iso-8859-2?q?abc?=' (P2.4)

      6>> Header('abc','iso-8859-2').encode()
      '=?iso-8859-2?q?abc?=' (P2.3)

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Mar 20, 2009
    3. xnovakj commented on Mar 23, 2009

      xnovakjmannequin
      MannequinAuthor

      I made some new tests in P2.6.1

      >> import email.charset

      >>> c=email.charset.Charset('utf-8')
      >>> print c.input_charset, type(c.input_charset)
      utf-8 <type 'unicode'>
      >>> print c.output_charset, type(c.output_charset)
      utf-8 <type 'str'>

      but

      >>> c=email.charset.Charset('iso-8859-2')
      >>> print c.input_charset, type(c.input_charset)
      iso-8859-2 <type 'unicode'>
      >>> print c.output_charset, type(c.output_charset)
      iso-8859-2 <type 'unicode'>

      but if you use alias latin-2 it's OK

      >>> c=email.charset.Charset('latin-2')
      >>> print c.input_charset, type(c.input_charset)
      iso-8859-2 <type 'str'>
      >>> print c.output_charset, type(c.output_charset)
      iso-8859-2 <type 'str'>
      >>> 

      Error is here for unicode input-charset:
      self.input_charset->conv->self.output_charset

      module email/charset.py line 219

              if not conv:
                  conv = self.input_charset

      for the charsets where aren't output conversions

      CHARSETS = {
          # input        header enc  body enc output conv
          'iso-8859-1':  (QP,        QP,      None),
          'iso-8859-2':  (QP,        QP,      None),

      and if you don't use alias

      ALIASES = {
          'latin_1': 'iso-8859-1',
          'latin-1': 'iso-8859-1',
          'latin_2': 'iso-8859-2',
          'latin-2': 'iso-8859-2',

      But the realy source of this error is on line 208
      input_charset = unicode(input_charset, 'ascii')

      because this construction returns unicode

      >>> print type(unicode('iso-8859-2','ascii'))
      <type 'unicode'>
    4. changed the title [-]email.Header encode() unicode P2.3xP2.4[/-] [+]email.Header encode() unicode P2.6[/+] on Mar 23, 2009
    5. changed the title [-]email.Header encode() unicode P2.3xP2.4[/-] [+]email.Header encode() unicode P2.6[/+] on Mar 23, 2009
    6. exarkun commented on Jan 7, 2010

      exarkunmannequin
      Mannequin

      Any hope of this being fixed?

    7. assigned and unassigned on May 5, 2010
    8. BreamoreBoy commented on Aug 26, 2010

      BreamoreBoymannequin
      Mannequin

      I believe that RDM is working on this sort of issue as part of email6.

    9. bitdancer commented on Aug 26, 2010

      @bitdancer
      Member

      I've attached a fix and test. I've uploaded them separately since the fix only applies to 2.7, but I want to put the test into 3.x as well.

    10. bitdancer commented on Dec 27, 2010

      @bitdancer
      Member

      Committed to 2.7 in r87515. On second thought there's no reason to forward port the test because Python3 doesn't have the equivalent type-promotion issues.

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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions