def compose(wfile, inreplyto=None, is_reply_all=False): inreplyto_msg = None recips_replyall = None recips_replyto = None recip_sender = None # Reply elements if inreplyto: inreplyto_msg = email.message_from_string(database.get_message(inreplyto)) if inreplyto_msg is not None: # Convert ["sam shelton <*****@*****.**>"] to ["*****@*****.**"] for to, cc, and from fields cc = [email.utils.parseaddr(field)[1] for field in (inreplyto_msg.get("Cc") or "").split(",")] to = [email.utils.parseaddr(field)[1] for field in (inreplyto_msg.get("To") or "").split(",")] #TODO remove self email from recips replyto = [email.utils.parseaddr(field)[1] for field in inreplyto_msg.get("Reply-To").split(",")] fr = email.utils.parseaddr(inreplyto_msg.get("From"))[1] # Merge lists for use in script element recips_replyall = list(set(cc) | set(to) | set((fr,))) recips_replyto = list(set(replyto)) recip_sender = [fr] # No need to convert it to set; it's duplicate-free. else: inreplyto = None # Tell the parser that it isn't a reply # Accounts accounts = [] for account in database.get_account_list(): acc_dict = {"address":account[0], "name":account[1]} acc_dict["default"] = account[0] == DEFAULT_SENDER accounts.append(acc_dict) html = temp_compose.render(inreplyto=inreplyto, is_reply_all=is_reply_all, recips_replyall=recips_replyall, recips_replyto=recips_replyto, recip_sender=recip_sender, accounts=accounts) wfile.write(html.encode("UTF-8"))
def get_accounts_dropdown(sender=""): default_sender = ( "*****@*****.**" ) # database.get_setting("default_sender") #TODO SETTINGS SHOULD BE RETRIEVED ONE TIME AND STORED IN GLOBALS text = """<select class="sender">\n""" for account in database.get_account_list(): if sender == "": if account[0] == default_sender: selected = "selected" else: selected = "" else: selected = sender text += ACCOUNTS_DROPDOWN_TEMPLATE.format(selected=selected, address=account[0], name=account[1]) text += "</select>\n" return text