Skip to content

Commit

Permalink
Merge branch 'release/3.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedelemantuano committed Jan 12, 2020
2 parents b4e195c + 0be4821 commit 16d4a50
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 267 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mail-parser supports Python 3.

## mail-parser on Web
- [Splunk app](https://splunkbase.splunk.com/app/4129/)
- [FreeBSD port](https://www.freshports.org/mail/py-mail-parser/)
- [Arch User Repository](https://aur.archlinux.org/packages/mailparser/)


## Description
Expand Down Expand Up @@ -58,6 +60,16 @@ There are other properties to get:
- to domains
- timezone

The `attachments` property is a list of objects. Every object has the following keys:
- binary: it's true if the attachment is a binary
- charset
- content_transfer_encoding
- content-disposition
- content-id
- filename
- mail_content_type
- payload: attachment payload in base64

To get custom headers you should replace "-" with "\_".
Example for header `X-MSMail-Priority`:

Expand Down Expand Up @@ -171,6 +183,7 @@ mail.received
mail.subject
mail.text_plain: only text plain mail parts in a list
mail.text_html: only text html mail parts in a list
mail.text_not_managed: all not managed text (check the warning logs to find content subtype)
mail.to
mail.to_domains
mail.timezone: returns the timezone, offset from UTC
Expand Down
263 changes: 0 additions & 263 deletions README.rst

This file was deleted.

20 changes: 18 additions & 2 deletions mailparser/mailparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def _reset(self):
self._attachments = []
self._text_plain = []
self._text_html = []
self._text_not_managed = []
self._defects = []
self._defects_categories = set()
self._has_defects = False
Expand Down Expand Up @@ -352,6 +353,7 @@ def parse(self):
charset_raw = p.get_content_charset()
log.debug("Charset {!r} part {!r}".format(charset, i))

# this is an attachment
if filename:
log.debug("Email part {!r} is an attachment".format(i))
log.debug("Filename {!r} part {!r}".format(filename, i))
Expand Down Expand Up @@ -395,15 +397,22 @@ def parse(self):
"content-disposition": content_disposition,
"charset": charset_raw,
"content_transfer_encoding": transfer_encoding})

# this isn't an attachments
else:
log.debug("Email part {!r} is not an attachment".format(i))
payload = ported_string(
p.get_payload(decode=True), encoding=charset)
if payload:
if p.get_content_subtype() == 'html':
self._text_html.append(payload)
else:
elif p.get_content_subtype() == 'plain':
self._text_plain.append(payload)
else:
log.warning(
'Email content {!r} not handled'.format(
p.get_content_subtype()))
self._text_not_managed.append(payload)
else:
# Parsed object mail with all parts
self._mail = self._make_mail()
Expand Down Expand Up @@ -528,7 +537,7 @@ def body(self):
"--- mail_boundary ---"
"""
return "\n--- mail_boundary ---\n".join(
self.text_plain + self.text_html)
self.text_plain + self.text_html + self.text_not_managed)

@property
def headers(self):
Expand Down Expand Up @@ -561,6 +570,13 @@ def text_html(self):
"""
return self._text_html

@property
def text_not_managed(self):
"""
Return a list of all text not managed of email.
"""
return self._text_not_managed

@property
def date(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion mailparser/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
limitations under the License.
"""

__version__ = "3.10.0"
__version__ = "3.11.0"

if __name__ == "__main__":
print(__version__)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

current = os.path.realpath(os.path.dirname(__file__))

with io.open(os.path.join(current, 'README.rst'), encoding="utf-8") as f:
with io.open(os.path.join(current, 'README.md'), encoding="utf-8") as f:
long_description = f.read()

with open(os.path.join(current, 'requirements.txt')) as f:
Expand Down
Loading

0 comments on commit 16d4a50

Please sign in to comment.