This commit is contained in:
Denis Zheleztsov 2017-11-13 11:59:44 +03:00
parent fcf28eda57
commit 8be6a9312c
3 changed files with 43 additions and 30 deletions

View File

@ -31,7 +31,7 @@
(defun replace-in-string (what with str) (defun replace-in-string (what with str)
"Replace WHAT WITH in STR." "Replace WHAT WITH in STR."
(replace-regexp-in-string (regexp-quote what) with str nil 'literal)) (replace-regexp-in-string (regexp-quote what) with str nil 'literal))
(defun base64-to-base64url (str) (defun base64-to-base64url (str)
"Make url safe base64 string STR." "Make url safe base64 string STR."
@ -153,20 +153,30 @@
(defun get-answers-hash (id msg-hash) (defun get-answers-hash (id msg-hash)
"Make answers hashtable from ID and MSG-HASH." "Make answers hashtable from ID and MSG-HASH."
(let (answer-hash) (if (gethash "content" msg-hash)
(setq answer-hash (make-hash-table :test 'equal)) (let (answer-hash)
(puthash "id" id answer-hash) (setq answer-hash (make-hash-table :test 'equal))
(puthash "echo" (get-message-field (gethash "content" msg-hash) "echo") answer-hash) (puthash "id" id answer-hash)
(puthash "author" (get-message-field (gethash "content" msg-hash) "author") answer-hash) (puthash "echo" (get-message-field (gethash "content" msg-hash) "echo") answer-hash)
(puthash "time" (get-message-field (gethash "content" msg-hash) "time") answer-hash) (puthash "author" (get-message-field (gethash "content" msg-hash) "author") answer-hash)
(puthash "time" (get-message-field (gethash "content" msg-hash) "time") answer-hash)
(setq subj (get-message-field (gethash "content" msg-hash) "subj")) (setq subj (get-message-field (gethash "content" msg-hash) "subj"))
;; Make `Re:' in subj if it not present. ;; Make `Re:' in subj if it not present.
(if (not (string-match "Re:" subj)) (if (not (string-match "Re:" subj))
(puthash "subj" (concat "Re: " subj) answer-hash) (puthash "subj" (concat "Re: " subj) answer-hash)
(puthash "subj" subj answer-hash)) (puthash "subj" subj answer-hash))
answer-hash)) answer-hash)
(let (subj)
(setq subj (gethash "subj" msg-hash))
;; Make `Re:' in subj if it not present.
(if (not subj)
(puthash "subj" (concat "Re: " "") msg-hash)
(if (not (string-match "Re:" subj))
(puthash "subj" (concat "Re: " subj) msg-hash)))
msg-hash)))
(defun make-answer-header (id msg-hash) (defun make-answer-header (id msg-hash)
"Make header with reto to ID from MSG-HASH." "Make header with reto to ID from MSG-HASH."
@ -184,6 +194,7 @@
(defun edit-answer-without-quote (id msg-hash) (defun edit-answer-without-quote (id msg-hash)
"Answer to message with ID MSG-HASH." "Answer to message with ID MSG-HASH."
msg-hash
(let (answer-hash p) (let (answer-hash p)
(setq answer-hash (get-answers-hash id msg-hash)) (setq answer-hash (get-answers-hash id msg-hash))
(switch-to-buffer (get-buffer-create (concat "*IDEC: answer to " id "*"))) (switch-to-buffer (get-buffer-create (concat "*IDEC: answer to " id "*")))
@ -198,7 +209,7 @@
'action (lambda (x) (send-reply-message (button-get x 'msg))) 'action (lambda (x) (send-reply-message (button-get x 'msg)))
'msg answer-hash) 'msg answer-hash)
(goto-char p) (goto-char p)
(org-idec))) (org-idec)))
;; END OF ANSWERS ;; END OF ANSWERS

View File

@ -83,6 +83,7 @@
([(id :primary-key) ([(id :primary-key)
tags tags
author author
address
recipient recipient
repto repto
echo echo
@ -121,10 +122,11 @@ unread by default, but you can MARK-READ it."
(if (not (emacsql (open-echo-db (get-message-field msg "echo")) (if (not (emacsql (open-echo-db (get-message-field msg "echo"))
[:insert :into messages [:insert :into messages
:values ([$s1 $s2 $s3 $s4 $s5 $s6 $s7 $s8 $s9 $s10])] :values ([$s1 $s2 $s3 $s4 $s5 $s6 $s7 $s8 $s9 $s10 $s11])]
id id
(get-message-field msg "tags") (get-message-field msg "tags")
(get-message-field msg "author") (get-message-field msg "author")
(get-message-field msg "address")
(get-message-field msg "recipient") (get-message-field msg "recipient")
repto repto
(get-message-field msg "echo") (get-message-field msg "echo")
@ -153,13 +155,14 @@ unread by default, but you can MARK-READ it."
(puthash "id" (nth 0 msg-list) msg-hash) (puthash "id" (nth 0 msg-list) msg-hash)
(puthash "tags" (nth 1 msg-list) msg-hash) (puthash "tags" (nth 1 msg-list) msg-hash)
(puthash "author" (nth 2 msg-list) msg-hash) (puthash "author" (nth 2 msg-list) msg-hash)
(puthash "recipient" (nth 3 msg-list) msg-hash) (puthash "address" (nth 3 msg-list) msg-hash)
(puthash "repto" (nth 4 msg-list) msg-hash) (puthash "recipient" (nth 4 msg-list) msg-hash)
(puthash "echo" (nth 5 msg-list) msg-hash) (puthash "repto" (nth 5 msg-list) msg-hash)
(puthash "subj" (nth 6 msg-list) msg-hash) (puthash "echo" (nth 6 msg-list) msg-hash)
(puthash "body" (nth 7 msg-list) msg-hash) (puthash "subj" (nth 7 msg-list) msg-hash)
(puthash "time" (nth 8 msg-list) msg-hash) (puthash "body" (nth 8 msg-list) msg-hash)
(puthash "unread" (nth 9 msg-list) msg-hash))) (puthash "time" (nth 9 msg-list) msg-hash)
(puthash "unread" (nth 10 msg-list) msg-hash)))
msg-hash)) msg-hash))
(defun get-echo-messages (echo) (defun get-echo-messages (echo)
@ -167,10 +170,9 @@ unread by default, but you can MARK-READ it."
(let (msgs) (let (msgs)
(setq msgs (make-list 0 (make-hash-table :test 'equal))) (setq msgs (make-list 0 (make-hash-table :test 'equal)))
(dolist (l (emacsql (open-echo-db echo) (dolist (l (emacsql (open-echo-db echo)
[:select [id, tags, author, recipient, repto, echo, subj, body, time, unread] [:select [id, tags, author, address, recipient, repto, echo, subj, body, time, unread]
:from messages :from messages
:order-by time :order-by time]))
:desc]))
(if (> (length l) 0) (if (> (length l) 0)
(setq msgs (append msgs (make-list 1 (make-hash-from-msg-list l)))))) (setq msgs (append msgs (make-list 1 (make-hash-from-msg-list l))))))
msgs)) msgs))

View File

@ -277,13 +277,13 @@ optionaly return cursor to CHECKPOINT."
(setq counter 0) (setq counter 0)
(dolist (msg (get-echo-messages echo)) (dolist (msg (get-echo-messages echo))
(insert-button (concat (gethash "subj" msg)) (insert-button (concat (gethash "subj" msg))
'action (lambda (x) (display-message-hash (button-get x 'msg))) 'action (lambda (x) (display-message-hash (button-get x 'msg-hash)))
'subj (gethash "subj" msg) 'subj (gethash "subj" msg)
'help-echo (concat "Read message *" (gethash "subj" msg) "*") 'help-echo (concat "Read message *" (gethash "subj" msg) "*")
'msg msg) 'msg-hash msg)
(princ (concat "\t" (gethash "time" msg) "\n")) (princ (concat "\t" (gethash "time" msg)))
)) (princ (concat "\t" (gethash "author" msg) "\n")))
(idec-mode))) (idec-mode))))
;; NAVIGATION FUNCTIONS ;; NAVIGATION FUNCTIONS