Although Gnus is my primary mail reader, there’s lots of things i like about Gmail (actually, Gmail is my primary inbox: Gnus reads mail from there). For instance, a little feature i love in Gmail is those markers that tell you whether you’re one of the direct recipients of a mail. When seeing a long list of mails in a mail list, i can quickly identify those with me explicitly in the To: or Cc: headers: chances are i’m slightly more interested in them.
In Gnus, one can customize the information shown in the message list by tweaking the variable gnus-summary-line-format
. If you press C-h v gnus-summary-line-format
to see all the formatting options, you’ll see there’s a lot of information to be shown, but not the one we want. But, as is always the case, we have a hook to extend the format to our hearts content: the %uX
directive, where X
is any letter you want. When Gnus sees that directive, it calls gnus-user-format-function-X
, a function you must write returning a string that gets inserted in the summary line. So here we go: first i define a string with a regexp of my email addresses:
(defvar *jao-mails* "jao@foo\\.org\\|jao@baz\\.com\\|jao@grogle\\.com")
and then i function which returns a “»” if i’m the only recipient of the message, or a “~” if i’m in the To:, Cc: or BCc: headers among others:
(defun gnus-user-format-function-j (headers) (let ((to (gnus-extra-header 'To headers))) (if (string-match *jao-mails* to) (if (string-match "," to) "~" "»") (if (or (string-match *jao-mails* (gnus-extra-header 'Cc headers)) (string-match *jao-mails* (gnus-extra-header 'BCc headers))) "~" " "))))
Then all that is left is using it in my gnus-summary-line-format
:
(setq gnus-summary-line-format "%U%R %~(pad-right 2)t%* %uj %B%~(max-right 20)~(pad-right 20)n %s\n")
Notice the %uj
doing the trick here. I’m sure you’ll come up with other uses to this extension mechanism, which, by the way, is also available for gnus-group-line-format
, the variable governing how lines in the *Group* buffer are displayed.
October 8, 2007 at 7:09 pm
Oh, that’s like my hack for showing priority based on recipients in Gnus. =)
October 8, 2007 at 7:10 pm
(Hmm, hyperlinks are non-obvious, so let’s link to that again: http://sachachua.com/notebook/wiki/2006.10.04.php#anchor-2)
April 21, 2008 at 8:19 pm
[…] I’ve copied my whole line format so that you can see, in addition, how i manage to keep things aligned in a frame around 180 columns wide. For details on the %uj directive, see this previous post. […]
February 15, 2009 at 3:12 pm
Love the trick you just posted, but one question how sure are you of Gnus actually getting all your mail. I mean I have faced this repeatedly with Gnus emails that I know are there just do not appear. It is the main reason I do not use Gnus as a primary reader and still use Gmail web-based tool
January 15, 2012 at 4:51 pm
Personally, I don’t trust Gnus to fetch all my email either. Use offlineimap + dovecot. Bonus: Gnus is now super-fast!
January 15, 2012 at 4:54 pm
Neat trick. Missing a tiny detail: the To, Cc and BCc fields need to be in the gnus-extra-headers and nnmail-extra-headers.
(setq gnus-extra-headers ‘(To Cc BCc)
nnmail-extra-headers gnus-extra-headers)