开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

source-code-analysis/python3.8.1

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.8.1
/
Doc
/
library
/
poplib.rst
python3.8.1
/
Doc
/
library
/
poplib.rst
poplib.rst 8.64 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月16日 09:46 +08:00 . git init

:mod:`poplib` --- POP3 protocol client

.. module:: poplib
 :synopsis: POP3 protocol client (requires sockets).

.. sectionauthor:: Andrew T. Csillag

Source code: :source:`Lib/poplib.py`

.. index:: pair: POP3; protocol


This module defines a class, :class:`POP3`, which encapsulates a connection to a POP3 server and implements the protocol as defined in :class:`POP3` class supports both the minimal and optional command sets from :class:`POP3` class also supports the STLS command introduced in :class:`POP3_SSL`, which provides support for connecting to POP3 servers that use SSL as an underlying protocol layer.

Note that POP3, though widely supported, is obsolescent. The implementation quality of POP3 servers varies widely, and too many are quite poor. If your mailserver supports IMAP, you would be better off using the :class:`imaplib.IMAP4` class, as IMAP servers tend to be better implemented.

The :mod:`poplib` module provides two classes:

This class implements the actual POP3 protocol. The connection is created when the instance is initialized. If port is omitted, the standard POP3 port (110) is used. The optional timeout parameter specifies a timeout in seconds for the connection attempt (if not specified, the global default timeout setting will be used).

.. audit-event:: poplib.connect self,host,port poplib.POP3

.. audit-event:: poplib.putline self,line poplib.POP3

 All commands will raise an :ref:`auditing event <auditing>`
 ``poplib.putline`` with arguments ``self`` and ``line``,
 where ``line`` is the bytes about to be sent to the remote host.

This is a subclass of :class:`POP3` that connects to the server over an SSL encrypted socket. If port is not specified, 995, the standard POP3-over-SSL port is used. timeout works as in the :class:`POP3` constructor. context is an optional :class:`ssl.SSLContext` object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Please read :ref:`ssl-security` for best practices.

keyfile and certfile are a legacy alternative to context - they can point to PEM-formatted private key and certificate chain files, respectively, for the SSL connection.

.. audit-event:: poplib.connect self,host,port poplib.POP3_SSL

.. audit-event:: poplib.putline self,line popplib.POP3_SSL

 All commands will raise an :ref:`auditing event <auditing>`
 ``poplib.putline`` with arguments ``self`` and ``line``,
 where ``line`` is the bytes about to be sent to the remote host.

.. versionchanged:: 3.2
 *context* parameter added.

.. versionchanged:: 3.4
 The class now supports hostname check with
 :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
 :data:`ssl.HAS_SNI`).

.. deprecated:: 3.6

 *keyfile* and *certfile* are deprecated in favor of *context*.
 Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
 :func:`ssl.create_default_context` select the system's trusted CA
 certificates for you.

One exception is defined as an attribute of the :mod:`poplib` module:

.. exception:: error_proto

 Exception raised on any errors from this module (errors from :mod:`socket`
 module are not caught). The reason for the exception is passed to the
 constructor as a string.


.. seealso::

 Module :mod:`imaplib`
 The standard Python IMAP module.

 `Frequently Asked Questions About Fetchmail <http://www.catb.org/~esr/fetchmail/fetchmail-FAQ.html>`_
 The FAQ for the :program:`fetchmail` POP/IMAP client collects information on
 POP3 server variations and RFC noncompliance that may be useful if you need to
 write an application based on the POP protocol.


POP3 Objects

All POP3 commands are represented by methods of the same name, in lower-case; most return the response text sent by the server.

An :class:`POP3` instance has the following methods:

.. method:: POP3.set_debuglevel(level)

 Set the instance's debugging level. This controls the amount of debugging
 output printed. The default, ``0``, produces no debugging output. A value of
 ``1`` produces a moderate amount of debugging output, generally a single line
 per request. A value of ``2`` or higher produces the maximum amount of
 debugging output, logging each line sent and received on the control connection.


