From ee0edac577baa702859e6bbd38685339fdef088b Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Thu, 24 Sep 2020 15:03:28 -0400 Subject: [PATCH] Directory Information now has specific keys for information within the direcctory --- api/ECNQueue.py | 99 ++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 58 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 1042cb6..8caaff0 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -181,13 +181,21 @@ def __parseSections(self) -> list: contentStart = self.__getHeaderBoundary() + 1 contentEnd = len(self.__rawItem) - 1 - # Find line numbers where sections start - sectionBoundaries = [ {"start": contentStart} ] - - directoryInfo = [] + directoryInfo = {"type": "directoryInformation"} initialMessageContent = [] endInitialMessage = False + if self.__rawItem[contentStart] == "\n" : + rawDirectoryInfo = self.__rawItem[contentStart + 1: contentStart + 13] + directoryInfo["content"] = self.__directoryParsing(rawDirectoryInfo) + contentStart = contentStart + 14 + + # Appends Directory Information into the sections array + sections.append(directoryInfo) + + # Find line numbers where sections start + sectionBoundaries = [ {"start": contentStart} ] + # Parses the entire contents of the message, stores everything before any delimiter as the initial message for lineNumber in range(contentStart, contentEnd + 1): @@ -206,54 +214,6 @@ def __parseSections(self) -> list: # Delimiter not encountered yet, so append line to initial message list initialMessageContent.append(line) - # All possible Directory Items - directoryInfoPattern = [ - "\tName: ", - " Login: ", - " Computer: ", - " Location: ", - " Email: ", - " Phone: ", - " Office: ", - " UNIX Dir: ", - " Zero Dir: ", - " User ECNDB: ", - " Host ECNDB: ", - " Subject: " - ] - - # Reference to Remove Directory Items from initial message - directoryLinesToRemove = [] - - # Line Counter - lineCounter = 0 - - # Parses the initial message for directory information - for lineContents in initialMessageContent: - - for itemsindirectory in directoryInfoPattern: - - # Checks if the line starts with any of the directory parameters - if lineContents.startswith(itemsindirectory): - - # Appends line number to be removed from initial message - directoryLinesToRemove.append(lineCounter) - - # Adds the contents of the line to the directory info - directoryInfo.append(lineContents) - - # allows to move to the next iteration of the parent for loop, no need to continue parsing directory delimiters - break - - # Increment the line counter by after each line - lineCounter = lineCounter + 1 - - # Parses the initial message to remove directory information - for lineNumber in sorted(directoryLinesToRemove, reverse=True): - - # Remove the directory line from the intital message - initialMessageContent.pop(lineNumber) - # Removes unecessary newlines from the begining and the end of the initial message newLinebegining = True @@ -284,12 +244,6 @@ def __parseSections(self) -> list: elif newLinebegining == True: newLinebegining = False - - # Appends Directory Information into the sections array - sections.append( - {"type": "directoryInformation", - "content": directoryInfo} - ) # Gets the initial message date from the header initialMessageDateStr = self.__getMostRecentHeaderByType("Date") @@ -449,6 +403,35 @@ def __parseSections(self) -> list: return sections + def __directoryParsing(self, directoryContent: list) -> dict: + """Returns a dictionary with directory information + + Returns: dictionary: + "Name": name, + "Login": login, + "Computer": computer, + "Location": location, + "Email": email, + "Phone": phone, + "Office": office, + "UNIX Dir": unix_dir, + "Zero Dir": zero_dir, + "User ECNDB": user_ecndb, + "Host ECNDB": host_ecdbn, + "Subject": subject + """ + directoryInformation = {} + + for info in directoryContent: + strippedInfo = info.strip() + try: + key, value = strippedInfo.split(": ") + except: + key, value = strippedInfo.split(":") + + directoryInformation[key] = value + + return directoryInformation def __editParsing(self, line: str) -> dict: """Returns a dictionary with edit information