unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jameson Rollins <jrollins@finestructure.net>
To: notmuch@notmuchmail.org
Subject: Re: Fcc, Maildir, and Emacs message-mode -- a bit of code
Date: Wed, 27 Jan 2010 09:44:41 -0500	[thread overview]
Message-ID: <878wbj4nfq.fsf@servo.finestructure.net> (raw)
In-Reply-To: <873a1zs3t5.fsf@jhu.edu>


[-- Attachment #1.1: Type: text/plain, Size: 929 bytes --]

Hey, folks.  Following up on this thread about better fcc handling,
Jesse passed on a simple python script he wrote that uses the python
"mailbox" module to deliver a message on stdin to a specified maildir
directory.  It's very a simple, elegant and general purpose script
(attached).

I then put the following in my notmuch .emacs to use the new script in
message-mode to fcc sent mail to my ~/.mail/sent directory:

;; fcc handler
(defun maildir-deliver-region(destdir)
  (shell-command-on-region
   (point-min) (point-max)
   (concat "maildir-deliver.py -c -s -d " destdir)))
(setq message-fcc-handler-function 'maildir-deliver-region)
(defun my-message-header-setup ()
  (message-add-header "Fcc: ~/.mail/sent"))
(add-hook 'message-send-hook 'my-message-header-setup)

Works like a charm.  Thanks Jesse!

I think we should look at packaging this in a set of notmuch helper
scripts, hopefully including notmuchsync.

jamie.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 835 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python maildir delivery script --]
[-- Type: text/x-python, Size: 1090 bytes --]

#!/usr/bin/env python

import mailbox
import sys
import optparse

def maildir_deliver(msg, maildir, mark_read=False, mark_cur=False):
    if mark_read:
        msg.set_flags("S")
    if mark_cur:
        msg.set_subdir('cur')
    md = mailbox.Maildir(maildir)
    key = md.add(msg)
    md.close

if __name__ == '__main__':
    parser = optparse.OptionParser()
    parser.add_option("-d", "--destdir",
                      dest="maildir", 
                      help="destination maildir")
    parser.add_option("-s", "--seen",
                      action="store_true", 
                      dest="mark_read",
                      default=False,
                      help="mark message as read")
    parser.add_option("-c", "--cur",
                      action="store_true", 
                      dest="mark_cur",
                      default=False,
                      help="deliver message to cur instead of new")
    (options, args) = parser.parse_args()
    msg = mailbox.MaildirMessage(sys.stdin)
    maildir_deliver(msg, options.maildir, options.mark_read, options.mark_cur)

  reply	other threads:[~2010-01-27 14:44 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 [this message]
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       ` [PATCH v3 1/4] Add elisp file for FCC to maildir solution Sebastian Spaeth
2010-04-26 21:21         ` 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=878wbj4nfq.fsf@servo.finestructure.net \
    --to=jrollins@finestructure.net \
    --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).