-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods to fetch actual messages
- Loading branch information
1 parent
37cf865
commit 2243e41
Showing
5 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import email | ||
import email.header | ||
|
||
|
||
class Message(object): | ||
def __init__(self, rfc822_bytes): | ||
self.raw = rfc822_bytes | ||
self.mail = email.message_from_bytes(self.raw) | ||
|
||
@property | ||
def To(self): | ||
ret = self.mail['To'] | ||
if ret is None: | ||
ret = '' | ||
return ret | ||
|
||
@property | ||
def Recipients(self): | ||
return ', '.join(_ for _ in (self.mail['To'], self.mail['CC']) | ||
if _ is not None) | ||
|
||
@property | ||
def Subject(self): | ||
return self.mail['Subject'] | ||
|
||
@property | ||
def SaneSubject(self): | ||
ret = self.mail['Subject'] | ||
ret = email.header.decode_header(ret)[0] | ||
if ret[1] is not None: | ||
ret = ret[0].decode('ascii', errors='replace') | ||
else: | ||
ret = ret[0] | ||
ret = ret.replace('\n', '') | ||
return ret | ||
|
||
@property | ||
def From(self): | ||
return self.mail['From'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters