/
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.policy.html
(75241B)
<!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.4. email.policy: Policy 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.5. email.errors: Exception and Defect classes" href="email.errors.html" /> <link rel="prev" title="19.1.3. email.generator: Generating MIME documents" href="email.generator.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/email.policy.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.errors.html" title="19.1.5. email.errors: Exception and Defect classes" accesskey="N">next</a> |</li> <li class="right" > <a href="email.generator.html" title="19.1.3. email.generator: Generating MIME documents" 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.policy"> <span id="email-policy-policy-objects"></span><h1>19.1.4. <a class="reference internal" href="#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">email.policy</span></code></a>: Policy Objects<a class="headerlink" href="#module-email.policy" title="Permalink to this headline">¶</a></h1> <div class="versionadded"> <p><span class="versionmodified">New in version 3.3.</span></p> </div> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/email/policy.py">Lib/email/policy.py</a></p> <hr class="docutils" /> <p>The <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> package’s prime focus is the handling of email messages as described by the various email and MIME RFCs. However, the general format of email messages (a block of header fields each consisting of a name followed by a colon followed by a value, the whole block followed by a blank line and an arbitrary ‘body’), is a format that has found utility outside of the realm of email. Some of these uses conform fairly closely to the main email RFCs, some do not. Even when working with email, there are times when it is desirable to break strict compliance with the RFCs, such as generating emails that interoperate with email servers that do not themselves follow the standards, or that implement extensions you want to use in ways that violate the standards.</p> <p>Policy objects give the email package the flexibility to handle all these disparate use cases.</p> <p>A <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> object encapsulates a set of attributes and methods that control the behavior of various components of the email package during use. <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> instances can be passed to various classes and methods in the email package to alter the default behavior. The settable values and their defaults are described below.</p> <p>There is a default policy used by all classes in the email package. For all of the <a class="reference internal" href="email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a> classes and the related convenience functions, and for the <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> class, this is the <a class="reference internal" href="#email.policy.Compat32" title="email.policy.Compat32"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compat32</span></code></a> policy, via its corresponding pre-defined instance <a class="reference internal" href="#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-const docutils literal notranslate"><span class="pre">compat32</span></code></a>. This policy provides for complete backward compatibility (in some cases, including bug compatibility) with the pre-Python3.3 version of the email package.</p> <p>This default value for the <em>policy</em> keyword to <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> is the <a class="reference internal" href="#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a> policy, via its pre-defined instance <a class="reference internal" href="#email.policy.default" title="email.policy.default"><code class="xref py py-data docutils literal notranslate"><span class="pre">default</span></code></a>.</p> <p>When a <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> or <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> object is created, it acquires a policy. If the message is created by a <a class="reference internal" href="email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a>, a policy passed to the parser will be the policy used by the message it creates. If the message is created by the program, then the policy can be specified when it is created. When a message is passed to a <a class="reference internal" href="email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a>, the generator uses the policy from the message by default, but you can also pass a specific policy to the generator that will override the one stored on the message object.</p> <p>The default value for the <em>policy</em> keyword for the <a class="reference internal" href="email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.parser</span></code></a> classes and the parser convenience functions <strong>will be changing</strong> in a future version of Python. Therefore you should <strong>always specify explicitly which policy you want to use</strong> when calling any of the classes and functions described in the <a class="reference internal" href="email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a> module.</p> <p>The first part of this documentation covers the features of <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a>, an <a class="reference internal" href="../glossary.html#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> that defines the features that are common to all policy objects, including <a class="reference internal" href="#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-const docutils literal notranslate"><span class="pre">compat32</span></code></a>. This includes certain hook methods that are called internally by the email package, which a custom policy could override to obtain different behavior. The second part describes the concrete classes <a class="reference internal" href="#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a> and <a class="reference internal" href="#email.policy.Compat32" title="email.policy.Compat32"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compat32</span></code></a>, which implement the hooks that provide the standard behavior and the backward compatible behavior and features, respectively.</p> <p><a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> instances are immutable, but they can be cloned, accepting the same keyword arguments as the class constructor and returning a new <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> instance that is a copy of the original but with the specified attributes values changed.</p> <p>As an example, the following code could be used to read an email message from a file on disk and pass it to the system <code class="docutils literal notranslate"><span class="pre">sendmail</span></code> program on a Unix system:</p> <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">email</span> <span class="kn">import</span> <span class="n">message_from_binary_file</span> <span class="gp">>>> </span><span class="kn">from</span> <span class="nn">email.generator</span> <span class="kn">import</span> <span class="n">BytesGenerator</span> <span class="gp">>>> </span><span class="kn">from</span> <span class="nn">email</span> <span class="kn">import</span> <span class="n">policy</span> <span class="gp">>>> </span><span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">Popen</span><span class="p">,</span> <span class="n">PIPE</span> <span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'mymsg.txt'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="gp">... </span> <span class="n">msg</span> <span class="o">=</span> <span class="n">message_from_binary_file</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">policy</span><span class="o">=</span><span class="n">policy</span><span class="o">.</span><span class="n">default</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">([</span><span class="s1">'sendmail'</span><span class="p">,</span> <span class="n">msg</span><span class="p">[</span><span class="s1">'To'</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="n">stdin</span><span class="o">=</span><span class="n">PIPE</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">BytesGenerator</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">stdin</span><span class="p">,</span> <span class="n">policy</span><span class="o">=</span><span class="n">msg</span><span class="o">.</span><span class="n">policy</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">linesep</span><span class="o">=</span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">'</span><span class="p">))</span> <span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">rc</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span> </pre></div> </div> <p>Here we are telling <a class="reference internal" href="email.generator.html#email.generator.BytesGenerator" title="email.generator.BytesGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">BytesGenerator</span></code></a> to use the RFC correct line separator characters when creating the binary string to feed into <code class="docutils literal notranslate"><span class="pre">sendmail's</span></code> <code class="docutils literal notranslate"><span class="pre">stdin</span></code>, where the default policy would use <code class="docutils literal notranslate"><span class="pre">\n</span></code> line separators.</p> <p>Some email package methods accept a <em>policy</em> keyword argument, allowing the policy to be overridden for that method. For example, the following code uses the <a class="reference internal" href="email.compat32-message.html#email.message.Message.as_bytes" title="email.message.Message.as_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_bytes()</span></code></a> method of the <em>msg</em> object from the previous example and writes the message to a file using the native line separators for the platform on which it is running:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span> <span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'converted.txt'</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="gp">... </span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">as_bytes</span><span class="p">(</span><span class="n">policy</span><span class="o">=</span><span class="n">msg</span><span class="o">.</span><span class="n">policy</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">linesep</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)))</span> <span class="go">17</span> </pre></div> </div> <p>Policy objects can also be combined using the addition operator, producing a policy object whose settings are a combination of the non-default values of the summed objects:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">compat_SMTP</span> <span class="o">=</span> <span class="n">policy</span><span class="o">.</span><span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">linesep</span><span class="o">=</span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">compat_strict</span> <span class="o">=</span> <span class="n">policy</span><span class="o">.</span><span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">raise_on_defect</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">compat_strict_SMTP</span> <span class="o">=</span> <span class="n">compat_SMTP</span> <span class="o">+</span> <span class="n">compat_strict</span> </pre></div> </div> <p>This operation is not commutative; that is, the order in which the objects are added matters. To illustrate:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">policy100</span> <span class="o">=</span> <span class="n">policy</span><span class="o">.</span><span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">max_line_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">policy80</span> <span class="o">=</span> <span class="n">policy</span><span class="o">.</span><span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">max_line_length</span><span class="o">=</span><span class="mi">80</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">apolicy</span> <span class="o">=</span> <span class="n">policy100</span> <span class="o">+</span> <span class="n">policy80</span> <span class="gp">>>> </span><span class="n">apolicy</span><span class="o">.</span><span class="n">max_line_length</span> <span class="go">80</span> <span class="gp">>>> </span><span class="n">apolicy</span> <span class="o">=</span> <span class="n">policy80</span> <span class="o">+</span> <span class="n">policy100</span> <span class="gp">>>> </span><span class="n">apolicy</span><span class="o">.</span><span class="n">max_line_length</span> <span class="go">100</span> </pre></div> </div> <dl class="class"> <dt id="email.policy.Policy"> <em class="property">class </em><code class="descclassname">email.policy.</code><code class="descname">Policy</code><span class="sig-paren">(</span><em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy" title="Permalink to this definition">¶</a></dt> <dd><p>This is the <a class="reference internal" href="../glossary.html#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> for all policy classes. It provides default implementations for a couple of trivial methods, as well as the implementation of the immutability property, the <a class="reference internal" href="#email.policy.Policy.clone" title="email.policy.Policy.clone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clone()</span></code></a> method, and the constructor semantics.</p> <p>The constructor of a policy class can be passed various keyword arguments. The arguments that may be specified are any non-method properties on this class, plus any additional non-method properties on the concrete class. A value specified in the constructor will override the default value for the corresponding attribute.</p> <p>This class defines the following properties, and thus values for the following may be passed in the constructor of any policy class:</p> <dl class="attribute"> <dt id="email.policy.Policy.max_line_length"> <code class="descname">max_line_length</code><a class="headerlink" href="#email.policy.Policy.max_line_length" title="Permalink to this definition">¶</a></dt> <dd><p>The maximum length of any line in the serialized output, not counting the end of line character(s). Default is 78, per <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>. A value of <code class="docutils literal notranslate"><span class="pre">0</span></code> or <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> indicates that no line wrapping should be done at all.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.Policy.linesep"> <code class="descname">linesep</code><a class="headerlink" href="#email.policy.Policy.linesep" title="Permalink to this definition">¶</a></dt> <dd><p>The string to be used to terminate lines in serialized output. The default is <code class="docutils literal notranslate"><span class="pre">\n</span></code> because that’s the internal end-of-line discipline used by Python, though <code class="docutils literal notranslate"><span class="pre">\r\n</span></code> is required by the RFCs.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.Policy.cte_type"> <code class="descname">cte_type</code><a class="headerlink" href="#email.policy.Policy.cte_type" title="Permalink to this definition">¶</a></dt> <dd><p>Controls the type of Content Transfer Encodings that may be or are required to be used. The possible values are:</p> <table border="1" class="docutils"> <colgroup> <col width="11%" /> <col width="89%" /> </colgroup> <tbody valign="top"> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">7bit</span></code></td> <td>all data must be “7 bit clean” (ASCII-only). This means that where necessary data will be encoded using either quoted-printable or base64 encoding.</td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">8bit</span></code></td> <td>data is not constrained to be 7 bit clean. Data in headers is still required to be ASCII-only and so will be encoded (see <a class="reference internal" href="#email.policy.Policy.fold_binary" title="email.policy.Policy.fold_binary"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fold_binary()</span></code></a> and <a class="reference internal" href="#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> below for exceptions), but body parts may use the <code class="docutils literal notranslate"><span class="pre">8bit</span></code> CTE.</td> </tr> </tbody> </table> <p>A <code class="docutils literal notranslate"><span class="pre">cte_type</span></code> value of <code class="docutils literal notranslate"><span class="pre">8bit</span></code> only works with <code class="docutils literal notranslate"><span class="pre">BytesGenerator</span></code>, not <code class="docutils literal notranslate"><span class="pre">Generator</span></code>, because strings cannot contain binary data. If a <code class="docutils literal notranslate"><span class="pre">Generator</span></code> is operating under a policy that specifies <code class="docutils literal notranslate"><span class="pre">cte_type=8bit</span></code>, it will act as if <code class="docutils literal notranslate"><span class="pre">cte_type</span></code> is <code class="docutils literal notranslate"><span class="pre">7bit</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.Policy.raise_on_defect"> <code class="descname">raise_on_defect</code><a class="headerlink" href="#email.policy.Policy.raise_on_defect" title="Permalink to this definition">¶</a></dt> <dd><p>If <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a>, any defects encountered will be raised as errors. If <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> (the default), defects will be passed to the <a class="reference internal" href="#email.policy.Policy.register_defect" title="email.policy.Policy.register_defect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_defect()</span></code></a> method.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.Policy.mangle_from_"> <code class="descname">mangle_from_</code><a class="headerlink" href="#email.policy.Policy.mangle_from_" title="Permalink to this definition">¶</a></dt> <dd><p>If <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a>, lines starting with <em>“From “</em> in the body are escaped by putting a <code class="docutils literal notranslate"><span class="pre">></span></code> in front of them. This parameter is used when the message is being serialized by a generator. Default: <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5: </span>The <em>mangle_from_</em> parameter.</p> </div> </dd></dl> <dl class="attribute"> <dt id="email.policy.Policy.message_factory"> <code class="descname">message_factory</code><a class="headerlink" href="#email.policy.Policy.message_factory" title="Permalink to this definition">¶</a></dt> <dd><p>A factory function for constructing a new empty message object. Used by the parser when building messages. Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>, in which case <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> is used.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <p>The following <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> method is intended to be called by code using the email library to create policy instances with custom settings:</p> <dl class="method"> <dt id="email.policy.Policy.clone"> <code class="descname">clone</code><span class="sig-paren">(</span><em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.clone" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> instance whose attributes have the same values as the current instance, except where those attributes are given new values by the keyword arguments.</p> </dd></dl> <p>The remaining <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> methods are called by the email package code, and are not intended to be called by an application using the email package. A custom policy must implement all of these methods.</p> <dl class="method"> <dt id="email.policy.Policy.handle_defect"> <code class="descname">handle_defect</code><span class="sig-paren">(</span><em>obj</em>, <em>defect</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.handle_defect" title="Permalink to this definition">¶</a></dt> <dd><p>Handle a <em>defect</em> found on <em>obj</em>. When the email package calls this method, <em>defect</em> will always be a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Defect</span></code>.</p> <p>The default implementation checks the <a class="reference internal" href="#email.policy.Policy.raise_on_defect" title="email.policy.Policy.raise_on_defect"><code class="xref py py-attr docutils literal notranslate"><span class="pre">raise_on_defect</span></code></a> flag. If it is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <em>defect</em> is raised as an exception. If it is <code class="docutils literal notranslate"><span class="pre">False</span></code> (the default), <em>obj</em> and <em>defect</em> are passed to <a class="reference internal" href="#email.policy.Policy.register_defect" title="email.policy.Policy.register_defect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_defect()</span></code></a>.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.register_defect"> <code class="descname">register_defect</code><span class="sig-paren">(</span><em>obj</em>, <em>defect</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.register_defect" title="Permalink to this definition">¶</a></dt> <dd><p>Register a <em>defect</em> on <em>obj</em>. In the email package, <em>defect</em> will always be a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Defect</span></code>.</p> <p>The default implementation calls the <code class="docutils literal notranslate"><span class="pre">append</span></code> method of the <code class="docutils literal notranslate"><span class="pre">defects</span></code> attribute of <em>obj</em>. When the email package calls <a class="reference internal" href="#email.policy.Policy.handle_defect" title="email.policy.Policy.handle_defect"><code class="xref py py-attr docutils literal notranslate"><span class="pre">handle_defect</span></code></a>, <em>obj</em> will normally have a <code class="docutils literal notranslate"><span class="pre">defects</span></code> attribute that has an <code class="docutils literal notranslate"><span class="pre">append</span></code> method. Custom object types used with the email package (for example, custom <code class="docutils literal notranslate"><span class="pre">Message</span></code> objects) should also provide such an attribute, otherwise defects in parsed messages will raise unexpected errors.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.header_max_count"> <code class="descname">header_max_count</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.header_max_count" title="Permalink to this definition">¶</a></dt> <dd><p>Return the maximum allowed number of headers named <em>name</em>.</p> <p>Called when a header is added to an <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> or <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> object. If the returned value is not <code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">None</span></code>, and there are already a number of headers with the name <em>name</em> greater than or equal to the value returned, 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> is raised.</p> <p>Because the default behavior of <code class="docutils literal notranslate"><span class="pre">Message.__setitem__</span></code> is to append the value to the list of headers, it is easy to create duplicate headers without realizing it. This method allows certain headers to be limited in the number of instances of that header that may be added to a <code class="docutils literal notranslate"><span class="pre">Message</span></code> programmatically. (The limit is not observed by the parser, which will faithfully produce as many headers as exist in the message being parsed.)</p> <p>The default implementation returns <code class="docutils literal notranslate"><span class="pre">None</span></code> for all header names.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.header_source_parse"> <code class="descname">header_source_parse</code><span class="sig-paren">(</span><em>sourcelines</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.header_source_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The email package calls this method with a list of strings, each string ending with the line separation characters found in the source being parsed. The first line includes the field header name and separator. All whitespace in the source is preserved. The method should return the <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> tuple that is to be stored in the <code class="docutils literal notranslate"><span class="pre">Message</span></code> to represent the parsed header.</p> <p>If an implementation wishes to retain compatibility with the existing email package policies, <em>name</em> should be the case preserved name (all characters up to the ‘<code class="docutils literal notranslate"><span class="pre">:</span></code>’ separator), while <em>value</em> should be the unfolded value (all line separator characters removed, but whitespace kept intact), stripped of leading whitespace.</p> <p><em>sourcelines</em> may contain surrogateescaped binary data.</p> <p>There is no default implementation</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.header_store_parse"> <code class="descname">header_store_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.header_store_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The email package calls this method with the name and value provided by the application program when the application program is modifying a <code class="docutils literal notranslate"><span class="pre">Message</span></code> programmatically (as opposed to a <code class="docutils literal notranslate"><span class="pre">Message</span></code> created by a parser). The method should return the <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> tuple that is to be stored in the <code class="docutils literal notranslate"><span class="pre">Message</span></code> to represent the header.</p> <p>If an implementation wishes to retain compatibility with the existing email package policies, the <em>name</em> and <em>value</em> should be strings or string subclasses that do not change the content of the passed in arguments.</p> <p>There is no default implementation</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.header_fetch_parse"> <code class="descname">header_fetch_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.header_fetch_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The email package calls this method with the <em>name</em> and <em>value</em> currently stored in the <code class="docutils literal notranslate"><span class="pre">Message</span></code> when that header is requested by the application program, and whatever the method returns is what is passed back to the application as the value of the header being retrieved. Note that there may be more than one header with the same name stored in the <code class="docutils literal notranslate"><span class="pre">Message</span></code>; the method is passed the specific name and value of the header destined to be returned to the application.</p> <p><em>value</em> may contain surrogateescaped binary data. There should be no surrogateescaped binary data in the value returned by the method.</p> <p>There is no default implementation</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.fold"> <code class="descname">fold</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.fold" title="Permalink to this definition">¶</a></dt> <dd><p>The email package calls this method with the <em>name</em> and <em>value</em> currently stored in the <code class="docutils literal notranslate"><span class="pre">Message</span></code> for a given header. The method should return a string that represents that header “folded” correctly (according to the policy settings) by composing the <em>name</em> with the <em>value</em> and inserting <a class="reference internal" href="#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 at the appropriate places. See <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> for a discussion of the rules for folding email headers.</p> <p><em>value</em> may contain surrogateescaped binary data. There should be no surrogateescaped binary data in the string returned by the method.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Policy.fold_binary"> <code class="descname">fold_binary</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Policy.fold_binary" title="Permalink to this definition">¶</a></dt> <dd><p>The same as <a class="reference internal" href="#email.policy.Policy.fold" title="email.policy.Policy.fold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fold()</span></code></a>, except that the returned value should be a bytes object rather than a string.</p> <p><em>value</em> may contain surrogateescaped binary data. These could be converted back into binary data in the returned bytes object.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="email.policy.EmailPolicy"> <em class="property">class </em><code class="descclassname">email.policy.</code><code class="descname">EmailPolicy</code><span class="sig-paren">(</span><em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy" title="Permalink to this definition">¶</a></dt> <dd><p>This concrete <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> provides behavior that is intended to be fully compliant with the current email RFCs. These include (but are not limited to) <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>, <span class="target" id="index-3"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a>, and the current MIME RFCs.</p> <p>This policy adds new header parsing and folding algorithms. Instead of simple strings, headers are <code class="docutils literal notranslate"><span class="pre">str</span></code> subclasses with attributes that depend on the type of the field. The parsing and folding algorithm fully implement <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> and <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>.</p> <p>The default value for the <a class="reference internal" href="#email.policy.Policy.message_factory" title="email.policy.Policy.message_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">message_factory</span></code></a> attribute is <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a>.</p> <p>In addition to the settable attributes listed above that apply to all policies, this policy adds the following additional attributes:</p> <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> <dl class="attribute"> <dt id="email.policy.EmailPolicy.utf8"> <code class="descname">utf8</code><a class="headerlink" href="#email.policy.EmailPolicy.utf8" title="Permalink to this definition">¶</a></dt> <dd><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, follow <span class="target" id="index-6"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a>, supporting non-ASCII characters in headers by encoding them as “encoded words”. If <code class="docutils literal notranslate"><span class="pre">True</span></code>, follow <span class="target" id="index-7"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6532.html"><strong>RFC 6532</strong></a> and use <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> encoding for headers. Messages formatted in this way may be passed to SMTP servers that support the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> extension (<span class="target" id="index-8"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6531.html"><strong>RFC 6531</strong></a>).</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.EmailPolicy.refold_source"> <code class="descname">refold_source</code><a class="headerlink" href="#email.policy.EmailPolicy.refold_source" title="Permalink to this definition">¶</a></dt> <dd><p>If the value for a header in the <code class="docutils literal notranslate"><span class="pre">Message</span></code> object originated from a <a class="reference internal" href="email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a> (as opposed to being set by a program), this attribute indicates whether or not a generator should refold that value when transforming the message back into serialized form. The possible values are:</p> <table border="1" class="docutils"> <colgroup> <col width="11%" /> <col width="89%" /> </colgroup> <tbody valign="top"> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">none</span></code></td> <td>all source values use original folding</td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">long</span></code></td> <td>source values that have any line that is longer than <code class="docutils literal notranslate"><span class="pre">max_line_length</span></code> will be refolded</td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">all</span></code></td> <td>all values are refolded.</td> </tr> </tbody> </table> <p>The default is <code class="docutils literal notranslate"><span class="pre">long</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.EmailPolicy.header_factory"> <code class="descname">header_factory</code><a class="headerlink" href="#email.policy.EmailPolicy.header_factory" title="Permalink to this definition">¶</a></dt> <dd><p>A callable that takes two arguments, <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">value</span></code>, where <code class="docutils literal notranslate"><span class="pre">name</span></code> is a header field name and <code class="docutils literal notranslate"><span class="pre">value</span></code> is an unfolded header field value, and returns a string subclass that represents that header. A default <code class="docutils literal notranslate"><span class="pre">header_factory</span></code> (see <a class="reference internal" href="email.headerregistry.html#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">headerregistry</span></code></a>) is provided that supports custom parsing for the various address and date <span class="target" id="index-9"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5322.html"><strong>RFC 5322</strong></a> header field types, and the major MIME header field stypes. Support for additional custom parsing will be added in the future.</p> </dd></dl> <dl class="attribute"> <dt id="email.policy.EmailPolicy.content_manager"> <code class="descname">content_manager</code><a class="headerlink" href="#email.policy.EmailPolicy.content_manager" title="Permalink to this definition">¶</a></dt> <dd><p>An object with at least two methods: get_content and set_content. When the <a class="reference internal" href="email.message.html#email.message.EmailMessage.get_content" title="email.message.EmailMessage.get_content"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_content()</span></code></a> or <a class="reference internal" href="email.message.html#email.message.EmailMessage.set_content" title="email.message.EmailMessage.set_content"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_content()</span></code></a> method of an <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> object is called, it calls the corresponding method of this object, passing it the message object as its first argument, and any arguments or keywords that were passed to it as additional arguments. By default <code class="docutils literal notranslate"><span class="pre">content_manager</span></code> is set to <a class="reference internal" href="email.contentmanager.html#email.contentmanager.raw_data_manager" title="email.contentmanager.raw_data_manager"><code class="xref py py-data docutils literal notranslate"><span class="pre">raw_data_manager</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> <p>The class provides the following concrete implementations of the abstract methods of <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a>:</p> <dl class="method"> <dt id="email.policy.EmailPolicy.header_max_count"> <code class="descname">header_max_count</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.header_max_count" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the value of the <a class="reference internal" href="email.headerregistry.html#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> attribute of the specialized class used to represent the header with the given name.</p> </dd></dl> <dl class="method"> <dt id="email.policy.EmailPolicy.header_source_parse"> <code class="descname">header_source_parse</code><span class="sig-paren">(</span><em>sourcelines</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.header_source_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The name is parsed as everything up to the ‘<code class="docutils literal notranslate"><span class="pre">:</span></code>’ and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters.</p> </dd></dl> <dl class="method"> <dt id="email.policy.EmailPolicy.header_store_parse"> <code class="descname">header_store_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.header_store_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The name is returned unchanged. If the input value has a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute and it matches <em>name</em> ignoring case, the value is returned unchanged. Otherwise the <em>name</em> and <em>value</em> are passed to <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>, and the resulting header object is returned as the value. In this case a <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> is raised if the input value contains CR or LF characters.</p> </dd></dl> <dl class="method"> <dt id="email.policy.EmailPolicy.header_fetch_parse"> <code class="descname">header_fetch_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.header_fetch_parse" title="Permalink to this definition">¶</a></dt> <dd><p>If the value has a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute, it is returned to unmodified. Otherwise the <em>name</em>, and the <em>value</em> with any CR or LF characters removed, are passed to the <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>, and the resulting header object is returned. Any surrogateescaped bytes get turned into the unicode unknown-character glyph.</p> </dd></dl> <dl class="method"> <dt id="email.policy.EmailPolicy.fold"> <code class="descname">fold</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.fold" title="Permalink to this definition">¶</a></dt> <dd><p>Header folding is controlled by the <a class="reference internal" href="#email.policy.EmailPolicy.refold_source" title="email.policy.EmailPolicy.refold_source"><code class="xref py py-attr docutils literal notranslate"><span class="pre">refold_source</span></code></a> policy setting. A value is considered to be a ‘source value’ if and only if it does not have a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute (having a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute means it is a header object of some sort). If a source value needs to be refolded according to the policy, it is converted into a header object by passing the <em>name</em> and the <em>value</em> with any CR and LF characters removed to the <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>. Folding of a header object is done by calling its <code class="docutils literal notranslate"><span class="pre">fold</span></code> method with the current policy.</p> <p>Source values are split into lines using <a class="reference internal" href="stdtypes.html#str.splitlines" title="str.splitlines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">splitlines()</span></code></a>. If the value is not to be refolded, the lines are rejoined using the <code class="docutils literal notranslate"><span class="pre">linesep</span></code> from the policy and returned. The exception is lines containing non-ascii binary data. In that case the value is refolded regardless of the <code class="docutils literal notranslate"><span class="pre">refold_source</span></code> setting, which causes the binary data to be CTE encoded using the <code class="docutils literal notranslate"><span class="pre">unknown-8bit</span></code> charset.</p> </dd></dl> <dl class="method"> <dt id="email.policy.EmailPolicy.fold_binary"> <code class="descname">fold_binary</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.EmailPolicy.fold_binary" title="Permalink to this definition">¶</a></dt> <dd><p>The same as <a class="reference internal" href="#email.policy.EmailPolicy.fold" title="email.policy.EmailPolicy.fold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fold()</span></code></a> if <a class="reference internal" href="#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> is <code class="docutils literal notranslate"><span class="pre">7bit</span></code>, except that the returned value is bytes.</p> <p>If <a class="reference internal" href="#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> is <code class="docutils literal notranslate"><span class="pre">8bit</span></code>, non-ASCII binary data is converted back into bytes. Headers with binary data are not refolded, regardless of the <code class="docutils literal notranslate"><span class="pre">refold_header</span></code> setting, since there is no way to know whether the binary data consists of single byte characters or multibyte characters.</p> </dd></dl> </dd></dl> <p>The following instances of <a class="reference internal" href="#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a> provide defaults suitable for specific application domains. Note that in the future the behavior of these instances (in particular the <code class="docutils literal notranslate"><span class="pre">HTTP</span></code> instance) may be adjusted to conform even more closely to the RFCs relevant to their domains.</p> <dl class="data"> <dt id="email.policy.default"> <code class="descclassname">email.policy.</code><code class="descname">default</code><a class="headerlink" href="#email.policy.default" title="Permalink to this definition">¶</a></dt> <dd><p>An instance of <code class="docutils literal notranslate"><span class="pre">EmailPolicy</span></code> with all defaults unchanged. This policy uses the standard Python <code class="docutils literal notranslate"><span class="pre">\n</span></code> line endings rather than the RFC-correct <code class="docutils literal notranslate"><span class="pre">\r\n</span></code>.</p> </dd></dl> <dl class="data"> <dt id="email.policy.SMTP"> <code class="descclassname">email.policy.</code><code class="descname">SMTP</code><a class="headerlink" href="#email.policy.SMTP" title="Permalink to this definition">¶</a></dt> <dd><p>Suitable for serializing messages in conformance with the email RFCs. Like <code class="docutils literal notranslate"><span class="pre">default</span></code>, but with <code class="docutils literal notranslate"><span class="pre">linesep</span></code> set to <code class="docutils literal notranslate"><span class="pre">\r\n</span></code>, which is RFC compliant.</p> </dd></dl> <dl class="data"> <dt id="email.policy.SMTPUTF8"> <code class="descclassname">email.policy.</code><code class="descname">SMTPUTF8</code><a class="headerlink" href="#email.policy.SMTPUTF8" title="Permalink to this definition">¶</a></dt> <dd><p>The same as <code class="docutils literal notranslate"><span class="pre">SMTP</span></code> except that <a class="reference internal" href="#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">True</span></code>. Useful for serializing messages to a message store without using encoded words in the headers. Should only be used for SMTP transmission if the sender or recipient addresses have non-ASCII characters (the <a class="reference internal" href="smtplib.html#smtplib.SMTP.send_message" title="smtplib.SMTP.send_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">smtplib.SMTP.send_message()</span></code></a> method handles this automatically).</p> </dd></dl> <dl class="data"> <dt id="email.policy.HTTP"> <code class="descclassname">email.policy.</code><code class="descname">HTTP</code><a class="headerlink" href="#email.policy.HTTP" title="Permalink to this definition">¶</a></dt> <dd><p>Suitable for serializing headers with for use in HTTP traffic. Like <code class="docutils literal notranslate"><span class="pre">SMTP</span></code> except that <code class="docutils literal notranslate"><span class="pre">max_line_length</span></code> is set to <code class="docutils literal notranslate"><span class="pre">None</span></code> (unlimited).</p> </dd></dl> <dl class="data"> <dt id="email.policy.strict"> <code class="descclassname">email.policy.</code><code class="descname">strict</code><a class="headerlink" href="#email.policy.strict" title="Permalink to this definition">¶</a></dt> <dd><p>Convenience instance. The same as <code class="docutils literal notranslate"><span class="pre">default</span></code> except that <code class="docutils literal notranslate"><span class="pre">raise_on_defect</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>. This allows any policy to be made strict by writing:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">somepolicy</span> <span class="o">+</span> <span class="n">policy</span><span class="o">.</span><span class="n">strict</span> </pre></div> </div> </dd></dl> <p>With all of these <a class="reference internal" href="#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicies</span></code></a>, the effective API of the email package is changed from the Python 3.2 API in the following ways:</p> <blockquote> <div><ul class="simple"> <li>Setting a header on a <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> results in that header being parsed and a header object created.</li> <li>Fetching a header value from a <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> results in that header being parsed and a header object created and returned.</li> <li>Any header object, or any header that is refolded due to the policy settings, is folded using an algorithm that fully implements the RFC folding algorithms, including knowing where encoded words are required and allowed.</li> </ul> </div></blockquote> <p>From the application view, this means that any header obtained through the <a class="reference internal" href="email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> is a header object with extra attributes, whose string value is the fully decoded unicode value of the header. Likewise, a header may be assigned a new value, or a new header created, using a unicode string, and the policy will take care of converting the unicode string into the correct RFC encoded form.</p> <p>The header objects and their attributes are described in <a class="reference internal" href="email.headerregistry.html#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">headerregistry</span></code></a>.</p> <dl class="class"> <dt id="email.policy.Compat32"> <em class="property">class </em><code class="descclassname">email.policy.</code><code class="descname">Compat32</code><span class="sig-paren">(</span><em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32" title="Permalink to this definition">¶</a></dt> <dd><p>This concrete <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> is the backward compatibility policy. It replicates the behavior of the email package in Python 3.2. The <a class="reference internal" href="#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> module also defines an instance of this class, <a class="reference internal" href="#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-const docutils literal notranslate"><span class="pre">compat32</span></code></a>, that is used as the default policy. Thus the default behavior of the email package is to maintain compatibility with Python 3.2.</p> <p>The following attributes have values that are different from the <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> default:</p> <dl class="attribute"> <dt id="email.policy.Compat32.mangle_from_"> <code class="descname">mangle_from_</code><a class="headerlink" href="#email.policy.Compat32.mangle_from_" title="Permalink to this definition">¶</a></dt> <dd><p>The default is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </dd></dl> <p>The class provides the following concrete implementations of the abstract methods of <a class="reference internal" href="#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a>:</p> <dl class="method"> <dt id="email.policy.Compat32.header_source_parse"> <code class="descname">header_source_parse</code><span class="sig-paren">(</span><em>sourcelines</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32.header_source_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The name is parsed as everything up to the ‘<code class="docutils literal notranslate"><span class="pre">:</span></code>’ and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Compat32.header_store_parse"> <code class="descname">header_store_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32.header_store_parse" title="Permalink to this definition">¶</a></dt> <dd><p>The name and value are returned unmodified.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Compat32.header_fetch_parse"> <code class="descname">header_fetch_parse</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32.header_fetch_parse" title="Permalink to this definition">¶</a></dt> <dd><p>If the value contains binary data, it is converted into a <a class="reference internal" href="email.header.html#email.header.Header" title="email.header.Header"><code class="xref py py-class docutils literal notranslate"><span class="pre">Header</span></code></a> object using the <code class="docutils literal notranslate"><span class="pre">unknown-8bit</span></code> charset. Otherwise it is returned unmodified.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Compat32.fold"> <code class="descname">fold</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32.fold" title="Permalink to this definition">¶</a></dt> <dd><p>Headers are folded using the <a class="reference internal" href="email.header.html#email.header.Header" title="email.header.Header"><code class="xref py py-class docutils literal notranslate"><span class="pre">Header</span></code></a> folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the <code class="docutils literal notranslate"><span class="pre">max_line_length</span></code>. Non-ASCII binary data are CTE encoded using the <code class="docutils literal notranslate"><span class="pre">unknown-8bit</span></code> charset.</p> </dd></dl> <dl class="method"> <dt id="email.policy.Compat32.fold_binary"> <code class="descname">fold_binary</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#email.policy.Compat32.fold_binary" title="Permalink to this definition">¶</a></dt> <dd><p>Headers are folded using the <a class="reference internal" href="email.header.html#email.header.Header" title="email.header.Header"><code class="xref py py-class docutils literal notranslate"><span class="pre">Header</span></code></a> folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the <code class="docutils literal notranslate"><span class="pre">max_line_length</span></code>. If <code class="docutils literal notranslate"><span class="pre">cte_type</span></code> is <code class="docutils literal notranslate"><span class="pre">7bit</span></code>, non-ascii binary data is CTE encoded using the <code class="docutils literal notranslate"><span class="pre">unknown-8bit</span></code> charset. Otherwise the original source header is used, with its existing line breaks and any (RFC invalid) binary data it may contain.</p> </dd></dl> </dd></dl> <dl class="data"> <dt id="email.policy.compat32"> <code class="descclassname">email.policy.</code><code class="descname">compat32</code><a class="headerlink" href="#email.policy.compat32" title="Permalink to this definition">¶</a></dt> <dd><p>An instance of <a class="reference internal" href="#email.policy.Compat32" title="email.policy.Compat32"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compat32</span></code></a>, providing backward compatibility with the behavior of the email package in Python 3.2.</p> </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 feature</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.generator.html" title="previous chapter">19.1.3. <code class="docutils literal notranslate"><span class="pre">email.generator</span></code>: Generating MIME documents</a></p> <h4>Next topic</h4> <p class="topless"><a href="email.errors.html" title="next chapter">19.1.5. <code class="docutils literal notranslate"><span class="pre">email.errors</span></code>: Exception and Defect classes</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.policy.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.errors.html" title="19.1.5. email.errors: Exception and Defect classes" >next</a> |</li> <li class="right" > <a href="email.generator.html" title="19.1.3. email.generator: Generating MIME documents" >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