ٚ(pdZgdZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddl mZddl mZmZmZddlmZd Zd Zd Zd Zd Zejd ZejdZdZdZd,dZdZdZ dZ!dddZ"dZ#dZ$dZ%dZ&d-dZ'd.dZ(d/dZ)d Z*ddd!Z+d"Z,d#Z-d/d$Z.ejd%ej/Z0d&Z1 d0d)Z2d1d+Z3dS)2zMiscellaneous utilities.)collapse_rfc2231_value decode_paramsdecode_rfc2231encode_rfc2231 formataddr formatdateformat_datetime getaddresses make_msgid mktime_tz parseaddr parsedate parsedate_tzparsedate_to_datetimeunquoteN)quote) AddressList)r )r r _parsedate_tz)Charsetz, z 'z[][\\()<>@,:;".]z[\\"]cR |dS#t$rYdSwxYw)z;Return True if s may contain surrogate-escaped binary data.FT)encodeUnicodeEncodeError)ss 2/opt/alt/python311/lib64/python3.11/email/utils.py_has_surrogatesr4s;   u tts  &&cZ|dd}|ddS)Nutf-8surrogateescapereplace)rdecode)stringoriginal_bytess r _sanitizer%As. ]]7,=>>N  ) 4 44rc|\}}|d|r |dd}t|rd}td|}|||d|dS#t $rDt |trt|}| |}|d|dcYSwxYw|S)aThe inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header. If the first element of pair is false, then the second element is returned unmodified. The optional charset is the character set that is used to encode realname in case realname is not ASCII safe. Can be an instance of str or a Charset-like object which has a header_encode method. Default is 'utf-8'. asciir"z\\\g<0>z <>) r specialsresearch escapesresubr isinstancestrr header_encode)paircharsetnameaddressquotes encoded_names rrrMsMD' NN7 C C KK F  && ==T22D$*FDD&&&'''B B" 7 7 7'3'' +!'**"0066L , ggg6 6 6 6  7 NsA88A CCc#Kd}d}t|D]"\}}|r |d|zfVd}|dkrd}||fV#|r|dfVdSdS)NrF\T) enumerate)addrposescapechs r_iter_escaped_charsr?ns C FT??R  r " " " "FF 4ZZFF)OOOO Dkr&c8d|vr|Sd}d}g}t|D]:\}}|dkr/||}||kr|||||dz}d};|t|kr|||dd|S)z Strip real names between quotes.r)rNr)r?appendlenjoin)r;startopen_posresultr<r>s r_strip_quoted_realnamesrH}s $ EH F&t,,  R 99H$$MM$uX~"6777a s4yy d566l### 776??r&T)strictc|s:td|D}t|}|jSd|D}t |}t|}t|}t |j}d}|D],}t |}|d|dzz }-t||krdgS|S)zReturn a list of (REALNAME, EMAIL) or ('','') for each fieldvalue. When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in its place. If strict is true, use a strict parser which rejects malformed inputs. c34K|]}t|VdS)Nr0.0vs r zgetaddresses..s(::c!ff::::::r&c,g|]}t|SrLrMs r z getaddresses..s///a3q66///r&rrA,rr) COMMASPACErD _AddressList addresslist_pre_parse_validation_post_parse_validationrHcountrC) fieldvaluesrIallar;rGnrOs rr r s$ oo::k:::::   }//;///K' 44K ??; ' 'DTA #AM 2 2F A  $A & & Q  6{{az Mr&ct|}d}t|D]%\}}|dkr|dz }|dkr|dz}|dkrdS&|dkS)Nr(rA)F)rHr?)r;opensr<r>s r_check_parenthesisrdsp "4 ( (D E&t,,R 99 QJEE 3YY QJEqyyuu QJr&c`g}|D](}t|sd}||)|S)Nz('', ''))rdrB)email_header_fieldsaccepted_valuesrOs rrYrYsHO ""!!$$ Aq!!!! r&cVg}|D]#}d|dvrd}||$|S)N[rArU)rB)parsed_email_header_tuplesrgrOs rrZrZsGO("" !A$;;Aq!!!! r&c dgd|d|dgd|ddz |d|d|d |d |fzS) Nz"%s, %02d %s %04d %02d:%02d:%02d %s)MonTueWedThuFriSatSun) JanFebMarAprMayJunJulAugSepOctNovDecrArrR) timetuplezones r_format_timetuple_and_zonersj /999)A,G!  3 3 33-B B BDEE E  {{4   %c4 0 00r&cttjdz}tj}t jd}|d}nd|z}|t j}d|||||fz}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g: <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. Optional domain if given provides the portion of the message id after the '@'. It defaults to the locally defined hostname. d@Nr.z<%d.%d.%d%s@%s>)introsgetpidrandom getrandbitssocketgetfqdn)idstringdomainrpidrandintmsgids rr r "sx$)++c/""G )++C $$G> ~!! #w& I IE Lr&c t|}|tdt|z|^}}|tj|ddStj|dddtjtj|iS)Nz!Invalid date value or format "%s"rsrseconds)rrr0rr timedelta)dataparsed_date_tzdtupletzs rrr9s"4((N>#   G3<<#4#4 Gqt9$$VT22::5#FF F >>#   3<<#4#4 qt9  Jr&cl|td}t|dkrdd|fS|S)z#Decode string according to RFC 2231rtN)splitTICKrC)rpartss rrros5 GGD!  E 5zzQT1} Lr&crtj|d|pd}|||S|d}|d|d|S)zEncode string according to RFC 2231. If neither charset nor language is given, then s is returned as-is. If charset is given but not language, the string is encoded using the empty string for language. rr()safeencodingNr)urllibparser)rr3languages rrrwsV  120B7CCA8+ (((AA ..r&z&^(?P\w+)\*((?P[0-9]+)\*?)?$c|dg}i}|ddD]\}}|d}t|}t|}|rW|dd\}}|t |}||g|||f||dt|zf|r| D]\}}g}d} | |D]@\}} }|r#tj | d } d } || Att|}| r1t|\} } }||| | d|zff||d|zf|S) zDecode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value). rrAN*r4numz"%s"Fzlatin-1)rT)rrrfc2231_continuationmatchgroupr setdefaultrBritemssortrr EMPTYSTRINGrDr) params new_paramsrfc2231_paramsr4valueencodedmor continuationsextendedrr3rs rrrs )JNabbz = = e--$$ ! ' ' - -  =//ID##hh  % %dB / / 6 6UG7L M M M M   tVeEll%:; < < < <:#1#7#7#9#9 : : D-EH    $1  Q$ ,,Q,CCA#H Q+**51122E :+9%+@+@(5!!4'8Ve^)L"MNNNN!!4%"89999 r&r!us-asciict|trt|dkrt|S|\}}}||}t |d} t |||S#t $rt|cYSwxYw)Nrzraw-unicode-escape)r/tuplerCrbytesr0 LookupError)rerrorsfallback_charsetr3rtextrawbytess rrrs eU # #s5zzQu~~$GXt#T/00H8Wf--- t}}sA$$B?Brcd|@tjtjjS|j|S|dd|fz}tj|}tj |} tj |j }tj||j }n#t$r|tjtj|ddz }tjo |jdk}|r tjn tj }|tj |kr&tj|tj|}ntj|}YnwxYw||S)aReturn local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a datetime instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, dt.tzinfo is None), it is assumed to be in local time. In this case, a positive or zero value for *isdst* causes localtime to presume initially that summer time (for example, Daylight Saving Time) is or is not (respectively) in effect for the specified time. A negative value for *isdst* causes the localtime() function to attempt to divine whether summer time is in effect for the specified time. Nrrrsr)r)rrrrrrrrmktimerr tm_gmtofftm_zoneAttributeErrorgmtimedaylighttm_isdstaltzonetznamer!) risdsttmrlocaltmdeltardstgmtoffs rrrs{ z $$X%6%:;;FFHHH y}}  x 'Bk"ooGnW%%G *"7+<===  ugo 6 6  * * *X& G(<(rs    $ """"""888888&&&&&&CCCCCCCCCC"!!!!!       RZ+ , , BJx    555B   2(,)))))X      '''':1111&.FFF#> / / / /"rz"KH...`*3,64%!%!%!%!%!%!r&