开源 企业版 高校版 私有云 模力方舟 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
/
smtpd.rst
python3.8.1
/
Doc
/
library
/
smtpd.rst
smtpd.rst 10.55 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月16日 09:46 +08:00 . git init

:mod:`smtpd` --- SMTP Server

.. module:: smtpd
 :synopsis: A SMTP server implementation in Python.

.. moduleauthor:: Barry Warsaw <barry@python.org>
.. sectionauthor:: Moshe Zadka <moshez@moshez.org>

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


This module offers several classes to implement SMTP (email) servers.

.. seealso::

 The `aiosmtpd <http://aiosmtpd.readthedocs.io/>`_ package is a recommended
 replacement for this module. It is based on :mod:`asyncio` and provides a
 more straightforward API. :mod:`smtpd` should be considered deprecated.

Several server implementations are present; one is a generic do-nothing implementation, which can be overridden, while the other two offer specific mail-sending strategies.

Additionally the SMTPChannel may be extended to implement very specific interaction behaviour with SMTP clients.

The code supports RFC 1870 SIZE and SMTPServer Objects

Create a new :class:`SMTPServer` object, which binds to local address localaddr. It will treat remoteaddr as an upstream SMTP relayer. Both localaddr and remoteaddr should be a :ref:`(host, port) <host_port>` tuple. The object inherits from :class:`asyncore.dispatcher`, and so will insert itself into :mod:`asyncore`'s event loop on instantiation.

data_size_limit specifies the maximum number of bytes that will be accepted in a DATA command. A value of None or 0 means no limit.

map is the socket map to use for connections (an initially empty dictionary is a suitable value). If not specified the :mod:`asyncore` global socket map is used.

