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