[mail] Partial fix for trashing emails

This commit is contained in:
2026-08-05 10:12:07 -04:00
parent b4935c82d7
commit 48f6adeaad
6 changed files with 25 additions and 22 deletions

View File

@ -16,6 +16,10 @@ sysu enable --now django@project
#+end_src
* Backlog
** TODO Fix issue with trashing emails in notmuch :email:notmuch:dotfiles:
#+begin_src bash
opencode -s ses_02fd1d8dbffe7m2AhnSa7FJUHo
#+end_src
** DONE Figure out why SSH key loading isn't working in terminal Emacs :personal:bug:dotfiles:emacs:ssh:
:PROPERTIES:
:ID: f4d738a4-ffcb-7352-06f1-4f0dd89dff08

View File

@ -18,36 +18,36 @@ def extract_text(body_parts):
def walk(parts):
for part in parts:
content_type = part.get('content-type', '')
content = part.get('content')
content_type = part.get("content-type", "")
content = part.get("content")
if isinstance(content, list):
walk(content)
elif content:
if 'text/plain' in content_type:
if "text/plain" in content_type:
plain.append(content)
elif 'text/html' in content_type:
elif "text/html" in content_type:
html.append(content)
walk(body_parts)
return '\n'.join(plain) if plain else '\n'.join(html)
return "\n".join(plain) if plain else "\n".join(html)
def send_ntfy(headers, payload):
data = payload.encode('utf-8')
data = payload.encode("utf-8")
for attempt in range(3):
conn = http.client.HTTPSConnection(NTFY_HOST, timeout=15)
try:
conn.putrequest("POST", NTFY_PATH, skip_host=True)
conn.putheader(b"Host", NTFY_HOST.encode('utf-8'))
conn.putheader(b"Host", NTFY_HOST.encode("utf-8"))
for name, value in headers.items():
conn.putheader(name.encode('utf-8'), value.encode('utf-8'))
conn.putheader(name.encode("utf-8"), value.encode("utf-8"))
conn.putheader("Content-Type", b"text/plain; charset=utf-8")
conn.putheader("Content-Length", str(len(data)))
conn.endheaders(data)
resp = conn.getresponse()
resp.read()
if resp.status == 429:
retry = resp.getheader('Retry-After', '5') or '5'
retry = resp.getheader("Retry-After", "5") or "5"
time.sleep(float(retry))
continue
if resp.status < 200 or resp.status >= 300:
@ -64,18 +64,18 @@ def main():
new_mail = json.loads(
subprocess.check_output(
["notmuch", "show", "--format=json", "tag:new"],
).decode('utf-8')
).decode("utf-8")
)
for thread in new_mail:
for message_pair in thread:
headers = message_pair[0]['headers']
subject = headers.get('Subject', '')
sender = headers.get('From', '')
date = headers.get('Date', '')
body = extract_text(message_pair[0].get('body', []))[:MAX_BODY]
headers = message_pair[0]["headers"]
subject = headers.get("Subject", "")
sender = headers.get("From", "")
date = headers.get("Date", "")
body = extract_text(message_pair[0].get("body", []))[:MAX_BODY]
payload = f"{sender}\n\n{body}\n\n{date}"
payload = f"{sender}\n\n{body}\n{date}"
send_ntfy(
{
"Title": subject,

View File

@ -57,6 +57,6 @@ folders = colin@unbl.ink/INBOX colin@unbl.ink/Archive colin@unbl.ink/Trash
rename = True
max_age = 15
colin@unbl.ink/INBOX = 'tag:spam':colin@unbl.ink/Junk 'NOT tag:inbox':colin@unbl.ink/Archive 'tag:trash':colin@unbl.ink/Trash
colin@unbl.ink/Archive = 'tag:inbox':colin@unbl.ink/INBOX 'tag:trash':colin@unbl.ink/Trash
colin@unbl.ink/Trash = 'tag:inbox':colin@unbl.ink/INBOX 'tag:archive':colin@unbl.ink/Archive
colin@unbl.ink/INBOX = 'tag:trash':colin@unbl.ink/Trash 'tag:deleted':colin@unbl.ink/Trash 'tag:spam':colin@unbl.ink/Junk 'NOT tag:inbox AND NOT tag:trash AND NOT tag:deleted AND NOT tag:spam':colin@unbl.ink/Archive
colin@unbl.ink/Archive = 'tag:trash':colin@unbl.ink/Trash 'tag:deleted':colin@unbl.ink/Trash 'tag:inbox AND NOT tag:trash AND NOT tag:deleted':colin@unbl.ink/INBOX
colin@unbl.ink/Trash = 'tag:inbox AND NOT tag:trash AND NOT tag:deleted':colin@unbl.ink/INBOX 'tag:archive AND NOT tag:trash AND NOT tag:deleted':colin@unbl.ink/Archive

View File

@ -93,7 +93,7 @@ thread_subject= oldest
t = toggletags todo
y = toggletags travel
F = toggletags flat
D = toggletags delete
D = "tag trash; untag inbox; untag archive"
#enter = "select; fold NOT is:unread"
[[thread]]

View File

@ -12,7 +12,6 @@ MaildirStore unblink-local
# trailing "/" is important
Path ~/Mail/colin@unbl.ink/
Inbox ~/Mail/colin@unbl.ink/INBOX
Trash Trash
Channel unblink-folders
Far :unblink-remote:

View File

@ -2,7 +2,7 @@
Description=Sync mail timer
[Timer]
OnCalendar=*:0/15
OnCalendar=*:0/3
Unit=syncmail.service
[Install]