Skip to content

Commit

Permalink
Full functionality for reply from user section parsing and partial pa…
Browse files Browse the repository at this point in the history
…rsing functionaltiy for initial message parsing
  • Loading branch information
Jacob Daniel Bennett committed Sep 16, 2020
1 parent 58381c5 commit d0aebf6
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def __getContent(self) -> list:

def __parseSections(self) -> list:
sections = []
headerEnd = self.__getHeaderBoundary()
initialMessageContent = []
#headerEnd = self.__getHeaderBoundary()

contentStart = self.__getHeaderBoundary() + 1
contentEnd = len(self.__rawItem) - 1
Expand All @@ -199,14 +200,37 @@ def __parseSections(self) -> list:
" Subject: "]
directoryInfo = ["\n"]

endInitialMessage = False
for lineNumber in range(contentStart, contentEnd + 1):
line = self.__rawItem[lineNumber]
if line.startswith("***") or line.startswith("===") and not line.startswith("===="):
endInitialMessage = True
sectionBoundaries.append({"start": lineNumber})
else:
for item in directoryInfoPattern:
if(line.startswith(item)):
directoryInfo.append(line)

if endInitialMessage == False:
initialMessageContent.append(line)

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

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

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

sections.append(
{"type": "initialMessage",
"date": "",
"time": "",
"userName": "",
"ccRecipients": "",
"content": initialMessageContent}
)

if len(directoryInfo) > 1:
sections.append(
Expand All @@ -223,7 +247,8 @@ def __parseSections(self) -> list:
# Remove End of File boundary
del sectionBoundaries[-1]


#for linestuff in range(contentStart, contentEnd):
#initialMessageContent.append(linestuff)
# Make list of sections and parse content
delimiters = [
{"name": "edit", "pattern": "*** Edited"},
Expand All @@ -243,6 +268,8 @@ def __parseSections(self) -> list:

sectionContent = self.__rawItem[boundary["start"] : boundary["end"]]



if sectionType is None:
sectionType = "initialMessage"

Expand Down Expand Up @@ -341,7 +368,7 @@ def __parseSections(self) -> list:
repliedByEmail = ""
subject = ""
ccRecipientsList = []
ccRecipientDict = {}
#ccRecipientDict = {}

"""
ccRecipientDict Format:
Expand All @@ -351,17 +378,32 @@ def __parseSections(self) -> list:
}
"""

#Counter for line number and list of lines that can be deleted from the content
lineNum = 0
linesToBeDeleted = [0]
newLineCounter = 0

#Parses the section content looking for any line that starts with a metadata
for items in sectionContent:

#Checks for a newline and breaks for loop on second occurance of a newline
if items == "\n":
newLineCounter = newLineCounter + 1
if newLineCounter == 2:
break
else:
continue
#Checks for lines starting with these delimiters
if items.startswith("Subject: "):
subject = (re.search("(?<=Subject: )(.*)", items)).group()
linesToBeDeleted.append(lineNum)

elif items.startswith("From: "):
repliedByEmail = (re.search("(?<=From: )(.*)(?= <)", items)).group()
repliedByName = (re.search("(?<= <)(.*)(?=>)", items)).group()
emailList = email.utils.getaddresses([items])
#repliedByName = (re.search("(?<=From: )(.*)(?= <)", items)).group()
repliedByName = emailList[0][0]
#repliedByEmail = (re.search("(?<= <)(.*)(?=>)", items)).group()
repliedByEmail = emailList[0][1]
linesToBeDeleted.append(lineNum)

elif items.startswith("Date: "):
Expand All @@ -377,8 +419,12 @@ def __parseSections(self) -> list:
formattedTime = "Invalid"

elif items.startswith("Cc: "):
ccString = (re.search("(?<=Cc: )(.*)", items)).group()
#######################################################################################
recipientsList = email.utils.getaddresses([items])
for cc in recipientsList:
ccRecipientsList.append(
{"name":cc[0],
"email":cc[1]}
)

lineNum = lineNum + 1

Expand All @@ -396,7 +442,8 @@ def __parseSections(self) -> list:
"subject": subject,
"userName": repliedByName,
"userEmail": repliedByEmail,
"content": sectionContent}
"content": sectionContent,
"ccRecipients": ccRecipientsList}
)

else:
Expand Down Expand Up @@ -581,5 +628,5 @@ def getQueues() -> list:
return queues

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

0 comments on commit d0aebf6

Please sign in to comment.