Lc @sdZdgZddkZddkZddkZddkZddklZddkZ ddk l Z ddk l Z dZ ei dZd Zded Zd Zd Zddd YZdS(s8Basic message object for the email package object model.tMessageiN(tStringIO(tutils(terrorss; s[ \(\)<>@,;:\\"/\[\]\?=]cCsF|id\}}}|p|idfS|i|ifS(Nt;(t partitiontstriptNone(tparamtatseptb((s%/usr/lib64/python2.6/email/message.pyt _splitparamscCs|dj ot|djot|to/|d7}ti|d|d|d}n|pti|od|ti|fSd||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( Rtlent isinstancettupleRtencode_rfc2231t tspecialstsearchtquote(RtvalueR((s%/usr/lib64/python2.6/email/message.pyt _formatparam&s  %cCs$g}x|d djo|d}|id}xU|djoG|idd||idd|do|id|d}q6W|djot|}n|| }d|jo?|id}|| iid||di}n|i|i||}q W|S(NiRit"s\"it=(tfindtcountRtindexRtlowertappend(tstplisttendtfti((s%/usr/lib64/python2.6/email/message.pyt _parseparam<s" :   0cCsDt|to#|d|dti|dfSti|SdS(Niii(RRRtunquote(R((s%/usr/lib64/python2.6/email/message.pyt _unquotevalueNs#cBseZdZdZdZedZdZdZdZ dZ d.edZ d.d Z d Zd Zd Zd ZdZdZdZdZdZdZdZd.dZd.dZdZdZdZdZdZdZ dZ!dZ"d.de#d Z$d.de#d!Z%d"e#d.d#d$Z&de#d%Z'd"e#d&Z(d.d'Z)d.d(Z*d)Z+d.d*Z,d.d+Z-d,d-k.l/Z/RS(/sBasic 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( t_headersRt _unixfromt_payloadt_charsettpreambletepiloguetdefectst _default_type(tself((s%/usr/lib64/python2.6/email/message.pyt__init__is     cCs|idtS(swReturn the entire formatted message as a string. This includes the headers, body, and envelope header. tunixfrom(t as_stringtTrue(R.((s%/usr/lib64/python2.6/email/message.pyt__str__tscCsBddkl}t}||}|i|d||iS(sReturn 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. i(t GeneratorR0(temail.generatorR4Rtflattentgetvalue(R.R0R4tfptg((s%/usr/lib64/python2.6/email/message.pyR1zs   cCst|itS(s6Return True if the message consists of multiple parts.(RR(tlist(R.((s%/usr/lib64/python2.6/email/message.pyt is_multipartscCs ||_dS(N(R'(R.R0((s%/usr/lib64/python2.6/email/message.pyt set_unixfromscCs|iS(N(R'(R.((s%/usr/lib64/python2.6/email/message.pyt get_unixfromscCs4|idjo|g|_n|ii|dS(sAdd 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(RR(R.tpayload((s%/usr/lib64/python2.6/email/message.pytattachscCsK|d jo |i}n>t|itptdt|in|i|}|o|iod S|iddi}|djot i |S|djo/yt i |SWqCt i j o|SXqG|d joWt}y0tit|d |d t|i}WqCti j o|SXqGn|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-uuencodeRBRCsx-uue(RR(RR:t TypeErrorttypeR;tgetRRt_qdecodet_bdecodetbinasciitErrorRtuutdecodeR2R7(R.R"RMR>tctetsfp((s%/usr/lib64/python2.6/email/message.pyt get_payloads0          cCs+||_|dj o|i|ndS(sSet the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. N(R(Rt set_charset(R.R>tcharset((s%/usr/lib64/python2.6/email/message.pyt set_payloads  cCs|djo|idd|_dSt|totii|}nt|tiipt|n||_|i dp|i ddn|i dp |i ddd|i n|i d|i t|i to|i i|i|_ nt||i jo|i|i |_ n|i dpY|i}y||Wqtj o,|i|i |_ |i d|qXndS(sSet 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. RRNs MIME-Versions1.0s Content-Types text/plainsContent-Transfer-Encoding(Rt del_paramR)Rt basestringtemailRRtCharsetREthas_keyt add_headertget_output_charsett set_paramR(tunicodetencodetoutput_charsettstrt body_encodetget_body_encoding(R.RRRN((s%/usr/lib64/python2.6/email/message.pyRQs4     cCs|iS(sKReturn the Charset instance associated with the message's payload. (R)(R.((s%/usr/lib64/python2.6/email/message.pyt get_charsetscCs t|iS(s9Return the total number of headers, including duplicates.(RR&(R.((s%/usr/lib64/python2.6/email/message.pyt__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. (RG(R.tname((s%/usr/lib64/python2.6/email/message.pyt __getitem__s cCs|ii||fdS(sSet 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(R.Rdtval((s%/usr/lib64/python2.6/email/message.pyt __setitem__&scCsc|i}g}xA|iD]6\}}|i|jo|i||fqqW||_dS(swDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N(RR&R(R.Rdt newheaderstktv((s%/usr/lib64/python2.6/email/message.pyt __delitem__.s  cCs:|ig}|iD]\}}||iq~jS(N(RR&(R.Rdt_[1]RiRj((s%/usr/lib64/python2.6/email/message.pyt __contains__:scCst}|i|||j S(s/Return true if the message contains the header.(tobjectRG(R.Rdtmissing((s%/usr/lib64/python2.6/email/message.pyRX=s 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. (R&(R.RlRiRj((s%/usr/lib64/python2.6/email/message.pytkeysBscCs(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. (R&(R.RlRiRj((s%/usr/lib64/python2.6/email/message.pytvaluesLscCs|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. (R&(R.((s%/usr/lib64/python2.6/email/message.pytitemsVscCsB|i}x/|iD]$\}}|i|jo|SqW|S(s~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. (RR&(R.RdtfailobjRiRj((s%/usr/lib64/python2.6/email/message.pyRG`s    cCs`g}|i}x;|iD]0\}}|i|jo|i|qqW|p|S|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). (RR&R(R.RdRsRqRiRj((s%/usr/lib64/python2.6/email/message.pytget_allps   cKsg}xf|iD]X\}}|djo|i|iddq|it|idd|qW|dj o|id|n|ii|ti|fdS(sExtended 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( RrRRtreplaceRtinsertR&t SEMISPACEtjoin(R.t_namet_valuet_paramstpartsRiRj((s%/usr/lib64/python2.6/email/message.pyRYs   & cCs|i}xlttt|i|iD]=\}\}}|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@RR$(RXRRRRyRzRG(R.RRRt new_ctypeRRj((s%/usr/lib64/python2.6/email/message.pyRTfs   cCs|iddjp tn|idjo|d=d|ds