a  zeB@sngdZddlmZddlZddlZddlmZddlmZdZ dZ dZ d Z d Z d Zd Ze e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfd e e dfe e dfe ddfe ddfe ddfe e dfe e dfdZdddddddddddddddddddddddd dZdd dd!Zd,d"d#Zd$d%Zd&d'Zd(d)ZGd*d+d+ZdS)-)Charset add_alias add_charset add_codec)partialN)errors)encode_7or8bitus-asciiz unknown-8bit)NNN iso-2022-jputf-8) iso-8859-1 iso-8859-2 iso-8859-3 iso-8859-4 iso-8859-9 iso-8859-10 iso-8859-13 iso-8859-14 iso-8859-15 iso-8859-16z windows-1252Zvisciir big5gb2312euc-jp shift_jisrzkoi8-rrrrrrrrrrrrzks_c_5601-1987rzeuc-kr)latin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10cp949euc_jpeuc_krascii eucgb2312_cnbig5_tw)rrr cCs"|tkrtd|||ft|<dS)Nz!SHORTEST not allowed for body_enc)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr+A/opt/bitninja-python-dojo/embedded/lib/python3.9/email/charset.pyrmsrcCs |t|<dSN)ALIASES)aliasZ canonicalr+r+r,rsrcCs |t|<dSr-) CODEC_MAP)r)Z codecnamer+r+r,rsrcCs"|tkr|ddS||SdS)Nr#surrogateescape) UNKNOWN8BITencode)stringcodecr+r+r,_encodes r6c@sXeZdZefddZddZddZddZd d Zd d Z d dZ ddZ ddZ dS)rcCsz$t|tr|dn t|d}Wnty@t|Yn0|}t|||_ t |j t t df\}}}|s||j }||_ ||_t|||_t|j |j |_t|j|j|_dS)Nr#) isinstancestrr3 UnicodeErrorrZ CharsetErrorlowerr.get input_charsetr(r&BASE64header_encoding body_encodingr*r0Z input_codec output_codec)selfr<ZhencZbencconvr+r+r,__init__s,    zCharset.__init__cCs |jSr-)r<r:rAr+r+r,__repr__szCharset.__repr__cCst|t|kSr-)r8r:)rAotherr+r+r,__eq__szCharset.__eq__cCs$|jtkrdS|jtkrdStSdS)Nzquoted-printablebase64)r?QPr=rrDr+r+r,get_body_encodings   zCharset.get_body_encodingcCs |jp |jSr-)r*r<rDr+r+r,get_output_charsetszCharset.get_output_charsetcCs6|jpd}t||}||}|dur*|S|||S)Nr )r@r6 _get_encoder header_encode)rAr4r5 header_bytesencoder_moduler+r+r,rMs   zCharset.header_encodecCs |jpd}t||}||}t|j|d}|}t|t}g} g} t||} |D]} | | t | } | t| |}|| krX| | s| s| dn.| rdnd}t | }t||}| ||| g} t||} qXt | }t||}| ||| S)Nr )r) r)r@r6rLrrMrKlenRFC2047_CHROME_LENnextappend EMPTYSTRINGjoin header_lengthpop)rAr4Z maxlengthsr5rNrOencoderr)extralinesZ current_linemaxlen characterZ this_linelength separatorZ joined_liner+r+r,header_encode_lines*s6             zCharset.header_encode_linescCs`|jtkrtjS|jtkr tjS|jtkrXtj|}tj|}||krPtjStjSndSdSr-)r>r=email base64mimerI quoprimimer&rW)rArNZlen64Zlenqpr+r+r,rLhs     zCharset._get_encodercCs|s|S|jtur4t|tr(||j}tj|S|jt urjt|trT||j}| d}tj |St|tr||j d}|SdS)Nlatin1r#) r?r=r7r8r3r*rarb body_encoderIdecoderc)rAr4r+r+r,rews           zCharset.body_encodeN) __name__ __module__ __qualname__DEFAULT_CHARSETrCrErGrJrKrMr`rLrer+r+r+r,rs, !>r)NNN)__all__ functoolsrZemail.base64mimeraZemail.quoprimimerZemail.encodersrrIr=r&rRrjr2rUr(r.r0rrrr6rr+r+r+r,s