/
usr
/
share
/
doc
/
python3-docs
/
html
/
library
/
/usr/share/doc/python3-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
61709
0644
edit
dl
rm
abc.html
41394
0644
edit
dl
rm
aifc.html
28114
0644
edit
dl
rm
allos.html
32236
0644
edit
dl
rm
archiving.html
11992
0644
edit
dl
rm
argparse.html
274984
0644
edit
dl
rm
array.html
33547
0644
edit
dl
rm
ast.html
39595
0644
edit
dl
rm
asynchat.html
32546
0644
edit
dl
rm
asyncio-dev.html
51869
0644
edit
dl
rm
asyncio-eventloop.html
111215
0644
edit
dl
rm
asyncio-eventloops.html
33026
0644
edit
dl
rm
asyncio-protocol.html
87431
0644
edit
dl
rm
asyncio-queue.html
23957
0644
edit
dl
rm
asyncio-stream.html
61005
0644
edit
dl
rm
asyncio-subprocess.html
58015
0644
edit
dl
rm
asyncio-sync.html
35678
0644
edit
dl
rm
asyncio-task.html
83968
0644
edit
dl
rm
asyncio.html
28026
0644
edit
dl
rm
asyncore.html
42706
0644
edit
dl
rm
atexit.html
18433
0644
edit
dl
rm
audioop.html
35442
0644
edit
dl
rm
base64.html
36454
0644
edit
dl
rm
bdb.html
43423
0644
edit
dl
rm
binary.html
12723
0644
edit
dl
rm
binascii.html
24745
0644
edit
dl
rm
binhex.html
11669
0644
edit
dl
rm
bisect.html
25602
0644
edit
dl
rm
builtins.html
11604
0644
edit
dl
rm
bz2.html
33358
0644
edit
dl
rm
calendar.html
39539
0644
edit
dl
rm
cgi.html
55881
0644
edit
dl
rm
cgitb.html
12765
0644
edit
dl
rm
chunk.html
16872
0644
edit
dl
rm
cmath.html
34171
0644
edit
dl
rm
cmd.html
43811
0644
edit
dl
rm
code.html
27886
0644
edit
dl
rm
codecs.html
134071
0644
edit
dl
rm
codeop.html
14304
0644
edit
dl
rm
collections.abc.html
60912
0644
edit
dl
rm
collections.html
154946
0644
edit
dl
rm
colorsys.html
12627
0644
edit
dl
rm
compileall.html
28263
0644
edit
dl
rm
concurrency.html
21203
0644
edit
dl
rm
concurrent.futures.html
60660
0644
edit
dl
rm
concurrent.html
7959
0644
edit
dl
rm
configparser.html
141052
0644
edit
dl
rm
constants.html
17500
0644
edit
dl
rm
contextlib.html
88801
0644
edit
dl
rm
copy.html
13841
0644
edit
dl
rm
copyreg.html
14725
0644
edit
dl
rm
crypt.html
20331
0644
edit
dl
rm
crypto.html
10914
0644
edit
dl
rm
csv.html
69043
0644
edit
dl
rm
ctypes.html
264529
0644
edit
dl
rm
curses.ascii.html
25197
0644
edit
dl
rm
curses.html
175551
0644
edit
dl
rm
curses.panel.html
16706
0644
edit
dl
rm
custominterp.html
8734
0644
edit
dl
rm
datatypes.html
23950
0644
edit
dl
rm
datetime.html
306435
0644
edit
dl
rm
dbm.html
43119
0644
edit
dl
rm
debug.html
13983
0644
edit
dl
rm
decimal.html
233486
0644
edit
dl
rm
development.html
25123
0644
edit
dl
rm
difflib.html
96156
0644
edit
dl
rm
dis.html
106191
0644
edit
dl
rm
distribution.html
10506
0644
edit
dl
rm
distutils.html
10884
0644
edit
dl
rm
doctest.html
179752
0644
edit
dl
rm
dummy_threading.html
9316
0644
edit
dl
rm
email.charset.html
26431
0644
edit
dl
rm
email.compat32-message.html
86150
0644
edit
dl
rm
email.contentmanager.html
30028
0644
edit
dl
rm
email.encoders.html
14250
0644
edit
dl
rm
email.errors.html
19704
0644
edit
dl
rm
email.examples.html
57872
0644
edit
dl
rm
email.generator.html
41798
0644
edit
dl
rm
email.header.html
31219
0644
edit
dl
rm
email.headerregistry.html
57670
0644
edit
dl
rm
email.html
27741
0644
edit
dl
rm
email.iterators.html
13532
0644
edit
dl
rm
email.message.html
87210
0644
edit
dl
rm
email.mime.html
36081
0644
edit
dl
rm
email.parser.html
47430
0644
edit
dl
rm
email.policy.html
75241
0644
edit
dl
rm
email.util.html
33853
0644
edit
dl
rm
ensurepip.html
18700
0644
edit
dl
rm
enum.html
133949
0644
edit
dl
rm
errno.html
41331
0644
edit
dl
rm
exceptions.html
85151
0644
edit
dl
rm
faulthandler.html
23396
0644
edit
dl
rm
fcntl.html
27321
0644
edit
dl
rm
filecmp.html
25036
0644
edit
dl
rm
fileformats.html
11129
0644
edit
dl
rm
fileinput.html
30030
0644
edit
dl
rm
filesys.html
13418
0644
edit
dl
rm
fnmatch.html
16987
0644
edit
dl
rm
formatter.html
37666
0644
edit
dl
rm
fpectl.html
17538
0644
edit
dl
rm
fractions.html
29918
0644
edit
dl
rm
frameworks.html
13471
0644
edit
dl
rm
ftplib.html
54429
0644
edit
dl
rm
functional.html
9002
0644
edit
dl
rm
functions.html
201486
0644
edit
dl
rm
functools.html
64951
0644
edit
dl
rm
gc.html
29524
0644
edit
dl
rm
getopt.html
25353
0644
edit
dl
rm
getpass.html
12061
0644
edit
dl
rm
gettext.html
76641
0644
edit
dl
rm
glob.html
18432
0644
edit
dl
rm
grp.html
12383
0644
edit
dl
rm
gzip.html
32669
0644
edit
dl
rm
hashlib.html
79554
0644
edit
dl
rm
heapq.html
35529
0644
edit
dl
rm
hmac.html
17827
0644
edit
dl
rm
html.entities.html
11361
0644
edit
dl
rm
html.html
11108
0644
edit
dl
rm
html.parser.html
41842
0644
edit
dl
rm
http.client.html
65250
0644
edit
dl
rm
http.cookiejar.html
96195
0644
edit
dl
rm
http.cookies.html
39329
0644
edit
dl
rm
http.html
37602
0644
edit
dl
rm
http.server.html
58191
0644
edit
dl
rm
i18n.html
10464
0644
edit
dl
rm
idle.html
48412
0644
edit
dl
rm
imaplib.html
67339
0644
edit
dl
rm
imghdr.html
13456
0644
edit
dl
rm
imp.html
48153
0644
edit
dl
rm
importlib.html
173109
0644
edit
dl
rm
index.html
67768
0644
edit
dl
rm
inspect.html
130355
0644
edit
dl
rm
internet.html
31087
0644
edit
dl
rm
intro.html
9904
0644
edit
dl
rm
io.html
122685
0644
edit
dl
rm
ipaddress.html
105873
0644
edit
dl
rm
ipc.html
33743
0644
edit
dl
rm
itertools.html
132824
0644
edit
dl
rm
json.html
81078
0644
edit
dl
rm
keyword.html
8918
0644
edit
dl
rm
language.html
13648
0644
edit
dl
rm
linecache.html
13492
0644
edit
dl
rm
locale.html
61540
0644
edit
dl
rm
logging.config.html
85489
0644
edit
dl
rm
logging.handlers.html
112397
0644
edit
dl
rm
logging.html
134850
0644
edit
dl
rm
lzma.html
56484
0644
edit
dl
rm
macpath.html
9257
0644
edit
dl
rm
mailbox.html
157315
0644
edit
dl
rm
mailcap.html
14676
0644
edit
dl
rm
markup.html
19356
0644
edit
dl
rm
marshal.html
18317
0644
edit
dl
rm
math.html
53661
0644
edit
dl
rm
mimetypes.html
31410
0644
edit
dl
rm
misc.html
8123
0644
edit
dl
rm
mm.html
10022
0644
edit
dl
rm
mmap.html
34294
0644
edit
dl
rm
modulefinder.html
18559
0644
edit
dl
rm
modules.html
10914
0644
edit
dl
rm
msilib.html
57205
0644
edit
dl
rm
msvcrt.html
21989
0644
edit
dl
rm
multiprocessing.html
365487
0644
edit
dl
rm
netdata.html
17470
0644
edit
dl
rm
netrc.html
14568
0644
edit
dl
rm
nis.html
11659
0644
edit
dl
rm
nntplib.html
69601
0644
edit
dl
rm
numbers.html
41432
0644
edit
dl
rm
numeric.html
15535
0644
edit
dl
rm
operator.html
81460
0644
edit
dl
rm
optparse.html
249942
0644
edit
dl
rm
os.html
398039
0644
edit
dl
rm
os.path.html
53818
0644
edit
dl
rm
ossaudiodev.html
47947
0644
edit
dl
rm
othergui.html
10256
0644
edit
dl
rm
parser.html
42408
0644
edit
dl
rm
pathlib.html
116726
0644
edit
dl
rm
pdb.html
52661
0644
edit
dl
rm
persistence.html
15281
0644
edit
dl
rm
pickle.html
115052
0644
edit
dl
rm
pickletools.html
17094
0644
edit
dl
rm
pipes.html
15991
0644
edit
dl
rm
pkgutil.html
31878
0644
edit
dl
rm
platform.html
33728
0644
edit
dl
rm
plistlib.html
29290
0644
edit
dl
rm
poplib.html
30940
0644
edit
dl
rm
posix.html
17608
0644
edit
dl
rm
pprint.html
41969
0644
edit
dl
rm
profile.html
71848
0644
edit
dl
rm
pty.html
17594
0644
edit
dl
rm
pwd.html
13098
0644
edit
dl
rm
pyclbr.html
16520
0644
edit
dl
rm
pydoc.html
15991
0644
edit
dl
rm
pyexpat.html
88938
0644
edit
dl
rm
python.html
17133
0644
edit
dl
rm
py_compile.html
15508
0644
edit
dl
rm
queue.html
28199
0644
edit
dl
rm
quopri.html
13858
0644
edit
dl
rm
random.html
60646
0644
edit
dl
rm
re.html
191176
0644
edit
dl
rm
readline.html
42133
0644
edit
dl
rm
reprlib.html
24964
0644
edit
dl
rm
resource.html
36552
0644
edit
dl
rm
rlcompleter.html
14392
0644
edit
dl
rm
runpy.html
26607
0644
edit
dl
rm
sched.html
20034
0644
edit
dl
rm
secrets.html
24734
0644
edit
dl
rm
select.html
62819
0644
edit
dl
rm
selectors.html
35845
0644
edit
dl
rm
shelve.html
28777
0644
edit
dl
rm
shlex.html
48979
0644
edit
dl
rm
shutil.html
74207
0644
edit
dl
rm
signal.html
55064
0644
edit
dl
rm
site.html
32242
0644
edit
dl
rm
smtpd.html
35892
0644
edit
dl
rm
smtplib.html
68433
0644
edit
dl
rm
sndhdr.html
12439
0644
edit
dl
rm
socket.html
196077
0644
edit
dl
rm
socketserver.html
81918
0644
edit
dl
rm
spwd.html
12328
0644
edit
dl
rm
sqlite3.html
161872
0644
edit
dl
rm
ssl.html
266327
0644
edit
dl
rm
stat.html
44722
0644
edit
dl
rm
statistics.html
50050
0644
edit
dl
rm
stdtypes.html
465658
0644
edit
dl
rm
string.html
95262
0644
edit
dl
rm
stringprep.html
18654
0644
edit
dl
rm
struct.html
51100
0644
edit
dl
rm
subprocess.html
141926
0644
edit
dl
rm
sunau.html
31757
0644
edit
dl
rm
superseded.html
13781
0644
edit
dl
rm
symbol.html
8848
0644
edit
dl
rm
symtable.html
26112
0644
edit
dl
rm
sys.html
141670
0644
edit
dl
rm
sysconfig.html
30259
0644
edit
dl
rm
syslog.html
21026
0644
edit
dl
rm
tabnanny.html
12269
0644
edit
dl
rm
tarfile.html
96758
0644
edit
dl
rm
telnetlib.html
30409
0644
edit
dl
rm
tempfile.html
41394
0644
edit
dl
rm
termios.html
18181
0644
edit
dl
rm
test.html
78555
0644
edit
dl
rm
text.html
13786
0644
edit
dl
rm
textwrap.html
37998
0644
edit
dl
rm
threading.html
103464
0644
edit
dl
rm
time.html
79629
0644
edit
dl
rm
timeit.html
45249
0644
edit
dl
rm
tk.html
23299
0644
edit
dl
rm
tkinter.html
82932
0644
edit
dl
rm
tkinter.scrolledtext.html
9957
0644
edit
dl
rm
tkinter.tix.html
51858
0644
edit
dl
rm
tkinter.ttk.html
110673
0644
edit
dl
rm
token.html
22660
0644
edit
dl
rm
tokenize.html
32149
0644
edit
dl
rm
trace.html
29145
0644
edit
dl
rm
traceback.html
57588
0644
edit
dl
rm
tracemalloc.html
101144
0644
edit
dl
rm
tty.html
10540
0644
edit
dl
rm
turtle.html
250367
0644
edit
dl
rm
types.html
37060
0644
edit
dl
rm
typing.html
139175
0644
edit
dl
rm
undoc.html
9181
0644
edit
dl
rm
unicodedata.html
21108
0644
edit
dl
rm
unittest.html
250689
0644
edit
dl
rm
unittest.mock-examples.html
168144
0644
edit
dl
rm
unittest.mock.html
300089
0644
edit
dl
rm
unix.html
11780
0644
edit
dl
rm
urllib.error.html
14474
0644
edit
dl
rm
urllib.html
9566
0644
edit
dl
rm
urllib.parse.html
76334
0644
edit
dl
rm
urllib.request.html
177199
0644
edit
dl
rm
urllib.robotparser.html
17156
0644
edit
dl
rm
uu.html
12209
0644
edit
dl
rm
uuid.html
31957
0644
edit
dl
rm
venv.html
73909
0644
edit
dl
rm
warnings.html
50320
0644
edit
dl
rm
wave.html
29868
0644
edit
dl
rm
weakref.html
65292
0644
edit
dl
rm
webbrowser.html
26901
0644
edit
dl
rm
windows.html
10626
0644
edit
dl
rm
winreg.html
66730
0644
edit
dl
rm
winsound.html
21268
0644
edit
dl
rm
wsgiref.html
94492
0644
edit
dl
rm
xdrlib.html
33751
0644
edit
dl
rm
xml.dom.html
97570
0644
edit
dl
rm
xml.dom.minidom.html
41481
0644
edit
dl
rm
xml.dom.pulldom.html
24214
0644
edit
dl
rm
xml.etree.elementtree.html
135491
0644
edit
dl
rm
xml.html
19261
0644
edit
dl
rm
xml.sax.handler.html
42659
0644
edit
dl
rm
xml.sax.html
25515
0644
edit
dl
rm
xml.sax.reader.html
45869
0644
edit
dl
rm
xml.sax.utils.html
16928
0644
edit
dl
rm
xmlrpc.client.html
71947
0644
edit
dl
rm
xmlrpc.html
8535
0644
edit
dl
rm
xmlrpc.server.html
49195
0644
edit
dl
rm
zipapp.html
45105
0644
edit
dl
rm
zipfile.html
80039
0644
edit
dl
rm
zipimport.html
23052
0644
edit
dl
rm
zlib.html
34557
0644
edit
dl
rm
_dummy_thread.html
9193
0644
edit
dl
rm
_thread.html
22588
0644
edit
dl
rm
__future__.html
15792
0644
edit
dl
rm
__main__.html
9019
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/library/email.headerregistry.html
(57670B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>19.1.6. email.headerregistry: Custom Header Objects — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="19.1.7. email.contentmanager: Managing MIME Content" href="email.contentmanager.html" /> <link rel="prev" title="19.1.5. email.errors: Exception and Defect classes" href="email.errors.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/email.headerregistry.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="email.contentmanager.html" title="19.1.7. email.contentmanager: Managing MIME Content" accesskey="N">next</a> |</li> <li class="right" > <a href="email.errors.html" title="19.1.5. email.errors: Exception and Defect classes" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="netdata.html" >19. Internet Data Handling</a> »</li> <li class="nav-item nav-item-3"><a href="email.html" accesskey="U">19.1. <code class="docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-email.headerregistry"> <span id="email-headerregistry-custom-header-objects"></span><h1>19.1.6. <a class="reference internal" href="#module-email.headerregistry" title="email.headerregistry: Automatic Parsing of headers based on the field name"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.headerregistry</span></code></a>: Custom Header Objects<a class="headerlink" href="#module-email.headerregistry" title="Permalink to this headline">¶</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/email/headerregistry.py">Lib/email/headerregistry.py</a></p> <hr class="docutils" /> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6: </span><a class="footnote-reference" href="#id2" id="id1">[1]</a></p> </div> <p>Headers are represented by customized subclasses of <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>. The particular class used to represent a given header is determined by the <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy.header_factory" title="email.policy.EmailPolicy.header_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">header_factory</span></code></a> of the <a class="reference internal" href="email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> in effect when the headers are created. This section documents the particular <code class="docutils literal notranslate"><span class="pre">header_factory</span></code> implemented by the email package for handling <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> compliant email messages, which not only provides customized header objects for various header types, but also provides an extension mechanism for applications to add their own custom header types.</p> <p>When using any of the policy objects derived from <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-data docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a>, all headers are produced by <a class="reference internal" href="#email.headerregistry.HeaderRegistry" title="email.headerregistry.HeaderRegistry"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderRegistry</span></code></a> and have <a class="reference internal" href="#email.headerregistry.BaseHeader" title="email.headerregistry.BaseHeader"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHeader</span></code></a> as their last base class. Each header class has an additional base class that is determined by the type of the header. For example, many headers have the class <a class="reference internal" href="#email.headerregistry.UnstructuredHeader" title="email.headerregistry.UnstructuredHeader"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnstructuredHeader</span></code></a> as their other base class. The specialized second class for a header is determined by the name of the header, using a lookup table stored in the <a class="reference internal" href="#email.headerregistry.HeaderRegistry" title="email.headerregistry.HeaderRegistry"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderRegistry</span></code></a>. All of this is managed transparently for the typical application program, but interfaces are provided for modifying the default behavior for use by more complex applications.</p> <p>The sections below first document the header base classes and their attributes, followed by the API for modifying the behavior of <a class="reference internal" href="#email.headerregistry.HeaderRegistry" title="email.headerregistry.HeaderRegistry"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderRegistry</span></code></a>, and finally the support classes used to represent the data parsed from structured headers.</p> <dl class="class"> <dt id="email.headerregistry.BaseHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">BaseHeader</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.BaseHeader" title="Permalink to this definition">¶</a></dt> <dd><p><em>name</em> and <em>value</em> are passed to <code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> from the <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy.header_factory" title="email.policy.EmailPolicy.header_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">header_factory</span></code></a> call. The string value of any header object is the <em>value</em> fully decoded to unicode.</p> <p>This base class defines the following read-only properties:</p> <dl class="attribute"> <dt id="email.headerregistry.BaseHeader.name"> <code class="descname">name</code><a class="headerlink" href="#email.headerregistry.BaseHeader.name" title="Permalink to this definition">¶</a></dt> <dd><p>The name of the header (the portion of the field before the ‘:’). This is exactly the value passed in the <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy.header_factory" title="email.policy.EmailPolicy.header_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">header_factory</span></code></a> call for <em>name</em>; that is, case is preserved.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.BaseHeader.defects"> <code class="descname">defects</code><a class="headerlink" href="#email.headerregistry.BaseHeader.defects" title="Permalink to this definition">¶</a></dt> <dd><p>A tuple of <code class="xref py py-exc docutils literal notranslate"><span class="pre">HeaderDefect</span></code> instances reporting any RFC compliance problems found during parsing. The email package tries to be complete about detecting compliance issues. See the <a class="reference internal" href="email.errors.html#module-email.errors" title="email.errors: The exception classes used by the email package."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errors</span></code></a> module for a discussion of the types of defects that may be reported.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.BaseHeader.max_count"> <code class="descname">max_count</code><a class="headerlink" href="#email.headerregistry.BaseHeader.max_count" title="Permalink to this definition">¶</a></dt> <dd><p>The maximum number of headers of this type that can have the same <code class="docutils literal notranslate"><span class="pre">name</span></code>. A value of <code class="docutils literal notranslate"><span class="pre">None</span></code> means unlimited. The <code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> value for this attribute is <code class="docutils literal notranslate"><span class="pre">None</span></code>; it is expected that specialized header classes will override this value as needed.</p> </dd></dl> <p><code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> also provides the following method, which is called by the email library code and should not in general be called by application programs:</p> <dl class="method"> <dt id="email.headerregistry.BaseHeader.fold"> <code class="descname">fold</code><span class="sig-paren">(</span><em>*</em>, <em>policy</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.BaseHeader.fold" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string containing <a class="reference internal" href="email.policy.html#email.policy.Policy.linesep" title="email.policy.Policy.linesep"><code class="xref py py-attr docutils literal notranslate"><span class="pre">linesep</span></code></a> characters as required to correctly fold the header according to <em>policy</em>. A <a class="reference internal" href="email.policy.html#email.policy.Policy.cte_type" title="email.policy.Policy.cte_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">cte_type</span></code></a> of <code class="docutils literal notranslate"><span class="pre">8bit</span></code> will be treated as if it were <code class="docutils literal notranslate"><span class="pre">7bit</span></code>, since headers may not contain arbitrary binary data. If <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy.utf8" title="email.policy.EmailPolicy.utf8"><code class="xref py py-attr docutils literal notranslate"><span class="pre">utf8</span></code></a> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, non-ASCII data will be <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a> encoded.</p> </dd></dl> <p><code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> by itself cannot be used to create a header object. It defines a protocol that each specialized header cooperates with in order to produce the header object. Specifically, <code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> requires that the specialized class provide a <a class="reference internal" href="functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod()</span></code></a> named <code class="docutils literal notranslate"><span class="pre">parse</span></code>. This method is called as follows:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">parse</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">kwds</span><span class="p">)</span> </pre></div> </div> <p><code class="docutils literal notranslate"><span class="pre">kwds</span></code> is a dictionary containing one pre-initialized key, <code class="docutils literal notranslate"><span class="pre">defects</span></code>. <code class="docutils literal notranslate"><span class="pre">defects</span></code> is an empty list. The parse method should append any detected defects to this list. On return, the <code class="docutils literal notranslate"><span class="pre">kwds</span></code> dictionary <em>must</em> contain values for at least the keys <code class="docutils literal notranslate"><span class="pre">decoded</span></code> and <code class="docutils literal notranslate"><span class="pre">defects</span></code>. <code class="docutils literal notranslate"><span class="pre">decoded</span></code> should be the string value for the header (that is, the header value fully decoded to unicode). The parse method should assume that <em>string</em> may contain content-transfer-encoded parts, but should correctly handle all valid unicode characters as well so that it can parse un-encoded header values.</p> <p><code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code>’s <code class="docutils literal notranslate"><span class="pre">__new__</span></code> then creates the header instance, and calls its <code class="docutils literal notranslate"><span class="pre">init</span></code> method. The specialized class only needs to provide an <code class="docutils literal notranslate"><span class="pre">init</span></code> method if it wishes to set additional attributes beyond those provided by <code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> itself. Such an <code class="docutils literal notranslate"><span class="pre">init</span></code> method should look like this:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">_myattr</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'myattr'</span><span class="p">)</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span> </pre></div> </div> <p>That is, anything extra that the specialized class puts in to the <code class="docutils literal notranslate"><span class="pre">kwds</span></code> dictionary should be removed and handled, and the remaining contents of <code class="docutils literal notranslate"><span class="pre">kw</span></code> (and <code class="docutils literal notranslate"><span class="pre">args</span></code>) passed to the <code class="docutils literal notranslate"><span class="pre">BaseHeader</span></code> <code class="docutils literal notranslate"><span class="pre">init</span></code> method.</p> </dd></dl> <dl class="class"> <dt id="email.headerregistry.UnstructuredHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">UnstructuredHeader</code><a class="headerlink" href="#email.headerregistry.UnstructuredHeader" title="Permalink to this definition">¶</a></dt> <dd><p>An “unstructured” header is the default type of header in <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a>. Any header that does not have a specified syntax is treated as unstructured. The classic example of an unstructured header is the <em class="mailheader">Subject</em> header.</p> <p>In <span class="target" id="index-3"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a>, an unstructured header is a run of arbitrary text in the ASCII character set. <span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a>, however, has an <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> compatible mechanism for encoding non-ASCII text as ASCII characters within a header value. When a <em>value</em> containing encoded words is passed to the constructor, the <code class="docutils literal notranslate"><span class="pre">UnstructuredHeader</span></code> parser converts such encoded words into unicode, following the <span class="target" id="index-6"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a> rules for unstructured text. The parser uses heuristics to attempt to decode certain non-compliant encoded words. Defects are registered in such cases, as well as defects for issues such as invalid characters within the encoded words or the non-encoded text.</p> <p>This header type provides no additional attributes.</p> </dd></dl> <dl class="class"> <dt id="email.headerregistry.DateHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">DateHeader</code><a class="headerlink" href="#email.headerregistry.DateHeader" title="Permalink to this definition">¶</a></dt> <dd><p><span class="target" id="index-7"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> specifies a very specific format for dates within email headers. The <code class="docutils literal notranslate"><span class="pre">DateHeader</span></code> parser recognizes that date format, as well as recognizing a number of variant forms that are sometimes found “in the wild”.</p> <p>This header type provides the following additional attributes:</p> <dl class="attribute"> <dt id="email.headerregistry.DateHeader.datetime"> <code class="descname">datetime</code><a class="headerlink" href="#email.headerregistry.DateHeader.datetime" title="Permalink to this definition">¶</a></dt> <dd><p>If the header value can be recognized as a valid date of one form or another, this attribute will contain a <a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> instance representing that date. If the timezone of the input date is specified as <code class="docutils literal notranslate"><span class="pre">-0000</span></code> (indicating it is in UTC but contains no information about the source timezone), then <a class="reference internal" href="#email.headerregistry.DateHeader.datetime" title="email.headerregistry.DateHeader.datetime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">datetime</span></code></a> will be a naive <a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>. If a specific timezone offset is found (including <cite>+0000</cite>), then <a class="reference internal" href="#email.headerregistry.DateHeader.datetime" title="email.headerregistry.DateHeader.datetime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">datetime</span></code></a> will contain an aware <code class="docutils literal notranslate"><span class="pre">datetime</span></code> that uses <a class="reference internal" href="datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timezone</span></code></a> to record the timezone offset.</p> </dd></dl> <p>The <code class="docutils literal notranslate"><span class="pre">decoded</span></code> value of the header is determined by formatting the <code class="docutils literal notranslate"><span class="pre">datetime</span></code> according to the <span class="target" id="index-8"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> rules; that is, it is set to:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">email</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">format_datetime</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">datetime</span><span class="p">)</span> </pre></div> </div> <p>When creating a <code class="docutils literal notranslate"><span class="pre">DateHeader</span></code>, <em>value</em> may be <a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> instance. This means, for example, that the following code is valid and does what one would expect:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">msg</span><span class="p">[</span><span class="s1">'Date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">21</span><span class="p">)</span> </pre></div> </div> <p>Because this is a naive <code class="docutils literal notranslate"><span class="pre">datetime</span></code> it will be interpreted as a UTC timestamp, and the resulting value will have a timezone of <code class="docutils literal notranslate"><span class="pre">-0000</span></code>. Much more useful is to use the <a class="reference internal" href="email.util.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> function from the <a class="reference internal" href="email.util.html#module-email.utils" title="email.utils: Miscellaneous email package utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">utils</span></code></a> module:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">msg</span><span class="p">[</span><span class="s1">'Date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">localtime</span><span class="p">()</span> </pre></div> </div> <p>This example sets the date header to the current time and date using the current timezone offset.</p> </dd></dl> <dl class="class"> <dt id="email.headerregistry.AddressHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">AddressHeader</code><a class="headerlink" href="#email.headerregistry.AddressHeader" title="Permalink to this definition">¶</a></dt> <dd><p>Address headers are one of the most complex structured header types. The <code class="docutils literal notranslate"><span class="pre">AddressHeader</span></code> class provides a generic interface to any address header.</p> <p>This header type provides the following additional attributes:</p> <dl class="attribute"> <dt id="email.headerregistry.AddressHeader.groups"> <code class="descname">groups</code><a class="headerlink" href="#email.headerregistry.AddressHeader.groups" title="Permalink to this definition">¶</a></dt> <dd><p>A tuple of <a class="reference internal" href="#email.headerregistry.Group" title="email.headerregistry.Group"><code class="xref py py-class docutils literal notranslate"><span class="pre">Group</span></code></a> objects encoding the addresses and groups found in the header value. Addresses that are not part of a group are represented in this list as single-address <code class="docutils literal notranslate"><span class="pre">Groups</span></code> whose <a class="reference internal" href="#email.headerregistry.Group.display_name" title="email.headerregistry.Group.display_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">display_name</span></code></a> is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.AddressHeader.addresses"> <code class="descname">addresses</code><a class="headerlink" href="#email.headerregistry.AddressHeader.addresses" title="Permalink to this definition">¶</a></dt> <dd><p>A tuple of <a class="reference internal" href="#email.headerregistry.Address" title="email.headerregistry.Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">Address</span></code></a> objects encoding all of the individual addresses from the header value. If the header value contains any groups, the individual addresses from the group are included in the list at the point where the group occurs in the value (that is, the list of addresses is “flattened” into a one dimensional list).</p> </dd></dl> <p>The <code class="docutils literal notranslate"><span class="pre">decoded</span></code> value of the header will have all encoded words decoded to unicode. <a class="reference internal" href="codecs.html#module-encodings.idna" title="encodings.idna: Internationalized Domain Names implementation"><code class="xref py py-class docutils literal notranslate"><span class="pre">idna</span></code></a> encoded domain names are also decoded to unicode. The <code class="docutils literal notranslate"><span class="pre">decoded</span></code> value is set by <a class="reference internal" href="stdtypes.html#str.join" title="str.join"><code class="xref py py-attr docutils literal notranslate"><span class="pre">join</span></code></a>ing the <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> value of the elements of the <code class="docutils literal notranslate"><span class="pre">groups</span></code> attribute with <code class="docutils literal notranslate"><span class="pre">',</span> <span class="pre">'</span></code>.</p> <p>A list of <a class="reference internal" href="#email.headerregistry.Address" title="email.headerregistry.Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">Address</span></code></a> and <a class="reference internal" href="#email.headerregistry.Group" title="email.headerregistry.Group"><code class="xref py py-class docutils literal notranslate"><span class="pre">Group</span></code></a> objects in any combination may be used to set the value of an address header. <code class="docutils literal notranslate"><span class="pre">Group</span></code> objects whose <code class="docutils literal notranslate"><span class="pre">display_name</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code> will be interpreted as single addresses, which allows an address list to be copied with groups intact by using the list obtained from the <code class="docutils literal notranslate"><span class="pre">groups</span></code> attribute of the source header.</p> </dd></dl> <dl class="class"> <dt id="email.headerregistry.SingleAddressHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">SingleAddressHeader</code><a class="headerlink" href="#email.headerregistry.SingleAddressHeader" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#email.headerregistry.AddressHeader" title="email.headerregistry.AddressHeader"><code class="xref py py-class docutils literal notranslate"><span class="pre">AddressHeader</span></code></a> that adds one additional attribute:</p> <dl class="attribute"> <dt id="email.headerregistry.SingleAddressHeader.address"> <code class="descname">address</code><a class="headerlink" href="#email.headerregistry.SingleAddressHeader.address" title="Permalink to this definition">¶</a></dt> <dd><p>The single address encoded by the header value. If the header value actually contains more than one address (which would be a violation of the RFC under the default <a class="reference internal" href="email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a>), accessing this attribute will result in a <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p> </dd></dl> </dd></dl> <p>Many of the above classes also have a <code class="docutils literal notranslate"><span class="pre">Unique</span></code> variant (for example, <code class="docutils literal notranslate"><span class="pre">UniqueUnstructuredHeader</span></code>). The only difference is that in the <code class="docutils literal notranslate"><span class="pre">Unique</span></code> variant, <a class="reference internal" href="#email.headerregistry.BaseHeader.max_count" title="email.headerregistry.BaseHeader.max_count"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_count</span></code></a> is set to 1.</p> <dl class="class"> <dt id="email.headerregistry.MIMEVersionHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">MIMEVersionHeader</code><a class="headerlink" href="#email.headerregistry.MIMEVersionHeader" title="Permalink to this definition">¶</a></dt> <dd><p>There is really only one valid value for the <em class="mailheader">MIME-Version</em> header, and that is <code class="docutils literal notranslate"><span class="pre">1.0</span></code>. For future proofing, this header class supports other valid version numbers. If a version number has a valid value per <span class="target" id="index-9"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2045.html"><strong>RFC 2045</strong></a>, then the header object will have non-<code class="docutils literal notranslate"><span class="pre">None</span></code> values for the following attributes:</p> <dl class="attribute"> <dt id="email.headerregistry.MIMEVersionHeader.version"> <code class="descname">version</code><a class="headerlink" href="#email.headerregistry.MIMEVersionHeader.version" title="Permalink to this definition">¶</a></dt> <dd><p>The version number as a string, with any whitespace and/or comments removed.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.MIMEVersionHeader.major"> <code class="descname">major</code><a class="headerlink" href="#email.headerregistry.MIMEVersionHeader.major" title="Permalink to this definition">¶</a></dt> <dd><p>The major version number as an integer</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.MIMEVersionHeader.minor"> <code class="descname">minor</code><a class="headerlink" href="#email.headerregistry.MIMEVersionHeader.minor" title="Permalink to this definition">¶</a></dt> <dd><p>The minor version number as an integer</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="email.headerregistry.ParameterizedMIMEHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">ParameterizedMIMEHeader</code><a class="headerlink" href="#email.headerregistry.ParameterizedMIMEHeader" title="Permalink to this definition">¶</a></dt> <dd><p>MIME headers all start with the prefix ‘Content-‘. Each specific header has a certain value, described under the class for that header. Some can also take a list of supplemental parameters, which have a common format. This class serves as a base for all the MIME headers that take parameters.</p> <dl class="attribute"> <dt id="email.headerregistry.ParameterizedMIMEHeader.params"> <code class="descname">params</code><a class="headerlink" href="#email.headerregistry.ParameterizedMIMEHeader.params" title="Permalink to this definition">¶</a></dt> <dd><p>A dictionary mapping parameter names to parameter values.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="email.headerregistry.ContentTypeHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">ContentTypeHeader</code><a class="headerlink" href="#email.headerregistry.ContentTypeHeader" title="Permalink to this definition">¶</a></dt> <dd><p>A <a class="reference internal" href="#email.headerregistry.ParameterizedMIMEHeader" title="email.headerregistry.ParameterizedMIMEHeader"><code class="xref py py-class docutils literal notranslate"><span class="pre">ParameterizedMIMEHeader</span></code></a> class that handles the <em class="mailheader">Content-Type</em> header.</p> <dl class="attribute"> <dt id="email.headerregistry.ContentTypeHeader.content_type"> <code class="descname">content_type</code><a class="headerlink" href="#email.headerregistry.ContentTypeHeader.content_type" title="Permalink to this definition">¶</a></dt> <dd><p>The content type string, in the form <code class="docutils literal notranslate"><span class="pre">maintype/subtype</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.ContentTypeHeader.maintype"> <code class="descname">maintype</code><a class="headerlink" href="#email.headerregistry.ContentTypeHeader.maintype" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="attribute"> <dt id="email.headerregistry.ContentTypeHeader.subtype"> <code class="descname">subtype</code><a class="headerlink" href="#email.headerregistry.ContentTypeHeader.subtype" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> </dd></dl> <dl class="class"> <dt id="email.headerregistry.ContentDispositionHeader"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">ContentDispositionHeader</code><a class="headerlink" href="#email.headerregistry.ContentDispositionHeader" title="Permalink to this definition">¶</a></dt> <dd><p>A <a class="reference internal" href="#email.headerregistry.ParameterizedMIMEHeader" title="email.headerregistry.ParameterizedMIMEHeader"><code class="xref py py-class docutils literal notranslate"><span class="pre">ParameterizedMIMEHeader</span></code></a> class that handles the <em class="mailheader">Content-Disposition</em> header.</p> <dl class="attribute"> <dt> <code class="descname">content-disposition</code></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">inline</span></code> and <code class="docutils literal notranslate"><span class="pre">attachment</span></code> are the only valid values in common use.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="email.headerregistry.ContentTransferEncoding"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">ContentTransferEncoding</code><a class="headerlink" href="#email.headerregistry.ContentTransferEncoding" title="Permalink to this definition">¶</a></dt> <dd><p>Handles the <em class="mailheader">Content-Transfer-Encoding</em> header.</p> <dl class="attribute"> <dt id="email.headerregistry.ContentTransferEncoding.cte"> <code class="descname">cte</code><a class="headerlink" href="#email.headerregistry.ContentTransferEncoding.cte" title="Permalink to this definition">¶</a></dt> <dd><p>Valid values are <code class="docutils literal notranslate"><span class="pre">7bit</span></code>, <code class="docutils literal notranslate"><span class="pre">8bit</span></code>, <code class="docutils literal notranslate"><span class="pre">base64</span></code>, and <code class="docutils literal notranslate"><span class="pre">quoted-printable</span></code>. See <span class="target" id="index-10"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2045.html"><strong>RFC 2045</strong></a> for more information.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="email.headerregistry.HeaderRegistry"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">HeaderRegistry</code><span class="sig-paren">(</span><em>base_class=BaseHeader</em>, <em>default_class=UnstructuredHeader</em>, <em>use_default_map=True</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.HeaderRegistry" title="Permalink to this definition">¶</a></dt> <dd><p>This is the factory used by <a class="reference internal" href="email.policy.html#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a> by default. <code class="docutils literal notranslate"><span class="pre">HeaderRegistry</span></code> builds the class used to create a header instance dynamically, using <em>base_class</em> and a specialized class retrieved from a registry that it holds. When a given header name does not appear in the registry, the class specified by <em>default_class</em> is used as the specialized class. When <em>use_default_map</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), the standard mapping of header names to classes is copied in to the registry during initialization. <em>base_class</em> is always the last class in the generated class’s <code class="docutils literal notranslate"><span class="pre">__bases__</span></code> list.</p> <p>The default mappings are:</p> <blockquote> <div><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">subject:</th><td class="field-body">UniqueUnstructuredHeader</td> </tr> <tr class="field-even field"><th class="field-name">date:</th><td class="field-body">UniqueDateHeader</td> </tr> <tr class="field-odd field"><th class="field-name">resent-date:</th><td class="field-body">DateHeader</td> </tr> <tr class="field-even field"><th class="field-name">orig-date:</th><td class="field-body">UniqueDateHeader</td> </tr> <tr class="field-odd field"><th class="field-name">sender:</th><td class="field-body">UniqueSingleAddressHeader</td> </tr> <tr class="field-even field"><th class="field-name">resent-sender:</th><td class="field-body">SingleAddressHeader</td> </tr> <tr class="field-odd field"><th class="field-name">to:</th><td class="field-body">UniqueAddressHeader</td> </tr> <tr class="field-even field"><th class="field-name">resent-to:</th><td class="field-body">AddressHeader</td> </tr> <tr class="field-odd field"><th class="field-name">cc:</th><td class="field-body">UniqueAddressHeader</td> </tr> <tr class="field-even field"><th class="field-name">resent-cc:</th><td class="field-body">AddressHeader</td> </tr> <tr class="field-odd field"><th class="field-name">from:</th><td class="field-body">UniqueAddressHeader</td> </tr> <tr class="field-even field"><th class="field-name">resent-from:</th><td class="field-body">AddressHeader</td> </tr> <tr class="field-odd field"><th class="field-name">reply-to:</th><td class="field-body">UniqueAddressHeader</td> </tr> </tbody> </table> </div></blockquote> <p><code class="docutils literal notranslate"><span class="pre">HeaderRegistry</span></code> has the following methods:</p> <dl class="method"> <dt id="email.headerregistry.HeaderRegistry.map_to_type"> <code class="descname">map_to_type</code><span class="sig-paren">(</span><em>self</em>, <em>name</em>, <em>cls</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.HeaderRegistry.map_to_type" title="Permalink to this definition">¶</a></dt> <dd><p><em>name</em> is the name of the header to be mapped. It will be converted to lower case in the registry. <em>cls</em> is the specialized class to be used, along with <em>base_class</em>, to create the class used to instantiate headers that match <em>name</em>.</p> </dd></dl> <dl class="method"> <dt id="email.headerregistry.HeaderRegistry.__getitem__"> <code class="descname">__getitem__</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.HeaderRegistry.__getitem__" title="Permalink to this definition">¶</a></dt> <dd><p>Construct and return a class to handle creating a <em>name</em> header.</p> </dd></dl> <dl class="method"> <dt id="email.headerregistry.HeaderRegistry.__call__"> <code class="descname">__call__</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.HeaderRegistry.__call__" title="Permalink to this definition">¶</a></dt> <dd><p>Retrieves the specialized header associated with <em>name</em> from the registry (using <em>default_class</em> if <em>name</em> does not appear in the registry) and composes it with <em>base_class</em> to produce a class, calls the constructed class’s constructor, passing it the same argument list, and finally returns the class instance created thereby.</p> </dd></dl> </dd></dl> <p>The following classes are the classes used to represent data parsed from structured headers and can, in general, be used by an application program to construct structured values to assign to specific headers.</p> <dl class="class"> <dt id="email.headerregistry.Address"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">Address</code><span class="sig-paren">(</span><em>display_name=''</em>, <em>username=''</em>, <em>domain=''</em>, <em>addr_spec=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.Address" title="Permalink to this definition">¶</a></dt> <dd><p>The class used to represent an email address. The general form of an address is:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">display_name</span><span class="p">]</span> <span class="o"><</span><span class="n">username</span><span class="nd">@domain</span><span class="o">></span> </pre></div> </div> <p>or:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">username</span><span class="nd">@domain</span> </pre></div> </div> <p>where each part must conform to specific syntax rules spelled out in <span class="target" id="index-11"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a>.</p> <p>As a convenience <em>addr_spec</em> can be specified instead of <em>username</em> and <em>domain</em>, in which case <em>username</em> and <em>domain</em> will be parsed from the <em>addr_spec</em>. An <em>addr_spec</em> must be a properly RFC quoted string; if it is not <code class="docutils literal notranslate"><span class="pre">Address</span></code> will raise an error. Unicode characters are allowed and will be property encoded when serialized. However, per the RFCs, unicode is <em>not</em> allowed in the username portion of the address.</p> <dl class="attribute"> <dt id="email.headerregistry.Address.display_name"> <code class="descname">display_name</code><a class="headerlink" href="#email.headerregistry.Address.display_name" title="Permalink to this definition">¶</a></dt> <dd><p>The display name portion of the address, if any, with all quoting removed. If the address does not have a display name, this attribute will be an empty string.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.Address.username"> <code class="descname">username</code><a class="headerlink" href="#email.headerregistry.Address.username" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">username</span></code> portion of the address, with all quoting removed.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.Address.domain"> <code class="descname">domain</code><a class="headerlink" href="#email.headerregistry.Address.domain" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">domain</span></code> portion of the address.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.Address.addr_spec"> <code class="descname">addr_spec</code><a class="headerlink" href="#email.headerregistry.Address.addr_spec" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">username@domain</span></code> portion of the address, correctly quoted for use as a bare address (the second form shown above). This attribute is not mutable.</p> </dd></dl> <dl class="method"> <dt id="email.headerregistry.Address.__str__"> <code class="descname">__str__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.Address.__str__" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">str</span></code> value of the object is the address quoted according to <span class="target" id="index-12"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> rules, but with no Content Transfer Encoding of any non-ASCII characters.</p> </dd></dl> <p>To support SMTP (<span class="target" id="index-13"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5321.html"><strong>RFC 5321</strong></a>), <code class="docutils literal notranslate"><span class="pre">Address</span></code> handles one special case: if <code class="docutils literal notranslate"><span class="pre">username</span></code> and <code class="docutils literal notranslate"><span class="pre">domain</span></code> are both the empty string (or <code class="docutils literal notranslate"><span class="pre">None</span></code>), then the string value of the <code class="docutils literal notranslate"><span class="pre">Address</span></code> is <code class="docutils literal notranslate"><span class="pre"><></span></code>.</p> </dd></dl> <dl class="class"> <dt id="email.headerregistry.Group"> <em class="property">class </em><code class="descclassname">email.headerregistry.</code><code class="descname">Group</code><span class="sig-paren">(</span><em>display_name=None</em>, <em>addresses=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.Group" title="Permalink to this definition">¶</a></dt> <dd><p>The class used to represent an address group. The general form of an address group is:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">display_name</span><span class="p">:</span> <span class="p">[</span><span class="n">address</span><span class="o">-</span><span class="nb">list</span><span class="p">];</span> </pre></div> </div> <p>As a convenience for processing lists of addresses that consist of a mixture of groups and single addresses, a <code class="docutils literal notranslate"><span class="pre">Group</span></code> may also be used to represent single addresses that are not part of a group by setting <em>display_name</em> to <code class="docutils literal notranslate"><span class="pre">None</span></code> and providing a list of the single address as <em>addresses</em>.</p> <dl class="attribute"> <dt id="email.headerregistry.Group.display_name"> <code class="descname">display_name</code><a class="headerlink" href="#email.headerregistry.Group.display_name" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">display_name</span></code> of the group. If it is <code class="docutils literal notranslate"><span class="pre">None</span></code> and there is exactly one <code class="docutils literal notranslate"><span class="pre">Address</span></code> in <code class="docutils literal notranslate"><span class="pre">addresses</span></code>, then the <code class="docutils literal notranslate"><span class="pre">Group</span></code> represents a single address that is not in a group.</p> </dd></dl> <dl class="attribute"> <dt id="email.headerregistry.Group.addresses"> <code class="descname">addresses</code><a class="headerlink" href="#email.headerregistry.Group.addresses" title="Permalink to this definition">¶</a></dt> <dd><p>A possibly empty tuple of <a class="reference internal" href="#email.headerregistry.Address" title="email.headerregistry.Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">Address</span></code></a> objects representing the addresses in the group.</p> </dd></dl> <dl class="method"> <dt id="email.headerregistry.Group.__str__"> <code class="descname">__str__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#email.headerregistry.Group.__str__" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">str</span></code> value of a <code class="docutils literal notranslate"><span class="pre">Group</span></code> is formatted according to <span class="target" id="index-14"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a>, but with no Content Transfer Encoding of any non-ASCII characters. If <code class="docutils literal notranslate"><span class="pre">display_name</span></code> is none and there is a single <code class="docutils literal notranslate"><span class="pre">Address</span></code> in the <code class="docutils literal notranslate"><span class="pre">addresses</span></code> list, the <code class="docutils literal notranslate"><span class="pre">str</span></code> value will be the same as the <code class="docutils literal notranslate"><span class="pre">str</span></code> of that single <code class="docutils literal notranslate"><span class="pre">Address</span></code>.</p> </dd></dl> </dd></dl> <p class="rubric">Footnotes</p> <table class="docutils footnote" frame="void" id="id2" rules="none"> <colgroup><col class="label" /><col /></colgroup> <tbody valign="top"> <tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Originally added in 3.3 as a <a class="reference internal" href="../glossary.html#term-provisional-package"><span class="xref std std-term">provisional module</span></a></td></tr> </tbody> </table> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="email.errors.html" title="previous chapter">19.1.5. <code class="docutils literal notranslate"><span class="pre">email.errors</span></code>: Exception and Defect classes</a></p> <h4>Next topic</h4> <p class="topless"><a href="email.contentmanager.html" title="next chapter">19.1.7. <code class="docutils literal notranslate"><span class="pre">email.contentmanager</span></code>: Managing MIME Content</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.6/Doc/library/email.headerregistry.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="email.contentmanager.html" title="19.1.7. email.contentmanager: Managing MIME Content" >next</a> |</li> <li class="right" > <a href="email.errors.html" title="19.1.5. email.errors: Exception and Defect classes" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="netdata.html" >19. Internet Data Handling</a> »</li> <li class="nav-item nav-item-3"><a href="email.html" >19.1. <code class="docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run