.. method:: POP3.getwelcome()

 Returns the greeting string sent by the POP3 server.


.. method:: POP3.capa()

 Query the server's capabilities as specified in :rfc:`2449`.
 Returns a dictionary in the form ``{'name': ['param'...]}``.

 .. versionadded:: 3.4


.. method:: POP3.user(username)

 Send user command, response should indicate that a password is required.


.. method:: POP3.pass_(password)

 Send password, response includes message count and mailbox size. Note: the
 mailbox on the server is locked until :meth:`~poplib.quit` is called.


.. method:: POP3.apop(user, secret)

 Use the more secure APOP authentication to log into the POP3 server.


.. method:: POP3.rpop(user)

 Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.


.. method:: POP3.stat()

 Get mailbox status. The result is a tuple of 2 integers: ``(message count,
 mailbox size)``.


.. method:: POP3.list([which])

 Request message list, result is in the form ``(response, ['mesg_num octets',
 ...], octets)``. If *which* is set, it is the message to list.


.. method:: POP3.retr(which)

 Retrieve whole message number *which*, and set its seen flag. Result is in form
 ``(response, ['line', ...], octets)``.


.. method:: POP3.dele(which)

 Flag message number *which* for deletion. On most servers deletions are not
 actually performed until QUIT (the major exception is Eudora QPOP, which
 deliberately violates the RFCs by doing pending deletes on any disconnect).


.. method:: POP3.rset()

 Remove any deletion marks for the mailbox.


.. method:: POP3.noop()

 Do nothing. Might be used as a keep-alive.


.. method:: POP3.quit()

 Signoff: commit changes, unlock mailbox, drop connection.


.. method:: POP3.top(which, howmuch)

 Retrieves the message header plus *howmuch* lines of the message after the
 header of message number *which*. Result is in form ``(response, ['line', ...],
 octets)``.

 The POP3 TOP command this method uses, unlike the RETR command, doesn't set the
 message's seen flag; unfortunately, TOP is poorly specified in the RFCs and is
 frequently broken in off-brand servers. Test this method by hand against the
 POP3 servers you will use before trusting it.


.. method:: POP3.uidl(which=None)

 Return message digest (unique id) list. If *which* is specified, result contains
 the unique id for that message in the form ``'response mesgnum uid``, otherwise
 result is list ``(response, ['mesgnum uid', ...], octets)``.


.. method:: POP3.utf8()

 Try to switch to UTF-8 mode. Returns the server response if successful,
 raises :class:`error_proto` if not. Specified in :RFC:`6856`.

 .. versionadded:: 3.5


.. method:: POP3.stls(context=None)

 Start a TLS session on the active connection as specified in :rfc:`2595`.
 This is only allowed before user authentication

 *context* parameter is a :class:`ssl.SSLContext` object which allows
 bundling SSL configuration options, certificates and private keys into
 a single (potentially long-lived) structure. Please read :ref:`ssl-security`
 for best practices.

 This method supports hostname checking via
 :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
 :data:`ssl.HAS_SNI`).

 .. versionadded:: 3.4


Instances of :class:`POP3_SSL` have no additional methods. The interface of this subclass is identical to its parent.

POP3 Example

Here is a minimal example (without error checking) that opens a mailbox and retrieves and prints all messages:

import getpass, poplib

M = poplib.POP3('localhost')
M.user(getpass.getuser())
M.pass_(getpass.getpass())
numMessages = len(M.list()[1])
for i in range(numMessages):
 for j in M.retr(i+1)[1]:
 print(j)

At the end of the module, there is a test section that contains a more extensive example of usage.

Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.8.1.git
git@gitee.com:python_sourcecode/python3.8.1.git
python_sourcecode
python3.8.1
python3.8.1
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /