diff --git a/api/ECNQueue.py b/api/ECNQueue.py index bb82f73..a716fa8 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -338,11 +338,22 @@ def __directoryParsing(self, directoryStartLine: int) -> dict: """ directoryInformation = {"type": "directory_information"} - # Assumes a full directory with 12 items including the starting line - directoryEndingLine = directoryStartLine + 11 - + directoryPossibleKeys=[ + "Name", + "Login", + "Computer", + "Location", + "Email", + "Phone", + "Office", + "UNIX Dir", + "Zero Dir", + "User ECNDB", + "Host ECNDB", + "Subject" + ] # Executies until the directory start line is greater than the directory ending line - while directoryStartLine <= directoryEndingLine: + while True: # Returns the line number at directory start line info = self.__rawItem[directoryStartLine] @@ -364,17 +375,47 @@ def __directoryParsing(self, directoryStartLine: int) -> dict: # swt1 key, value = strippedInfo.split(": ", 1) - # Adds the key value pair to the directory info dictionary - directoryInformation[key] = value - + if key in directoryPossibleKeys: + # Adds the key value pair to the directory info dictionary + directoryInformation[key] = value + else: + # Casts the list type on to a dictionary + dictionaryList = list(directoryInformation) + # Length of dictionary list + lenDictionaryList = len(dictionaryList) + # The last key appended to the directory dictionary + lastKeyAppended = dictionaryList[lenDictionaryList - 1] + + directoryInformation[lastKeyAppended] = directoryInformation[lastKeyAppended] + " " + strippedInfo + elif ":" in strippedInfo: # Seperates the directory info line into two variables, the first variable being the key, the second being the value key, value = strippedInfo.split(":", 1) - # Adds the key value pair to the directory info dictionary - directoryInformation[key] = value - + if key in directoryPossibleKeys: + # Adds the key value pair to the directory info dictionary + directoryInformation[key] = value + else: + # Casts the list type on to a dictionary + dictionaryList = list(directoryInformation) + # Length of dictionary list + lenDictionaryList = len(dictionaryList) + # The last key appended to the directory dictionary + lastKeyAppended = dictionaryList[lenDictionaryList - 1] + + directoryInformation[lastKeyAppended] = directoryInformation[lastKeyAppended] + " " + strippedInfo + + # Signifies that this line belongs to the most previous line + elif ": " not in strippedInfo and ":" not in strippedInfo: + # Casts the list type on to a dictionary + dictionaryList = list(directoryInformation) + # Length of dictionary list + lenDictionaryList = len(dictionaryList) + # The last key appended to the directory dictionary + lastKeyAppended = dictionaryList[lenDictionaryList - 1] + + directoryInformation[lastKeyAppended] = directoryInformation[lastKeyAppended] + " " + strippedInfo # Counter to denote the end of the directory directoryStartLine = directoryStartLine + 1 @@ -635,14 +676,19 @@ def __userReplyParsing(self, replyContent: list, lineNumber: int) -> dict: return self.__errorParsing(line, lineNumber + lineNum + 1, errorMessage) if newLineCounter == 1 and line != "\n": + + try: + # Append header information for each headr line + headerType, content = line.split(": ", 1) + replyFromHeaders.append( + {"type": headerType, + "content": content + } + ) + except: + lenReplyFromHeaders = len(replyFromHeaders) - # Append header information for each headr line - headerType, content = line.split(": ", 1) - replyFromHeaders.append( - {"type": headerType, - "content": content - } - ) + replyFromHeaders[lenReplyFromHeaders - 1]["content"] = replyFromHeaders[lenReplyFromHeaders - 1]["content"] + " " + line linesToRemove.append(lineNum) #Checks for a newline and breaks for loop on second occurance of a newline