@@ -324,6 +324,13 @@ def ch_oneline(headerstr):
324324 # copied and modified from ToDigest.py and Utils.py
325325 # return (string, cset) tuple as check for failure
326326 try :
327+ # Ensure headerstr is a string, not bytes
328+ if isinstance (headerstr , bytes ):
329+ try :
330+ headerstr = headerstr .decode ('utf-8' )
331+ except UnicodeDecodeError :
332+ headerstr = headerstr .decode ('us-ascii' , 'replace' )
333+
327334 d = decode_header (headerstr )
328335 # at this point, we should rstrip() every string because some
329336 # MUA deliberately add trailing spaces when composing return
@@ -341,4 +348,9 @@ def ch_oneline(headerstr):
341348 return oneline .encode (cset , 'replace' ), cset
342349 except (LookupError , UnicodeError , ValueError , HeaderParseError ):
343350 # possibly charset problem. return with undecoded string in one line.
351+ if isinstance (headerstr , bytes ):
352+ try :
353+ headerstr = headerstr .decode ('utf-8' )
354+ except UnicodeDecodeError :
355+ headerstr = headerstr .decode ('us-ascii' , 'replace' )
344356 return '' .join (headerstr .splitlines ()), 'us-ascii'
0 commit comments