Skip to content

Commit

Permalink
Reply-from-user dictionary includes a list of headers passed in the r…
Browse files Browse the repository at this point in the history
…eply-from-user section
  • Loading branch information
Jacob Daniel Bennett committed Oct 16, 2020
1 parent f389afb commit 1b734b7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
errorMessage = "Did not encounter a reply-from-user ending delimiter"
return self.__errorParsing(line, lineNumber + lineNum + 1, errorMessage)

if newLineCounter == 1 and line != "\n":

# Append header information for each headr line
headerType, content = line.split(": ", 1)
replyFromHeaders.append(
{"type": headerType,
"content": content
}
)

linesToRemove.append(lineNum)
#Checks for a newline and breaks for loop on second occurance of a newline
if line == "\n":
newLineCounter = newLineCounter + 1
Expand All @@ -645,7 +656,6 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
replyFromInfo["from_name"] = emailList[0][0]
replyFromInfo["from_email"] = emailList[0][1]

linesToRemove.append(lineNum)
elif line.startswith("Subject: ") and newLineCounter == 1:
# Matches everything after "Subject: "
try:
Expand All @@ -657,8 +667,6 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
# Formatts the date to UTC
replyFromInfo["subject"] = subjectStr

linesToRemove.append(lineNum)

elif line.startswith("Date: ") and newLineCounter == 1:
# Matches everything after "Date: "
try:
Expand All @@ -670,8 +678,6 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
# Formatts the date to UTC
replyFromInfo["datetime"] = self.__getFormattedDate(dateStr)

linesToRemove.append(lineNum)

elif line.startswith("Cc: ") and newLineCounter == 1:

replyFromInfo["cc"] = []
Expand All @@ -685,9 +691,7 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
replyFromInfo["cc"].append(
{"name": cc[0],
"email": cc[1]}
)

linesToRemove.append(lineNum)
)

# Deletes reduntant lines from the message content in reverse order
for lineNum in sorted(linesToRemove, reverse = True):
Expand All @@ -696,6 +700,8 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict:
# Strips any unnecessary newlines or any delimiters frm the message content
replyFromInfo["content"] = self.__getFormattedMessageContent(replyContent)

replyFromInfo["headers"] = replyFromHeaders

return replyFromInfo

def __getFormattedMessageContent(self, messageContent: list) -> list:
Expand Down

0 comments on commit 1b734b7

Please sign in to comment.