Gmail envy

Gmail markers 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")

Picture 2.pngNotice 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.

About these ads
Posted in Gnus. 6 Comments »

6 Responses to “Gmail envy”

  1. Sacha Chua Says:

    Oh, that’s like my hack for showing priority based on recipients in Gnus. =)

  2. Sacha Chua Says:

    (Hmm, hyperlinks are non-obvious, so let’s link to that again: http://sachachua.com/notebook/wiki/2006.10.04.php#anchor-2)

  3. Two Gnus tricks « minor emacs wizardry Says:

    [...] 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. [...]

  4. Mackram G. Raydan Says:

    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

    • artagnon Says:

      Personally, I don’t trust Gnus to fetch all my email either. Use offlineimap + dovecot. Bonus: Gnus is now super-fast!

  5. artagnon Says:

    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)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: