Commit 9058e27b authored by Benjamin Krause's avatar Benjamin Krause
Browse files

Implement small wizard to test the functionality.

parent 6a715414
from email.message import EmailMessage
from pprint import pprint
from app.mail import Mail
from app.mail_provider import MailProvider
from app.user import User
from app.utils import get_mail_formatted_date, subject_identifier
mail_providers = dict(
webde=MailProvider(
base_url="web.de", imap_url="imap.web.de", smtp_url="smtp.web.de", smtp_port=587
)
)
def create_user() -> User:
print("Create a login")
mail = input("Type here the mail address: ")
password = input("Type here the password to the mail address: ")
return User(mail=mail, password=password)
def create_receiver() -> User:
print("Create a user to receive the email")
mail = input("Type here the receiver mail address: ")
return User(mail=mail, password="")
def create_mail(from_user: User, to: User) -> Mail:
print("Create the a mail.")
date = get_mail_formatted_date()
subject = input("Type here your subject: ")
body = input("Type here your message: ")
return Mail(
date=date,
subject=f"{subject} - {subject_identifier}",
mail_from=from_user.mail,
mail_to=to.mail,
cc="",
body=body,
)
def create_mail_message(mail: Mail) -> EmailMessage:
msg = EmailMessage()
msg.set_content(mail.body)
msg["Date"] = mail.date
msg["Subject"] = mail.subject
msg["From"] = mail.mail_from
msg["To"] = mail.mail_to
msg["CC"] = mail.cc
return msg
def send_mail():
print("Send a mail.")
from_user = create_user()
to = create_receiver()
message = create_mail(from_user, to)
if mail_providers.get("webde").send_mail(from_user, to, create_mail_message(message)):
print("The email was send successfully!")
else:
print("Failed to send the email!")
def get_relevant_mails():
user = create_user()
mailbox = input("Type here the mailbox, in which you want to search: ")
mails = mail_providers.get("webde").search_relevant_mails(user, mailbox)
pprint(mails)
if __name__ == "__main__":
select = input("Type send to 'send' a mail or 'get' to show relevant mails: ")
if select == "send":
send_mail()
elif select == "get":
get_relevant_mails()
else:
print("You should type 'send' or 'get'! Try it again.")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment