gnus-alias integration bug

2014-04-08 Thread Michael Hudson-Doyle
Ian Kelling  writes:

> gnus-alias allows you to set your identity based on the headers in the
> message you are replying. This is an essential feature in a mail client
> for me, I want to automatically reply as the person an email was sent to
> for certain addresses. This does not work in notmuch.

Which version of notmuch are you using?  gnus-alias is working fine for
me with notmuch 0.17 and emacs-version "GNU Emacs 24.4.50.2
(x86_64-pc-linux-gnu, GTK+ Version 3.8.6) of 2014-04-04 on wani04"

Cheers,
mwh


gnus-alias integration bug

2014-04-08 Thread David Mazieres
Ian Kelling  writes:

> gnus-alias allows you to set your identity based on the headers in the
> message you are replying. This is an essential feature in a mail client
> for me, I want to automatically reply as the person an email was sent to
> for certain addresses. This does not work in notmuch.

I need this feature, too.  There is some support for the same
functionality built into notmuch.  The big problem for me is that
.notmuch-config does not support wildcards (e.g., *@mydomain.com or
user-*@mydomain.com).  Compounding this issue is that, other than
notmuch reply's internals, notmuch pretty much suppresses the
Delivered-To header, which is crucial for knowing in a non-heuristic way
where an email was actually delivered to.  I want to compute my From:
header based on the Delivered-To, so I created a
mail-delivered-to-reply-from alist that maps one to the other.

It's pretty horrifying what I had to do to get this to work, but it
looks something like the following.  (Apologies for any mistakes, I had
to strip out additional complexity I have for other things in there, so
it's not verbatim the code that I'm using, but it's pretty close.)

If someone knows a better way of doing this with stock notmuch, please
let me know.  I know it's simpler to fix notmuch-reply, but I really
don't want to start depending on a custom-forked version on the notmuch
binary, as I read my mail from multiple operating systems and I'm sure
I'd forget to update one of them.

David


;;; Regular expression matching all of my own email addresses.  Note
;;; this is also used by mail-dont-reply-to (which ships with emacs).
(setq mail-dont-reply-to-names
  (concat "REXEXP MATCHING ALL YOUR EMAIL ALIASES"))

;;; Alist mapping Delivered-To addresses to the address that should be
;;; in the From header of replies.
(setq mail-delivered-to-reply-from
  '(("delivered-to-\\(.*\\)@address.com"
 . "Name ")
;; ...
))

