;ò œA?c@súdZdkZdkZdkZdkZdklZdklZl Z l Z dk l Z dk l Z dk lZdZyeefWnej odZd ZnXeid ƒZeid ƒZeed „Zd „Zdfd„ƒYZdS(s9Basic message object for the email package object model. N(sStringIO(sListTypes TupleTypes StringType(sUtils(sErrors(sCharsets; iis\s*;\s*s[ \(\)<>@,;:\\"/\[\]\?=]cCs«|tj ot|ƒdjoƒt|tƒo/|d7}ti|d|d|dƒ}n|p t 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. is*iis%s="%s"s%s=%sN( svaluesNoneslens isinstances TupleTypesparamsUtilssencode_rfc2231squotes tspecialsssearch(sparamsvaluesquote((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys _formatparam's  %cCsGt|tƒo&|d|dti|dƒfSnti|ƒSdS(Niii(s isinstancesvalues TupleTypesUtilssunquote(svalue((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys _unquotevalue>s&sMessagecBstZdZd„Zd„Zed„Zd„Zd„Zd„Z d„Z d„Z e ed „Z e d „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Ze d„Ze d„Zd„Zd„Ze d„Ze d„Ze d„Z d„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/yd.k0l1Z1Wn e2j od.k3l1Z1nXe d/„Z4e d0„Z5RS(1sÈ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. cCsAg|_t|_t|_t|_t|_|_d|_dS(Ns text/plain( sselfs_headerssNones _unixfroms_payloads_charsetspreamblesepilogues _default_type(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys__init__Us     cCs|idtƒSdS(swReturn the entire formatted message as a string. This includes the headers, body, and envelope header. sunixfromN(sselfs as_stringsTrue(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys__str___scCsCdkl}tƒ}||ƒ}|i|d|ƒ|iƒSdS(sMReturn 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. For more flexibility, use the flatten() method of a Generator instance. (s GeneratorsunixfromN( semail.Generators GeneratorsStringIOsfpsgsflattensselfsunixfromsgetvalue(sselfsunixfromsfps Generatorsg((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys as_stringes    cCs#t|itƒotSntSdS(s6Return True if the message consists of multiple parts.N(s isinstancesselfs_payloadsListTypesTruesFalse(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys is_multiparttscCs ||_dS(N(sunixfromsselfs _unixfrom(sselfsunixfrom((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys set_unixfrom}scCs |iSdS(N(sselfs _unixfrom(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys get_unixfrom€scCs™tidtdƒ|itjo ||_nft|itƒo|ii |ƒn?|i ƒtdfjot i dƒ‚n|i|g|_dS(sòAdd the given payload to the current payload. If the current payload is empty, then the current payload will be made a scalar, set to the given value. Note: This method is deprecated. Use .attach() instead. s2add_payload() is deprecated, use attach() instead.is multiparts8Message main content type must be "multipart" or missingN( swarningsswarnsDeprecationWarningsselfs_payloadsNonespayloads isinstancesListTypesappends get_main_typesErrorssMultipartConversionError(sselfspayload((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys add_payload†s   cCs4|itjo|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(sselfs_payloadsNonespayloadsappend(sselfspayload((s//usr/pkg/lib/mailman/pythonlib/email/Message.pysattachšscCs_|tjo |i}n<t|itƒ otdt|iƒ‚n|i|}|oû|i ƒotSn|i ddƒi ƒ}|djoti|ƒSqW|djo2yti|ƒSWqStij o |SqSXqW|dddd fjoTtƒ}y*ti t|d ƒ|ƒ|iƒ}WqStij o |SqSXqWn|Sd 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-encodingssquoted-printablesbase64s x-uuencodesuuencodesuuesx-uues N(sisNonesselfs_payloadspayloads isinstancesListTypes TypeErrorstypesdecodes is_multipartsgetslowersctesUtilss_qdecodes_bdecodesbinasciisErrorsStringIOssfpsuusgetvalue(sselfsisdecodessfpsctespayload((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys get_payload¦s2        cCs+||_|tj 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(spayloadsselfs_payloadscharsetsNones set_charset(sselfspayloadscharset((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys set_payloadØs  cCs4|tjo|idƒt|_dSnt|tƒoti|ƒ}nt|tiƒ o t|‚n||_|i dƒ o|i ddƒn|i dƒ o |i ddd|i ƒƒn|i d|i ƒƒ|i dƒ o;|i ƒ}t|ƒo||ƒq0|i d|ƒndS(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. scharsetNs MIME-Versions1.0s Content-Types text/plainsContent-Transfer-Encoding(scharsetsNonesselfs del_params_charsets isinstances StringTypesCharsets TypeErrorshas_keys add_headersget_output_charsets set_paramsget_body_encodingsctescallable(sselfscharsetscte((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys set_charsetâs*        cCs |iSdS(sKReturn the Charset instance associated with the message's payload. N(sselfs_charset(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys get_charset scCst|iƒSdS(s9Return the total number of headers, including duplicates.N(slensselfs_headers(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys__len__scCs|i|ƒSdS(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 getall() to get all the values matching a header field name. N(sselfsgetsname(sselfsname((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys __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(sselfs_headerssappendsnamesval(sselfsnamesval((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys __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(snameslowers newheaderssselfs_headerssksvsappend(sselfsnamesks newheaderssv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys __delitem__)s  cCsD|iƒgi}|iD]\}}||iƒƒq~jSdS(N(snameslowersappends_[1]sselfs_headerssksv(sselfsnames_[1]sksv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys __contains__5scCs g}|i||ƒ|j SdS(s/Return true if the message contains the header.N(smissingsselfsgetsname(sselfsnamesmissing((s//usr/pkg/lib/mailman/pythonlib/email/Message.pyshas_key8scCs2gi}|iD]\}}||ƒq~SdS(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(sappends_[1]sselfs_headerssksv(sselfs_[1]sksv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pyskeys=scCs2gi}|iD]\}}||ƒq~SdS(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(sappends_[1]sselfs_headerssksv(sselfs_[1]sksv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pysvaluesGscCs |iSdS(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(sselfs_headers(sself((s//usr/pkg/lib/mailman/pythonlib/email/Message.pysitemsQscCsI|iƒ}x2|iD]'\}}|iƒ|jo|SqqW|SdS(s~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. N(snameslowersselfs_headerssksvsfailobj(sselfsnamesfailobjsksv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pysget[s   cCshg}|iƒ}x;|iD]0\}}|iƒ|jo|i|ƒqqW| o|Sn|SdS(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( svaluessnameslowersselfs_headerssksvsappendsfailobj(sselfsnamesfailobjsvaluessvsk((s//usr/pkg/lib/mailman/pythonlib/email/Message.pysget_allks  cKs³g}xf|iƒD]X\}}|tjo|i|iddƒƒq|it|iddƒ|ƒƒqW|tj 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') s_s-iN(spartss_paramssitemssksvsNonesappendsreplaces _formatparams_valuesinsertsselfs_headerss_names SEMISPACEsjoin(sselfs_names_values_paramsspartssvsk((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys add_header}s   & cCs||iƒ}xittt|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. Nssunquote(sselfshas_keysheaders new_ctypes get_paramssrequotespsvslowersparams _formatparams SEMISPACEsjoinsget(sselfsparamsheadersrequotes new_ctypespsv((s//usr/pkg/lib/mailman/pythonlib/email/Message.pys del_param‡s )cCsÇ|idƒdj o t‚n|iƒdjo|d=d|d