Skip to content

Commit

Permalink
Implement getUserEmail in Item class
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Jul 26, 2020
1 parent 8d6c5fe commit 89ad2a1
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TODO: Add ECNQueue module documentation
# TODO: Add ECNQueue module documentation

#------------------------------------------------------------------------------#
# Imports
Expand Down Expand Up @@ -33,6 +33,7 @@ def __init__(self, queue: str, number: int) -> None:
self.headers = self.__parseHeaders()
self.content = self.__getContent()
self.isLocked = self.__isLocked()
self.userEmail = self.__getUserEmail()

def __getLastUpdated(self) -> float:
"""Returns last modified time of item reported by the filesystem in mm-dd-yy hh:mm am/pm format.
Expand Down Expand Up @@ -114,7 +115,7 @@ def __parseHeaders(self) -> list:
# TODO: Implement attachment parsing

def __getContent(self) -> list:
"""Returns a dictionary lines of the item body.
"""Returns a dictionary of lines of the item body.
Example:
"Hello. I need help.\\n\\n*** Status updated by: campb303 at: 6/23/2020 13:26:55 ***\\nDont Delete" becomes
Expand Down Expand Up @@ -156,6 +157,30 @@ def __isLocked(self) -> Union[str, bool]:
else:
return False

def __getMostRecentHeaderByType(self, headerType: str) -> Union[dict, None]:
"""Return most recent header of the given type.
If no header of that type exists, returns None.
Args:
headerType (str): Type of header to return.
Returns:
Union[dict, None]: dict of header if it exists or None
"""
for header in self.headers:
if header["type"] == headerType: return header
return None

def __getUserEmail(self) -> str:
"""Returns the email address that the item originated from.
Returns:
str: Email address that the item originated from.
"""
fromHeader = self.__getMostRecentHeaderByType("From")
userEmail = email.utils.parseaddr(fromHeader["content"])[1]
return userEmail

def __repr__(self) -> str:
return self.queue + str(self.number)

Expand Down

0 comments on commit 89ad2a1

Please sign in to comment.