[PATCH] emacs: Show cleaner addresses during message display.

2010-11-12 Thread David Edmondson
Simplify the display of addresses by setting
`notmuch-show-address-simplication' to:

- 'full: Only the name component of the address, if present, is
  shown,
- 'partial: Addresses are stripped of redundant information (the
  default),
- 'none: Addresses are shown as-is.

`mail-header-parse-address' fails for some addresses, in particular
"undisclosed-recipients:;". Accommodate this by returning the original
address if the parser fails.

Adjust the test results accordingly.
---

Default is now 'partial (most similar to the old behaviour). Allow for
un-parseable addresses. Don't add unnecessary quotes. Oh, and, fix the
test suite.

Carl: You can ignore the notmuch-lkml.el chunk, as you don't have that
yet.

 emacs/notmuch-lkml.el  |4 +-
 emacs/notmuch-show.el  |   65 +++-
 .../notmuch-show-thread-maildir-storage|6 +-
 3 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-lkml.el b/emacs/notmuch-lkml.el
index 750370b..fc04be6 100644
--- a/emacs/notmuch-lkml.el
+++ b/emacs/notmuch-lkml.el
@@ -29,7 +29,7 @@
 (declare-function notmuch-call-notmuch-process "notmuch" ( args))
 (declare-function notmuch-show "notmuch-show" ( args))
 (declare-function notmuch-show-strip-re "notmuch-show" (subject))
-(declare-function notmuch-show-clean-address "notmuch-show" (parsed-address))
+(declare-function notmuch-show-clean-address "notmuch-show" (address))
 (declare-function notmuch-show-spaces-n "notmuch-show" (n))

 (defcustom notmuch-lkml-author-width 30
@@ -71,7 +71,7 @@
 (notmuch-lkml-string-width 
  (concat (notmuch-show-spaces-n depth)
  (notmuch-show-clean-address
-  (mail-header-parse-address (plist-get headers :From
+  (plist-get headers :From)))
  notmuch-lkml-author-width)
 " "
 (if (string= notmuch-lkml-previous-subject
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index d8773e6..aa89cfd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)

 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -82,6 +83,21 @@ any given message."
 notmuch-wash-elide-blank-lines
 notmuch-wash-excerpt-citations))

+(defcustom notmuch-show-address-simplification 'partial
+  "How should addresses be displayed?
+
+Set `notmuch-show-address-simplication' to:
+
+- 'full: Only the name component of the address, if present, is
+  shown,
+- 'partial: Addresses are stripped of redundant information,
+- 'none: Addresses are shown as-is."
+  :group 'notmuch
+  :type '(choice
+ (const :tag "Full simplification" full)
+ (const :tag "Partial simplification" partial)
+ (const :tag "No simplification" none)))
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -198,12 +214,46 @@ any given message."
 'face 'notmuch-tag-face)
 ")"))

+(defun notmuch-show-clean-address (original-address)
+  "Prepare a single email address for display."
+  (let* ((parsed-address (mail-header-parse-address original-address))
+(address (car parsed-address))
+(name (cdr parsed-address))
+(displayed-name name))
+
+;; If the parser failed, use the original string.
+(if (not parsed-address)
+   original-address
+
+  ;; If the address is 'foo at bar.com ' then show just
+  ;; 'foo at bar.com'.
+  (when (string= displayed-name address)
+   (setq displayed-name nil))
+
+  (cond
+   ((eq notmuch-show-address-simplification 'full)
+   (if displayed-name
+   (propertize displayed-name 'help-echo address)
+ address))
+
+   ((eq notmuch-show-address-simplification 'partial)
+   (if displayed-name
+   ;; `mail-header-make-address' is enthusiastic about
+   ;; quoting the displayed name if it contains spaces (which
+   ;; is visually unappealing) so generate the displayed
+   ;; string directly here.
+   (concat displayed-name " <" address ">")
+ address))
+
+   (t ;; All other settings, but mostly 'none.
+   original-address)
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
 (insert (notmuch-show-spaces-n depth)
-   (plist-get headers :From)
+   (notmuch-show-clean-address (plist-get headers :From))
" ("
date
") ("
@@ -214,7 +264,18 @@ message at DEPTH in the current thread."

 (defun notmuch-show-insert-header (header header-value)
   "Insert a single 

[PATCH] emacs: Show cleaner addresses during message display.

2010-11-11 Thread Carl Worth
On Wed, 10 Nov 2010 09:23:07 +, David Edmondson  wrote:
> Simplify the display of addresses by setting
> `notmuch-show-address-simplication' to:
> 
> - 'full: Only the name component of the address, if present, is
>   shown (the default),
> - 'partial: Addresses are stripped of redundant information,
> - 'none: Addresses are shown as-is.

Now that we've got emacs-based testing, this change needs to update the
test suite as well.

Personally, I like to see email addresses, and I think that's a sane
default, so I'd actually prefer 'partial as the default setting here.

I tried changing that and hoped that that would let me not even update
the test suite. But then I found that comapred to the current state,
adding this patch actually adds unnecessary double-quotation marks
around user's names. That's annoying.

Can we get that cleaned up?

Meanwhile, I just pushed your three patches for cleaning up the display
of subjects[*]. So, thanks!

-Carl

[*] None of these needed test-suite changes, which actually just points
out holes in our test suite here.

-- 
carl.d.worth at intel.com
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



Re: [PATCH] emacs: Show cleaner addresses during message display.

2010-11-11 Thread Carl Worth
On Wed, 10 Nov 2010 09:23:07 +, David Edmondson d...@dme.org wrote:
 Simplify the display of addresses by setting
 `notmuch-show-address-simplication' to:
 
 - 'full: Only the name component of the address, if present, is
   shown (the default),
 - 'partial: Addresses are stripped of redundant information,
 - 'none: Addresses are shown as-is.

Now that we've got emacs-based testing, this change needs to update the
test suite as well.

Personally, I like to see email addresses, and I think that's a sane
default, so I'd actually prefer 'partial as the default setting here.

I tried changing that and hoped that that would let me not even update
the test suite. But then I found that comapred to the current state,
adding this patch actually adds unnecessary double-quotation marks
around user's names. That's annoying.

Can we get that cleaned up?

Meanwhile, I just pushed your three patches for cleaning up the display
of subjects[*]. So, thanks!

-Carl

[*] None of these needed test-suite changes, which actually just points
out holes in our test suite here.

-- 
carl.d.wo...@intel.com


pgpXhBh3BKtSZ.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Show cleaner addresses during message display.

2010-11-10 Thread Sebastian Spaeth
On Wed, 10 Nov 2010 08:27:08 +, David Edmondson  wrote:
> The latest change goes further - for an address such as:
>   Fred Blogs 
> it will display only "Fred Blogs". It's to this that Jameson is objecting.

Ohh, I see. Sorry then. I can see that someone wants to retain
that. 

Addressbooks are so 20th century anyway, I have notmuch-based
address lookup :).

Sebastian


[PATCH] emacs: Show cleaner addresses during message display.

2010-11-10 Thread David Edmondson
Simplify the display of addresses by setting
`notmuch-show-address-simplication' to:

- 'full: Only the name component of the address, if present, is
  shown (the default),
- 'partial: Addresses are stripped of redundant information,
- 'none: Addresses are shown as-is.
---
 emacs/notmuch-show.el |   55 +++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9e5d72d..054aba1 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)

 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -82,6 +83,21 @@ any given message."
 notmuch-wash-elide-blank-lines
 notmuch-wash-excerpt-citations))

+(defcustom notmuch-show-address-simplification 'full
+  "How should addresses be displayed?
+
+Set `notmuch-show-address-simplication' to:
+
+- 'full: Only the name component of the address, if present, is
+  shown,
+- 'partial: Addresses are stripped of redundant information,
+- 'none: Addresses are shown as-is."
+  :group 'notmuch
+  :type '(choice
+ (const :tag "Full simplification" full)
+ (const :tag "Partial simplification" partial)
+ (const :tag "No simplification" none)))
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -198,12 +214,36 @@ any given message."
 'face 'notmuch-tag-face)
 ")"))

