mò &U²Ic@sºdZdkZdkZdkZdkZdklZdklZdkl Z dkl Z dZ ei dƒZ ei dƒZded „Zd „Zd „Zd fd „ƒYZdS(s8Basic message object for the email package object model.N(sStringIO(sUtils(sErrors(sCharsets; s\s*;\s*s[ \(\)<>@,;:\\"/\[\]\?=]cCs«|dj o–t|ƒdjoƒt|tƒo/|d7}ti|d|d|dƒ}n|pt i |ƒod|ti|ƒfSq§d||fSn|SdS(s~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. it*iis%s="%s"s%s=%sN( tvaluetNonetlent isinstancettupletparamtUtilstencode_rfc2231tquotet tspecialstsearch(RRR ((t*/data/zmath/lib/python2.4/email/Message.pyt _formatparam s  %cCsg}x|d djoò|d}|idƒ}xB|djo4|idd|ƒdo|id|dƒ}q6W|djot|ƒ}n|| }d|jo?|idƒ}|| i ƒi ƒd||di ƒ}n|i |i ƒƒ||}q W|S(Nit;it"it=( tplisttstfindtendtcountRtftindextitstriptlowertappend(RRRRR((R t _parseparam6s" '   0cCsGt|tƒo&|d|dti|dƒfSnti|ƒSdS(Niii(RRRRtunquote(R((R t _unquotevalueHs&tMessagecBsïtZdZd„Zd„Zed„Zd„Zd„Zd„Z d„Z e ed„Z e d „Z d „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Ze d„Ze d„Zd„Zd„Ze d„Ze d„Ze d„Zd„Z d„Z!d„Z"d„Z#d „Z$d!„Z%e d"e&d#„Z'e d"e&d$„Z(d%e&e d&d'„Z)d"e&d(„Z*d%e&d)„Z+e d*„Z,e d+„Z-d,„Z.e d-„Z/e d.„Z0d/k1l2Z2RS(0sÈBasic message object. A message object is defined as something that has a bunch of RFC 2822 headers and a payload. It may optionally have an envelope header (a.k.a. Unix-From or From_ header). If the message is a container (i.e. a multipart or a message/rfc822), then the payload is a list of Message objects, otherwise it is a string. Message objects implement part of the `mapping' interface, which assumes there is exactly one occurrance of the header per message. Some headers do in fact appear multiple times (e.g. Received) and for those headers, you must use the explicit API to set or get all the headers. Not all of the mapping methods are implemented. cCsJg|_d|_d|_d|_d|_|_g|_d|_ dS(Ns text/plain( tselft_headersRt _unixfromt_payloadt_charsettpreambletepiloguetdefectst _default_type(R ((R t__init__cs     cCs|idtƒS(swReturn the entire formatted message as a string. This includes the headers, body, and envelope header. tunixfromN(R t as_stringtTrue(R ((R t__str__nscCs?dkl}tƒ}||ƒ}|i|d|ƒ|iƒS(s‘Return the entire formatted message as a string. Optional `unixfrom' when True, means include the Unix From_ envelope header. This is a convenience method and may not generate the message exactly as you intend because by default it mangles lines that begin with "From ". For more flexibility, use the flatten() method of a Generator instance. (s GeneratorR*N( temail.Generatort GeneratortStringIOtfptgtflattenR R*tgetvalue(R R*R1R/R2((R R+ts    cCst|itƒS(s6Return True if the message consists of multiple parts.N(RR R#tlist(R ((R t is_multipart„scCs ||_dS(N(R*R R"(R R*((R t set_unixfrom‹scCs|iS(N(R R"(R ((R t get_unixfromŽscCs4|idjo|g|_n|ii|ƒdS(sðAdd 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(R R#RtpayloadR(R R9((R tattach”scCsW|d jo |i}n>t|itƒptdt|iƒƒ‚n|i|}|oõ|i ƒod Sn|i ddƒi ƒ}|djoti|ƒSqS|djo2yti|ƒSWqOtij o |SqOXqS|d joZtƒ}y0ti t|d ƒ|d tƒ|iƒ}WqOtij o |SqOXqSn|S(sZReturn 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. sExpected list, got %sscontent-transfer-encodingtsquoted-printabletbase64s x-uuencodetuuencodetuuesx-uues tquietN(s x-uuencodeR=R>sx-uue(RRR R#R9RR5t TypeErrorttypetdecodeR6tgetRtcteRt_qdecodet_bdecodetbinasciitErrorR0tsfptuuR,R4(R RRBRIRDR9((R t get_payload s2          cCs+||_|dj o|i|ƒndS(s˜Set the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. N(R9R R#tcharsetRt set_charset(R R9RL((R t set_payloadÒs  cCsƒ|djo|idƒd|_dSnt|tƒoti|ƒ}nt|tiƒpt|ƒ‚n||_|i dƒp|i ddƒn|i dƒp |i ddd|i ƒƒn|i d|i ƒƒt|ƒ|i ƒjo|i |iƒ|_n|i dƒpY|iƒ}y||ƒWqtj o,|i |iƒ|_|i d|ƒqXndS(sÜSet 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. RLNs MIME-Versions1.0s Content-Types text/plainsContent-Transfer-Encoding(RLRR t del_paramR$RtstrtCharsetR@thas_keyt add_headertget_output_charsett set_paramt body_encodeR#tget_body_encodingRD(R RLRD((R RMÜs2      cCs|iS(sKReturn the Charset instance associated with the message's payload. N(R R$(R ((R t get_charsetscCs t|iƒS(s9Return the total number of headers, including duplicates.N(RR R!(R ((R t__len__scCs |i|ƒS(s-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 occurrance gets returned is undefined. Use get_all() to get all the values matching a header field name. N(R RCtname(R RZ((R t __getitem__scCs|ii||fƒdS(s¸Set 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. N(R R!RRZtval(R RZR\((R t __setitem__scCsc|iƒ}g}xA|iD]6\}}|iƒ|jo|i||fƒqqW||_dS(swDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N(RZRt newheadersR R!tktvR(R RZR_R^R`((R t __delitem__&s  cCs:|iƒg}|iD]\}}||iƒq~jS(N(RZRt_[1]R R!R_R`(R RZRbR_R`((R t __contains__2scCstƒ}|i||ƒ|j S(s/Return true if the message contains the header.N(tobjecttmissingR RCRZ(R RZRe((R RR5s cCs(g}|iD]\}}||q~S(s.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. N(RbR R!R_R`(R RbR_R`((R tkeys:scCs(g}|iD]\}}||q~S(s)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. N(RbR R!R_R`(R RbR_R`((R tvaluesDscCs|iS(s'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. N(R R!(R ((R titemsNscCsE|iƒ}x2|iD]'\}}|iƒ|jo|SqqW|S(s~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. N(RZRR R!R_R`tfailobj(R RZRiR_R`((R RCXs   cCscg}|iƒ}x;|iD]0\}}|iƒ|jo|i|ƒqqW|p|Sn|S(sQReturn 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). N( RgRZRR R!R_R`RRi(R RZRiRgR`R_((R tget_allhs  cKs³g}xf|iƒD]X\}}|djo|i|iddƒƒq|it|iddƒ|ƒƒqW|dj o|i d|ƒn|i i|ti|ƒfƒdS(s³Extended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. Example: msg.add_header('content-disposition', 'attachment', filename='bud.gif') t_t-iN(tpartst_paramsRhR_R`RRtreplaceR t_valuetinsertR R!t_namet SEMISPACEtjoin(R RrRpRnRmR`R_((R RSzs   & cCs|iƒ}xlttt|iƒƒ|iƒD]=\}\}}|iƒ|jo||f|i|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ˆR(R RRRˆt new_ctypeRŽR‘RŠR`RRR RsRtRC(R RRˆR‘R•RŠR`((R RO‰s )cCsÈ|idƒdjp t‚n|iƒdjo|d=d|d