enable_SMTPUTF8 determines whether the SMTPUTF8 extension (as defined in :meth:`process_message` in the kwargs['mail_options'] list. decode_data and enable_SMTPUTF8 cannot be set to True at the same time.

decode_data specifies whether the data portion of the SMTP transaction should be decoded using UTF-8. When decode_data is False (the default), the server advertises the 8BITMIME extension (:meth:`process_message` in the kwargs['mail_options'] list. decode_data and enable_SMTPUTF8 cannot be set to True at the same time.

.. method:: process_message(peer, mailfrom, rcpttos, data, **kwargs)

 Raise a :exc:`NotImplementedError` exception. Override this in subclasses to
 do something useful with this message. Whatever was passed in the
 constructor as *remoteaddr* will be available as the :attr:`_remoteaddr`
 attribute. *peer* is the remote host's address, *mailfrom* is the envelope
 originator, *rcpttos* are the envelope recipients and *data* is a string
 containing the contents of the e-mail (which should be in :rfc:`5321`
 format).

 If the *decode_data* constructor keyword is set to ``True``, the *data*
 argument will be a unicode string. If it is set to ``False``, it
 will be a bytes object.

 *kwargs* is a dictionary containing additional information. It is empty
 if ``decode_data=True`` was given as an init argument, otherwise
 it contains the following keys:

 *mail_options*:
 a list of all received parameters to the ``MAIL``
 command (the elements are uppercase strings; example:
 ``['BODY=8BITMIME', 'SMTPUTF8']``).

 *rcpt_options*:
 same as *mail_options* but for the ``RCPT`` command.
 Currently no ``RCPT TO`` options are supported, so for now
 this will always be an empty list.

 Implementations of ``process_message`` should use the ``**kwargs``
 signature to accept arbitrary keyword arguments, since future feature
 enhancements may add keys to the kwargs dictionary.

 Return ``None`` to request a normal ``250 Ok`` response; otherwise
 return the desired response string in :RFC:`5321` format.

.. attribute:: channel_class

 Override this in subclasses to use a custom :class:`SMTPChannel` for
 managing SMTP clients.

.. versionadded:: 3.4
 The *map* constructor argument.

.. versionchanged:: 3.5
 *localaddr* and *remoteaddr* may now contain IPv6 addresses.

.. versionadded:: 3.5
 The *decode_data* and *enable_SMTPUTF8* constructor parameters, and the
 *kwargs* parameter to :meth:`process_message` when *decode_data* is
 ``False``.

.. versionchanged:: 3.6
 *decode_data* is now ``False`` by default.

DebuggingServer Objects

Create a new debugging server. Arguments are as per :class:`SMTPServer`. Messages will be discarded, and printed on stdout.

PureProxy Objects

Create a new pure proxy server. Arguments are as per :class:`SMTPServer`. Everything will be relayed to remoteaddr. Note that running this has a good chance to make you into an open relay, so please be careful.

MailmanProxy Objects

Create a new pure proxy server. Arguments are as per :class:`SMTPServer`. Everything will be relayed to remoteaddr, unless local mailman configurations knows about an address, in which case it will be handled via mailman. Note that running this has a good chance to make you into an open relay, so please be careful.

SMTPChannel Objects

Create a new :class:`SMTPChannel` object which manages the communication between the server and a single SMTP client.

conn and addr are as per the instance variables described below.

data_size_limit specifies the maximum number of bytes that will be accepted in a DATA command. A value of None or 0 means no limit.

enable_SMTPUTF8 determines whether the SMTPUTF8 extension (as defined in :attr:`SMTPServer.channel_class` of your :class:`SMTPServer`.

.. versionchanged:: 3.5
 The *decode_data* and *enable_SMTPUTF8* parameters were added.

.. versionchanged:: 3.6
 *decode_data* is now ``False`` by default.

The :class:`SMTPChannel` has the following instance variables:

.. attribute:: smtp_server

 Holds the :class:`SMTPServer` that spawned this channel.

.. attribute:: conn

 Holds the socket object connecting to the client.

.. attribute:: addr

 Holds the address of the client, the second value returned by
 :func:`socket.accept <socket.socket.accept>`

.. attribute:: received_lines

 Holds a list of the line strings (decoded using UTF-8) received from
 the client. The lines have their ``"\r\n"`` line ending translated to
 ``"\n"``.

.. attribute:: smtp_state

 Holds the current state of the channel. This will be either
 :attr:`COMMAND` initially and then :attr:`DATA` after the client sends
 a "DATA" line.

.. attribute:: seen_greeting

 Holds a string containing the greeting sent by the client in its "HELO".

.. attribute:: mailfrom

 Holds a string containing the address identified in the "MAIL FROM:" line
 from the client.

.. attribute:: rcpttos

 Holds a list of strings containing the addresses identified in the
 "RCPT TO:" lines from the client.

.. attribute:: received_data

 Holds a string containing all of the data sent by the client during the
 DATA state, up to but not including the terminating ``"\r\n.\r\n"``.

.. attribute:: fqdn

 Holds the fully-qualified domain name of the server as returned by
 :func:`socket.getfqdn`.

.. attribute:: peer

 Holds the name of the client peer as returned by ``conn.getpeername()``
 where ``conn`` is :attr:`conn`.

The :class:`SMTPChannel` operates by invoking methods named smtp_<command> upon reception of a command line from the client. Built into the base :class:`SMTPChannel` class are methods for handling the following commands (and responding to them appropriately):

Command Action taken
HELO Accepts the greeting from the client and stores it in :attr:`seen_greeting`. Sets server to base command mode.
EHLO Accepts the greeting from the client and stores it in :attr:`seen_greeting`. Sets server to extended command mode.
NOOP Takes no action.
QUIT Closes the connection cleanly.
MAIL Accepts the "MAIL FROM:" syntax and stores the supplied address as :attr:`mailfrom`. In extended command mode, accepts the :attr:`rcpttos` list.
RSET Resets the :attr:`mailfrom`, :attr:`rcpttos`, and :attr:`received_data`, but not the greeting.
DATA Sets the internal state to :attr:`DATA` and stores remaining lines from the client in :attr:`received_data` until the terminator "\r\n.\r\n" is received.
HELP Returns minimal information on command syntax
VRFY Returns code 252 (the server doesn't know if the address is valid)
EXPN Reports that the command is not implemented.
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 によって変換されたページ (->オリジナル) /