+(defun notmuch-show-clean-address (parsed-address)
+  "Prepare a single email address for display."
+  (let* ((address (car parsed-address))
+(name (cdr parsed-address))
+(displayed-name name))
+
+;; If the address is 'foo at bar.com ' then show just
+;; 'foo at bar.com'.
+(when (string= displayed-name address)
+  (setq displayed-name nil))
+
+(cond
+ ((eq notmuch-show-address-simplification 'full)
+  (if displayed-name
+ (propertize displayed-name 'help-echo address)
+   address))
+
+ ((eq notmuch-show-address-simplification 'partial)
+  (mail-header-make-address displayed-name address))
+
+ (t ;; All other settings, but mostly 'none.
+  (mail-header-make-address name address)
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
 (insert (notmuch-show-spaces-n depth)
-   (plist-get headers :From)
+   (notmuch-show-clean-address
+(mail-header-parse-address (plist-get headers :From)))
" ("
date
") ("
@@ -214,7 +254,18 @@ message at DEPTH in the current thread."

 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
-  (insert header ": " header-value "\n"))
+  (insert header ": "
+ (cond
+  ((or (string= "To" header)
+   (string= "Cc" header)
+   (string= "Bcc" header)
+   (string= "From" header))
+   (mapconcat 'notmuch-show-clean-address
+  (mail-header-parse-addresses header-value)
+  ", "))
+  (t
+   header-value))
+ "\n"))

 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-- 
1.7.2.3



[PATCH] emacs: Show cleaner addresses during message display.

2010-11-10 Thread David Edmondson
On Wed, 10 Nov 2010 08:20:29 +0100, Sebastian Spaeth  
wrote:
> On Tue, 09 Nov 2010 15:53:49 -0500, Jameson Rollins wrote:
> > Hi, David.  I am personally not interested in this collapse for a couple
> > of reasons.  I really like seeing the full address that the mail comes
> > from.
> But what is the added benefit of 
> "me at foo.com" 
> over 
> me at foo.com
> ? This is essentially a nonsense name that can just as well be left
> out...
> 
> >  I also don't like tooltips since I don't like using the mouse.
> > Is it possible to make this particular feature an option?
> 
> If you don't use a mouse, how does the existence of tooltips annoy you?
>  
> > I actually frequently yank this whole line to ease filling my address
> > book.
> 
> But what is the point of having "me at foo.com"  in your
> address book, can't you just as well say "me at foo.com" without loosing
> information?

The latest change goes further - for an address such as:
Fred Blogs 
it will display only "Fred Blogs". It's to this that Jameson is objecting.

I'll update the patch such that you can choose, with the default being
the maximum simplification.

dme.
-- 
David Edmondson, http://dme.org


[PATCH] emacs: Show cleaner addresses during message display.

2010-11-10 Thread Sebastian Spaeth
On Tue, 09 Nov 2010 15:53:49 -0500, Jameson Rollins wrote:
> Hi, David.  I am personally not interested in this collapse for a couple
> of reasons.  I really like seeing the full address that the mail comes
> from.
But what is the added benefit of 
"me at foo.com" 
over 
me at foo.com
? This is essentially a nonsense name that can just as well be left
out...

>  I also don't like tooltips since I don't like using the mouse.
> Is it possible to make this particular feature an option?

If you don't use a mouse, how does the existence of tooltips annoy you?

> I actually frequently yank this whole line to ease filling my address
> book.

But what is the point of having "me at foo.com"  in your
address book, can't you just as well say "me at foo.com" without loosing
information?

Anyway, I don't care strongly either way. I have just gotten very
careful in adding new preferences rather than setting sensible defaults
:).

Sebastian
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



Re: [PATCH] emacs: Show cleaner addresses during message display.

2010-11-10 Thread David Edmondson
On Wed, 10 Nov 2010 08:20:29 +0100, Sebastian Spaeth sebast...@sspaeth.de 
wrote:
 On Tue, 09 Nov 2010 15:53:49 -0500, Jameson Rollins wrote:
  Hi, David.  I am personally not interested in this collapse for a couple
  of reasons.  I really like seeing the full address that the mail comes
  from.
 But what is the added benefit of 
 m...@foo.com m...@foo.com
 over 
 m...@foo.com
 ? This is essentially a nonsense name that can just as well be left
 out...
 
   I also don't like tooltips since I don't like using the mouse.
  Is it possible to make this particular feature an option?
 
 If you don't use a mouse, how does the existence of tooltips annoy you?
  
  I actually frequently yank this whole line to ease filling my address
  book.
 
 But what is the point of having m...@foo.com m...@foo.com in your
 address book, can't you just as well say m...@foo.com without loosing
 information?

The latest change goes further - for an address such as:
Fred Blogs f...@fredco.com
it will display only Fred Blogs. It's to this that Jameson is objecting.

I'll update the patch such that you can choose, with the default being
the maximum simplification.

dme.
-- 
David Edmondson, http://dme.org
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Show cleaner addresses during message display.

2010-11-09 Thread David Edmondson
Remove double quotes and flatten "foo at bar.com " to
"foo at bar.com". If the address is of the form "name ",
show only 'name' with a tooltip of the address.
---
More aggressive simplification and tooltips.

 emacs/notmuch-show.el |   29 +++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9e5d72d..098146b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)

 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -198,12 +199,25 @@ any given message."
 'face 'notmuch-tag-face)
 ")"))

+(defun notmuch-show-clean-address (parsed-address)
+  "Prepare a single email address for display."
+  (let ((address (car parsed-address))
+   (name (cdr parsed-address)))
+;; If the address is 'foo at bar.com ' then show just
+;; 'foo at bar.com'.
+(when (string= name address)
+  (setq name nil))
+(if name
+   (propertize name 'help-echo address)
+   address)))
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
 (insert (notmuch-show-spaces-n depth)
-   (plist-get headers :From)
+   (notmuch-show-clean-address
+(mail-header-parse-address (plist-get headers :From)))
" ("
date
") ("
@@ -214,7 +228,18 @@ message at DEPTH in the current thread."

 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
-  (insert header ": " header-value "\n"))
+  (insert header ": "
+ (cond
+  ((or (string= "To" header)
+   (string= "Cc" header)
+   (string= "Bcc" header)
+   (string= "From" header))
+   (mapconcat 'notmuch-show-clean-address
+  (mail-header-parse-addresses header-value)
+  ", "))
+  (t
+   header-value))
+ "\n"))

 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-- 
1.7.2.3



[PATCH] emacs: Show cleaner addresses during message display.

2010-11-09 Thread Jameson Rollins
On Tue,  9 Nov 2010 17:34:50 +, David Edmondson  wrote:
> Remove double quotes and flatten "foo at bar.com " to
> "foo at bar.com". If the address is of the form "name ",
> show only 'name' with a tooltip of the address.

Hi, David.  I am personally not interested in this collapse for a couple
of reasons.  I really like seeing the full address that the mail comes
from.  I also don't like tooltips since I don't like using the mouse.
Is it possible to make this particular feature an option?

I actually frequently yank this whole line to ease filling my address
book.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



[PATCH] emacs: Show cleaner addresses during message display.

2010-11-09 Thread David Edmondson
Remove double quotes and flatten f...@bar.com f...@bar.com to
f...@bar.com. If the address is of the form name f...@bar.com,
show only 'name' with a tooltip of the address.
---
More aggressive simplification and tooltips.

 emacs/notmuch-show.el |   29 +++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9e5d72d..098146b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)
 
 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -198,12 +199,25 @@ any given message.
 'face 'notmuch-tag-face)
 )))
 
