def add_contact(name, surname, mail, note, nick): db_api.insert( "contact", { "name": name, "surname": surname, "mail": mail, "note": note, "nick": nick }, )
def get_mails(year, month, day): # Messages received after specific date # inbox_messages_received_after = imbox.messages(date__gt=datetime.date(2018, 7, 30)) mails = [] with Imbox(get_user_connection_data()) as imbox: logging.info("Account information correct. Connected.") # Gets all messages after the day x # to get the mails of today: all_inbox_messages = imbox.messages(date__on=datetime.date(year, month, day)) logging.debug("Gathered all inbox messages") for uid, message in reversed(all_inbox_messages): # print(message.attachments) sanitized_body = str(message.body["html"]) sanitized_body = sanitized_body.replace(r"['\r\n", " ") sanitized_body = sanitized_body.replace(r"[b'", " ") sanitized_body = sanitized_body.replace(r"\r\n", " ") sanitized_body = sanitized_body.replace(r"\r", " ") sanitized_body = sanitized_body.replace(r"\n", " ") sanitized_body = sanitized_body.replace(r"\t", "") sanitized_body = sanitized_body.replace(r"['", "") sanitized_body = sanitized_body.replace(r"']", "") # Apply local time to base server time from_name = message.sent_from[0]["name"] from_mail = message.sent_from[0]["email"] to_name = message.sent_to[0]["name"] to_mail = message.sent_to[0]["email"] subject = str(message.subject) if str(message.subject) else "(No subject)" db_api.insert( "emails", { "uid": uid.decode(), "from_name": str(from_name), "from_mail": str(from_mail), "to_name": str(to_name), "to_mail": str(to_mail), "subject": str(subject), "bodyHTML": str(sanitized_body), "bodyPLAIN": str(message.body["plain"]), "directory": "", "datetimes": datetime.date(year, month, day), }, )
def set_user(name, nick, mail, passw, imapserver, smtpserver): db_api.insert( "user", { "name": name, "surname": "", "nickname": nick, "bio": "", "mail": mail, "password": passw, "profilepic": "", "imapserver": imapserver, "smtpserver": smtpserver, "datetime": datetime.datetime.now(), }, )
def add_note(text, uid, attach): db_api.insert("notes", {"uid": uid, "attach": attach})