More updats
This commit is contained in:
parent
6e2d18e5e8
commit
2dec159f8a
@ -4,14 +4,17 @@
|
|||||||
(import threading [Thread])
|
(import threading [Thread])
|
||||||
(import enum [StrEnum])
|
(import enum [StrEnum])
|
||||||
(import os [path])
|
(import os [path])
|
||||||
|
(import re)
|
||||||
(import json)
|
(import json)
|
||||||
(import shutil)
|
(import shutil)
|
||||||
|
|
||||||
|
(setv global-did-delete False)
|
||||||
|
|
||||||
(defclass OutputType [StrEnum]
|
(defclass OutputType [StrEnum]
|
||||||
(setv LINES "text"
|
(setv LINES "text"
|
||||||
JSON "json"))
|
JSON "json"))
|
||||||
|
|
||||||
(defn notmuch [#* args [output OutputType.LINES]]
|
(defn notmuch [#* args [output None]]
|
||||||
(let [result (run ["notmuch"
|
(let [result (run ["notmuch"
|
||||||
#* args]
|
#* args]
|
||||||
:stdout (if (is-not output None)
|
:stdout (if (is-not output None)
|
||||||
@ -27,39 +30,39 @@
|
|||||||
mail-root None
|
mail-root None
|
||||||
sender None
|
sender None
|
||||||
subject None
|
subject None
|
||||||
file None
|
|
||||||
attachment? False
|
attachment? False
|
||||||
notified? False
|
notified? False
|
||||||
read? False)
|
read? False)
|
||||||
(defn __init__ [self uid mail-root sender subject
|
(defn __init__ [self uid mail-root sender subject
|
||||||
file attachment? notified? read?]
|
attachment? notified? read?]
|
||||||
(setv self.uid uid
|
(setv self.uid uid
|
||||||
self.mail-root mail-root
|
self.mail-root mail-root
|
||||||
self.sender sender
|
self.sender sender
|
||||||
self.subject subject
|
self.subject subject
|
||||||
self.file file
|
|
||||||
self.attachment? attachment?
|
self.attachment? attachment?
|
||||||
self.notified? notified?
|
self.notified? notified?
|
||||||
self.notified? read?))
|
self.notified? read?))
|
||||||
(defn tag [self #* tags]
|
(defn tag [self #* tags]
|
||||||
(when (is self.uid None)
|
|
||||||
(raise (ValueError "uid is None")))
|
|
||||||
(notmuch "tag" #* tags (+ "id:" self.uid)))
|
(notmuch "tag" #* tags (+ "id:" self.uid)))
|
||||||
(defn move [self dest]
|
(defn move [self dest]
|
||||||
(let [name (path.basename self.file)
|
(let [old-path (self.get-filename)
|
||||||
new_path (+ mail-root "/" dest "/cur/" name)]
|
name (re.sub "U=[0-9]+:[0-9]+,([DFPRS]*$)"
|
||||||
(shutil.move msg.file new_path)))
|
r"\1" (path.basename old-path))
|
||||||
|
new-path (+ self.mail-root "/" dest "/cur/" name)]
|
||||||
|
(shutil.move old-path new-path)))
|
||||||
|
(defn get-filename [self]
|
||||||
|
(get (notmuch "search" "--output=files" (+ "id:" (str self.uid))
|
||||||
|
:output OutputType.LINES) 0))
|
||||||
(defn from-json [root mail-root]
|
(defn from-json [root mail-root]
|
||||||
(let [uid (get root "id")
|
(let [uid (get root "id")
|
||||||
headers (get root "headers")
|
headers (get root "headers")
|
||||||
sender (parse-from-address (get headers "From"))
|
sender (parse-from-address (get headers "From"))
|
||||||
subject (get headers "Subject")
|
subject (get headers "Subject")
|
||||||
file (. root ["filename"] [0])
|
|
||||||
tags (get root "tags")
|
tags (get root "tags")
|
||||||
attachment? (in "attachment" tags)
|
attachment? (in "attachment" tags)
|
||||||
notified? (not-in "notnotified" tags)
|
notified? (not-in "notnotified" tags)
|
||||||
read? (not-in "unread" tags)]
|
read? (not-in "unread" tags)]
|
||||||
(Message uid mail-root sender subject file attachment? notified? read?)))
|
(Message uid mail-root sender subject attachment? notified? read?)))
|
||||||
(defn __str__ [self]
|
(defn __str__ [self]
|
||||||
(+ "Message From \"" self.sender "\": " self.subject
|
(+ "Message From \"" self.sender "\": " self.subject
|
||||||
" ("
|
" ("
|
||||||
@ -96,10 +99,12 @@
|
|||||||
(match result
|
(match result
|
||||||
0 (msg.tag "-unread")
|
0 (msg.tag "-unread")
|
||||||
1 (do
|
1 (do
|
||||||
|
(setv global-did-delete True)
|
||||||
(msg.tag "-unread")
|
(msg.tag "-unread")
|
||||||
(msg.move "Trash")))))
|
(msg.move "Trash")))))
|
||||||
|
|
||||||
(let [mail-root (get (notmuch "config" "get" "database.mail_root") 0)
|
(let [mail-root (get (notmuch "config" "get" "database.mail_root"
|
||||||
|
:output OutputType.LINES) 0)
|
||||||
json-root (notmuch "show" "--format=json" "--body=false"
|
json-root (notmuch "show" "--format=json" "--body=false"
|
||||||
"tag:notnotified" "and"
|
"tag:notnotified" "and"
|
||||||
"tag:unread" "and"
|
"tag:unread" "and"
|
||||||
@ -111,3 +116,6 @@
|
|||||||
:args #(msg))))))
|
:args #(msg))))))
|
||||||
|
|
||||||
(notmuch "tag" "-notnotified" "*")
|
(notmuch "tag" "-notnotified" "*")
|
||||||
|
(when global-did-delete
|
||||||
|
(notmuch "tag" "+deleted" "folder:Trash")
|
||||||
|
(notmuch "new" "--no-hooks"))
|
||||||
|
6
notmuch-mbsync-refresh.sh
Executable file
6
notmuch-mbsync-refresh.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
~/scripts/notmuch-pre.sh
|
||||||
|
mbsync -a
|
||||||
|
notmuch new
|
||||||
|
~/scripts/notmuch-post.sh
|
Loading…
Reference in New Issue
Block a user