<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>18.1.10. email: Iterators — Python v2.6.6 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.6.6',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python v2.6.6 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="top" title="Python v2.6.6 documentation" href="../index.html" />
<link rel="up" title="18.1. email — An email and MIME handling package" href="email.html" />
<link rel="next" title="18.1.11. email: Examples" href="email-examples.html" />
<link rel="prev" title="18.1.9. email: Miscellaneous utilities" href="email.util.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li class="right" >
<a href="email-examples.html" title="18.1.11. email: Examples"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="email.util.html" title="18.1.9. email: Miscellaneous utilities"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python v2.6.6 documentation</a> »</li>
<li><a href="index.html" >The Python Standard Library</a> »</li>
<li><a href="netdata.html" >18. Internet Data Handling</a> »</li>
<li><a href="email.html" accesskey="U">18.1. <tt class="docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">email</span></tt> — An email and MIME handling package</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-email.iterators">
<h1>18.1.10. <a title="Package supporting the parsing, manipulating, and generating email messages, including MIME documents." class="reference external" href="email.html#module-email"><tt class="xref docutils literal"><span class="pre">email</span></tt></a>: Iterators<a class="headerlink" href="#module-email.iterators" title="Permalink to this headline">¶</a></h1>
<p>Iterating over a message object tree is fairly easy with the
<tt class="xref docutils literal"><span class="pre">Message.walk()</span></tt> method. The <tt class="xref docutils literal"><span class="pre">email.iterators</span></tt> module provides some
useful higher level iterations over message object trees.</p>
<dl class="function">
<dt id="email.iterators.body_line_iterator">
<tt class="descclassname">email.iterators.</tt><tt class="descname">body_line_iterator</tt><big>(</big><em>msg</em><span class="optional">[</span>, <em>decode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#email.iterators.body_line_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>This iterates over all the payloads in all the subparts of <em>msg</em>, returning the
string payloads line-by-line. It skips over all the subpart headers, and it
skips over any subpart with a payload that isn’t a Python string. This is
somewhat equivalent to reading the flat text representation of the message from
a file using <tt class="xref docutils literal"><span class="pre">readline()</span></tt>, skipping over all the intervening headers.</p>
<p>Optional <em>decode</em> is passed through to <tt class="xref docutils literal"><span class="pre">Message.get_payload()</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="email.iterators.typed_subpart_iterator">
<tt class="descclassname">email.iterators.</tt><tt class="descname">typed_subpart_iterator</tt><big>(</big><em>msg</em><span class="optional">[</span>, <em>maintype</em><span class="optional">[</span>, <em>subtype</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#email.iterators.typed_subpart_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>This iterates over all the subparts of <em>msg</em>, returning only those subparts that
match the MIME type specified by <em>maintype</em> and <em>subtype</em>.</p>
<p>Note that <em>subtype</em> is optional; if omitted, then subpart MIME type matching is
done only with the main type. <em>maintype</em> is optional too; it defaults to
<em>text</em>.</p>
<p>Thus, by default <a title="email.iterators.typed_subpart_iterator" class="reference internal" href="#email.iterators.typed_subpart_iterator"><tt class="xref docutils literal"><span class="pre">typed_subpart_iterator()</span></tt></a> returns each subpart that has a
MIME type of <em>text/*</em>.</p>
</dd></dl>
<p>The following function has been added as a useful debugging tool. It should
<em>not</em> be considered part of the supported public interface for the package.</p>
<dl class="function">
<dt id="email.iterators._structure">
<tt class="descclassname">email.iterators.</tt><tt class="descname">_structure</tt><big>(</big><em>msg</em><span class="optional">[</span>, <em>fp</em><span class="optional">[</span>, <em>level</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#email.iterators._structure" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints an indented representation of the content types of the message object
structure. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">msg</span> <span class="o">=</span> <span class="n">email</span><span class="o">.</span><span class="n">message_from_file</span><span class="p">(</span><span class="n">somefile</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">_structure</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="go">multipart/mixed</span>
<span class="go"> text/plain</span>
<span class="go"> text/plain</span>
<span class="go"> multipart/digest</span>
<span class="go"> message/rfc822</span>
<span class="go"> text/plain</span>
<span class="go"> message/rfc822</span>
<span class="go"> text/plain</span>
<span class="go"> message/rfc822</span>
<span class="go"> text/plain</span>
<span class="go"> message/rfc822</span>
<span class="go"> text/plain</span>
<span class="go"> message/rfc822</span>
<span class="go"> text/plain</span>
<span class="go"> text/plain</span>
</pre></div>
</div>
<p>Optional <em>fp</em> is a file-like object to print the output to. It must be suitable
for Python’s extended print statement. <em>level</em> is used internally.</p>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="email.util.html"
title="previous chapter">18.1.9. <tt class="docutils literal docutils literal"><span class="pre">email</span></tt>: Miscellaneous utilities</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="email-examples.html"
title="next chapter">18.1.11. <tt class="docutils literal docutils literal"><span class="pre">email</span></tt>: Examples</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li><a href="../_sources/library/email.iterators.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../modindex.html" title="Global Module Index"
>modules</a> |</li>
<li class="right" >
<a href="email-examples.html" title="18.1.11. email: Examples"
>next</a> |</li>
<li class="right" >
<a href="email.util.html" title="18.1.9. email: Miscellaneous utilities"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python v2.6.6 documentation</a> »</li>
<li><a href="index.html" >The Python Standard Library</a> »</li>
<li><a href="netdata.html" >18. Internet Data Handling</a> »</li>
<li><a href="email.html" >18.1. <tt class="docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">email</span></tt> — An email and MIME handling package</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="http://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on Jul 20, 2011.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.6.
</div>
</body>
</html>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez