« Coding Styles for Open Source Software Projects | Main | UML Tools »

Mew: An Excellent Mail/News Reader for Emacs

Mew (http://www.mew.org/) is a very powerful mail/news reader that runs on emacs developed by Kazu Yamamoto. It supports pop3/imap/smtp/nntp, and it can nicely work together with pgp/ssl/ssh, etc. Mew began as a variant of mh ten years ago, but now it has evolved into a completely independent, far more powerful and flexible program. I've been using it for about 8 years. Several things I like about Mew are:

  • It produces mails strictly conforming RFCs. It fully supports MIME.

  • It has very well-designed user interfaces for those who like emacs.

  • It is still actively being developed, and cutting-edge features are added day by day.

  • It is safe. I am using Mew on Linux, as well as Windows with Meadow (http://www.meadowy.org/meadow/), an emacs for Windows. I have to worry few less about viruses or other threats related to e-mails compared to other MUAs. (Of course it depends on how you use it, though:)

Here I explain how to setup and use Mew in the junkfood unix environment. Since Mew is not installed on the junkfood machines, you need to install it by yourself. The method should work on any other machines running common *nix OS.

Installation
First you need to download Mew from the link on the official site, http://www.mew.org/. The current stable release is 4.2, and I explain the installation process based on this version.

  1. Download the mew-4.2.tar.gz to your favorite directory (you can use a browser, of course,) and extract it.
    $ wget http://www.mew.org/Release/mew-4.2.tar.gz
    $ gzip -d < mew-4.2.tar.gz | tar xf -
    $ cd mew-4.2
    
  2. Beginning from version 4.2, Mew comes with a standard "configure" script. So those who have an experience of compiling other free software shouldn't have much problem. Since you probably don't have a root previlege, you need to add a --prefix option to configure. Here I assume you put everything under $HOME/local, i.e., the directory named "local" under your home directory. You can change it to whatever you like.
    $ ./configure --prefix=$HOME/local
    
  3. You may need to create some directories where you install Mew. (I'm not sure about this. I know this was necessary in order version without the configure script, but now those directory may be automatically created if they are missing.)
    $ mkdir $HOME/local
    $ mkdir $HOME/local/bin
    $ mkdir $HOME/local/info
    $ mkdir $HOME/local/lib
    $ mkdir $HOME/local/man
    $ mkdir $HOME/local/share
    
  4. Run make
    $ make
    $ make info
    $ make install
    
    
  5. If everything above is successful, you can delete the directory you used for compiling Mew.
  6. Add Mew to the path. If you are using bash, add the following to your .bashrc:
    export PATH=$PATH:$HOME/local/bin
    export MANPATH=$MANPATH:$HOME/local/man
    
    If you are using csh, add the following to your .cshrc:
    setenv PATH $PATH:$HOME/local/bin
    setenv MANPATH $MANPATH:$HOME/local/man
    
  7. Edit ~/.emacs (or ~/.emacs.el). Add the following:
    (setq load-path
          (append
           (list
           (expand-file-name "~/local/share/emacs/site-lisp/mew")
           )
           load-path))
    (require 'info)
    (setq Info-directory-list
          (cons (expand-file-name "~/local/info")
    	    Info-directory-list))
    (autoload 'mew "mew" nil t)
    (autoload 'mew-send "mew" nil t)
    (setq mew-icon-directory "~/local/lib/emacs/etc/Mew")
    ;; Optional setup (Read Mail menu for Emacs 21):
    (if (boundp 'read-mail-command)
        (setq read-mail-command 'mew))
    ;; Optional setup (e.g. C-xm for sending a message):
    (autoload 'mew-user-agent-compose "mew" nil t)
    (if (boundp 'mail-user-agent)
        (setq mail-user-agent 'mew-user-agent))
    (if (fboundp 'define-mail-user-agent)
        (define-mail-user-agent
          'mew-user-agent
          'mew-user-agent-compose
          'mew-draft-send-message
          'mew-draft-kill
          'mew-send-hook))
    
  8. Create a new file named ~/.mew.el. Write the following in this file. ("username" below should be your account name.)
    (setq mew-config-alist
          '(("default"
    	 ("name"             . "Your Name")
    	 ("mailbox-type"     . mbox)
    	 ("mbox-command"     . "incm")
    	 ("mbox-command-arg" . "-c -u -d /var/spool/mail/username")
    	 ("mail-domain"      . "cs.umd.edu"))))
    (setq mew-nntp-server "news.umd.edu")
    
    
  9. Now start emacs, and type M-x mew (Meta-x-mew, or Esc-x-mew). If everything went well, you'll see an opening message, then the "+inbox" buffer will appear. Congratulations! You have succeeded in installing Mew.

I think I need to make several notes here.


  • (Important) All mails you have received is stored in ~/Mail/inbox by default. Each mail is stored in a separate file, and by default, Mew deletes the retrieved mails from the spool, like any other traditional mail reader. Mew can be configured to leave mails in the spool by adding the "-b" option to "mbox-command-arg", but unfortunately it doesn't work as expected with the department mail server. (This is because the department mail system uses a traditional the mbox style as opposed to the maildir. With "-b" option for mbox, Mew just receives the same mails again and again.) Therefore, if you want to leave mails in the spool, I recommend you use IMAP settings instead. I'll explain how to setup Mew with IMAP setting here.
  • The file ~/.mew.el is the configuration file. The setting written above is the very minimum you'll need, and you can customize Mew by adding stuffs here.
  • mew-config-alist determines the basic behavior of Mew for receiving/sending mails; For example, if you want Mew to use IMAP or POP3, you must change the definition of this variable. You can even prepare several patterns and switch between them.
  • There are a lot of other options you'll find interesting once you start using it. For the full list, type 'M-x info' in emacs, find "* Mew", and push the space key on it. Here are some options I'm using. you can add them in ~/.mew.el if you like.

    (setq mew-use-header-veil nil) ;; do not truncate long header
    (setq mew-auto-get nil) ;; do not get mail when startup (offline mode)
    (setq mew-end-of-message-string nil) ;; do not show 'end-of-message' string
    (setq mew-end-of-part-string nil) ;; do not show 'end-of-part' string

  • incm is an external program of Mew, which retrieves mails from the local mail spool. It should have been installed in $(HOME)/local/bin if you have followed the example shown above. "-c" option is necessary for Solaris platform.

How to read/write a mail with Mew
Here I just list several commands you need to know to read and write a
mail. This is a very minimum list; If you look at the manual, you'll
see how various commands are designed and organized. You can also look
at the HTML version of manual here.

Basic commands
The following commands should be entered on the buffer where the list of mail is displayed. (It is called a summary mode.)


  • 'i': retrieve a mail from the spool:
  • space: display a mail. As you push space multiple times, you can proceed to the next mail.
  • '.': display a mail you want

  • 'w': write a new mail: enter in the summary buffer, and a draft buffer will appear.
  • 'a' or 'A': reply (answer). 'a' will open the draft without citation, while 'A' (shift+a) will open the draft with citation.
  • 'f': forward. Note that Mew creates the multi-part mail - the mail forward as an attachment. Although this behavior is strictly conforming to RFC 822, I often use 'A' (reply with citation) instead.
  • 'y': save an attachment, multi-part, or the whole mail.
  • 'tt': display threads. You can enter and leave the virtual mode by 'tt'. (Read the manual if you want what this precicely means.)

The following commands are used in the draft mode; i.e., in the buffer you are writing a mail.


  • 'C-c C-c': (ctrl+c twice) send the mail to the server.
  • 'C-c C-m': (ctrl+c ctrl+m) send the mail to the queue (~/Mail/queue directory). The mails in the queue will be automatically sent when you enter 'i' (retrieved the mail) next time. This is useful when you're using Mew in offline environment or you want to confirm the mail content later.
  • 'C-c C-q': (ctrl+c ctrl+q) discard the draft.
  • 'C-x C-s': Save the draft for later (this is actually not a Mew comman, but an ordinary emacs command to save a file.) The file will be stored in ~/Mail/draft directory.
  • 'C-c tab' (ctrl+c TAB): If you have the file ~/.signature, you can insert it by this command.
  • 'C-c C-a': Create a multipart (see below)

MIME (attachments)
To add/edit an attachment to a mail, you first need to enter 'C-c C-a' in the draft buffer. This will create a multi-part structure in your draft. Move to the second part (the line marked '2'), and press c, then choose the file to attach. Content type is automatically determined according to the file you are attaching. If you need to change the content type, enter 'T' (shift+t). To delete the attachment, enter 'D'.

Although this may seem complicated, it's actually a very flexible and powerful mechanism. This works as if you're building a tree sructure of MIME step by step. You can precicely control what will be sent in your mail.

Spam filtering
Mew 4 has a set of functions to cooperate with spam-filtering software such as spamassassin, bogofilter, etc. to handle spam mails. You can do several things; you can make them learn spam/ham on Mew, and you can have spam mails stored to a separate directory.

Here I describe how to use Mew with the department mailscanner system. Here I assume you're not using procmail, so spam-tagged mails are stored in your spool. If you're running procmail or your own local instance of spamassassin, you can add rules for a standard tag like "X-Spam-Status: yes". Write the following in .emacs


(setq mew-spam: "X-CSD-MailScanner-SpamCheck:")

and write the following in .mew.el
(defun mew-spam-assassin (val)
  (let ((case-fold-search t))
    (if (string-match "^spam" val) ?D)))
(setq mew-inbox-action-alist
      '(("X-CSD-MailScanner-SpamCheck:" mew-spam-assassin)
       ))
This will make spam-tagged mails marked 'D' (delete) in the +inbox. If you enter 'x', they are all sent to +trash. (You can modify the setting above to make spam-tagged mails stored to a special folder like +spam in the first place. I just prefer to get everything +inbox once.)

How to read/write news with Mew
First, you may want to retrieve the list of newsgroups on the server. You can do that by entering '2Z' (2, then Shift+z) in the summary buffer. You need to do this only once.

At the summary buffer, enter 'g', then enter '-' at the minibuffer. New "+" gets replaced with "-". Now you can enter the group name, or enter space to display the list of groups on the server. Then you'll get the articles on that group. The interface is as same as that for a mail, so you'll know how to use it easily. In case you want to know, the articles are stored under the ~/Mail/.nntp/ directory.