Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

email.utils.decode_params not supporting params that contain hyphens #130110

Open
Labels
stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error
@mholschbach

Description

@mholschbach

Bug report

Bug description:

The decode_params function from email.utils is failing to combine the parameters from multiple lines if the name of the parameter includes a hyphen "-". Maybe it's this regex which is too strict:

rfc2231_continuation=re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$',
re.ASCII)

The decode_params function always ignores the first 2-tuple but the first parameter in a SMTP header can already be a multiline parameter. I don't see a reason why the first array element is skipped here:

params is a sequence of 2-tuples containing (param name, string value).
"""
new_params= [params[0]]
# Map parameter's name to a list of continuations. The values are a
# 3-tuple of the continuation number, the string value, and a flag
# specifying whether a particular segment is %-encoded.
rfc2231_params= {}
forname,valueinparams[1:]:

my code to reproduce:

fromemail.utilsimportdecode_paramsdecode_params([('parameter-name*0*',"utf-8''start;"),("parameter-name*1*","-middle-;"),("parameter-name*2*","end;")])# parameter-name is not combined:#  [('parameter-name*0*', "utf-8''start;"), ('parameter-name*1*', '"-middle-;"'), ('parameter-name*2*', '"end;"')]decode_params([('parametername*0*',"utf-8''start;"),("parametername*1*","-middle-;"),("parametername*2*","end;")])# parametername is combined but not the first 2-tuple:# [('parametername*0*', "utf-8''start;"), ('parametername', (None, None, '"-middle-;end;"'))]decode_params([("ignored","ignored"),('parametername*0*',"utf-8''start;"),("parametername*1*","-middle-;"),("parametername*2*","end;")])# parametername is now combined as expected, the additional entry can be ignored when processing the output# [('ignored', 'ignored'), ('parametername', ('utf-8', '', '"start;-middle-;end;"'))]

Thank you
Michael

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp