Skip to content

Commit

Permalink
Merge branch 'release/3.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedelemantuano committed Jan 6, 2020
2 parents 2d27e6e + 2ba6f86 commit b4e195c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ build/
dist/
mail_parser.egg-info/
venv
venv27
venv3
report/
report/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
2 changes: 1 addition & 1 deletion mailparser/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
r'envelope-sender|\s+from|\s+by|\s+id|\s+for|\s+via|;))'
),
(
r'(?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*'
r'[^\w](?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*'
r'[(]?envelope-sender|\s+from|\s+by|\s+with'
r'(?! cipher)|\s+for|\s+via|;))'
),
Expand Down
5 changes: 5 additions & 0 deletions mailparser/mailparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def parse(self):
content_id = ported_string(p.get('content-id'))
log.debug("content-id {!r} part {!r}".format(
content_id, i))
content_disposition = ported_string(
p.get('content-disposition'))
log.debug("content-disposition {!r} part {!r}".format(
content_disposition, i))

if transfer_encoding == "base64" or (
transfer_encoding == "quoted-\
Expand All @@ -388,6 +392,7 @@ def parse(self):
"binary": binary,
"mail_content_type": mail_content_type,
"content-id": content_id,
"content-disposition": content_disposition,
"charset": charset_raw,
"content_transfer_encoding": transfer_encoding})
else:
Expand Down
7 changes: 4 additions & 3 deletions mailparser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ def convert_mail_date(date):
t = email.utils.mktime_tz(d)
log.debug("Date parsed in timestamp: {!r}".format(t))
date_utc = datetime.datetime.utcfromtimestamp(t)
timezone = d[9] / 3600 if d[9] else 0
timezone = "{:+.0f}".format(timezone)
timezone = d[9] / 3600.0 if d[9] else 0
timezone = "{:+.1f}".format(timezone)
log.debug("Calculated timezone: {!r}".format(timezone))
return date_utc, timezone


Expand Down Expand Up @@ -507,7 +508,7 @@ def print_attachments(attachments, flag_hash): # pragma: no cover
if flag_hash:
for i in attachments:
if i.get("content_transfer_encoding") == "base64":
payload = i["payload"].decode("base64")
payload = base64.b64decode(i["payload"])
else:
payload = i["payload"]

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.9.3"
__version__ = "3.10.0"

if __name__ == "__main__":
print(__version__)
16 changes: 10 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
coverage
flake8
ipaddress
rope
simplejson
six
# tool
ipaddress==1.0.23
simplejson==3.17.0
six==1.13.0

# dev
coverage==5.0.2
flake8==3.7.9
tox==3.14.3
twine==1.15.0
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ipaddress
simplejson
six
ipaddress==1.0.23
simplejson==3.17.0
six==1.13.0
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
install_requires=requires,
entry_points={'console_scripts': [
Expand Down
15 changes: 12 additions & 3 deletions tests/test_mail_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ def test_add_content_type(self):
self.assertEqual(
result["attachments"][0]["charset"],
"iso-8859-1")
self.assertEqual(
result["attachments"][0]["content-disposition"], "inline")

mail = mailparser.parse_from_file(mail_malformed_1)
attachments = mail.mail["attachments"]
self.assertEqual(attachments[0]["content-disposition"], "")

def test_from_bytes(self):
if six.PY2:
Expand Down Expand Up @@ -489,7 +495,7 @@ def test_from_file_obj(self):
self.assertIsInstance(result, list)

result = mail.timezone
self.assertEqual(result, "+1")
self.assertEqual(result, "+1.0")

def test_get_to_domains(self):
m = mailparser.parse_from_file(mail_test_6)
Expand All @@ -508,11 +514,14 @@ def test_get_to_domains(self):
def test_convert_mail_date(self):
s = "Mon, 20 Mar 2017 05:12:54 +0600"
d, t = convert_mail_date(s)
self.assertEqual(t, "+6")
self.assertEqual(t, "+6.0")
self.assertEqual(str(d), "2017-03-19 23:12:54")
s = "Mon, 20 Mar 2017 05:12:54 -0600"
d, t = convert_mail_date(s)
self.assertEqual(t, "-6")
self.assertEqual(t, "-6.0")
s = "Mon, 11 Dec 2017 15:27:44 +0530"
d, t = convert_mail_date(s)
self.assertEqual(t, "+5.5")

def test_ported_string(self):
raw_data = ""
Expand Down

0 comments on commit b4e195c

Please sign in to comment.