mň &U˛Ic@sĆdZdkZdkZdkZdkZdkZdkZdkZdkZdk l Z dk l Z dk l Zdk lZdk lZdk lZdklZd klZlZd Zd Zd Zd ZdZeidƒZ eidƒZ!d„Z"d„Z#d„Z$d„Z%d„Z&eidei'ei(BƒZ)de+e+d„Z,dd„Z-d„Zd„Zd„Z.d„Z/d„Z0ddd„Z1eidƒZ2d „Z3d!d"d#„Z4dS($sMiscellaneous utilities.N(sStringIO(squote(s AddressList(s mktime_tz(s parsedate(s parsedate_tz(s decodestring(s_bencodes_qencodes, tus t's[][\\()<>@,:;".]s [][\\()"]cCs|S(N(ts(R((t(/data/zmath/lib/python2.4/email/Utils.pyt _identity+scCsO|p|Snti|ƒ}|idƒ o|idƒo |d Sn|S(Ns i˙˙˙˙(Rtbase64t decodestringtvaluetendswith(RR((Rt_bdecode/s ! cCs.tidt|ƒ}tidt|ƒ}|S(s+Replace all line-ending characters with .s (?s %s%s%s <%s>N(tpairtnametaddresstquotest specialsretsearcht escapesreR (RRRR((Rt formataddrEs  cCs"ti|ƒ}t|ƒ}|iS(s7Return a list of (REALNAME, EMAIL) for each fieldvalue.N(t COMMASPACEtjoint fieldvaluestallt _AddressListtat addresslist(RRR((Rt getaddressesXs s_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= c CsX|d$jotiƒ}n|oti|ƒ}tio|do ti}n ti}t t |ƒdƒ\}}|djo d}nd}d|||df}n'ti|ƒ}|o d}nd }d d d d ddddg|d|dddddddddddddg |d d |d|d!|d"|d#|fS(%sƒReturns a date string as specified by RFC 2822, e.g.: Fri, 09 Nov 2001 01:08:47 -0000 Optional timeval if given is a floating point time value as accepted by gmtime() and localtime(), otherwise the current time is used. Optional localtime is a flag that when True, interprets timeval, and returns a date relative to the local timezone instead of UTC, properly taking daylight savings time into account. Optional argument usegmt means that the timezone is written out as an ascii string, not numeric one (so "GMT" instead of "+0000"). This is needed for HTTP, and is only used when localtime==False. i˙˙˙˙iit-t+s %s%02d%02di<tGMTs-0000s"%s, %02d %s %04d %02d:%02d:%02d %stMontTuetWedtThutFritSattSuniitJantFebtMartAprtMaytJuntJultAugtSeptOcttNovtDeciiiiN(ttimevaltNonettimet localtimetnowtdaylighttaltzonetoffsetttimezonetdivmodtabsthourstminutestsigntzonetgmtimetusegmt( R5R8RERCR<RBR@R9RA((Rt formatdatels$      cCsŒtiƒ}tidti|ƒƒ}tiƒ}ti dƒ}|djo d}n d|}t iƒ}d|||||f}|S(sčReturns a string suitable for RFC 2822 compliant Message-ID, e.g: <20020201195627.33539.96671@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. s %Y%m%d%H%M%Si †Rt.s<%s.%s.%s%s@%s>N(R7R5tstrftimeRDtutcdatetostgetpidtpidtrandomt randrangetrandinttidstringR6tsockettgetfqdntidhosttmsgid(RPRIRORTRLR5RS((Rt make_msgidĄs      cCs|pdSnt|ƒS(N(tdataR6t _parsedate(RV((Rt parsedateşscCs|pdSnt|ƒS(N(RVR6t _parsedate_tz(RV((Rt parsedate_tzŔscCs&t|ƒi}|pdSn|dS(NRi(RR(RtaddrRtaddrs(R[R\((Rt parseaddrĆscCs‘t|ƒdjoz|idƒo7|idƒo'|dd!iddƒiddƒSn|idƒo|idƒo|dd!Sqn|S( sRemove quotes from a string.iRi˙˙˙˙s\\s\s\"tN(tlentstrt startswithRtreplace(Ra((RtunquoteÎs ' cCsC|itdƒ}t|ƒdjoddti|ƒfSn|S(s#Decode string according to RFC 2231iN(RtsplittTICKtpartsR`R6turllibRd(RRg((Rtdecode_rfc2231Ús cCshdk}|i|ddƒ}|djo|djo|Sn|djo d}nd|||fS(sÜEncode 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. NtsafeRs%s'%s'%s(RhtquoteRtcharsetR6tlanguage(RRlRmRh((Rtencode_rfc2231âs   s&^(?P\w+)\*((?P[0-9]+)\*?)?$c Cs|}g}h} |idƒ\}} |i|| fƒxŰ|oÓ|idƒ\}} |idƒo t}nt }t | ƒ} t i |ƒ} | o[| iddƒ\}}|dj ot|ƒ}n| i|gƒi|| |fƒq>|i|dt| ƒfƒq>W| oęxç| iƒD]Ő\}}g} t }|iƒxD|D]<\}} }|oti | ƒ} t}n| i| ƒqVWtti| ƒƒ} |o9t| ƒ\}}} |i|||d| ffƒq-|i|d| fƒq-Wn|S(sDecode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value). it*Rtnums"%s"N( tparamst new_paramstrfc2231_paramstpopRRtappendRtTruetencodedtFalseRdtrfc2231_continuationtmatchtmotgroupRpR6tintt setdefaultRktitemst continuationstextendedtsortRRht EMPTYSTRINGRRiRlRm( RqRpRlR€RRwRRmRrR{RRRs((Rt decode_paramsôsL   &"   $Rcsus-asciicCs}t|tƒo_t|dƒ}|dpd}yt|||ƒSWqytj ot|||ƒSqyXn t|ƒSdS(Niisus-ascii( t isinstanceRttupleRdtrawvalRltunicodeterrorst LookupErrortfallback_charset(RR‰R‹R‡Rl((Rtcollapse_rfc2231_value)s(5t__doc__RJR R7RRMRQRhtwarningst cStringIOtStringIOtemail._parseaddrRkt AddressListRt mktime_tzRXRWRZRYtquopriRt_qdecodetemail.Encoderst_bencodet_qencodeRRƒt UEMPTYSTRINGR RftcompileRRRR R RRtVERBOSEt IGNORECASEtecreR6RxRFRUR]RdRiRnRyR„RŒ()RXRdR™R˜RMRŒRfRRRR RRhRUR RZRFRRRyRiR•RRŽRkRnR R„R—R]RRQRRJR RƒR7RWRYR“R((Rt?sP                   5      5