From d3a0857a8fc110893bbb3cdf14489603c4dad23d Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 6 Jun 2020 21:04:48 -0400 Subject: Copy over some Maildir utilities from Notmuch These will be used for writing messages from a public-inbox t.mbox.gz into a Maildir directory. --- Makefile | 3 ++- piem-maildir.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 piem-maildir.el diff --git a/Makefile b/Makefile index bf09fae..2bcf8eb 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ EMACS = emacs BATCH = $(EMACS) --batch -Q -L . EL = piem.el piem-b4.el piem-elfeed.el piem-eww.el piem-gnus.el \ - piem-notmuch.el + piem-maildir.el piem-notmuch.el ELC = $(EL:.el=.elc) all: compile piem.info piem-autoloads.el @@ -23,6 +23,7 @@ piem-b4.elc: piem-b4.el piem.elc piem-elfeed.elc: piem-elfeed.el piem.elc piem-eww.elc: piem-eww.el piem.elc piem-gnus.elc: piem-gnus.el piem.elc +piem-maildir.elc: piem-maildir.el piem-notmuch.elc: piem-notmuch.el piem.elc piem.elc: piem.el diff --git a/piem-maildir.el b/piem-maildir.el new file mode 100644 index 0000000..8819f33 --- /dev/null +++ b/piem-maildir.el @@ -0,0 +1,63 @@ +;;; piem-maildir.el --- Maildir helpers for piem -*- lexical-binding: t; -*- + +;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; This file extracts parts of Notmuch's emacs/notmuch-maildir-fcc.el +;; (ed40579ad3882e6f9bbe9b1ba5e707ab289ca203), simply replacing +;; "notmuch-maildir-fcc-" with "piem-maildir-". No other +;; modifications have been made. The copyright notice above matches +;; what is in the original file. + +;;; Code: + +(defvar piem-maildir-count 0) + +(defun piem-maildir-host-fixer (hostname) + (replace-regexp-in-string "/\\|:" + (lambda (s) + (cond ((string-equal s "/") "\\057") + ((string-equal s ":") "\\072") + (t s))) + hostname + t + t)) + +(defun piem-maildir-make-uniq-maildir-id () + (let* ((ftime (float-time)) + (microseconds (mod (* 1000000 ftime) 1000000)) + (hostname (piem-maildir-host-fixer (system-name)))) + (setq piem-maildir-count (+ piem-maildir-count 1)) + (format "%d.%d_%d_%d.%s" + ftime + (emacs-pid) + microseconds + piem-maildir-count + hostname))) + +(defun piem-maildir-dir-is-maildir-p (dir) + (and (file-exists-p (concat dir "/cur/")) + (file-exists-p (concat dir "/new/")) + (file-exists-p (concat dir "/tmp/")))) + +(defun piem-maildir-move-tmp-to-new (destdir msg-id) + (add-name-to-file + (concat destdir "/tmp/" msg-id) + (concat destdir "/new/" msg-id ":2,"))) + +(provide 'piem-maildir) +;;; piem-maildir.el ends here -- cgit v1.2.3