library/library/emails.py

48 lines
1.6 KiB
Python

def format_reminder_email(quest_id: str,
days_signed_out: int,
librarian_name: str,
book_name) -> str:
"""
Formats an email as a plain string for sending out email reminders
for signed out books.
Example: _send_email("s455wang", "2017-02-04", 30, "csfmurph", "How to Design Programs")
"""
assert len(quest_id) <= 8
assert quest_id.isalnum()
assert days_signed_out > 0
assert librarian_name != ""
assert book_name != ""
email_message_body = \
"""Hi {},
Our records indicate that you have had the book {} signed out for {} days.
If you would like to keep this book checked out, tell us when in the next month you will return this book.
Otherwise, please return the book to the CS Club office (MC 3036) at your earliest convenience.
Thank you for using the CS Club library!
{} | Librarian
Computer Science Club | University of Waterloo
librarian@csclub.uwaterloo.ca""".format(
quest_id,
book_name,
days_signed_out,
librarian_name
)
email_message_subject = "Overdue book: {}".format(book_name)
email_message = (
"To: \"{0}@csclub.uwaterloo.ca\" <{0}@csclub.uwaterloo.ca>\n".format(quest_id) +
"Subject: {}\n".format(email_message_subject) +
"\n" +
email_message_body
)
assert email_message.replace("\n", "").isprintable(), \
"Our email should not have characters apart from normal characters and newline"
return email_message