Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ':' in header:
key,value = header.split(':', 1)
extra_headers[key.strip()] = value.strip()
else:
_LOG.warning(
'malformed bonus-header: {}'.format(
self.bonus_header))
content = self._get_entry_content(entry)
try:
content = self._process_entry_content(
entry=entry, content=content, subject=subject)
except _error.ProcessingError as e:
e.parsed = parsed
raise
message = _email.get_message(
sender=sender,
recipient=self.to,
subject=subject,
body=content['value'],
content_type=content['type'].split('/', 1)[1],
extra_headers=extra_headers,
config=self.config,
section=self.section)
return (guid, guid, sender, message)
def _send(self, sender, message):
_LOG.info('send message for {}'.format(self))
section = self.section
if section not in self.config:
section = 'DEFAULT'
_email.send(sender=sender, recipient=self.to, message=message,
config=self.config, section=section)
b'Subject: Homage'
b'Content-Transfer-Encoding: 8bit'
b''
b"\x00Y\x00o\x00u\x00'\x00r\x00e\x00 \x00g\x00r\x00e\x00a\x00t\x00,\x00 \x00\x96\x03\xb5\x03\xcd\x03\xc2\x03!\x00\n\x00"
"""
bytesio = _io.BytesIO()
# TODO: use policies argument instead of policy set in `message`
# see https://docs.python.org/3.5/library/email.generator.html?highlight=bytesgenerator#email.generator.BytesGenerator
generator = _BytesGenerator(bytesio)
try:
generator.flatten(message)
except UnicodeEncodeError as e:
# HACK: work around deficiencies in BytesGenerator
_LOG.warning(e)
b = message.as_string().encode(str(message.get_charset()))
m = _email.message_from_bytes(b)
if not m:
raise
h = {k:_decode_header(v) for k,v in m.items()}
head = {k:_decode_header(v) for k,v in message.items()}
body = str(m.get_payload(decode=True), str(m.get_charsets()[0]))
if (h == head and body == message.get_payload()):
return b
raise
else:
return bytesio.getvalue()
A very simple function that decodes the entry into a unicode
string and then calls BeautifulSoup on it and afterwards encodes
the feed entry
"""
# decode message
encoding = message.get_charsets()[0]
content = str(message.get_payload(decode=True), encoding)
# modify content
soup = BeautifulSoup(content)
content = soup.prettify()
# BeautifulSoup uses unicode, so we perhaps have to adjust the encoding.
# It's easy to get into encoding problems and this step will prevent
# them ;)
encoding = rss2email.email.guess_encoding(content, encodings=feed.encodings)
# clear CTE and set message. It can be important to clear the CTE
# before setting the payload, since the payload is only re-encoded
# if CTE is not already set.
del message['Content-Transfer-Encoding']
message.set_payload(content, charset=encoding)
return message