U e5d)@s.ddlZddlZddlZddlZddlmZGdddZeZd%ddZe ded d Z d D]Z e e e qfd d Z d D]Ze dee qddZe deddZddZddZddZd&ddZeeed'd d!Zeejjed(d#d$ZeeefD]ZeeeqdS))N) quoprimimec@s<eZdZddZddZddZddZd d Zd d Zd S)ContentManagercCsi|_i|_dSN) get_handlers set_handlers)selfr,/usr/lib64/python3.8/email/contentmanager.py__init__ szContentManager.__init__cCs||j|<dSr)r)rkeyhandlerrrr add_get_handler szContentManager.add_get_handlercOs||}||jkr(|j||f||S|}||jkrP|j||f||Sd|jkrp|jd|f||St|dS)N)Zget_content_typerget_content_maintypeKeyError)rmsgargskwZ content_typemaintyperrr get_contents   zContentManager.get_contentcCs||j|<dSr)r)rZtypekeyr rrr add_set_handlerszContentManager.add_set_handlercOs>|dkrtd|||}||||f||dS)NZ multipartz"set_content not valid on multipart)r TypeError_find_set_handlerZ clear_content)rrobjrrr rrr set_contents   zContentManager.set_contentc Csd}t|jD]}||jkr*|j|S|j}t|dd}|rNd||fn|}|dkr^|}||jkrv|j|S||jkr|j|S|j}||jkr|j|Sqd|jkr|jdSt|dS)N __module__r.)type__mro__r __qualname__getattrjoin__name__r) rrrZfull_path_for_errortypZqnamemodname full_pathnamerrr r's&       z ContentManager._find_set_handlerN) r"rrr r rrrrrrrr rs   rreplacecCs&|jdd}|dd}|j||dS)NTdecodecharsetASCII)errors) get_payloadZ get_paramr))rr,Zcontentr*rrr get_text_content@s  r.textcCs |jddS)NTr(r-rrrr get_non_text_contentGsr2zaudio image video applicationcCs |dSNrr0r1rrr get_message_contentMsr4zrfc822 external-bodyzmessage/cCst|dSr3)bytesr-r1rrr %get_and_fixup_unknown_message_contentSsr6messagec sd||f|d<|rt|dds<|jfdd|D}z(|D]}|jrV|jd|||j<qBWn@tjjk r}ztd |j |jd|W5d}~XYnXdS) N/z Content-Typerr&csg|]}j|gqSr)Zheader_factoryZheader_source_parse).0headerZmprr dsz _prepare_set..zInvalid header: {})policy) r!hasattrr=Zdefectsr&emailr,Z HeaderDefect ValueErrorformatZfold)rrsubtypeheadersr:excrr;r _prepare_set_s$   rEcCsx|dkr|dk rd}|dk r$||d<|dk r>|jd|ddd|dk rN||d<|dk rt|D]\}}|||q^dS)NZ attachmentzContent-DispositionfilenameT)r:r'z Content-ID) set_paramitems)r dispositionrFcidparamsr valuerrr _finalize_setpsrMcCsVg}|dd}tdt||D]*}||||}|t|dq d|S)Nrasciir)rangelenappendbinascii b2a_base64r)r!)datamax_line_lengthZ encoded_linesZunencoded_bytes_per_lineiZthislinerrr _encode_base64s  rYc s||}|jdfdd}dd}|dkrtdd|Ddd |jkrzd ||dfWStk rzYnX|jd krd ||dd fS||dd }t |d|j}t |} t |t | krd}nd}t |d kr||fS|d kr||d} nj|d kr,||dd } nN|dkrPt ||d|j} n*|dkrlt |||j} ntd||| fS)NrPcs|Srr!lineslineseprr embedded_bodyz#_encode_text..embedded_bodycSsd|dS)N rZr[rrr normal_bodyr`z!_encode_text..normal_bodycss|]}t|VqdSr)rR)r9xrrr sz_encode_text..r)default7bit8bitsurrogateescape zlatin-1base64quoted-printablez$Unknown content transfer encoding {})encode splitlinesr^maxrWr)UnicodeDecodeErrorZcte_typerZ body_encoderTrUrRrYr@rA) stringr*cter=r\r_rbZsniffZsniff_qpZ sniff_base64rVrr]r _encode_textsD          rrplainutf-8c Csdt|d|| t||||j\}} || |jdtjj||dd||d<t |||||dS)Nr/r*T)r'Content-Transfer-Encoding) rErrr= set_payloadrGr?r*ZALIASESgetrM) rrprBr*rqrIrFrJrKrCZpayloadrrr set_text_contents rxrfc822c Cs|dkrtd|dkr@|dkr.td||dkr:dn|}n0|dkrd|dkr^td |d }n |dkrpd }t|d ||||g||d <t|||||dS) Npartialz4message/partial is not supported for Message objectsry)Nrfrgbinaryz*message/rfc822 parts do not support cte={}rgz external-body)Nrfz1message/external-body parts do not support cte={}rfr7ru)r@rArErvrM) rr7rBrqrIrFrJrKrCrrr set_message_contents( r|rjc Cst|||| |dkr(t||jjd}nN|dkrNtj|dddd}|d}n(|dkrb|dn|d krv|dd }||||d <t |||||dS) Nrj)rWrkFT)istextr:Z quotetabsrPrf)rgr{rhru) rErYr=rWrTZb2a_qpr)rlrvrM) rrVrrBrqrIrFrJrKrCrrr set_bytes_contents    r~)r')rsrtNNNNNN)ryNNNNNN)rjNNNNN)rTZ email.charsetr?Z email.messageZ email.errorsrrZraw_data_managerr.r r2splitrr4rBr6rErMrYrrrxrstrr|r7ZMessager~r5 bytearray memoryviewr#rrrr s^ 6     '