[mail] Partial fix for trashing emails
This commit is contained in:
@ -16,6 +16,10 @@ sysu enable --now django@project
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Backlog
|
* 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:
|
** DONE Figure out why SSH key loading isn't working in terminal Emacs :personal:bug:dotfiles:emacs:ssh:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:ID: f4d738a4-ffcb-7352-06f1-4f0dd89dff08
|
:ID: f4d738a4-ffcb-7352-06f1-4f0dd89dff08
|
||||||
|
|||||||
@ -18,36 +18,36 @@ def extract_text(body_parts):
|
|||||||
|
|
||||||
def walk(parts):
|
def walk(parts):
|
||||||
for part in parts:
|
for part in parts:
|
||||||
content_type = part.get('content-type', '')
|
content_type = part.get("content-type", "")
|
||||||
content = part.get('content')
|
content = part.get("content")
|
||||||
if isinstance(content, list):
|
if isinstance(content, list):
|
||||||
walk(content)
|
walk(content)
|
||||||
elif content:
|
elif content:
|
||||||
if 'text/plain' in content_type:
|
if "text/plain" in content_type:
|
||||||
plain.append(content)
|
plain.append(content)
|
||||||
elif 'text/html' in content_type:
|
elif "text/html" in content_type:
|
||||||
html.append(content)
|
html.append(content)
|
||||||
|
|
||||||
walk(body_parts)
|
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):
|
def send_ntfy(headers, payload):
|
||||||
data = payload.encode('utf-8')
|
data = payload.encode("utf-8")
|
||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
conn = http.client.HTTPSConnection(NTFY_HOST, timeout=15)
|
conn = http.client.HTTPSConnection(NTFY_HOST, timeout=15)
|
||||||
try:
|
try:
|
||||||
conn.putrequest("POST", NTFY_PATH, skip_host=True)
|
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():
|
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-Type", b"text/plain; charset=utf-8")
|
||||||
conn.putheader("Content-Length", str(len(data)))
|
conn.putheader("Content-Length", str(len(data)))
|
||||||
conn.endheaders(data)
|
conn.endheaders(data)
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
resp.read()
|
resp.read()
|
||||||
if resp.status == 429:
|
if resp.status == 429:
|
||||||
retry = resp.getheader('Retry-After', '5') or '5'
|
retry = resp.getheader("Retry-After", "5") or "5"
|
||||||
time.sleep(float(retry))
|
time.sleep(float(retry))
|
||||||
continue
|
continue
|
||||||
if resp.status < 200 or resp.status >= 300:
|
if resp.status < 200 or resp.status >= 300:
|
||||||
@ -64,18 +64,18 @@ def main():
|
|||||||
new_mail = json.loads(
|
new_mail = json.loads(
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
["notmuch", "show", "--format=json", "tag:new"],
|
["notmuch", "show", "--format=json", "tag:new"],
|
||||||
).decode('utf-8')
|
).decode("utf-8")
|
||||||
)
|
)
|
||||||
|
|
||||||
for thread in new_mail:
|
for thread in new_mail:
|
||||||
for message_pair in thread:
|
for message_pair in thread:
|
||||||
headers = message_pair[0]['headers']
|
headers = message_pair[0]["headers"]
|
||||||
subject = headers.get('Subject', '')
|
subject = headers.get("Subject", "")
|
||||||
sender = headers.get('From', '')
|
sender = headers.get("From", "")
|
||||||
date = headers.get('Date', '')
|
date = headers.get("Date", "")
|
||||||
body = extract_text(message_pair[0].get('body', []))[:MAX_BODY]
|
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(
|
send_ntfy(
|
||||||
{
|
{
|
||||||
"Title": subject,
|
"Title": subject,
|
||||||
|
|||||||
@ -57,6 +57,6 @@ folders = colin@unbl.ink/INBOX colin@unbl.ink/Archive colin@unbl.ink/Trash
|
|||||||
rename = True
|
rename = True
|
||||||
max_age = 15
|
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/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:inbox':colin@unbl.ink/INBOX 'tag:trash':colin@unbl.ink/Trash
|
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':colin@unbl.ink/INBOX 'tag:archive':colin@unbl.ink/Archive
|
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
|
||||||
|
|||||||
@ -93,7 +93,7 @@ thread_subject= oldest
|
|||||||
t = toggletags todo
|
t = toggletags todo
|
||||||
y = toggletags travel
|
y = toggletags travel
|
||||||
F = toggletags flat
|
F = toggletags flat
|
||||||
D = toggletags delete
|
D = "tag trash; untag inbox; untag archive"
|
||||||
#enter = "select; fold NOT is:unread"
|
#enter = "select; fold NOT is:unread"
|
||||||
|
|
||||||
[[thread]]
|
[[thread]]
|
||||||
|
|||||||
@ -12,7 +12,6 @@ MaildirStore unblink-local
|
|||||||
# trailing "/" is important
|
# trailing "/" is important
|
||||||
Path ~/Mail/colin@unbl.ink/
|
Path ~/Mail/colin@unbl.ink/
|
||||||
Inbox ~/Mail/colin@unbl.ink/INBOX
|
Inbox ~/Mail/colin@unbl.ink/INBOX
|
||||||
Trash Trash
|
|
||||||
|
|
||||||
Channel unblink-folders
|
Channel unblink-folders
|
||||||
Far :unblink-remote:
|
Far :unblink-remote:
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
Description=Sync mail timer
|
Description=Sync mail timer
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
OnCalendar=*:0/15
|
OnCalendar=*:0/3
|
||||||
Unit=syncmail.service
|
Unit=syncmail.service
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
Reference in New Issue
Block a user