id: cb9d2fba360a4c09941f02deb04e3aca
parent_id: 
item_type: 1
item_id: 718c771169314d4ebb6446b9425ba854
item_updated_time: 1764345484724
title_diff: "[{\"diffs\":[[1,\"POP3收取邮件 · Python 3零起点教程 · 看云\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":29}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>POP3收取邮件 · Python 3零起点教程 · 看云</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"19800\\\"></a>\\\r\\\n<h1>POP3收取邮件 · Python 3零起点教程 · 看云</h1>\\\r\\\n\\\r\\\n<div><span>\\\n  <div>\\\n<div><br/></div><div style=\\\"font-size: 16px; display:block; min-width: 100%; position: relative;\\\"> <div style=\\\"-webkit-tap-highlight-color:transparent;-webkit-font-smoothing:antialiased;line-height:1.15;font-size:14px;box-sizing:border-box;text-size-adjust:100%;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;-webkit-font-smoothing:antialiased;overflow-x:hidden;min-width:320px;background:rgb(255, 255, 255);font-size:14px;line-height:1.4285em;color:rgba(0, 0, 0, 0.87);font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;text-rendering:optimizelegibility;text-size-adjust:100%;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;transition:margin-left 0.25s ease 0s;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;\\\"><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:10px 20px;height:50px;display:flex;\\\"><h1 style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;min-height:14px;flex:1 1 0%;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:rgb(126, 136, 139);font-size:20px;margin:0px;line-height:30px;font-weight:200;\\\">POP3收取邮件</h1></div><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;max-width:980px;padding:9px 24px;display:block;line-height:1.2;font-size:15px;overflow-wrap:break-word;color:rgb(82, 82, 82);font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, serif;margin-left:auto;margin-right:auto;\\\"><p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;margin-top:0px;\\\">SMTP用于发送邮件，如果要收取邮件呢？</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">收取邮件就是编写一个<strong style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-weight:bolder;\\\">MUA</strong>作为客户端，从<strong style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-weight:bolder;\\\">MDA</strong>把邮件获取到用户的电脑或者手机上。收取邮件最常用的协议是<strong style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-weight:bolder;\\\">POP</strong>协议，目前版本号是3，俗称<strong style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-weight:bolder;\\\">POP3</strong>。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">Python内置一个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">poplib</code>模块，实现了POP3协议，可以直接用来收邮件。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">注意到POP3协议收取的不是一个已经可以阅读的邮件本身，而是邮件的原始文本，这和SMTP协议很像，SMTP发送的也是经过编码后的一大段文本。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">要把POP3收取的文本变成可以阅读的邮件，还需要用<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">email</code>模块提供的各种类来解析原始文本，变成可阅读的邮件对象。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">所以，收取邮件分两步：</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">第一步：用<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">poplib</code>把邮件的原始文本下载到本地；</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">第二部：用<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">email</code>解析原始文本，还原为邮件对象。</p>\\\n<h3 style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;padding:0px;margin:14px 0px;font-weight:400;font-size:1.2em;line-height:1.2;\\\"><a style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;position:absolute;margin-top:-10px;\\\"></a>通过POP3下载邮件</h3>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">POP3协议本身很简单，以下面的代码为例，我们来获取最新的一封邮件内容：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\">import poplib\\\n\\\n# 输入邮件地址<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> 口令和POP3服务器地址<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nemail <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">input</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Email: '</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\npassword <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">input</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Password: '</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\npop3_server <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">input</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'POP3 server: '</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# 连接到POP3服务器<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nserver <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> poplib<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">POP3</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>pop3_server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# 可以打开或关闭调试信息<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nserver<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">set_debuglevel</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">1</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# 可选<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>打印POP3服务器的欢迎文字<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">getwelcome</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'utf-8'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# 身份认证<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nserver<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">user</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>email<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\nserver<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">pass_</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>password<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">stat</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>返回邮件数量和占用空间<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Messages: %s. Size: %s'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">stat</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">list</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>返回所有邮件的编号<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nresp<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> mails<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> octets <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">list</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# 可以查看返回的列表类似<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">[</span>b<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'1 82923'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> b<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'2 2184'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">]</span>\\\n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>mails<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# 获取最新一封邮件<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> 注意索引号从<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">1</span>开始<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nindex <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">len</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>mails<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\nresp<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> lines<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> octets <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">retr</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>index<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# lines存储了邮件的原始文本的每一行<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span>\\\n# 可以获得整个邮件的原始文本<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nmsg_content <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> b<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'\\\\\r\\\\\n'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">join</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>lines<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'utf-8'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# 稍后解析出邮件<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nmsg <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">Parser</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">parsestr</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg_content<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n# 可以根据邮件索引号直接从服务器删除邮件<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n# server<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">dele</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>index<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n# 关闭连接<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\nserver<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">quit</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">用POP3获取邮件其实很简单，要获取所有邮件，只需要循环使用<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">retr()</code>把每一封邮件内容拿到即可。真正麻烦的是把邮件的原始内容解析为可以阅读的邮件对象。</p>\\\n<h3 style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;padding:0px;margin:14px 0px;font-weight:400;font-size:1.2em;line-height:1.2;\\\"><a style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;position:absolute;margin-top:-10px;\\\"></a>解析邮件</h3>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">解析邮件的过程和上一节构造邮件正好相反，因此，先导入必要的模块：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\">from email<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>parser import Parser\\\nfrom email<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>header import decode_header\\\nfrom email<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>utils import parseaddr\\\n\\\nimport poplib\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">只需要一行代码就可以把邮件内容解析为<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Message</code>对象：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\">msg <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">Parser</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">parsestr</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg_content<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">但是这个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Message</code>对象本身可能是一个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEMultipart</code>对象，即包含嵌套的其他<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEBase</code>对象，嵌套可能还不止一层。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">所以我们要递归地打印出<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Message</code>对象的层次结构：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\"># indent用于缩进显示<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\ndef <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print_info</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> indent <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">==</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n        <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">for</span> header <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">in</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">[</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'From'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'To'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Subject'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">]</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n            value <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>header<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">''</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n                <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> header<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">==</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Subject'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n                    value <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode_str</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n                <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">else</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n                    hdr<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> addr <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">parseaddr</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n                    name <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode_str</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>hdr<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n                    value <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> u<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%s &lt;%s&gt;'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>name<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> addr<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%s%s: %s'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'  '</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">*</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> header<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">is_multipart</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n        parts <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get_payload</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n        <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">for</span> n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> part <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">in</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">enumerate</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>parts<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%spart %s'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'  '</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">*</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%s--------------------'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'  '</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">*</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print_info</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>part<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> indent <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">+</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">1</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">else</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n        content_type <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get_content_type</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n        <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> content_type<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">==</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'text/plain'</span> or content_type<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">==</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'text/html'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n            content <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get_payload</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>decode<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span>True<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            charset <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">guess_charset</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> charset<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n                content <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> content<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>charset<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%sText: %s'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'  '</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">*</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> content <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">+</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'...'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n        <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">else</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n            <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">print</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'%sAttachment: %s'</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">%</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'  '</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">*</span> indent<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> content_type<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">邮件的Subject或者Email中包含的名字都是经过编码后的str，要正常显示，就必须decode：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\">def <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode_str</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>s<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n    value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> charset <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode_header</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>s<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">[</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">]</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> charset<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n        value <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> value<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">decode</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>charset<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">return</span> value\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">decode_header()</code>返回一个list，因为像<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Cc</code>、<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Bcc</code>这样的字段可能包含多个邮件地址，所以解析出来的会有多个元素。上面的代码我们偷了个懒，只取了第一个元素。</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">文本邮件的内容也是str，还需要检测编码，否则，非UTF-8编码的邮件都无法正常显示：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\">def <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">guess_charset</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span>msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n    charset <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get_charset</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> charset is None<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n        content_type <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> msg<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">get</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'Content-Type'</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">,</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">''</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">lower</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n        pos <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> content_type<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">find</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">'charset='</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n        <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">if</span> pos <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&gt;=</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span>\\\n            charset <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span> content_type<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">[</span>pos <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">+</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">8</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">]</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(221, 74, 104);\\\">strip</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\n    <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(0, 119, 170);\\\">return</span> charset\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">把上面的代码整理好，我们就可以来试试收取一封邮件。先往自己的邮箱发一封邮件，然后用浏览器登录邮箱，看看邮件收到没，如果收到了，我们就来用Python程序把它收到本地：</p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\"><img src=\\\":/5908636e218a40d19d89ac3d18c921ea\\\" type=\\\"image/png\\\" data-filename=\\\"2015-06-25_558b9f66bbd13.png\\\" height=\\\"195\\\" style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;border-style:none;max-width:100%;display:inline-block;padding:3px;vertical-align:middle;\\\" width=\\\"364\\\"/></p>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">运行程序，结果如下：</p>\\\n<pre style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;margin:14px 0px;overflow:auto;background-color:rgb(247, 247, 247);border:0px;border-radius:3px;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;line-height:1.45;padding:16px;\\\"><code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;border-radius:4px;word-break:break-all;white-space:pre;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;max-width:100%;overflow:initial;border:0px;tab-size:4;display:inline;padding:0px;background-color:transparent;line-height:inherit;margin:0px;\\\"><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">+</span>OK Welcome to coremail Mail Pop3 Server <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">(</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">163</span>coms<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">[</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">]</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">)</span>\\\nMessages<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">126</span>\\\\<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span> Size<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">27228317</span>\\\n\\\nFrom<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> Test <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&lt;</span>xxxxxx@qq<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>com<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&gt;</span>\\\nTo<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> Python爱好者 <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&lt;</span>xxxxxx@<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">163.</span>com<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&gt;</span>\\\nSubject<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> 用POP3收取邮件\\\npart <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span>\\\n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span>\\\n  part <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">0</span>\\\n  <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span>\\\n    Text<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> Python可以使用POP3收取邮件……<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>\\\n  part <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">1</span>\\\n  <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span>\\\n    Text<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> Python可以<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&lt;</span>a href<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">=</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(102, 153, 0);\\\">&quot;...&quot;</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&gt;</span>使用POP3<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&lt;</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">/</span>a<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">&gt;</span>收取邮件……<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">.</span>\\\npart <span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 0, 85);\\\">1</span>\\\n<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">--</span>\\\n  Attachment<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(153, 153, 153);\\\">:</span> application<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">/</span>octet<span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;color:rgb(154, 110, 58);background:rgba(255, 255, 255, 0.5);\\\">-</span>stream\\\n\\\n</code></pre>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">我们从打印的结构可以看出，这封邮件是一个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEMultipart</code>，它包含两部分：第一部分又是一个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEMultipart</code>，第二部分是一个附件。而内嵌的<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEMultipart</code>是一个<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">alternative</code>类型，它包含一个纯文本格式的<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEText</code>和一个HTML格式的<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">MIMEText</code>。</p>\\\n<h3 style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;padding:0px;margin:14px 0px;font-weight:400;font-size:1.2em;line-height:1.2;\\\"><a style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;position:absolute;margin-top:-10px;\\\"></a>小结</h3>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;\\\">用Python的<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">poplib</code>模块收取邮件分两步：第一步是用POP3协议把邮件获取到本地，第二步是用<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">email</code>模块把原始邮件解析为<code style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-size:1em;display:inline-block;border-radius:4px;padding:0.2em 0.4em;background-color:rgb(247, 247, 247);word-break:break-all;white-space:pre;line-height:1.3;margin:-0.2em 0.4em;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;\\\">Message</code>对象，然后，用适当的形式把邮件内容展示给用户即可。</p>\\\n<h3 style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;font-family:&quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, Arial, Helvetica, sans-serif;padding:0px;margin:14px 0px;font-weight:400;font-size:1.2em;line-height:1.2;\\\"><a style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;position:absolute;margin-top:-10px;\\\"></a>参考源码</h3>\\\n<p style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;padding:0px;margin:14px 0px;line-height:1.2;margin-bottom:0px;\\\"><a href=\\\"https://github.com/michaelliao/learn-python3/blob/master/samples/mail/fetch_mail.py\\\" style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;\\\" target=\\\"_blank\\\">fetch_mail.py</a></p>\\\n</div><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;max-width:980px;position:relative;padding:9px 24px;margin-left:auto;margin-right:auto;\\\"><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;float:left;color:rgb(153, 153, 153);padding:2px 0px;\\\">上一篇：<a href=\\\"https://www.kancloud.cn/thinkphp/python-guide/39541\\\" style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;\\\">SMTP发送邮件</a></span><span style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;float:right;color:rgb(153, 153, 153);padding:2px 0px;\\\">下一篇：<a href=\\\"https://www.kancloud.cn/thinkphp/python-guide/39543\\\" style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:rgb(65, 131, 196);text-decoration:none;\\\">访问数据库</a></span><span style=\\\"display:block;height:0px;clear:both;visibility:hidden;\\\">.</span></div><div style=\\\"box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;max-width:980px;padding:9px 24px 24px;display:block;margin-left:auto;margin-right:auto;\\\"></div></div></div></div></div></div></div></div></div>\\\n</div>\\\n</span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":109849}]"
metadata_diff: {"new":{"id":"718c771169314d4ebb6446b9425ba854","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345749268,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:12:53.515Z
created_time: 2025-11-28T16:12:53.515Z
type_: 13