Click here to Skip to main content
15,887,135 members

Comments by Thandeka Zulu (Top 12 by date)

Thandeka Zulu 8-Oct-22 5:15am View    
@Richard Thank you so much.
Thandeka Zulu 8-Oct-22 5:14am View    
@OriginalGriff Noted.Thank you
Thandeka Zulu 2-Aug-22 4:15am View    
Thank you
Thandeka Zulu 2-Aug-22 2:47am View    
# This program simulates an email message
class Email:

# This constructor initialises senders email address,and has four variables
def __init__(self,from_address, email_contents):
self.from_address = from_address
self.email_contents = email_contents
self.has_been_read = False
self.is_spam = False

# This function changes "has_been_read" variable from false to true
def mark_as_read(self):
self.has_been_read = True

# This function allows us to print the email, especially when the user want to read
def __str__(self):
return f"From: {self.from_address} \nContent: {self.email_contents} "

# This function changes "is_spam" variable from false to true
def mark_as_spam(self):
self.is_spam = True

# List is created to store emaildetails
inbox = []

# Number of messages in the store are returned via this function
def get_count(inbox):
return len(inbox)

# Email content is returned by this function
def get_email(index):
message = inbox[index]
message.mark_as_read()
print(message)

# Non read emails from the list are returned via this function
def get_unread_emails():
messages =[]
for n, i in enumerate(inbox):
if not i.has_been_read:
message = inbox[n]
messages.append(message)
print(message.email_contents)
return messages

# This function returns a list of all the emails that have been marked as a spam
def get_spam_emails():
print()
messages =[]
for n, i in enumerate(inbox):
if not i.is_spam:
message = inbox[n]
messages.append(message)
print(f"spam: {message.email_contents}")
return messages

def add_spam(index):
messages = inbox[index]
messages.mark_as_spam()
print("Email added to spam")



# Delete function deletes an email in the inbox
def delete(index):
try:
inbox.remove(inbox[index])
print("Email deleted successfully")
except:
print("Error: couldn't delete email")

# This variable store user input, the choice they choose from the menu
user_choice = ""

inbox = []
def add_email(message, email):
send = Email(message, email)
inbox.append(send)


# Initial email
init_emails = [
'Hie how are you,alfred@gmail.com',
'Hie lets meet us,thuba@gmail.com'
]

for i in init_emails:
message, email = i.split(',')
add_email(message,email)

#This is the menu the user will be prompted with to enter choice
while user_choice != "quit":
user_choice = input("What would you like to do - read/mark spam/send/delete/quit?\n").lower()

if user_choice == "read":
print("List of unread email\n")
for i,mail in enumerate(init_emails):
print(f'{i+1}. {mail}')
num = int(input("\nEnter number of email you want to read: "))
get_email(num-1)
#num = int(input("Enter number of email you want to read: "))
#get_email(num-1)
elif user_choice == "mark spam":
print("List of emails\n")
for i,mail in enumerate(init_emails):
print(f'{i}. {mail}')
num = int(input("\nEnter number of email you want to spam :"))
add_spam(num-1)
get_spam_emails()
#add_spam(num-1)
#get_spam_emails()
elif user_choice == "send":
from_address = input("Enter your email address: ")
email_contents = input("Enter email content: ")
add_email(email_contents, from_address)
print("Email sent successfully!")
elif user_choice == "delete":
print("List of emails\n")
for i,mail in enumerate(init_emails):
print(f'{i}. {mail}')
num = int(input("enter number of email to delete"))
delete(num-1)
#num = int(input("enter number of email to delete"))
#delete(num-1)
elif user_choice == "quit":
print("Goodbye")
break
# else alet user that the entry is invalid
else:
print("Oops - incorrect input")
Thandeka Zulu 28-Jul-22 9:00am View    
Will definately look into that. Thank you.