You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
email.header: folding a long header takes quadratic time #161284
email.header.Header.encode() is quadratic in the number of words on an unfolded line: _Accumulator.__len__() sums all its parts on every call, and _ValueFormatter._append_chunk() calls it after every word.
Message.as_string() and mailbox write headers unfolded (maxheaderlen=0) with the default compat32 policy, so one long header is enough. A message with a 160 KB Subject: takes about 5 s in mailbox.mbox.add().
importemail, timemsg=email.message_from_string('Subject: '+'word '*8000+'\n\nbody\n')
start=time.perf_counter()
msg.as_string()
print(f'{time.perf_counter() -start:.3f} s') # 0.806 s on main, 0.004 s with the fix
Same kind of problem as gh-136063, but in the compat32email.header code.
Activity