76 lines
2.5 KiB
EmacsLisp
76 lines
2.5 KiB
EmacsLisp
|
;;; idec-db.el --- This file is a part of GNU Emacs client for IDEC network
|
||
|
|
||
|
;; Copyright (c) 2017 Denis Zheleztsov
|
||
|
|
||
|
;; Author: Denis Zheleztsov <difrex.punk@gmail.com>
|
||
|
;; Keywords: lisp,network,IDEC
|
||
|
;; Version: 0.1
|
||
|
|
||
|
;; This program is free software; you can redistribute it and/or modify
|
||
|
;; it under the terms of the GNU General Public License as published by
|
||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||
|
;; (at your option) any later version.
|
||
|
|
||
|
;; This program is distributed in the hope that it will be useful,
|
||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
;; GNU General Public License for more details.
|
||
|
|
||
|
;; You should have received a copy of the GNU General Public License
|
||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
;;; Commentary:
|
||
|
|
||
|
;; In active developent.
|
||
|
;; Fetched node must be support modern IDEC extensions like /list.txt, /x/c, etc.
|
||
|
|
||
|
;;; Code:
|
||
|
(require 'emacsql)
|
||
|
(require 'idec-parser)
|
||
|
|
||
|
(defun create-echo-mail-dir (echo)
|
||
|
"Create ECHO directory inside `idec-mail-dir'."
|
||
|
(if (file-exists-p idec-mail-dir)
|
||
|
(message idec-mail-dir)
|
||
|
(mkdir idec-mail-dir))
|
||
|
(if (file-exists-p (concat idec-mail-dir "/" echo))
|
||
|
(message (concat idec-mail-dir "/" echo))
|
||
|
(mkdir (concat idec-mail-dir "/" echo))))
|
||
|
|
||
|
(defun get-echo-dir (echo)
|
||
|
"Get ECHO dir from `idec-mail-dir'."
|
||
|
(concat idec-mail-dir (concat "/" echo)))
|
||
|
|
||
|
(defun filename-to-store (content id)
|
||
|
"Make filename from CONTENT unixtime and ID."
|
||
|
(concat (nth 2 (split-string content)) "-" id))
|
||
|
|
||
|
(defun get-message-file (echo id)
|
||
|
"Get ECHO message filename by ID."
|
||
|
(concat (get-echo-dir echo) "/" id))
|
||
|
|
||
|
(defun get-counter-file (echo)
|
||
|
"Get ECHO counter filename."
|
||
|
(concat (get-echo-dir echo) "/counter"))
|
||
|
|
||
|
(defun store-message (content echo id)
|
||
|
"Store CONTENT from ECHO message in `idec-mail-dir' with it ID."
|
||
|
(create-echo-mail-dir echo)
|
||
|
(write-region content nil (get-message-file echo id)))
|
||
|
|
||
|
(defun store-echo-counter (echo)
|
||
|
"Store count messages in ECHO."
|
||
|
(create-echo-mail-dir echo)
|
||
|
(write-region (echo-messages-count echo) nil (get-counter-file echo)))
|
||
|
|
||
|
(defun check-message-in-echo (msg echo)
|
||
|
"Check if exists message MSG in ECHO `idec-mail-dir'."
|
||
|
(not (f-file? (get-message-file echo msg))))
|
||
|
|
||
|
(defun open-echo-db (echo)
|
||
|
"Create or open sqlite database inside ECHO `idec-mail-dir'.")
|
||
|
|
||
|
(provide 'idec-db)
|
||
|
|
||
|
;;; idec-db.el ends here
|