Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Open
Description
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:
Lines 392 to 393 in9d1e668
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:
Lines 398 to 405 in9d1e668
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