Changeset 391 for python/trunk/Doc/library/email.message.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/email.message.rst
r2 r391 1 :mod:`email `: Representing an email message2 ------------------------------------------- 1 :mod:`email.message`: Representing an email message 2 --------------------------------------------------- 3 3 4 4 .. module:: email.message … … 49 49 format the message the way you want. For example, by default it mangles 50 50 lines that begin with ``From``. For more flexibility, instantiate a 51 :class:`~email.generator.Generator` instance and use its :meth:`flatten`52 method directly. For example::51 :class:`~email.generator.Generator` instance and use its 52 :meth:`~email.generator.Generator.flatten` method directly. For example:: 53 53 54 54 from cStringIO import StringIO … … 134 134 be converted to a :class:`~email.charset.Charset` instance. If *charset* 135 135 is ``None``, the ``charset`` parameter will be removed from the 136 :mailheader:`Content-Type` header. Anything else will generate a 137 :exc:`TypeError`. 138 139 The message will be assumed to be of type :mimetype:`text/\*` encoded with 140 *charset.input_charset*. It will be converted to *charset.output_charset* 141 and encoded properly, if needed, when generating the plain text 136 :mailheader:`Content-Type` header (the message will not be otherwise 137 modified). Anything else will generate a :exc:`TypeError`. 138 139 If there is no existing :mailheader:`MIME-Version` header one will be 140 added. If there is no existing :mailheader:`Content-Type` header, one 141 will be added with a value of :mimetype:`text/plain`. Whether the 142 :mailheader:`Content-Type` header already exists or not, its ``charset`` 143 parameter will be set to *charset.output_charset*. If 144 *charset.input_charset* and *charset.output_charset* differ, the payload 145 will be re-encoded to the *output_charset*. If there is no existing 146 :mailheader:`Content-Transfer-Encoding` header, then the payload will be 147 transfer-encoded, if needed, using the specified 148 :class:`~email.charset.Charset`, and a header with the appropriate value 149 will be added. If a :mailheader:`Content-Transfer-Encoding` header 150 already exists, the payload is assumed to already be correctly encoded 151 using that :mailheader:`Content-Transfer-Encoding` and is not modified. 152 153 The message will be assumed to be of type :mimetype:`text/\*`, with the 154 payload either in unicode or encoded with *charset.input_charset*. 155 It will be encoded or converted to *charset.output_charset* 156 and transfer encoded properly, if needed, when generating the plain text 142 157 representation of the message. MIME headers (:mailheader:`MIME-Version`, 143 158 :mailheader:`Content-Type`, :mailheader:`Content-Transfer-Encoding`) will … … 266 281 dashes are illegal in Python identifiers). Normally, the parameter will 267 282 be added as ``key="value"`` unless the value is ``None``, in which case 268 only the key will be added. 283 only the key will be added. If the value contains non-ASCII characters, 284 it must be specified as a three tuple in the format 285 ``(CHARSET, LANGUAGE, VALUE)``, where ``CHARSET`` is a string naming the 286 charset to be used to encode the value, ``LANGUAGE`` can usually be set 287 to ``None`` or the empty string (see :RFC:`2231` for other possibilities), 288 and ``VALUE`` is the string value containing non-ASCII code points. 269 289 270 290 Here's an example:: … … 275 295 276 296 Content-Disposition: attachment; filename="bud.gif" 297 298 An example with non-ASCII characters:: 299 300 msg.add_header('Content-Disposition', 'attachment', 301 filename=('iso-8859-1', '', 'FuÃballer.ppt')) 302 303 Which produces :: 304 305 Content-Disposition: attachment; filename*="iso-8859-1''Fu%DFballer.ppt" 277 306 278 307 … … 380 409 :func:`email.utils.collapse_rfc2231_value`, passing in the return value 381 410 from :meth:`get_param`. This will return a suitably decoded Unicode 382 string wh n the value is a tuple, or the original string unquoted if it411 string when the value is a tuple, or the original string unquoted if it 383 412 isn't. For example:: 384 413 … … 448 477 :mailheader:`Content-Disposition` header of the message. If the header 449 478 does not have a ``filename`` parameter, this method falls back to looking 450 for the ``name`` parameter. If neither is found, or the header is 451 missing, then *failobj* is returned. The returned string will always be 452 unquoted as per :func:`email.utils.unquote`. 479 for the ``name`` parameter on the :mailheader:`Content-Type` header. If 480 neither is found, or the header is missing, then *failobj* is returned. 481 The returned string will always be unquoted as per 482 :func:`email.utils.unquote`. 453 483 454 484 … … 465 495 Set the ``boundary`` parameter of the :mailheader:`Content-Type` header to 466 496 *boundary*. :meth:`set_boundary` will always quote *boundary* if 467 necessary. A :exc:` HeaderParseError` is raised if the message object has468 no :mailheader:`Content-Type` header.497 necessary. A :exc:`~email.errors.HeaderParseError` is raised if the 498 message object has no :mailheader:`Content-Type` header. 469 499 470 500 Note that using this method is subtly different than deleting the old … … 560 590 .. versionchanged:: 2.5 561 591 You do not need to set the epilogue to the empty string in order for the 562 :class:`Generator` to print a newline at the end of the file. 592 :class:`~email.generator.Generator` to print a newline at the end of the 593 file. 563 594 564 595
Note:
See TracChangeset
for help on using the changeset viewer.