(defun compute-from (email)
  (let ((case-fold-search t)
(subst (assoc-default email mail-delivered-to-reply-from
  #'string-match)))
(and subst
 (concat (notmuch-user-name) " <"
 (replace-match subst t nil email) ">"

(defun get-delivered-to-from-path (path)
  (with-temp-buffer
; It's weird to use sed, but there's also no reason to read a huge
; file into a buffer right here when we reply to messags with
; attachments.  (notmuch show doesn't support --body=false in
; --format=raw mode, and the other modes all get rid of Delivered-To.)
(call-process "sed" nil t t "-ne"
  "/^Delivered-To: */{s///p;q;}; /^$/q" path)
(goto-char (point-max))
(or (bobp) (delete-char -1))
(and (not (bobp)) (buffer-string

(defun get-msg-pathnames (query)
  (notmuch-call-notmuch-sexp
   "search" "--format=sexp" "--format-version=1"
   "--output=files" "--" query))

(defun compute-reply-from (pl)
  (let* ((orig (plist-get pl :original))
 (path (plist-get orig :filename))
 (orig-from (plist-get (plist-get orig :headers) :From))
 (addr
  (cond
   ((get-delivered-to-from-path path))
   ;; in case of maildir.synchronize_flags=true, the pathname
   ;; might already be incorrect, so try getting it again
   ((and (setq path (car (get-msg-pathnames query-string)))
 (get-delivered-to-from-path path)))
   ((string-match mail-dont-reply-to-names
  (setq orig-from (car (rfc822-addresses orig-from
orig-from)
   )))
(and addr (compute-from addr

;;; Somehow no plist-del function in emacs
(defun my-plist-del (plist0 prop)
  (if (eq prop (car plist0))
  (cddr plist0)
(let ((p (cdr plist0)))
  (while (and p (not (eq prop (cadr p
(setq p (cddr p)))
  (if p (setcdr p (cdddr p)))
  plist0)))

(defun fix-reply-sexp (pl)
  (let* ((rh (plist-get pl :reply-headers))
 (from (compute-reply-from pl))
 h)
(if from (setq rh (plist-put rh :From from)))
(and (setq h (plist-get rh :To))
 (setq h (mail-dont-reply-to h))
 (not (equal h ""))
 (setq rh (plist-put rh :To h)))
(and (setq h (plist-get rh :Cc))
 (setq h (mail-dont-reply-to h))
 (if (equal h "")
 (setq rh (my-plist-del rh :Cc))
   (setq rh (plist-put rh :Cc h
(plist-put pl :reply-headers rh)))
(defadvice notmuch-call-notmuch-sexp (after fix-reply activate)
  "Fix From/To/CC headers in reply"
  (if (equal (ad-get-arg 0) "reply")
  (setq ad-return-value (fix-reply-sexp ad-return-value


Re: gnus-alias integration bug

2014-04-08 Thread David Mazieres
Ian Kelling  writes:

> gnus-alias allows you to set your identity based on the headers in the
> message you are replying. This is an essential feature in a mail client
> for me, I want to automatically reply as the person an email was sent to
> for certain addresses. This does not work in notmuch.

I need this feature, too.  There is some support for the same
functionality built into notmuch.  The big problem for me is that
.notmuch-config does not support wildcards (e.g., *@mydomain.com or
user-*@mydomain.com).  Compounding this issue is that, other than
notmuch reply's internals, notmuch pretty much suppresses the
Delivered-To header, which is crucial for knowing in a non-heuristic way
where an email was actually delivered to.  I want to compute my From:
header based on the Delivered-To, so I created a
mail-delivered-to-reply-from alist that maps one to the other.

It's pretty horrifying what I had to do to get this to work, but it
looks something like the following.  (Apologies for any mistakes, I had
to strip out additional complexity I have for other things in there, so
it's not verbatim the code that I'm using, but it's pretty close.)

If someone knows a better way of doing this with stock notmuch, please
let me know.  I know it's simpler to fix notmuch-reply, but I really
don't want to start depending on a custom-forked version on the notmuch
binary, as I read my mail from multiple operating systems and I'm sure
I'd forget to update one of them.

David


;;; Regular expression matching all of my own email addresses.  Note
;;; this is also used by mail-dont-reply-to (which ships with emacs).
(setq mail-dont-reply-to-names
  (concat "REXEXP MATCHING ALL YOUR EMAIL ALIASES"))

;;; Alist mapping Delivered-To addresses to the address that should be
;;; in the From header of replies.
(setq mail-delivered-to-reply-from
  '(("delivered-to-\\(.*\\)@address.com"
 . "Name ")
;; ...
))

(defun compute-from (email)
  (let ((case-fold-search t)
(subst (assoc-default email mail-delivered-to-reply-from
  #'string-match)))
(and subst
 (concat (notmuch-user-name) " <"
 (replace-match subst t nil email) ">"

(defun get-delivered-to-from-path (path)
  (with-temp-buffer
; It's weird to use sed, but there's also no reason to read a huge
; file into a buffer right here when we reply to messags with
; attachments.  (notmuch show doesn't support --body=false in
; --format=raw mode, and the other modes all get rid of Delivered-To.)
(call-process "sed" nil t t "-ne"
  "/^Delivered-To: */{s///p;q;}; /^$/q" path)
(goto-char (point-max))
(or (bobp) (delete-char -1))
(and (not (bobp)) (buffer-string

(defun get-msg-pathnames (query)
  (notmuch-call-notmuch-sexp
   "search" "--format=sexp" "--format-version=1"
   "--output=files" "--" query))

(defun compute-reply-from (pl)
  (let* ((orig (plist-get pl :original))
 (path (plist-get orig :filename))
 (orig-from (plist-get (plist-get orig :headers) :From))
 (addr
  (cond
   ((get-delivered-to-from-path path))
   ;; in case of maildir.synchronize_flags=true, the pathname
   ;; might already be incorrect, so try getting it again
   ((and (setq path (car (get-msg-pathnames query-string)))
 (get-delivered-to-from-path path)))
   ((string-match mail-dont-reply-to-names
  (setq orig-from (car (rfc822-addresses orig-from
orig-from)
   )))
(and addr (compute-from addr

;;; Somehow no plist-del function in emacs
(defun my-plist-del (plist0 prop)
  (if (eq prop (car plist0))
  (cddr plist0)
(let ((p (cdr plist0)))
  (while (and p (not (eq prop (cadr p
(setq p (cddr p)))
  (if p (setcdr p (cdddr p)))
  plist0)))

(defun fix-reply-sexp (pl)
  (let* ((rh (plist-get pl :reply-headers))
 (from (compute-reply-from pl))
 h)
(if from (setq rh (plist-put rh :From from)))
(and (setq h (plist-get rh :To))
 (setq h (mail-dont-reply-to h))
 (not (equal h ""))
 (setq rh (plist-put rh :To h)))
(and (setq h (plist-get rh :Cc))
 (setq h (mail-dont-reply-to h))
 (if (equal h "")
 (setq rh (my-plist-del rh :Cc))
   (setq rh (plist-put rh :Cc h
(plist-put pl :reply-headers rh)))
(defadvice notmuch-call-notmuch-sexp (after fix-reply activate)
  "Fix From/To/CC headers in reply"
  (if (equal (ad-get-arg 0) "reply")
  (setq ad-return-value (fix-reply-sexp ad-return-value
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: gnus-alias integration bug

2014-04-07 Thread Ian Kelling
Michael Hudson-Doyle  writes:
> Which version of notmuch are you using? 

notmuch git version from 4/6/2014 bc10f63f9c2390dddfc3d6397889dab375107aa5

GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.4.2) of 2014-04-07

How is it that I compiled my emacs from today's sources and you have a
higher version number than me? lol

gnu aliases works, but not that part.


- Ian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


gnus-alias integration bug

2014-04-07 Thread Ian Kelling
Michael Hudson-Doyle  writes:
> Which version of notmuch are you using? 

notmuch git version from 4/6/2014 bc10f63f9c2390dddfc3d6397889dab375107aa5

GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.4.2) of 2014-04-07

How is it that I compiled my emacs from today's sources and you have a
higher version number than me? lol

gnu aliases works, but not that part.


- Ian


Re: gnus-alias integration bug

2014-04-07 Thread Michael Hudson-Doyle
Ian Kelling  writes:

> gnus-alias allows you to set your identity based on the headers in the
> message you are replying. This is an essential feature in a mail client
> for me, I want to automatically reply as the person an email was sent to
> for certain addresses. This does not work in notmuch.

Which version of notmuch are you using?  gnus-alias is working fine for
me with notmuch 0.17 and emacs-version "GNU Emacs 24.4.50.2
(x86_64-pc-linux-gnu, GTK+ Version 3.8.6) of 2014-04-04 on wani04"

Cheers,
mwh
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


gnus-alias integration bug

2014-04-07 Thread Ian Kelling
gnus-alias allows you to set your identity based on the headers in the
message you are replying. This is an essential feature in a mail client
for me, I want to automatically reply as the person an email was sent to
for certain addresses. This does not work in notmuch. gnus sets the
variable message-reply-buffer when it sets up a message, which
gnus-alias uses to go grab headers. It creates a buffer named
*gnus article copy* which contains all the headers and the message body. It 
seems notmuch does not set this
variable when it sets up a reply.

Here is an example of a rule needed to do this.

(setq gnus-alias-identity-rules
(quote
 (("work"
   ("to" "w...@example.com" previous)
   "workidentity"


___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


gnus-alias integration bug

2014-04-07 Thread Ian Kelling
gnus-alias allows you to set your identity based on the headers in the
message you are replying. This is an essential feature in a mail client
for me, I want to automatically reply as the person an email was sent to
for certain addresses. This does not work in notmuch. gnus sets the
variable message-reply-buffer when it sets up a message, which
gnus-alias uses to go grab headers. It creates a buffer named
*gnus article copy* which contains all the headers and the message body. It 
seems notmuch does not set this
variable when it sets up a reply.

Here is an example of a rule needed to do this.

(setq gnus-alias-identity-rules
(quote
 (("work"
   ("to" "work at example.com" previous)
   "workidentity"