diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 983b179..05e3d4f 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -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 @@ -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( @@ -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"}, @@ -243,6 +268,8 @@ def __parseSections(self) -> list: sectionContent = self.__rawItem[boundary["start"] : boundary["end"]] + + if sectionType is None: sectionType = "initialMessage" @@ -341,7 +368,7 @@ def __parseSections(self) -> list: repliedByEmail = "" subject = "" ccRecipientsList = [] - ccRecipientDict = {} + #ccRecipientDict = {} """ ccRecipientDict Format: @@ -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: "): @@ -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 @@ -396,7 +442,8 @@ def __parseSections(self) -> list: "subject": subject, "userName": repliedByName, "userEmail": repliedByEmail, - "content": sectionContent} + "content": sectionContent, + "ccRecipients": ccRecipientsList} ) else: @@ -581,5 +628,5 @@ def getQueues() -> list: return queues if __name__ == "__main__": - item = Item("ce", 100) + item = Item("ce", 11) print()