summaryrefslogtreecommitdiffhomepage
path: root/net/jao-maildir.el
diff options
context:
space:
mode:
Diffstat (limited to 'net/jao-maildir.el')
-rw-r--r--net/jao-maildir.el76
1 files changed, 76 insertions, 0 deletions
diff --git a/net/jao-maildir.el b/net/jao-maildir.el
new file mode 100644
index 0000000..ed082a0
--- /dev/null
+++ b/net/jao-maildir.el
@@ -0,0 +1,76 @@
+;; jao-maildir.el -- Utilities for reading maildirs -*- lexical-binding: t; -*-
+
+;; Copyright (c) 2019 jao
+
+;; Author: jao <mail@jao.io>
+;; Start date: Sun Dec 01, 2019 15:48
+;; Keywords: mail
+
+;; This file 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, or (at your option)
+;; any later version.
+
+;; This file 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 GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Comentary:
+
+;; Inspecting the contents of maildirs and reporting it.
+
+;;; Code:
+
+(defvar jao-maildirs nil)
+(defvar jao-maildir-counts nil)
+(defvar jao-maildir-debug-p nil)
+
+(defun jao-maildir--maildir-new (mbox) (expand-file-name "new" mbox))
+
+(defun jao-maildir--maildir-new-count (mbox)
+ (- (length (directory-files (jao-maildir--maildir-new mbox))) 2))
+
+(defun jao-maildir-counts ()
+ (mapcar (lambda (mbox) (cons mbox (jao-maildir--maildir-new-count mbox)))
+ jao-maildirs))
+
+(defvar jao-maildir--watches nil)
+
+(defun jao-maildir-cancel-watchers ()
+ (dolist (w jao-maildir--watches) (file-notify-rm-watch w))
+ (setq jao-maildir--watches nil))
+
+(defun jao-maildir--log-watch (mbox e)
+ (when jao-maildir-debug-p
+ (message "watch: %s: %s" mbox e)))
+
+(defun jao-maildir--watcher (mbox)
+ (lambda (e)
+ (jao-maildir--log-watch e mbox)
+ (when (memq (cadr e) '(created deleted))
+ (setcdr (assoc mbox jao-maildir-counts)
+ (jao-maildir--maildir-new-count mbox)))))
+
+(defun jao-maildir--setup-watches ()
+ (jao-maildir-cancel-watchers)
+ (setq jao-maildir--watches
+ (mapcar (lambda (mbox)
+ (file-notify-add-watch (jao-maildir--maildir-new mbox)
+ '(change)
+ (jao-maildir--watcher mbox)))
+ jao-maildirs)))
+
+(defun jao-maildir-setup (maildirs)
+ (setq jao-maildirs maildirs)
+ (setq jao-maildir-counts (jao-maildir-counts))
+ (jao-maildir--setup-watches))
+
+
+(provide 'jao-maildir)
+;;; jao-maildir.el ends here