Gnus for Mail and Newsgroups
E-mail has become an integral part of our lives. Many of us spend several hours reading it each day. Adding Netnews newsgroups to the mix only increases the burden. Many tools are available to help us manage and pre-sort e-mail and Netnews. One of the best is Gnus (pronounced guh-NEWS), which is included in the Emacs editor utility.
For some people (such as myself) receiving several hundred e-mail messages a day is not uncommon. Some are from friends and family; some relate to work. Dozens each day are from the several mailing lists I subscribe to, mostly technical one. And let's not forget the daily frying pan full of spam.
Separating the wheat from the chaff is time consuming. More importantly it is mistake prone. What if I miss an important message from an editor or, even worse, my mother?
The arrival of Netnews in the early eighties was one of the first really useful innovations in the virtual world. The Netnews system allowed thousands, and now millions of people, to form communities of common interest. Whether your interest is antiques, Fortran programming or bizarre sexual practices, you can find a newsgroup. Today, the Netnews system is bigger and more comprehensive than ever. In fact, my server lists over 37,000 different newsgroups.
E-mail and newsgroups can provide us with the most important commodity of our age: information. This quantity of information is too overwhelming to take on without some advanced tools.
The Gnus mail and news reader provides a single powerful interface to all of the information available out there. As a news reader it is similar to many others, showing the groups and the number of new messages in each. Selecting a group shows the subject lines of the postings. Replies to a posting are shown directly beneath that posting. This is called threading, because it makes it easier to follow the threads of conversation in the cacophony of a newsgroup.
It is as a mail reader that Gnus really shines. It allows you to set up any number of mail groups. Incoming mail messages are automatically categorized according to the rules you've established. From that point onwards, mail is treated like Netnews, and each mail category contains a threaded list of the messages.
So if I get 100 e-mails, I will still be able to spot my Mom's: hers end up in the Family group. Spam, on the other hand (if I manage to detect it) will end up in my Junk group. Mailing list traffic ends up in a Mail group. It's as if the mailing list were a newsgroup.
All these groups are tremendously useful when it comes time to search for some old e-mail message. For instance, finding old messages from friends is easy because their e-mail is all grouped together. I also can keep weeks of mailing list traffic on my computer, and it never gets in the way.
Emacs is a freely available text editor originally written by Richard Stallman, geek extraordinaire and founder of the Free Software Foundation. Emacs is one of Stallman's first and best contributions to free software. A programmers' editor, it is a superb tool for producing and working with source code in any computer language.
Many UNIX systems come with Emacs already installed. To check, type Emacs on the command line. If Emacs starts up, note the version, which should be on the start-up screen. (Or select Show Emacs Version from the Help menu). If it is not at least version 20.something, you may want to ask your system administrator to install the latest version. It can be found at www.gnu.org/directory/All_GNU_Packages/emacs.html.
Once you have Emacs running on your system, you can start to configure it to read mail and news. To learn more about using Emacs, consult the Emacs Tutorial in the Help menu.
Gnus can be configured for just about every possible situation. Below I will describe the configuration for one particular situation: connecting a home machine to an ISP.
Configuring Netnews is simple. Find out the name of your news server, and then insert the following code into the .gnus file (if it doesn't exist, then create it; it's an ASCII file in your home directory.)
; Tell Gnus about the news server. (setq gnus-select-method '(nntp "newsserver.your-isp.com"))
The .gnus file is interpreted by Emacs as Lisp, a programming language intimately associated with Emacs. The semi-colon is a comment delimiter, indicating that everything following it on the line is a comment.
Also while you are editing the .gnus file, add the following lines, substituting your name and e-mail address for mine.
(setq user-full-name "Ed") (setq user-mail-address "email@example.com")
Once you've added that information, fire up your dial-up connection. Select Read Net News from the Tools menu, and Gnus will start. It will connect to your server and download the list of all available newsgroups (this process can take a few minutes.) Then it will subscribe you to one or two by default and display them.
Select Listing -> List Active File from the Groups menu, which tells Gnus to download and display the entire list of groups available. Search for groups of interest by using Ctrl-S (Control+s) and then typing the string you are searching for. Use the return key to end the search. To subscribe to the groups you've selected, put the cursor on the line with the newsgroup and select Toggle subscription from the Group menu.
If you already know the name of the group you want to join, select Subscribe -> Subscribe to a group from the Groups menu. You will be prompted for the name of the group.
Once you've subscribed to a few groups, select Listing -> List unread subscribed groups from the Groups menu. You will see all the groups you subscribed to, with the number of unread message in each.
To read the message headers of a specific group, put the cursor on the group line and use Select from the Group menu. You'll see the name of the poster and the subject line for all the messages in the group. Move the cursor around the Subject buffer, and press the space bar to view an article if it looks interesting.
You can take a look at the Article menu to see the wide varieties of ways in which you can respond to a message. But don't try and send any mail yet--we still have some setup to do before we're ready for that.
To set up the Gnus mail feature, add the following lines to your .gnus file:
<pree> ;; Leave these two lines alone. (setq message-send-mail-function 'smtpmail-send-it) (setq send-mail-function 'smtpmail-send-it) ;; Customize the next three lines with your ISP information. (setq smtpmail-smtp-server "smtp.your-isp.com") (setq gnus-secondary-select-methods '((nnml "smtp.your-isp.com"))) (setq smtpmail-local-domain "your-isp.com")
You may have one e-mail address, or you may have several. If you have only one, include this line:
(setq mail-sources '((pop :server "your.pop3server2.com" :user "user" :password "password")))
If you have several, insert the following code to add a line for each e-mail address. They will be fetched in the order that you specify them here. Once fetched, all e-mail is treated more or less the same.
(setq mail-sources '( (pop :server "your.pop3server.com" :user "user" :password "password") (pop :server "your.pop3server2.com" :user "user2" :password "password2") ))
You don't have to include the password field. If you leave it off, though, you will be prompted to enter your password whenever you check for new mail.
Once all this configuration is done, try running Gnus, and it should fetch your mail. All mail will be dumped together into one pseudo-newsgroup. That's not the most helpful way for Gnus to act, but you need to give it more information in order for it to sort your mail intelligently.
Gnus treats your e-mail as one or more newsgroups, which is its power, because it will drop the mail into the groups you specify. Some groups will contain high priority mail; others will contain mailing lists that you only look at occasionally. You should establish a spam group and try and get Gnus to put all your spam there. Finally, there will be a catch-all group that collects the mail that doesn't fit anywhere else.
To create a mail group you have to specify its name and a regular expression. Mail that matches the regular expression will end up in that group.
The following simple example shows two groups, one for mail from firstname.lastname@example.org and another for all other mail.
(setq nnmail-split-methods '( ("mail.me" "^From:.*ed@telestoconsulting\\.com") ("mail.other" "")))
The first group, mail.me, will collect any message that has a line beginning with From: (the ^ indicates that this needs to be at the beginning of the line), and then contains any number of other characters, and then the string email@example.com. (Change this to your own e-mail address, of course).
Note the double slash (\\) in front of the dot between telestoconsulting and com. The double slash is necessary because the period character has a special meaning in Emacs regular expressions--it means zero or more of the following character. That's not what I want here, though; I want to match the string firstname.lastname@example.org exactly. To let Gnus know I want to match a literal period here, and not the special meaning of period in regular expressions, I need to insert the \\.
Regular expressions can become quite complex. To use a logical OR, parentheses and a vertical bar can be used. But these also need to be preceded by a double slash. For example, to have e-mail from both of my e-mail addresses dropped into the mail.me category, I can enter the following:
The regular expression now contains a sub-expression, which is delimited with parentheses \\(expression1\\|expression2\\). This line tells Gnus that when the From header is either expression1 or expression2, the mail should go in the me group. This gets a little confusing because expression1 and expression2 both need to contain \\ as they both contain a period. I still want those interpreted literally because it is part of the e-mail address.
The use of the parentheses and logical OR can be applied more than once in the regular expression. In the following example, I have a group called mail.ieee, which I want to use to collect all the incoming messages from IEEE. That includes any messages with IEEE in the address or subject line, as well as any mail from JWest, the local IEEE guy.
This regular expression looks for a line beginning with either To, CC, From, or Reply-To, followed by a colon, then followed by any number of any other characters (that's the .*), then either ieee or JWest@. (Sometimes JWest sends e-mail about IEEE from his work address, which doesn't have "ieee" in it.)
As you can see, regular expressions can get quite long. If they do, don't insert any line breaks;simply let the line wrap around in the editor. To make sure you can spot e-mail from friends, try this:
("mail.friends" "^From:.*\\(friend@myfriends\\.isp\\.com\\|friend2@myfriend2s \\.isp\\.com\\|friend3@myfriend3s\\.isp\\.com\\)")
The above regular expression will drop e-mail from three different e-mail addresses into mail.friends. The e-mail addresses are found in the parenthetically delimited list \\(e-mail1\\|e-mail2\\|e-mail3\\). It looks confusing, because once again I have to use a double slash before any period I want taken literally, and each e-mail address contains two such periods.
This is a great one if you get a lot of non-ASCII spam:
This regular expression tells Gnus to watch out for any e-mails with one or more non-ASCII characters in the subject line.
Gnus does not ever delete e-mail messages unless you instruct it to. To delete a message use Backend -> Delete from the Article menu.
This way of individually deleting messages, however, can get cumbersome. So this is a good time to learn about marks. Marks allow multiple selection. In the Summary buffer you can mark a message using the # key. A # appears to the left of the message header to indicate that this message has been marked.
Once you have marked a bunch of messages, any command you try will apply to all of them. For example, mark some messages with the # in the article buffer, and then select Backend -> Delete article. You will be asked to confirm that you want all of these e-mails deleted forever.
Some groups should be deleted automatically. Your spam group is a good candidate. You want to keep messages in there for a little while (so that you can make sure occasionally that nothing important ended up there), but you don't want hundreds of messages about Viagra and pyramid schemes to be cluttering up your hard drive. Gnus allows you to specify that some groups should be automatically deleted. Insert the following into your .gnus file:
(setq gnus-auto-expirable-newsgroups "mail.spam\\|mail.cygwin")
This will cause articles to be expired in the spam group and the Cygwin mailing list group. Expired means that about a week after you get them, they'll be deleted. Put as many mail groups as you like in this line, separating them with \\|.
Gnus also can help you decide which messages to read first. For example, if one author's news postings are always worth reading, you can ask Gnus to rate those articles higher than others so they are brought to your attention. This process is known as scoring. If you want to see more of something, increase its score. If you want to see less of it, lower the score.
It's helpful to score your own posts highly; that way you can easily find them. First select Post an article from the Post menu. If you do this while reading a group, you automatically will be posting to that group. If you are not reading a group, you must enter the name of a group at the top of your post.
When you've finished typing a message, select Send message from the Message menu. Give it a few minutes, then refresh Gnus by selecting Check for new news from the Misc menu. To set up scoring, find your posting. While reading it, select Increase score from the Score menu, which present you with a number of choices. Use the ? to see your choices. Then press the A key, which tells Gnus you are adjusting the score for the author. You are then offered another set of choices, select S. For your final choice, select P; your name and e-mail should appear. Now press the return key. You have just increased your score, and your posts will appear in bold face type.
So many groups, so little space on the screen! There is a way to create groups of groups, which can help organize your mail and news even further. These groups of groups are called topics. Select Toggle topics from the Misc menu. Put the cursor at the top of the screen and select Topics -> Create from the Topics menu. Enter the name of a topic, and a new (empty) topic will be created. To move a group into that topic, put the cursor on the group name, and select Groups -> Move from the Topic menu.
Play with these groups and groups of groups for a while; you'll find them a helpful way to further organize your mail and news.
Gnus has so many options and features that it can seem quite intimidating. The reason to use Gnus is it is a news and mail client you will never outgrow. Using group selection methods, you have apply sophisticated sorting to incoming e-mail. With scoring, Gnus can become an intelligent partner in your on-line existence.
A wealth of information about Gnus and Emacs is available for free on the Web.
Windows users should also look at the GNU Emacs FAQ for Windows 95/98/ME/NT/XP and 2000.
The Emacs manual is included in the Emacs distribution and can be found in Emacs by typing M-x info. If you want it in HTML, ASCII or some other formats, look here.
Once you get Gnus up and running, you can post questions to the gnu.emacs.gnus newsgroup.