6194 comments
2357 subscribers
Follow me on Twitter (@sachac)
Subscribe! Feed reader E-mail

Emacs Gnus: Searching Mail

There are several ways to find messages in Emacs. From the summary
buffer, you can use / o (gnus-summary-insert-old-articles) to display
all or some old messages. You can then scan through the headers in the
summary buffer by using C-s (isearch-forward), or you can limit the
displayed messages with these commands:

Messages from a given author / a gnus-summary-limit-to-author
Messages whose subjects matching a given regular expression / / gnus-summary-limit-to-subject
Messages that match a given extra header / x gnus-summary-limit-to-extra-headers
Messages at least N days old / t gnus-summary-limit-to-age

Limits work on the messages that are currently displayed, so you can
apply multiple limits. If you make a mistake, use / w
(gnus-summary-pop-limit) to remove the previous limit. You can repeat
/ w (gnus-summary-pop-limit) until satisfied. To remove all the
limits, type C-u / w (gnus-summary-popl-limit).

If you specify a prefix, the limit’s meaning is reversed. For
example, C-u / a (gnus-summary-limit-to-author) will remove the
messages from the matching author or authors.

You can use Gnus to search the currently-displayed messages by using
M-s (gnus-summary-search-article-forward) and M-r
(gnus-summary-search-article-backward).

If you want to search a lot of mail, you’ll find NNIR handy. NNIR is a
front-end to mail search engines which can index your mail and return
search results quickly. If you want to use NNIR with a local or remote
IMAP server, you will need to use nnir.el and imap.el. If you download
your mail using fetchmail or connect to a POP3 server and use an nnml
backend, you can use NNIR with a search engine such as swish-e to
search your ~/Mail directory efficiently.

1.6.7.1 Setting up IMAP and NNIR

If you use IMAP, then your mail is stored on the mail server and
you’ll need to use the IMAP search interface to search through
it. Download nnir.el from
http://www.emacswiki.org/cgi-bin/wiki/download/nnir.el and save it to
your ~/elisp directory. You will also need an imap.el that is newer
than the one that comes with Emacs 22. Download imap.el from
http://www.emacswiki.org/cgi-bin/wiki/download/imap.el and save it to
your ~/elisp directory as well. Because Gnus comes with an older
version of imap.el, you will need to make sure that the new version of
imap.el is loaded. Add the following to your ~/.gnus:

