Skip to content

Commit

Permalink
Directory Information now has specific keys for information within th…
Browse files Browse the repository at this point in the history
…e direcctory
  • Loading branch information
Jacob Daniel Bennett committed Sep 24, 2020
1 parent 6d9126b commit ee0edac
Showing 1 changed file with 41 additions and 58 deletions.
99 changes: 41 additions & 58 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

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

0 comments on commit ee0edac

Please sign in to comment.