Return the entire formatted message as a bytes object. Optional 'unixfrom', when true, means include the Unix From_ envelope header. 'policy' is passed to the BytesGenerator instance used to serialize the message; if not specified the policy associated with the mess
(self, unixfrom=False, policy=None)
| 200 | return self.as_bytes() |
| 201 | |
| 202 | def as_bytes(self, unixfrom=False, policy=None): |
| 203 | """Return the entire formatted message as a bytes object. |
| 204 | |
| 205 | Optional 'unixfrom', when true, means include the Unix From_ envelope |
| 206 | header. 'policy' is passed to the BytesGenerator instance used to |
| 207 | serialize the message; if not specified the policy associated with |
| 208 | the message instance is used. |
| 209 | """ |
| 210 | from email.generator import BytesGenerator |
| 211 | policy = self.policy if policy is None else policy |
| 212 | fp = BytesIO() |
| 213 | g = BytesGenerator(fp, mangle_from_=False, policy=policy) |
| 214 | g.flatten(self, unixfrom=unixfrom) |
| 215 | return fp.getvalue() |
| 216 | |
| 217 | def is_multipart(self): |
| 218 | """Return True if the message consists of multiple parts.""" |