(add-to-list 'load-path "~/elisp")
(load-file "~/elisp/imap.el")
(require 'nnir)

Restart your Emacs. You can check if the correct version of imap.el
has been loaded by typing M-x locate-library and specifying
imap.el. If Emacs reports “~/elisp/imap.el”, then Gnus is configured
to use the updated imap.el.

1.6.7.2 Setting up POP3 and NNIR

If you use the configuration for POP3 that is suggested in this
chapter, then your mail is stored in the nnml backend, which uses one
file per message. To search this using NNIR, to install nnir.el and an
external search mail engine. The Namazu search engine runs on Linux,
UNIX, and Microsoft Windows, so that’s what we’ll talk about here. To
find and configure other mail search engines supported by NNIR, check
out the comments in nnir.el.

First, you’ll need to download and install Namazu. If Namazu is
available as a package for your distribution, install it that way, as
it depends on a number of other programs. An installer for Microsoft
Windows can be found at http://www.namazu.org/windows/ . If you need
to build Namazu from source, you can get the source code and instructions
from http://www.namazu.org .

After you’ve installed Namazu, create a directory for Namazu’s index
files, such as ~/.namazu-mail. Then index your mail by typing this at
the command-line:

mknmz --mailnews -O ~/.namazu-mail ~/Mail

and add the following to your ~/.gnus:

(add-to-list 'load-path "~/elisp")
(require 'nnir)
(setq nnir-search-engine 'namazu)
(setq nnir-namazu-index-directory (expand-file-name "~/.namazu-mail"))
(setq nnir-namazu-remove-prefix (expand-file-name "~/Mail"))
(setq nnir-mail-backend gnus-select-method)
1.6.7.3 Searching your mail with NNIR

From the group buffer displayed by M-x gnus, you can type G G
(gnus-group-make-nnir-group) to search your mail for a keyword.

If you’re using the Namazu search engine, then you can use more
sophisticated search queries such as:

Linux Emacs messages that contain both “Linux” and “Emacs”
Linux or Emacs messages that contain either “Linux” or “Emacs”
Emacs not Linux messages that contain “Emacs” but not “Linux”
Emacs and (Linux or Windows) messages that contain “Emacs” and either “Linux” or “Windows”
“apple pie” messages that contain the phrase “apple pie”
{apple pie} messages that contain the phrase “apple pie”
+from:example@example.com messages with example@example.com in the From: header
+subject:”apple pie” messages with the phrase “apple pie” in the Subject: header
+subject:apple +subject:pie messages whose Subject: headers contain both “apple” and “pie”

If
matching messages are found, then you will see a temporary group with
the results. Although you can’t delete messages from this view,
reading and replying to these messages is the same as reading and
replying to regular messages.

To see a message in its original context, type G T
(gnus-summary-nnir-goto-thread) from the summary buffer. This opens
the message’s original group. If Gnus asks you how many articles to
load, press RET to accept the default of all the articles.


This is a draft for the Wicked Cool Emacs book I’m working on. =) Hope it helps!

Short URL: http://sachachua.com/blog/p/4902

On This Day...

  • 2013: On blogging and platforms, and experimenting with Google Hangout — I’ve been thinking about how I can take this blog to the next level. Blogging is a fantastic way for [...]
  • 2012: Thinking about the next mini-experiment — The consulting engagement I’m working on is great. It takes advantage of a hard-to-find combination of different skills and experiences, [...]
  • 2011: Learning from Mr. Collins: Practice, conversation, and what to do when someone says something mean — "You judge very properly," said Mr. Bennet, "and it is happy for you that you possess the talent of flattering [...]
  • 2010: Travel kaizen and the meaning of life — What do I want to do with my life? Is it worth the trade-offs? How can I make it more [...]
  • 2008: Emacs Gnus: Organize Your Mail — People handle large volumes of mail in different ways. Keeping everything in one mailbox can quickly become unmanageable because messages you need [...]
  • 2008: Too much time on her hands — “Where do you find the time to do that?” That’s what I often hear from people when I talk about [...]
  • 2007: Plodding away on my thesis — So I’m transcribing the interviews of the usability study. It’s nice hearing the good things again, but I’m seriously thinking that [...]
  • 2006: Another aspect of what I want to do — From netsquared comment: Although I’ve studied the material provided here, what I would really like is to be able to hire [...]
  • 2006: Social media for social change — This is one of the reasons I love technology. On Technorati: social, web2.0 Random Japanese sentence: ある日、彼女はペットの猫がほしいと私に知らせました。 One day, she told me that [...]
  • 2006: Yesterday was a hot chocolate day — The hot chocolate at Linux Caffe (Grace and Harbord Sts.) never fails to perk me up. Yesterday was no exception even though [...]
  • 2006: First baseball game — I watched my very first baseball game last night, thanks to Graduate House Council’s awesomely discounted $5 field-level seats (face price: $34.50, [...]
  • 2006: Congrats to Von Totanes! — Von Totanes has just received his Canadian visa, and will be starting his PhD in information studies Really Soon. Hooray [...]
  • 2006: Oatmeal hacking — One of the nice things about knowing geeks is that they often have another geek specialty. For example, Paul Lussier [...]
  • 2006: My mom reads my blog — My mom reads my blog, and that’s absolutely terrific. =) I love hearing her insights into the things I’m trying to [...]
  • 2006: Old friends and familiar strangers — I don’t know why so many people read about the cooking misadventures and existential crises of this 22-year-old girl, but I [...]
  • 2006: Downtime — As guilty as I feel about taking another day off, unavoidable personal circumstances have come up, and a little bit of [...]
  • 2006: I’m sorry! — I screwed up, and I feel terrible. I hate being virtual… Random Japanese sentence: 猫は夜行性の動物だ。 Cats are active at night.
  • 2006: Being a girl — Tara Hunt knows what it’s like to fade into the background if one has a partner in crime. I don’t really have [...]
  • 2006: Why blogging is cool — I hear this story again and again, in different words. This is one of the reasons why blogging is so [...]
  • 2006: Programming for kids — On the Kagay-anon Linux Users Group mailing list: we will just help kids learn the basics of programming, logic formulation, flowcharting and [...]
  • 2004: Double Room: prose poetry and short fiction — Double Room: prose poetry and short fiction — http://www.webdelsol.com/Double_Room/
  • 2004: Indexer for planner notes — Just realized that planner-search-notes with a match-all will do perfectly well. I don’t have to do this yet, then. =) WearableMemoryAugmentation
  • 2004: dabbrev-hover — dabbrev-hover http://gnufans.net/~deego Tooltip-show the next completion. Hmm, that’s nice. E-Mail from D. Goel
  • 2004: Musical letters — Musical letters — http://www.ma.utexas.edu/~jcorneli/a/elisp/musical-letters.el Joe Corneli’s written an interface to fluidsynth driven by Emacs typing. Sounds like the sort of multimedia stuff [...]
  • 2004: Japanese for nerds — Japanese for nerds — http://www.kuro5hin.org/story/2004/2/26/175722/727
  • 2004: BlueJ wiki — http://wiki.bluej.org E-Mail from Davin McCall
  • 2004: w000t! Got perfect on my general GRE! — Got 800 on both the verbal and quantitative sections of the general GRE test. Whee!
  • 2003: Xemacs text menus? — Does XEmacs even have text menu support? I’m looking for something like tmm.
  • 2003: message-sent-hook — Strange, the hook is locally set to (gnus-agent-possibly-do-gcc t), but message-to-planner gets called.
  • 2003: pda dev class — I need to look into dualbooting iPAQs so that Stanley and I can share the iPAQs. We’ll need high-capacity CompactFlash [...]
  • 2003: Message to planner — (defun message-to-planner () "Logs this message to the News and Mail section of today's planner file." (save-window-excursion [...]
  • 2003: Logging gnus messages — (defun message-to-diary () (make-diary-entry (concat (calendar-date-string (calendar-current-date) t) (if (message-fetch-field "newsgroups") [...]
  • 2003: Constructivism — - problem-based learning - case-based learning - goal-based scenarios CAI: Output should be a constructivist module
  • 2003: Stuff I need to take care of — - Mindstorms? Mostly Stanley - Alternative user interfaces: order my keyboards and HMDs, and think of good research projects Oooh! DoubleTalk speech [...]
  • 2003: Codestriker debs — Codestriker is a web-based collaborative code review tool. deb http://nthomas.free.fr/debian sid main deb-src http://nthomas.free.fr/debian sid main
  • 2003: Need to make a list of things I’d like — - Twiddler - other keyboards - head-mounted device
  • 2003: Debian-related HOWTOs — http://lyre.mit.edu/~powell/debian-howto/
  • 2003: List of UML products — http://www.objectsbydesign.com/tools/umltools_byPlatform.html
  • 2003: Pen tablet that can run Linux — Someone on PLUG said that the Fujitsu Stylistic 1000 is a “dirt-cheap” pen tablet that can run Linux, and that too [...]
  • 2003: CS161 William — CS161 CS becomes 162, which is a combination of CS161 and systems programming. Change of textbook back to Tanenbaum. Lab class. CS162a&b. [...]