Skip to content

Commit

Permalink
email.message.Message.add_header cannot handle Header objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortal committed Jan 27, 2015
1 parent 438c67b commit cadda17
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions emailtunnel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def add_received_line(self, value):
self.message._headers += headers

def add_header(self, key, value):
self.message.add_header(key, value)
self.message[key] = value

def get_header(self, key, default=None):
return self.message.get(key, default)
Expand All @@ -155,20 +155,19 @@ def set_unique_header(self, key, value):
try:
self.message.replace_header(key, value)
except KeyError:
self.message.add_header(key, value)
self.message[key] = value

def set_body_text(self, body, encoding):
body_part = email.message.MIMEPart()
if encoding:
encoded = body.encode(encoding)
body_part.set_payload(encoded)
body_part.add_header(
'Content-Type', 'text/plain')
body_part['Content-Type'] = 'text/plain'
email.charset.add_charset(encoding, QP, QP)
body_part.set_charset(encoding)
else:
body_part.set_payload(body)
body_part.add_header('Content-Type', 'text/plain')
body_part['Content-Type'] = 'text/plain'
self.message.set_payload(body_part)

@property
Expand Down

0 comments on commit cadda17

Please sign in to comment.