Skip to content

Commit

Permalink
Implementation of workaround for extreneous new lines in directory in…
Browse files Browse the repository at this point in the history
…formation and reply-from-user headers
  • Loading branch information
Jacob Daniel Bennett committed Oct 21, 2020
1 parent a5a7f9f commit 6dc675a
Showing 1 changed file with 63 additions and 17 deletions.
80 changes: 63 additions & 17 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6dc675a

Please sign in to comment.