MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / as_string

Method as_string

tools/python-3.11.9-amd64/Lib/email/message.py:167–189  ·  view source on GitHub ↗

Return the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. For backward compatibility reasons, if maxheaderlen is not specified it defaults to 0, so you must override it explicitly if you want

(self, unixfrom=False, maxheaderlen=0, policy=None)

Source from the content-addressed store, hash-verified

165 return self.as_string()
166
167 def as_string(self, unixfrom=False, maxheaderlen=0, policy=None):
168 """Return the entire formatted message as a string.
169
170 Optional 'unixfrom', when true, means include the Unix From_ envelope
171 header. For backward compatibility reasons, if maxheaderlen is
172 not specified it defaults to 0, so you must override it explicitly
173 if you want a different maxheaderlen. 'policy' is passed to the
174 Generator instance used to serialize the message; if it is not
175 specified the policy associated with the message instance is used.
176
177 If the message object contains binary data that is not encoded
178 according to RFC standards, the non-compliant data will be replaced by
179 unicode "unknown character" code points.
180 """
181 from email.generator import Generator
182 policy = self.policy if policy is None else policy
183 fp = StringIO()
184 g = Generator(fp,
185 mangle_from_=False,
186 maxheaderlen=maxheaderlen,
187 policy=policy)
188 g.flatten(self, unixfrom=unixfrom)
189 return fp.getvalue()
190
191 def __bytes__(self):
192 """Return the entire formatted message as a bytes object.

Callers 4

__str__Method · 0.95
get_stringMethod · 0.45
get_stringMethod · 0.45
as_stringMethod · 0.45

Calls 4

flattenMethod · 0.95
getvalueMethod · 0.95
StringIOClass · 0.90
GeneratorClass · 0.90

Tested by

no test coverage detected