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

email message.get_params() and related methods sometimes fail. #49527

Closed
msapiro mannequin opened this issue Feb 16, 2009 · 4 comments
Closed

email message.get_params() and related methods sometimes fail. #49527

msapiro mannequin opened this issue Feb 16, 2009 · 4 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@msapiro
Copy link
Mannequin

msapiro mannequin commented Feb 16, 2009

BPO 5277
Nosy @warsaw, @msapiro, @bitdancer
Files
  • message.patch: Patch to not count quoted quotes in _parseparams()
  • issue5277.patch: email.get_param() properly escapes quotations.
  • 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-04-14.19:08:09.054>
    created_at = <Date 2009-02-16.04:35:14.042>
    labels = ['easy', 'type-bug', 'library']
    title = 'email message.get_params() and related methods sometimes fail.'
    updated_at = <Date 2010-04-14.19:08:09.053>
    user = 'https://github.com/msapiro'

    bugs.python.org fields:

    activity = <Date 2010-04-14.19:08:09.053>
    actor = 'r.david.murray'
    assignee = 'r.david.murray'
    closed = True
    closed_date = <Date 2010-04-14.19:08:09.054>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2009-02-16.04:35:14.042>
    creator = 'msapiro'
    dependencies = []
    files = ['13105', '16426']
    hgrepos = []
    issue_num = 5277
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['82215', '100377', '102976', '103140']
    nosy_count = 5.0
    nosy_names = ['barry', 'msapiro', 'rcoyner', 'r.david.murray', 'l0nwlf']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5277'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @msapiro
    Copy link
    Mannequin Author

    msapiro mannequin commented Feb 16, 2009

    The message method get_params() and the related get_param() and
    get_filename() do not properly decode an RFC 2231 encoded parameter such
    as the following:

    Content-Disposition: inline;
    filename*0="Re: [Mailman-Users] Messages shunted with \"TypeError: ";
    filename*1="decodingUnicode is not supported\".eml"

    This is because the message helper function _parseparams() mistakenly
    thinks the second semicolon is inside a quoted string because it counts
    the quoted (escaped) quote and sees an odd number.

    The attached patch will fix this.

    @msapiro msapiro mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 16, 2009
    @bitdancer bitdancer added the easy label Jan 8, 2010
    @rcoyner
    Copy link
    Mannequin

    rcoyner mannequin commented Mar 4, 2010

    Okay, bug confirmed:

    >>> m = email.message_from_string('Content-Disposition: inline; filename*0="foo \\"test"; filename*1="\\"bar"')
    >>> m.get_filename()
    'foo "test"; filename*1=""bar'

    And here is the result with the patch applied:

    >>> m = email.message_from_string('Content-Disposition: inline; filename*0="foo \\"test"; filename*1="\\"bar"')
    >>> m.get_filename()
    'foo "test"bar'

    Attached a patch. Unit test included.

    @bitdancer bitdancer self-assigned this Mar 4, 2010
    @l0nwlf
    Copy link
    Mannequin

    l0nwlf mannequin commented Apr 12, 2010

    According to RFC2231 the named disposition (content disposition field) is provided by the MIME mechanism. The encoded parameter like the following:

    Content-Disposition: inline;
    filename*0="Re: [Mailman-Users] Messages shunted with \"TypeError: ";
    filename*1="decodingUnicode is not supported\".eml"

    is not behaving the way it should be.
    The patch by rcoyner seems fine to me as it rectifies the wrong behaviour of _parseparam i.e. the counting issue of nested 'double quotes' and clears the unit tests.

    @bitdancer
    Copy link
    Member

    Thanks Mark and Ryan for the patches, and Shashwat for the review. Committed to trunk in r80062, 2.6 in r80063, py3k in r80078, and 3.1 in r80079.

    @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
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant