Skip to content

Commit

Permalink
moved the email.policy configuration from the parser.py module to the…
Browse files Browse the repository at this point in the history
… item.py module
  • Loading branch information
benne238 committed Jun 30, 2021
1 parent 8289ae7 commit f5e5619
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/webqueue2api/parser/item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
import email
from email.policy import Policy
import re
import datetime
from dateutil.parser import parse
Expand Down Expand Up @@ -220,9 +221,15 @@ def __parse_sections(self) -> list:
# Convert list of lines to single string
raw_item_as_string = "".join(self.__raw_item)

# Temporarily make the email package raise an error upon encountering a defect in the headers
Policy.raise_on_defect = True

# Parse body
body_sections = parse_item(raw_item_as_string)

# Return the email oackage to its normal parsing state
Policy.raise_on_defect = False

# Add initial message headers to intial message section
for index, section in enumerate(body_sections):
if section["type"] == "initial_message":
Expand Down
2 changes: 0 additions & 2 deletions src/webqueue2api/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import json
import string
import email
from email.policy import Policy
import email.errors
import datetime
from .utils import format_date_string
from .errors import ParseError
Policy.raise_on_defect = True


parsed_item = []
Expand Down

0 comments on commit f5e5619

Please sign in to comment.