MH-E

Introduction to MH and MH-E

This is the standard Emacs frontend to Rand Mail Handler, aka MH. MH is a mail user agent (MUA) for unix shell environment. Instead of being one monolithic program, all functionality is provided by a collection of small tools. Thus one uses one’s shell itself to drive it, and because of the way the messages are each in their own file, and folders are implemented as file-system directories, any general command can be used too in the most natural, UnixWay?. The modern MH implementation is called “nmh”. It lives at Savannah, and has a homepage at http://www.nongnu.org/nmh.

Other, non-Emacs frontends to MH are the various shell commands (see the manpages for nmh(1) or mh-chart(1) for a list of the available commands), the basic X11 xmh(1x) and exmh, written in Tcl/Tk. Exmh homepage is at http://exmh.sourceforge.net/. Another Emacs interface called tmh was written by ThienThiNguyen, but since it hasn’t been updated since late 1994, it ought to be considered of historical interest only. It has been archived at the author’s webpage at http://www.gnuvola.org/software/tmh/.

We all know this is not the place to get into a MuaWar (though reasonable ComparisonOfMuas? would be fine) but let’s face it, MH-E r0xx0rz and h@Rd! It also has been blessed by inclusion with both flavours of Emacsen, and thus is Good.

About the documentation

The MH-E homepage is on SourceForge?, at http://mh-e.sourceforge.net. MH-E has it’s own InfoMode documentation which comes with Emacs. The most recent version is 8.0 which is now being kept in sync with the released version of the software. [1]

In many MH-E submodes `?’ (‘mh-help’) provides a quick list of some the most common keybindings.

Then there is the book O’Reilly book by Jerry Peek entitled “MH & nmh: Email for Users & Programmers” which is freely available at http://rand-mh.sourceforge.net/book/ (massive props to Jerry). It used to have a chapter on MH-E, but the official documentation included with Emacs has supplanted it due to Bill Wohler’s hard work.

Forums

Several mailinglists exist on SourceForge?, namely “mh-e-announce”, “mh-e-devel” and “mh-e-users”. All of these are bidirectionally gatewayed via the marvellous Gmane, which lives at http://www.gmane.org. Through this service one can access the lists not only with HTTP (SourceForge? provides this too), but with NNTP. Fancy that! Contact the NNTP server news.gmane.org or see webpage http://dir.gmane.org/index.php?prefix=gmane.mail.mh-e for a directory of all related groups. The archives make a good read.

Though it seems most of the people on the IRC EmacsChannel are using Gnus instead, if you wish to discuss MH-E, you’re of course most welcome.

Making MH-E dance to your tune

When configuring, it is often a GoodIdea to tweak the natural files of mh itself, the .mh_profile for example. This is the general way to configure things, and all the changes will inherit to any frontends. If you shun such a blasphemous suggestion, remember that this is only a suggestion of an UnixZealot? who wishes to a) also use mh via shell, and b) digs generality. So go ahead, just fiddle with the mh-* variables if you feel like it. Of course there are many options which make no sense to mh itself, and these frontend-specific things are to be set within the frontend itself. Like any large and decent EmacsLisp package, MH-E has it’s own group for the common user-friendly CustomizingAndSaving interface Customize to be accessed with the ‘customize-group’.

If you’d like to configure MH-E to be your preferred mail-composing system, set the MailclientConfiguration? variable ‘mail-user-agent’ to “mh-e-user-agent”. If you’re using the GnuEmacs, you can also prefer MH-E for reading your mail, by setting ‘read-mail-command’ to “mh-rmail”.

It’s hard to tell if MH-E is the most widely used MUA for Emacs, or in general, but tekonivel digs it, being such a UnixZealot?.

Some other folks around here are pretty fond of it as well! —JerameyCrawford

Basic MH-E setup with nmh, fetchmail and msmtp

msmtp is useful when you have more than one mail addresses. It reads “From:” field and uses corresponding account. Should be built with GNU TLS support to be used with gmail (make WITH_GNUTLS=YES).

Assuming you have already installed nmh, fetchmail and msmtp.

.emacs:

     (setq mh-send-uses-spost-flag t)
     (setq mail-user-agent 'mh-e-user-agent)

mts.conf (mine is here: /usr/local/etc/nmh/mts.conf):

     sendmail: /home/username/.msmtp-envelope-from.sh
     mts: sendmail
     masquerade: draft_from

.msmtp-envelope-from.sh:

     #!/bin/sh
     # can't just write "sendmail: /usr/local/bin/msmtp --read-envelope-from" in mts.conf
     # so it's a little workaround
     # makes msmtp to read "From:" field and to use corresponding account
     /usr/local/bin/msmtp --read-envelope-from $*

.mh_profile:

     Path: Mail
     postproc: /usr/local/libexec/nmh/spost

.fetchmailrc:

     poll pop.yandex.ru with proto POP3
       user 'username' password 'userpass'
    
     poll pop.gmail.com with proto POP3
       user 'username' password 'userpass' options ssl
       sslcertck sslcertpath /home/banan/.certs/

.msmtp:

     # username@yandex.ru
     account yandex
     host smtp.yandex.ru
     from username@yandex.ru
     auth login
     user username
     password userpass
 
     # username@gmail.com
     account gmail
     host smtp.gmail.com
     port 587
     from username@gmail.com
     auth on
     user username@gmail.com
     password userpass
     tls on
     tls_trust_file /home/banan/.certs/ThawtePremiumServerCA.crt

Also place “From: Your Name <username@gmail.com>” before “To:” in these files in ~/Mail: components, replcomps, forwcomps. After that you can send your mail using any of your accounts by editing “From:” field in your mail composing buffer.

How to get gmail certificates for fetchmail: http://www.axllent.org/docs/networking/gmail_pop3_with_fetchmail

ThawtePremiumServerCA.crt for gmail support in msmtp you can get here (I renamed ThawtePremiumServerCA_b64.txt) : https://www.verisign.com/support/thawte-roots.zip

When certificates are in ~/.certs/, do “$ c_rehash ~/.certs/”

For lazy guys here are three certificates, ~/.certs/gmail.pem:

   -----BEGIN CERTIFICATE-----
   MIIC3TCCAkagAwIBAgIDCDijMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
   MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
   aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDcxMDI1MTc1MzE2WhcNMDkxMjI0MTg1MzE2
   WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
   TW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xFjAUBgNVBAMTDXBv
   cC5nbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO03QxerFKZV
   8yeomuL4zSl8Pr7hMWnKMMgp/CwhwadeBmL0LQHHbjL/6z/Z59ZQvrztqkwhchA2
   APKzUwRVTyn7Shx6vBqk6oFmTqoOLmY6hbq6l8uVdUv0AfbHwio8CnLpK2+nbuFl
   flPwx1DH0E3grD8+CrH5SmScfTWbDkcXAgMBAAGjga4wgaswDgYDVR0PAQH/BAQD
   AgTwMB0GA1UdDgQWBBTJRG/OFpZt+BV43JM3NshHMjpwazA6BgNVHR8EMzAxMC+g
   LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDAf
   BgNVHSMEGDAWgBRI5mj5K9KylddH2CMgEE8zmJCf1DAdBgNVHSUEFjAUBggrBgEF
   BQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEAOKr3mhxtwFCS3J6lbeaf
   3KrHKi935BZkI75sRbON+hog0t2ovcM2i7fxs3xneH8USLsHgfxNBj9tkMogMK/K
   sO/NUVZ/IfyqcNNkp2619qTQXthKRH42JKpAKgNhT1bdno3pxn+eDEpqmU3CE7IP
   HDCjWOK1fGkZ/yFAuTxuxAc=
   -----END CERTIFICATE-----

~/.certs/equifax.pem:

   -----BEGIN CERTIFICATE-----
   MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV
   UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy
   dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1
   MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx
   dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B
   AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f
   BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A
   cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
   AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ
   MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aW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   b24gU2VydmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNl
   cnZlciBDQTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNv
   bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2aovXwlue2oFBYo847kkE
   VdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIhUdib0GfQ
   ug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMR
   uHM/qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG
   9w0BAQQFAAOBgQAmSCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUI
   hfzJATj/Tb7yFkJD57taRvvBxhEf8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JM
   pAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7tUCemDaYj+bvLpgcUQg==
   -----END CERTIFICATE-----

Important! Do not forget to “$ c_rehash ~/.certs/”

Add-ons

MhBiff? is apparently a mail-notification tool, with a Japanese webpage at http://www.yynet.tama.tokyo.jp/~yokota/mh-biff/ (editors note: anyone with a more fluent Japanese than my anime-japanese care to summarize the contents of that page onto MhBiff??). MhCrypt?, Lisp:mh-crypt.el, is an utility to store the messages in an encrypted format. With a quick glance it seems this would break mh outside of MH-E.

Alternative to MhBiff

For those who do not understand japanese well, there is another way to get mail notification: (display-time) function with some tweaks (useful in case of multiple mail folders)

    ;; Notification stuff: use display-time minor mode to notify about new mail
    ;; in mode-line, but omit time and load info. Print comma separated list
    ;; of folders with new mail in mode-line.
    (setq display-time-mail-function
          (lambda ()
            (let ((input (shell-command-to-string "/usr/local/nmh/bin/flist -all"))
                  (dirs nil)
                  (start 0))
              (while (string-match "^\\([a-z-+]*\\) *has [1-9].*$" input start)
                (push (match-string 1 input) dirs)
                (setq start (match-end 0)))
              (setq display-time-mail-string (mapconcat 'identity dirs ", ")))))
								  
    (setq display-time-interval 10
          display-time-format ""
          display-time-default-load-average nil
          display-time-mail-face 'custom-themed)
    
    (display-time)

CategoryMail