Skip to content

Commit

Permalink
Full section parsing for initial message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Daniel Bennett committed Sep 16, 2020
1 parent 593a532 commit 82c5fce
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def __parseSections(self) -> list:
" User ECNDB: ",
" Host ECNDB: ",
" Subject: "]
directoryInfo = ["\n"]
directoryInfo = []

endInitialMessage = False
for lineNumber in range(contentStart, contentEnd + 1):
Expand All @@ -212,27 +212,49 @@ def __parseSections(self) -> list:

lineCounter = 0
linesToRemove = []
initialMessageParsed = False
for lineContents in initialMessageContent:

for itemsindirectory in directoryInfoPattern:
if lineContents.startswith(itemsindirectory):
directoryInfo.append(lineContents)
linesToRemove.append(lineCounter)
lineCounter = lineCounter + 1
if lineContents.startswith(itemsindirectory):
directoryInfo.append(lineContents)
linesToRemove.append(lineCounter)

lineCounter = lineCounter + 1

for stuff in sorted(linesToRemove, reverse=True):
initialMessageContent.pop(stuff)

initialMessageDateStr = self.__getMostRecentHeaderByType("Date")
initialMessageFormattedDate = ""
initialMessageFormattedTime = ""
try:
dateObject = parse(initialMessageDateStr)
initialMessageFormattedDate = dateObject.strftime("%Y-%m-%dT%H:%M:%S%z")
initialMessageFormattedTime = dateObject.strftime("%H:%M:%S%z")
except:
initialMessageFormattedDate = "invalid"
initialMessageFormattedTime = "Invalid"

initialMessageCCMasterList =[]
initialMessageCCList = email.utils.getaddresses([self.__getMostRecentHeaderByType("CC")])
for ccRecipients in initialMessageCCList:
initialMessageCCMasterList.append(
{"name": ccRecipients[0],
"email": ccRecipients[1]}
)

sections.append(
{"type": "initialMessage",
"date": "",
"time": "",
"userName": "",
"ccRecipients": "",
"date": initialMessageFormattedDate,
"time": initialMessageFormattedTime,
"userName": self.__parseFromData(data="userName"),
"userEmail": self.__parseFromData(data="userEmail"),
"ccRecipients": initialMessageCCMasterList,
"content": initialMessageContent}
)

if len(directoryInfo) > 1:
if len(directoryInfo) > 0:
sections.append(
{"type": "directoryInformation",
"content": directoryInfo
Expand All @@ -257,6 +279,7 @@ def __parseSections(self) -> list:
{"name": "replyFromUser", "pattern": "=== "},
]


for boundary in sectionBoundaries:
line = self.__rawItem[boundary["start"]]
sectionType = None
Expand All @@ -270,10 +293,10 @@ def __parseSections(self) -> list:



if sectionType is None:
sectionType = "initialMessage"
#if sectionType is None:
#sectionType = "initialMessage"

elif sectionType == "edit":
if sectionType == "edit":
formattedDate = ""
formattedTime = ""
editedBy = ""
Expand Down Expand Up @@ -446,12 +469,6 @@ def __parseSections(self) -> list:
"ccRecipients": ccRecipientsList}
)

else:
sections.append(
{"type": sectionType,
"content": sectionContent}
)

return sections

def __isLocked(self) -> Union[str, bool]:
Expand Down Expand Up @@ -628,5 +645,5 @@ def getQueues() -> list:
return queues

if __name__ == "__main__":
item = Item("ce", 11)
item = Item("aae", 7)
print()

0 comments on commit 82c5fce

Please sign in to comment.