B /g^)c@s:ddlZddlZddlZddlZddlmZGdddZeZd%ddZe ded d Z xd D]Z e e e qhWd d Z x d D]Ze dee qWddZe deddZddZddZddZd&ddZeeed'd d!Zeejjed(d#d$Zx eeefD]Zeeeq WdS))N) quoprimimec@s<eZdZddZddZddZddZd d Zd d Zd S)ContentManagercCsi|_i|_dSN) get_handlers set_handlers)selfr,/usr/lib64/python3.7/email/contentmanager.py__init__ szContentManager.__init__cC||j|<dSr)r)rkeyhandlerrrradd_get_handler zContentManager.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_contentcCr r)r)rZtypekeyr rrradd_set_handlerrzContentManager.add_set_handlercOs>|dkrtd|||}||||f||dS)NZ multipartz"set_content not valid on multipart)rZ TypeError_find_set_handlerZ clear_content)rrobjrrr rrr set_contents   zContentManager.set_contentc Csd}xt|jD]}||jkr(|j|S|j}t|dd}|rLd||fn|}|dkr\|}||jkrp|j|S||jkr|j|S|j}||jkr|j|SqWd|jkr|jdSt|dS)N __module__rZ.)ZtypeZ__mro__r __qualname__Zgetattrjoin__name__r) rrrZfull_path_for_errortypZqnameZmodnameZ full_pathnamerrrr's&          z ContentManager._find_set_handlerN) rrrr r rrrrrrrrrs   rreplacecCs&|jdd}|dd}|j||dS)NTdecodecharsetZASCII)errors) get_payloadZ get_paramr#)rr%Zcontentr$rrrget_text_content@s  r'textcCs |jddS)NTr"r&rrrrget_non_text_contentGrr+zaudio image video applicationcCs |dSNrr)r*rrrget_message_contentMrr-zrfc822 external-bodyzmessage/cCst|dSr,)bytesr&r*rrr%get_and_fixup_unknown_message_contentSsr/messagec sd||f|d<|rt|dds<|jfdd|D}y,x&|D]}|jrX|jd|||j<qDWWn@tjjk r}ztd |j |jd|Wdd}~XYnXdS) Nz/z Content-Typerr csg|]}j|gqSr)Zheader_factoryZheader_source_parse).0headerZmprrz dsz _prepare_set..zInvalid header: {})policy) rZhasattrr4Zdefectsr emailr%Z HeaderDefect ValueErrorformatZfold)rrsubtypeheadersr2Zexcrr3r _prepare_set_s   r:cCs||dkr|dk rd}|dk r$||d<|dk r>|jd|ddd|dk rN||d<|dk rxx |D]\}}|||q`WdS)NZ attachmentzContent-DispositionfilenameT)r2r!z Content-ID) set_paramZitems)r dispositionr;cidparamsr Zvaluerrr _finalize_setpsr@cCsZg}|dd}x>tdt||D]*}||||}|t|dq"Wd|S)Niirasciir)ZrangelenZappendbinascii b2a_base64r#r)datamax_line_lengthZ encoded_linesZunencoded_bytes_per_lineZiZthislinerrr_encode_base64s  rGc s|||}|jdfdd}dd}|dkryd||dfStk r\YnX|jdkrtdd |D|jkrd||dd fS||dd }t |d |j}t |} t |t | krd }nd}t |d kr||fS|dkr ||d} nj|dkr&||dd } nN|dkrJt ||d |j} n*|d krft |||j} ntd||| fS)NrAcs|Srrlineslineseprr embedded_bodyz#_encode_text..embedded_bodycSsd|dS)Ns rHrIrrr normal_bodyrNz!_encode_text..normal_body7bit8bitcss|]}t|VqdSr)rB)r1Zxrrrz sz_encode_text..surrogateescapei zlatin-1base64quoted-printablez$Unknown content transfer encoding {})encodeZ splitlinesrLr#ZUnicodeDecodeErrorZcte_typeZmaxrFrZ body_encoderCrDrBrGr6r7) stringr$cter4rJrMrOZsniffZsniff_qpZ sniff_base64rErrKr _encode_texts@           rXplainutf-8c Csdt|d|| t||||j\}} || |jdtjj||dd||d<t |||||dS)Nr(r$Tr!Content-Transfer-Encoding) r:rXr4 set_payloadr<r5r$ZALIASESZgetr@) rrVr8r$rWr=r;r>r?r9Zpayloadrrrset_text_contents r^rfc822c Cs|dkrtd|dkr@|dkr.td||dkr:dn|}n0|dkrd|dkr^td |d }n |dkrpd }t|d ||||g||d <t|||||dS) NZpartialz4message/partial is not supported for Message objectsr_)NrPrQbinaryz*message/rfc822 parts do not support cte={}rQz external-body)NrPz1message/external-body parts do not support cte={}rPr0r\)r6r7r:r]r@) rr0r8rWr=r;r>r?r9rrrset_message_contents$   rarSc Cst|||| |dkr(t||jjd}nN|dkrNtj|dddd}|d}n(|dkrb|dn|d krv|dd }||||d <t |||||dS) NrS)rFrTFT)Zistextr2Z quotetabsrArP)rQr`rRr\) r:rGr4rFrCZb2a_qpr#rUr]r@) rrErr8rWr=r;r>r?r9rrrset_bytes_contents    rbr[)rYrZNNNNNN)r_NNNNNN)rSNNNNN)rCZ email.charsetr5Z email.messageZ email.errorsrrZraw_data_managerr'r r+Zsplitrr-r8r/r:r@rGrXr^rZstrrar0ZMessagerbr.Z bytearrayZ memoryviewrrrrrZsD 6   '