bgdZddlmZmZmZddlmZmZmZm Z dgZ ddl Z ddl Z ddl Z ddlZddlmZmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZejZd Ze jdZ dZ!ddZ"dZ#dZ$Gdde%Z&dS)z8Basic message object for the email package object model.)absolute_importdivisionunicode_literals)listrangestrzipMessageN)BytesIOStringIO) as_native_str)utils)errors)compat32charset)decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]ct|d\}}}|s|dfS||fS)N;)r partitionstrip)paramasepbs o/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/future/backports/email/message.py _splitparamr"sX E $$S))IAsA wwyy$ 7799aggii Tc|t|dkrt|tr4|dz }tj|d|d|d}|d|S |dn2#t $r%|dz }tj|dd }|d|cYSwxYw|st|r|d tj |d S|d|S|S) a~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. If value is a three tuple (charset, language, value), it will be encoded according to RFC2231 rules. If it contains non-ascii characters it will likewise be encoded according to RFC2231 rules, using the utf-8 charset and a null language. Nr*=asciiutf-8z="") len isinstancetuplerencode_rfc2231encodeUnicodeEncodeError tspecialssearchquote)rvaluer0s r _formatparamr2,s# SZZ!^^ eU # # 0 SLE(q58U1XFFE#eeUU+ + 0 W%%%%% 0 0 0 ,UGR@@"'%%//// 0  ,I$$U++ , %u{5'9'9'9'9: :#eeUU+ + s A66,B%$B%c.dt|z}g}|dddkrq|dd}|d}|dkr|dd||dd|z dzrQ|d|dz}|dkr2|dd||dd|z dzQ|dkrt|}|d|}d|vrf|d}|d|dz||dzdz}||||d}|dddkq|S)Nrr"rr'z\"r!r#)rfindcountr(indexrlowerappend)splistendfis r _parseparamr>Ns c!ff A E BQB%3,, abbEffSkkAgg17733//!''%C2H2HHAMg&&cAg&&CAgg17733//!''%C2H2HHAMg 77a&&C dsdG !88 A"1" ##%%+a!gmmoo=A QWWYY cddG BQB%3,, Lrct|tr)|d|dtj|dfStj|S)Nrr"r!)r)r*runquote)r1s r _unquotevaluerAbsI %$Qxq5=q#:#:::}U###rcfeZdZdZefdZeddZd6dZd Z d Z d Z d Z d7dZ d8dZdZdZdZdZdZdZdZdZdZdZdZd8dZdZdZd8dZdZd Zd!Z d"Z!d#Z"d$Z#d%Z$d&Z%d9d)Z& d9d*Z' d:d-Z(d;d.Z)d>>>> ZZ Ibu< H H H $ ***{{}}rc6t|jtS)z6Return True if the message consists of multiple parts.)r)rHrrSs r is_multipartzMessage.is_multiparts$-...rc||_dSNrG)rNrYs r set_unixfromzMessage.set_unixfroms !rc|jSrbrcrSs r get_unixfromzMessage.get_unixfroms ~rc\|j |g|_dS|j|dS)zAdd the given payload to the current payload. The current payload will always be a list of objects after this method is called. If you want to set the payload to a scalar object, use set_payload() instead. N)rHr8)rNpayloads rattachzMessage.attachs5 = $IDMMM M  ) ) ) ) )rNc |r|rdS||jS|j|S|>t|jts$t dt |jz|j}t |dd}t|t rt |}tj |rk| dd}|sR | | ddd}ne#t$r| dd}YnCwxYwn>|r< | d}n%#t$r| d }YnwxYw|s|S|d krtj|S|d krYt#d |\}}|D]}|j|||S|d vr`t-|} t-} t/j | | d| S#t.j$r|cYSwxYwt|t r|S|S)aZReturn a reference to the payload. The payload will either be a list object or a string. If you mutate the list object, you modify the message's payload in place. Optional i returns that index into the payload. Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header (default is False). When True and the message is not a multipart, the payload will be decoded if this header's value is `quoted-printable' or `base64'. If some other encoding is used, or the header is missing, or if the payload has bogus data (i.e. bogus base64 or uuencoded data), the payload is returned as-is. If the message is a multipart and the decode flag is True, then None is returned. NzExpected list, got %szcontent-transfer-encodingr&r$surrogateescaperreplaceraw-unicode-escapezquoted-printablebase64r)z x-uuencodeuuencodeuuezx-uueT)quiet)r`rHr)r TypeErrortypergetr7r_has_surrogatesr,decode get_param LookupError UnicodeError_qdecoderjoin splitlinesrE handle_defectr uur\Error) rNr=rvrhctebpayloadr1rLdefectin_fileout_files r get_payloadzMessage.get_payloadsD      ( ty}$}Q'' =DM4!@!@=3d4=6I6IIJJ J-$((6;;<<BBDD gs # # D'llG$W-- D">>'3DEEFF"*//$..G2T2TV_"`"`&FFF"*//'9"E"EFF  DD&~~g66HH#DDD '~~.BCCHHH D  N $ $ $>(++ + H__&chhx/B/B/D/D&E&EFFNE7! 8 8 ))$7777L > > >h''GyyH  '848888((***8     gs # # Os6<*D'' E  E E''F F +*II*)I*cF||_|||dSdS)zSet the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. N)rH set_charset)rNrhrs r set_payloadzMessage.set_payloads3       W % % % % %  rc||dd|_dSt|tst|}||_d|vr|ddd|vr+|dd|n(|d|||kr||j|_d|vrh| } ||dS#t$r9||j|_|d|YdSwxYwdS) aSet the charset of the payload to a given character set. charset can be a Charset instance, a string naming a character set, or None. If it is a string it will be converted to a Charset instance. If charset is None, the charset parameter will be removed from the Content-Type field. Anything else will generate a TypeError. The message will be assumed to be of type text/* encoded with charset.input_charset. It will be converted to charset.output_charset and encoded properly, if needed, when generating the plain text representation of the message. MIME headers (MIME-Version, Content-Type, Content-Transfer-Encoding) will be added as needed. Nr MIME-Version1.0 Content-TyperDrzContent-Transfer-Encoding) del_paramrIr)Charset add_headerget_output_charset set_param body_encoderHget_body_encodingrr)rNrrs rrzMessage.set_charsets ? NN9 % % % DM F'7++ 'g&&G  % % OONE 2 2 2  % % OONL$+$>$>$@$@  B B B B NN9g&@&@&B&B C C C g0022 2 2#// >>DM &d 2 2++--C BD  B B B ' 3 3DM B B  ;SAAAAAA B 3 2s D?EEc|jS)zKReturn the Charset instance associated with the message's payload. )rIrSs r get_charsetzMessage.get_charsetEs }rc*t|jS)z9Return the total number of headers, including duplicates.)r(rFrSs r__len__zMessage.__len__Ms4=!!!rc,||S)a-Get a header value. Return None if the header is missing instead of raising an exception. Note that if the header appeared multiple times, exactly which occurrence gets returned is undefined. Use get_all() to get all the values matching a header field name. )rtrNnames r __getitem__zMessage.__getitem__Qsxx~~rcv|j|}|ri|}d}|jD]K\}}||kr.|dz }||kr#t d||L|j|j||dS)zSet the value of a header. Note: this does not overwrite an existing header with the same field name. Use __delitem__() first to delete any existing headers. rr"z/There may be at most {} {} headers in a messageN)rEheader_max_countr7rF ValueErrorformatr8header_store_parse)rNrval max_countlnamefoundkvs r __setitem__zMessage.__setitem__\s K0066  QJJLLEE  Q Q17799%%QJE ))(*88>y$8O8OQQQ T[;;D#FFGGGGGrc|}t}|jD]4\}}||kr|||f5||_dS)zwDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N)r7rrFr8)rNr newheadersrrs r __delitem__zMessage.__delitem__nsf zz||VV M * *DAqwwyyD  !!1a&)))" rcL|d|jDvS)Nc<g|]\}}|S)r7.0rrs r z(Message.__contains__..{s$DDDda DDDr)r7rFrs r __contains__zMessage.__contains__zs&zz||DDdmDDDDDrc#,K|jD] \}}|V dSrbrF)rNfieldr1s r__iter__zMessage.__iter__}s0 M  LE5KKKK  rc$d|jDS)a.Return a list of all the message's header field names. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cg|]\}}|Srrrs rrz Message.keys..s,,,da,,,rrrSs rkeysz Message.keyss-,dm,,,,rc*fdjDS)a)Return a list of all the message's header values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cLg|] \}}j||!SrrEheader_fetch_parserrrrNs rrz"Message.values..s?+++Aq ..q!44+++rrrSs`rvalueszMessage.values0++++ M+++ +rc*fdjDS)a'Get all the message's header fields and values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cPg|]"\}}|j||f#Srrrs rrz!Message.items..sD+++AqDK221a889+++rrrSs`ritemsz Message.itemsrrc|}|jD]:\}}||kr|j||cS;|S)z~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. )r7rFrEr)rNrfailobjrrs rrtz Message.getsa zz||M < |j||fdS)zStore name and value in the model without modification. This is an "internal" API, intended only for use by a parser. N)rFr8)rNrr1s rset_rawzMessage.set_raws$ dE]+++++rcNt|jS)zReturn the (name, value) header pairs without modification. This is an "internal" API, intended only for use by a generator. )iterrFcopyrSs r raw_itemszMessage.raw_itemss DM&&(()))rcg}|}|jD]K\}}||kr.||j||L|s|S|S)aQReturn a list of all the values for the named field. These will be sorted in the order they appeared in the original message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. If no such fields exist, failobj is returned (defaults to None). )r7rFr8rEr)rNrrrrrs rget_allzMessage.get_allswzz||M D DDAqwwyyD   dk<|}ttt|j|jD]F\}\}}||kr&|j|||j|<dSGt|)zReplace a header. Replace the first matching header found in the message, retaining header order and case. If no matching header was found, a KeyError is raised. N)r7r rr(rFrErKeyError)rNrrr=rrs rreplace_headerzMessage.replace_headers U3t}#5#566 FF " "IAv1wwyyE!!#';#A#A!V#L#L a "5// !rct}|d|}||ur|St|d}|ddkrdS|S)a0Return the message's content type. The returned string is coerced to lower case of the form `maintype/subtype'. If there was no Content-Type header in the message, the default type as given by get_default_type() will be returned. Since according to RFC 2045, messages always have a default type this will always return a value. RFC 2045 defines a message's default type to be text/plain unless it appears inside a multipart/digest container, in which case it would be message/rfc822. content-typer/r"rD)objectrtget_default_typerr7r5)rNmissingr1ctypes rget_content_typezMessage.get_content_types|((11 G  ((** *E""1%++-- ;;s  q < rc`|}|ddS)zReturn the message's main content type. This is the `maintype' part of the string returned by get_content_type(). rrrsplitrNrs rget_content_maintypezMessage.get_content_maintype, %%''{{3""rc`|}|ddS)zReturns the message's sub-content type. This is the `subtype' part of the string returned by get_content_type(). rr"rrs rget_content_subtypezMessage.get_content_subtype(rrc|jS)aReturn the `default' content type. Most messages have a default content type of text/plain, except for messages that are subparts of multipart/digest containers. Such subparts have a default content type of message/rfc822. rMrSs rrzMessage.get_default_type1s !!rc||_dS)zSet the `default' content type. ctype should be either "text/plain" or "message/rfc822", although this is not enforced. The default content type is not stored in the Content-Type header. Nrrs rset_default_typezMessage.set_default_type:s#rct}|||}||ur|Sg}t|D]} |dd\}}|}|}n&#t $r|}d}YnwxYw|||ftj|}|S)Nr#r"r&) rrtr>rrrr8r decode_params) rNrheaderrr1paramsprrs r_get_params_preservezMessage._get_params_preserveCs(()) G  NU## ' 'A GGCOO czz||iikk   wwyy  MM4+ & & & &$V,, sAB B$#B$rTcvt}|||}||ur|S|r d|DS|S)amReturn the message's Content-Type parameters, as a list. The elements of the returned list are 2-tuples of key/value pairs, as split on the `=' sign. The left hand side of the `=' is the key, while the right hand side is the value. If there is no `=' sign in the parameter the value is the empty string. The value is as described in the get_param() method. Optional failobj is the object to return if there is no Content-Type header. Optional header is the header to search instead of Content-Type. If unquote is True, the value is unquoted. c6g|]\}}|t|fSr)rArs rrz&Message.get_params..js)===daQ a(()===r)rr)rNrrr@rrs r get_paramszMessage.get_paramsXsS((**7F;; W  N  ==f=== =Mrc||vr|S|||D]F\}}||kr|rt|cS|cSG|S)aReturn the parameter value if found in the Content-Type header. Optional failobj is the object to return if there is no Content-Type header, or the Content-Type header has no such parameter. Optional header is the header to search instead of Content-Type. Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider VALUE to be encoded in the us-ascii charset. You can usually ignore LANGUAGE. The parameter value (either the returned string, or the VALUE item in the 3-tuple) is always unquoted, unless unquote is set to False. If your application doesn't care whether the parameter was RFC 2231 encoded, it can turn the return value into a string as follows: param = msg.get_param('foo') param = email.utils.collapse_rfc2231_value(rawparam) )rr7rA)rNrrrr@rrs rrwzMessage.get_paramns0   N--gv>>  DAqwwyyEKKMM))(+++++HHH * rrr&ct|ts|r|||f}||vr|dkrd}n||}|||s@|st |||}nt |t |||g}nd}|||D]u\}} d} ||krt |||} nt || |} |s| }Yt || g}v|||kr ||=|||<dSdS)aSet a parameter in the Content-Type header. If the parameter already exists in the header, its value will be replaced with the new value. If header is Content-Type and has not yet been defined for this message, it will be set to "text/plain" and the new parameter and value will be appended as per RFC 2045. An alternate header can specified in the header argument, and all parameters will be quoted as necessary unless requote is False. If charset is specified, the parameter will be encoded according to RFC 2231. Optional language specifies the RFC 2231 language, defaulting to the empty string. Both charset and language should be strings. rrD)rr&rr@N) r)r*r7rtrwr2rr{r) rNrr1rrequoterlanguager old_param old_value append_params rrzMessage.set_params$%'' /G /h.E   &,,..N"B"B EEHHV$$E~~eF~33 B B$UE7;;!Lw??@BBE(,v@G)8)I)I B B$ 9! ??$$ 55#/ug#F#FLL#/ 9g#N#NLB(EE%NNE<+@AAEE DHHV$$ $ $V  DLLL % $rc h||vrdSd}|||D]n\}}||kr?|st|||}Ct|t|||g}o|||kr ||=|||<dSdS)a>Remove the given parameter completely from the Content-Type header. The header will be re-written in place without the parameter or its value. All values will be quoted as necessary unless requote is False. Optional header specifies an alternative to the Content-Type header. Nr&r)rr7r2rr{rt)rNrrr new_ctyperrs rrzMessage.del_params    F OO67OCC N NDAqwwyyEKKMM)) N ,Q7 ; ;II ) 0>^ + +^$#(D   DL F@@ LV 122J 2 2DAq NN1a 1 1 1 1 2 2rct}|d|d}||ur|d|d}||ur|Stj|S)a@Return the filename associated with the payload if present. The filename is extracted from the Content-Disposition header's `filename' parameter, and it is unquoted. If that header is missing the `filename' parameter, this method falls back to looking for the `name' parameter. filenamezcontent-dispositionrr)rrwrcollapse_rfc2231_valuer)rNrrrs r get_filenamezMessage.get_filenamesp((>>*g7LMM w  ~~fg~FFH w  N+H55;;===rct}|d|}||ur|Stj|S)zReturn the boundary associated with the payload if present. The boundary is extracted from the Content-Type header's `boundary' parameter, and it is unquoted. boundary)rrwrrrstrip)rNrrrs r get_boundaryzMessage.get_boundarysM ((>>*g66 w  N+H55<<>>>rcJt}||d}||urtjdt }d}|D]Q\}}|dkr|dd|zfd}:|||fR|s|dd|zft }|jD]\} } | dkrt } |D];\} } | dkr| | !| | d|    j&8*;< = = =VV M * *DAqwwyyN**%77DAqBww Q 11%56666nnU++!!$+"@"@C"H"HIIII!!1a&))))" rct}|d|}||ur|St|trV|dpd} |dd}t ||}n#t tf$r |d}YnwxYw |dn#t$r|cYSwxYw|S)zReturn the charset parameter of the Content-Type header. The returned string is always coerced to lower case. If there is no Content-Type header, or if that header has no charset parameter, failobj is returned. rrzus-asciir!rm) rrwr)r*r,rrxryr7)rNrrrpcharsetas_bytess rget_content_charsetzMessage.get_content_charsetAs((..G44 g  N gu % % %qz/ZH %#1:,,-ABBh11. % % %!!* %  NN: & & & &   NNN }}s$ +A77BBB-- B<;B<cDfd|DS)aReturn a list containing the charset(s) used in this message. The returned list of items describes the Content-Type headers' charset parameter for this message and all the subparts in its payload. Each item will either be a string (the value of the charset parameter in the Content-Type header of that part) or the value of the 'failobj' parameter (defaults to None), if the part does not have a main MIME type of "text", or the charset is not defined. The list will contain one string for each part of the message, plus one for the container message (i.e. self), so that a non-multipart message will still return a list of length 1. c:g|]}|Sr)r)rpartrs rrz(Message.get_charsets..os'JJJd((11JJJrwalk)rNrs `r get_charsetszMessage.get_charsets_s( KJJJdiikkJJJJrr)Fr)NFrb)NrT)rTNr&)rT)rT)2__name__ __module__ __qualname____doc__rrOr rTrRr`rdrfrirrrrrrrrrrrrrrtrrrrrrrrrrrrrwrrrrr rrr future.backports.email.iteratorsrrrrr r ms8  ' * * * *]G$$$  %$    ///""" * * *YYYYv&&&&$B$B$BL"""   HHH$ # # #EEE--- + + + + + +    ",,,***$,,,< " " "&0######"""###*,5C    DFJ)+.!.!.!.!`%%%%,2222@>>>> ? ? ? ?,#,#,#\<KKKK&65555555r)NT)'r __future__rrrfuture.builtinsrrrr __all__rer~rnbinasciiior r future.utilsr future.backports.emailrr"future.backports.email._policybaserrrI%future.backports.email._encoded_wordsrrrcompiler.rr2r>rArr rrrr,s ?>BBBBBBBBBB111111111111 +  '&&&&&(((((())))))777777666666::::::     BJ2 3 3        D($$$E 6E 6E 6E 6E 6fE 6E 6E 6E 6E 6r