+(defun notmuch-show-clean-address (parsed-address)
+  Prepare a single email address for display.
+  (let ((address (car parsed-address))
+   (name (cdr parsed-address)))
+;; If the address is 'f...@bar.com f...@bar.com' then show just
+;; 'f...@bar.com'.
+(when (string= name address)
+  (setq name nil))
+(if name
+   (propertize name 'help-echo address)
+   address)))
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread.
   (let ((start (point)))
 (insert (notmuch-show-spaces-n depth)
-   (plist-get headers :From)
+   (notmuch-show-clean-address
+(mail-header-parse-address (plist-get headers :From)))
 (
date
) (
@@ -214,7 +228,18 @@ message at DEPTH in the current thread.
 
 (defun notmuch-show-insert-header (header header-value)
   Insert a single header.
-  (insert header :  header-value \n))
+  (insert header : 
+ (cond
+  ((or (string= To header)
+   (string= Cc header)
+   (string= Bcc header)
+   (string= From header))
+   (mapconcat 'notmuch-show-clean-address
+  (mail-header-parse-addresses header-value)
+  , ))
+  (t
+   header-value))
+ \n))
 
 (defun notmuch-show-insert-headers (headers)
   Insert the headers of the current message.
-- 
1.7.2.3

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


Re: [PATCH] emacs: Show cleaner addresses during message display.

2010-11-09 Thread Jameson Rollins
On Tue,  9 Nov 2010 17:34:50 +, David Edmondson d...@dme.org wrote:
 Remove double quotes and flatten f...@bar.com f...@bar.com to
 f...@bar.com. If the address is of the form name f...@bar.com,
 show only 'name' with a tooltip of the address.

Hi, David.  I am personally not interested in this collapse for a couple
of reasons.  I really like seeing the full address that the mail comes
from.  I also don't like tooltips since I don't like using the mouse.
Is it possible to make this particular feature an option?

I actually frequently yank this whole line to ease filling my address
book.

jamie.


pgpZvJnNKVlKx.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: Show cleaner addresses during message display.

2010-11-09 Thread Sebastian Spaeth
On Tue, 09 Nov 2010 15:53:49 -0500, Jameson Rollins wrote:
 Hi, David.  I am personally not interested in this collapse for a couple
 of reasons.  I really like seeing the full address that the mail comes
 from.
But what is the added benefit of 
m...@foo.com m...@foo.com
over 
m...@foo.com
? This is essentially a nonsense name that can just as well be left
out...

  I also don't like tooltips since I don't like using the mouse.
 Is it possible to make this particular feature an option?

If you don't use a mouse, how does the existence of tooltips annoy you?
 
 I actually frequently yank this whole line to ease filling my address
 book.

But what is the point of having m...@foo.com m...@foo.com in your
address book, can't you just as well say m...@foo.com without loosing
information?

Anyway, I don't care strongly either way. I have just gotten very
careful in adding new preferences rather than setting sensible defaults
:).

Sebastian


pgpGW0NlSKqvZ.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Show cleaner addresses during message display.

2010-11-05 Thread David Edmondson
Remove double quotes and flatten "foo at bar.com " to
"foo at bar.com".
---
 emacs/notmuch-show.el |   30 --
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 07cf846..2838968 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)

 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -204,12 +205,26 @@ same as that of the previous message."
 'face 'notmuch-tag-face)
 ")"))

+(defun notmuch-show-clean-address (parsed-address)
+  "Clean a single email address for display."
+  (let ((address (car parsed-address))
+   (name (cdr parsed-address)))
+;; If the address is 'foo at bar.com ' then show just
+;; 'foo at bar.com'.
+(when (string= name address)
+  (setq name nil))
+
+(if (not name)
+   address
+  (concat name " <" address ">"
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
 (insert (notmuch-show-spaces-n depth)
-   (plist-get headers :From)
+   (notmuch-show-clean-address
+(mail-header-parse-address (plist-get headers :From)))
" ("
date
") ("
@@ -220,7 +235,18 @@ message at DEPTH in the current thread."

 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
-  (insert header ": " header-value "\n"))
+  (insert header ": "
+ (cond
+  ((or (string= "To" header)
+   (string= "Cc" header)
+   (string= "Bcc" header)
+   (string= "From" header))
+   (mapconcat 'notmuch-show-clean-address
+  (mail-header-parse-addresses header-value)
+  ", "))
+  (t
+   header-value))
+ "\n"))

 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-- 
1.7.2.3