Reply with list of existing reminders
This commit is contained in:
parent
a2969be439
commit
a048526722
1 changed files with 29 additions and 8 deletions
37
remindme.py
37
remindme.py
|
|
@ -14,6 +14,17 @@ from croniter import croniter
|
||||||
help_text = """
|
help_text = """
|
||||||
A very comprehensive help text
|
A very comprehensive help text
|
||||||
"""
|
"""
|
||||||
|
service_address = "remindme@friedersdorff.com"
|
||||||
|
|
||||||
|
def empty_reply(msg):
|
||||||
|
reply = email.message.EmailMessage()
|
||||||
|
reply["Subject"] = f"RE: {msg['Subject']}"
|
||||||
|
reply["Message-ID"] = email.utils.make_msgid()
|
||||||
|
reply["In-Reply-To"] = msg["Message-ID"]
|
||||||
|
reply["References"] = msg["Message-ID"]
|
||||||
|
reply["To"] = msg["Reply-To"] or msg["From"]
|
||||||
|
reply["From"] = service_address
|
||||||
|
return reply
|
||||||
|
|
||||||
|
|
||||||
def ack_message(uid, message, client):
|
def ack_message(uid, message, client):
|
||||||
|
|
@ -25,16 +36,26 @@ def ack_message(uid, message, client):
|
||||||
|
|
||||||
payload = msg.get_payload().strip()
|
payload = msg.get_payload().strip()
|
||||||
if payload.startswith("help"):
|
if payload.startswith("help"):
|
||||||
print("We should help")
|
reply = empty_reply(msg)
|
||||||
reply = email.message.EmailMessage()
|
|
||||||
reply.set_content(help_text)
|
reply.set_content(help_text)
|
||||||
reply["Subject"] = f"Help for remindme service (was {msg['Subject']})"
|
|
||||||
reply["Message-ID"] = email.utils.make_msgid()
|
|
||||||
reply["In-Reply-To"] = msg["Message-ID"]
|
|
||||||
reply["References"] = msg["Message-ID"]
|
|
||||||
reply["To"] = msg["Reply-To"] or msg["From"]
|
|
||||||
reply["From"] = "remindme@friedersdorff.com"
|
|
||||||
return reply, True
|
return reply, True
|
||||||
|
|
||||||
|
if payload.startswith("list"):
|
||||||
|
persons_messages = client.fetch(
|
||||||
|
client.search(["FROM", msg["From"]]), "RFC822"
|
||||||
|
)
|
||||||
|
reminders = []
|
||||||
|
for uid, reminder in persons_messages.items():
|
||||||
|
reminder = email.message_from_bytes(reminder[b"RFC822"])
|
||||||
|
reminders.append(
|
||||||
|
(reminder["Subject"], reminder.get_payload().strip())
|
||||||
|
)
|
||||||
|
reply = empty_reply(msg)
|
||||||
|
reply.set_content("\n".join(
|
||||||
|
[f"({i}) {r[0]}: {r[1]}" for i, r in enumerate(reminders)]
|
||||||
|
))
|
||||||
|
return reply, True
|
||||||
|
|
||||||
if payload.startswith("repeat"):
|
if payload.startswith("repeat"):
|
||||||
try:
|
try:
|
||||||
print(get_description(payload))
|
print(get_description(payload))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue