unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Sebastian Spaeth <Sebastian@SSpaeth.de>
To: Notmuch developer list <notmuch@notmuchmail.org>
Subject: [PATCH v3 1/4] Add elisp file for FCC to maildir solution
Date: Mon, 26 Apr 2010 10:23:15 +0200	[thread overview]
Message-ID: <1272270198-28357-1-git-send-email-Sebastian@SSpaeth.de> (raw)
In-Reply-To: <m3bpd8tpjk.fsf@x200.gr8dns.org>

From: Jesse Rosenthal <jrosenthal@jhu.edu>

File grabbed from http://jkr.acm.jhu.edu/jkr-maildir.el
but not integrated yet.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
---
 The patch series needed rebasing as it conflicts now with some of the
 notmuch-hello and notmuch-mua additions. Also, I integrated Dirk's proposal
 to use assoc-string which makes the address lookup case-insensitive.

 emacs/notmuch-maildir-fcc.el |  115 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 emacs/notmuch-maildir-fcc.el

diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
new file mode 100644
index 0000000..979428e
--- /dev/null
+++ b/emacs/notmuch-maildir-fcc.el
@@ -0,0 +1,115 @@
+;; 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 is the beginning of a solution for storing sent mail in a
+;; maildir in emacs message mode, presented because some people might
+;; find it useful. It is *not* fully tested, it *may* overwrite files,
+;; and any directories you point this at may no longer be there
+;; afterwards. Use at your own risk.
+;;
+;; To use this as the fcc handler for message-mode, put
+;; one of the following in your init file:
+;;
+;; if you want Fcc'd messages to be marked as read:
+;;
+;;     (setq message-fcc-handler-function
+;;          '(lambda (destdir)
+;;	     (jkr/maildir-write-buffer-to-maildir destdir t)))
+;;
+;; if you want Fcc'd messages to be marked as new:
+;;
+;;     (setq message-fcc-handler-function
+;;          '(lambda (destdir)
+;;	     (jkr/maildir-write-buffer-to-maildir destdir nil)))
+
+
+(defvar jkr/maildir-count 0)
+
+(defun jkr/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 jkr/maildir-make-uniq-maildir-id ()
+   (let* ((ct (current-time))
+	  (timeid (+ (* (car ct) 65536) (cadr ct)))
+	  (microseconds (caddr ct))
+	  (hostname (jkr/maildir-host-fixer system-name)))
+     (setq jkr/maildir-count (+ jkr/maildir-count 1))
+     (format "%d.%d_%d_%d.%s"
+	     timeid
+	     (emacs-pid)
+	     microseconds
+	     jkr/maildir-count
+	     hostname)))
+
+(defun jkr/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 jkr/maildir-save-buffer-to-tmp (destdir)
+  "Returns the msg id of the message written to the temp directory
+if successful, nil if not."
+  (let ((msg-id (jkr/maildir-make-uniq-maildir-id)))
+    (while (file-exists-p (concat destdir "/tmp/" msg-id))
+      (setq msg-id (jkr/maildir-make-uniq-maildir-id)))
+    (cond ((jkr/maildir-dir-is-maildir-p destdir)
+	   (write-file (concat destdir "/tmp/" msg-id))
+	   msg-id)
+	  (t
+	   (message (format "Can't write to %s. Not a maildir."
+		     destdir))
+	   nil))))
+
+(defun jkr/maildir-move-tmp-to-new (destdir msg-id)
+  (add-name-to-file
+   (concat destdir "/tmp/" msg-id)
+   (concat destdir "/new/" msg-id ":2,")))
+
+(defun jkr/maildir-move-tmp-to-cur (destdir msg-id &optional mark-seen)
+  (add-name-to-file
+   (concat destdir "/tmp/" msg-id)
+   (concat destdir "/cur/" msg-id ":2," (when mark-seen "S"))))
+
+(defun jkr/maildir-write-buffer-to-maildir (destdir &optional mark-seen)
+  "Writes the current buffer to maildir destdir. If mark-seen is
+non-nil, it will write it to cur/, and mark it as read. It should
+return t if successful, and nil otherwise."
+  (let ((orig-buffer (buffer-name)))
+    (with-temp-buffer
+      (insert-buffer orig-buffer)
+      (catch 'link-error
+	(let ((msg-id (jkr/maildir-save-buffer-to-tmp destdir)))
+	  (when msg-id
+	    (cond (mark-seen
+		   (condition-case err
+		       (jkr/maildir-move-tmp-to-cur destdir msg-id t)
+		     (file-already-exists
+		      (throw 'link-error nil))))
+		  (t
+		   (condition-case err
+		       (jkr/maildir-move-tmp-to-new destdir msg-id)
+		     (file-already-exists
+		      (throw 'link-error nil))))))
+	  (delete-file (concat destdir "/tmp/" msg-id))))
+      t)))
\ No newline at end of file
-- 
1.7.0.4

  reply	other threads:[~2010-04-26  8:23 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-21 18:36 Fcc, Maildir, and Emacs message-mode -- a bit of code Jesse Rosenthal
2010-01-27 14:44 ` Jameson Rollins
2010-01-29 13:21   ` Sebastian Spaeth
2010-01-29 14:46     ` Jameson Rollins
2010-01-29 14:54     ` Jesse Rosenthal
2010-04-07 20:04   ` Dirk Hohndel
2010-04-22  9:06 ` Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 1/6] Add elisp file for FCC to maildir solution Sebastian Spaeth
2010-04-22  9:07   ` [PATCH] notmuch.el: Make notmuch-show buffer name first subject, instead of thread-id (supersedes V1--3) Sebastian Spaeth
2010-04-22 13:34     ` Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 2/6] Integrate notmuch-maildir-fcc into notmuch Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 3/6] notmuch-maildir-fcc: rename all jkr/* functions to notmuch-maildir-fcc-* Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 4/6] add documentation example Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 5/6] notmuch-maildir-fcc: use insert-buffer-substring Sebastian Spaeth
2010-04-22  9:07   ` [PATCH 6/6] notmuch-maildir-fcc: replace caddr with (car (cdr (cdr))) Sebastian Spaeth
2010-04-22 23:17   ` Fcc, Maildir, and Emacs message-mode -- a bit of code Dirk Hohndel
2010-04-23  7:13     ` Sebastian Spaeth
2010-04-23 10:08       ` Updated elisp FCC patches (was: Fcc, Maildir, and Emacs message-mode) Sebastian Spaeth
2010-04-23 14:01         ` Dirk Hohndel
2010-04-23 19:01           ` [PATCH 1/4] Add elisp file for FCC to maildir solution Sebastian Spaeth
2010-04-23 19:01           ` [PATCH 2/4] Integrate notmuch-maildir-fcc into notmuch Sebastian Spaeth
2010-04-23 19:01           ` [PATCH 3/4] notmuch-maildir-fcc: elisp syntax fixes Sebastian Spaeth
2010-04-23 19:01           ` [PATCH 4/4] Integrate notmuch-fcc mechansim Sebastian Spaeth
2010-04-23  9:38   ` [PATCH 7/7] " Sebastian Spaeth
2010-04-24 23:10     ` Dirk Hohndel
2010-04-26  8:23       ` Sebastian Spaeth [this message]
2010-04-26 21:21         ` [PATCH v3 1/4] Add elisp file for FCC to maildir solution Carl Worth
2010-04-26  8:23       ` [PATCH v3 2/4] Integrate notmuch-maildir-fcc into notmuch Sebastian Spaeth
2010-04-26  8:23       ` [PATCH v3 3/4] notmuch-maildir-fcc: elisp syntax fixes Sebastian Spaeth
2010-04-26  8:23       ` [PATCH v3 4/4] Integrate notmuch-fcc mechansim Sebastian Spaeth
2010-04-27  0:29         ` [PATCH] emacs: fcc should fail at the right time if it doesn't point to a maildir Jesse Rosenthal
2010-04-27  1:33           ` [PATCH] emacs: add prompt to create maildir for fcc if it does not exist Jesse Rosenthal
2010-04-27  3:08             ` [PATCH] emacs: Ensure that message-directory for Fcc has a trailing slash Jesse Rosenthal
2010-04-27  2:51           ` [PATCH] emacs: fcc should fail at the right time if it doesn't point to a maildir Dirk Hohndel
2010-04-27  6:10           ` Carl Worth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1272270198-28357-1-git-send-email-Sebastian@SSpaeth.de \
    --to=sebastian@sspaeth.de \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).