Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3..../email
File: encoders.py
# Copyright (C) 2001-2006 Python Software Foundation
[0] Fix | Delete
# Author: Barry Warsaw
[1] Fix | Delete
# Contact: email-sig@python.org
[2] Fix | Delete
[3] Fix | Delete
"""Encodings and related functions."""
[4] Fix | Delete
[5] Fix | Delete
__all__ = [
[6] Fix | Delete
'encode_7or8bit',
[7] Fix | Delete
'encode_base64',
[8] Fix | Delete
'encode_noop',
[9] Fix | Delete
'encode_quopri',
[10] Fix | Delete
]
[11] Fix | Delete
[12] Fix | Delete
[13] Fix | Delete
from base64 import encodebytes as _bencode
[14] Fix | Delete
from quopri import encodestring as _encodestring
[15] Fix | Delete
[16] Fix | Delete
[17] Fix | Delete
[18] Fix | Delete
def _qencode(s):
[19] Fix | Delete
enc = _encodestring(s, quotetabs=True)
[20] Fix | Delete
# Must encode spaces, which quopri.encodestring() doesn't do
[21] Fix | Delete
return enc.replace(b' ', b'=20')
[22] Fix | Delete
[23] Fix | Delete
[24] Fix | Delete
def encode_base64(msg):
[25] Fix | Delete
"""Encode the message's payload in Base64.
[26] Fix | Delete
[27] Fix | Delete
Also, add an appropriate Content-Transfer-Encoding header.
[28] Fix | Delete
"""
[29] Fix | Delete
orig = msg.get_payload(decode=True)
[30] Fix | Delete
encdata = str(_bencode(orig), 'ascii')
[31] Fix | Delete
msg.set_payload(encdata)
[32] Fix | Delete
msg['Content-Transfer-Encoding'] = 'base64'
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
[36] Fix | Delete
def encode_quopri(msg):
[37] Fix | Delete
"""Encode the message's payload in quoted-printable.
[38] Fix | Delete
[39] Fix | Delete
Also, add an appropriate Content-Transfer-Encoding header.
[40] Fix | Delete
"""
[41] Fix | Delete
orig = msg.get_payload(decode=True)
[42] Fix | Delete
encdata = _qencode(orig)
[43] Fix | Delete
msg.set_payload(encdata)
[44] Fix | Delete
msg['Content-Transfer-Encoding'] = 'quoted-printable'
[45] Fix | Delete
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
def encode_7or8bit(msg):
[49] Fix | Delete
"""Set the Content-Transfer-Encoding header to 7bit or 8bit."""
[50] Fix | Delete
orig = msg.get_payload(decode=True)
[51] Fix | Delete
if orig is None:
[52] Fix | Delete
# There's no payload. For backwards compatibility we use 7bit
[53] Fix | Delete
msg['Content-Transfer-Encoding'] = '7bit'
[54] Fix | Delete
return
[55] Fix | Delete
# We play a trick to make this go fast. If decoding from ASCII succeeds,
[56] Fix | Delete
# we know the data must be 7bit, otherwise treat it as 8bit.
[57] Fix | Delete
try:
[58] Fix | Delete
orig.decode('ascii')
[59] Fix | Delete
except UnicodeError:
[60] Fix | Delete
msg['Content-Transfer-Encoding'] = '8bit'
[61] Fix | Delete
else:
[62] Fix | Delete
msg['Content-Transfer-Encoding'] = '7bit'
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
def encode_noop(msg):
[67] Fix | Delete
"""Do nothing."""
[68] Fix | Delete
[69] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function