'Body-encode a string and convert it to output_charset.
If convert is True (the default), the string will be converted from
the input charset to output charset automatically.  Unlike
header_encode(), there are no issues with byte boundaries and
multibyte charsets in email bodies, so this is usually pretty safe.
The type of encoding (base64 or quoted-printable) will be based on
self.body_encoding.'

def body_encode(self, s, convert=True):

    if convert:
        s = self.convert(s)
    if (self.body_encoding is BASE64):
        return email.base64mime.body_encode(s)
    else:
        if (self.body_encoding is QP):
            return email.quoprimime.body_encode(s)
        return s
