Diff: MuttOnMacOs

Differences between current version and predecessor to the previous major change of MuttOnMacOs.

Other diffs: Previous Revision, Previous Author

Newer page: version 12 Last edited on March 1, 2012 9:10 pm by PhilHollenback
Older page: version 9 Last edited on October 12, 2007 3:37 pm by PhilHollenback Revert
@@ -1,5 +1,9 @@
 !!Mutt On Mac Os X 
+  
+__Note 5/21/11__: these instructions are obviously quite old. Lots of stuff in here is still relevant, but there have been some changes. For example, I think the mutt that comes in macports now supplies everything you need. mutt-ng is abandoned. -phil  
+  
+-----  
  
 My current home system is an Apple Powerbook 667DVI running Mac OS X 10.4.3. I've been using mutt as my mail editor on that platform and it works quite well. Here are some things I've learned: 
  
 You need to first install [fink|http://fink.sourceforge.net], the collection of free gnu/linux/etc software for Mac OS X. The following fink packages are generally useful in conjunction with mutt: 
@@ -72,11 +76,11 @@
 $ sudo mv /usr/bin/emacsclient /usr/bin/emacsclient.orig 
 $ sudo ln -s /Applications/Aquamacs\ Emacs.app/Contents/MacOS/bin/emacsclient /usr/bin/ 
 </pre> 
  
-Then I made sure I had the [latest post.el|http://www .drao-ofr.hia-iha.nrc-cnrc.gc.ca /~rreid /software/mutt /] and set up my .emacs as indicated in that file. 
+Then I made sure I had the [latest post.el|http://sourceforge .net /projects /post-mode /] and set up my .emacs as indicated in that file. 
  
-Normally now I would just change my mutt editor to emacsclient in ~/.muttngrc. However, I discovered a slight annoyance: when you call emacsclient from mutt in the Mac terminal, the new window appears *behind* the terminal window. The fix (as suggested on the [Emacs on Mac mailing list|http://article.gmane.org/gmane.emacs.macintosh.osx/1735]) was a script like this: 
+Normally now I would just change my mutt editor to emacsclient in <code>~ ~/.muttngrc</code> . However, I discovered a slight annoyance: when you call emacsclient from mutt in the Mac terminal, the new window appears *behind* the terminal window. The fix (as suggested on the [Emacs on Mac mailing list|http://article.gmane.org/gmane.emacs.macintosh.osx/1735]) was a script like this: 
  
 <pre> 
 #!/bin/sh 
  
@@ -88,9 +92,9 @@
 </pre> 
  
 which ensures the editor window opens in front of the terminal and also makes sure the terminal gets the focus after the editor window closes. 
  
-I saved this script as <code>~/bin/emacs-mail</code> and set my mutt editor to point to the script. Works like a charm. One slight weakness is that if your mouse pointer is over a different terminal window when the editor window closes, that other terminal will get the focus instead of the terminal running mutt. Haven't thought of a fix for that yet. 
+I saved this script as <code>~ ~/bin/emacs-mail</code> and set my mutt editor to point to the script. Works like a charm. One slight weakness is that if your mouse pointer is over a different terminal window when the editor window closes, that other terminal will get the focus instead of the terminal running mutt. Haven't thought of a fix for that yet. 
  
 Another improvement I still need to make is instead of just blindly running emacsclient to edit a message, I need to do two things: 
  
 # Check if emacs is already running and launch it if not. 
@@ -192,21 +196,11 @@
 <pre> 
 set sendmail="/usr/local/bin/msmtp" 
 </pre> 
  
-I also needed to configure my <code>~/.mstmp</code> with my mail server, username, and password. After that mutt was sending mail with no problems. 
+I also needed to configure my <code>~ ~/.mstmp</code> with my mail server, username, and password. After that mutt was sending mail with no problems. 
  
 ----- 
-<?plugin RawHtml  
-<center>  
-<script type="text/javascript"><!--  
-google_ad_client = "pub-5011581245921339";  
-google_ad_width = 728;  
-google_ad_height = 90;  
-google_ad_format = "728x90_as";  
-google_ad_channel ="";  
-//--></script>  
-<script type="text/javascript"  
- src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  
-</script>  
-</center>  
-?>  
+  
+CategoryGeekStuff  
+  
+CategoryMacStuff  

current version

Mutt On Mac Os X

Note 5/21/11: these instructions are obviously quite old. Lots of stuff in here is still relevant, but there have been some changes. For example, I think the mutt that comes in macports now supplies everything you need. mutt-ng is abandoned. -phil


My current home system is an Apple Powerbook 667DVI running Mac OS X 10.4.3. I've been using mutt as my mail editor on that platform and it works quite well. Here are some things I've learned:

You need to first install fink, the collection of free gnu/linux/etc software for Mac OS X. The following fink packages are generally useful in conjunction with mutt:

  • aspell

    • spell checker
  • lynx

    • text-mode web browser (useful for previewing html documents)
  • openssl & openssl-devel

    • necessarily if you want ssl support in mutt
  • gdbm & gdbm-shlibs

    • necessary if you want header caching in mutt

Fink does include mutt but the version is somewhat old. I elected to build mutt-ng from source and use it instead. Mutt-ng is a more experimental split from mutt that incorporates a number of extra patches.

I hacked mutt-ng two ways before running the configure:

1. Change the tempfile name string so that other programs think it is old mutt:

--- muttlib.c.orig      2005-12-13 00:41:12.000000000 -0500
+++ muttlib.c   2005-12-13 13:50:03.000000000 -0500
@@ -657,10 +657,8 @@

 void _mutt_mktemp (char *s, const char *src, int line)
 {
-
-  snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
-            NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
-            (unsigned int) rand(), (unsigned int) rand());
+  snprintf (s, _POSIX_PATH_MAX, "%s/mutt-%s-%d-%d", NONULL (Tempdir),
+            NONULL (Hostname), (int) getpid (), Counter++);
   debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
   unlink (s);
 }

2. Make configure look in /sw for gdbm:

--- configure.orig      2005-12-13 13:52:57.000000000 -0500
+++ configure   2005-12-13 00:43:36.000000000 -0500
@@ -14528,7 +14528,7 @@
 fi;
     if test x$ac_prefer_gdbm != xno -a x$ac_cv_vlopen != xyes; then
         ac_cv_gdbmopen=no
-        GDBM_DIRS="$mutt_cv_prefix /usr/local /usr"
+        GDBM_DIRS="$mutt_cv_prefix /usr/local /usr /sw"
         echo "$as_me:$LINENO: checking for gdbm_open" >&5
 echo $ECHO_N "checking for gdbm_open... $ECHO_C" >&6
         for d in $GDBM_DIRS; do

Then I ran configure as follows:

./configure --enable-hcache --enable-imap --with-ssl

and did the usual make && make-install to install in /usr/local. I chose not to install in /sw to keep Fink packages (which go in /sw by default) separate from packages I built myself.

Next I needed an editor to use with mutt. Previously I used vim on Mac OS X. but I decided I really wanted emacs back. The answer is Aquamacs Emacs. Aquamacs is by far the best emacs for Mac OS:

  • Its a native Mac OS program so you don't have to launch X11 to run it.
  • It incorporates both the emacs keybindings and the mac keybindings in a logical way.

I have a heavily customized .emacs file so starting Aquamacs fresh for each mail message is not practical. I also use the post.el mode in emacs to edit my messages. The answer is emacsclient, which attaches to a running emacs and displays a fresh edit window. Aquamcs comes with it's own emacsclient, you can't just use the /usr/bin/emacsclient installed by default (that is for the lame stock emacs that comes with Mac OS). Move that one aside and link in the Aquamacs version:

$ sudo mv /usr/bin/emacsclient /usr/bin/emacsclient.orig
$ sudo ln -s /Applications/Aquamacs\ Emacs.app/Contents/MacOS/bin/emacsclient /usr/bin/

Then I made sure I had the latest post.el and set up my .emacs as indicated in that file.

Normally now I would just change my mutt editor to emacsclient in ~/.muttngrc. However, I discovered a slight annoyance: when you call emacsclient from mutt in the Mac terminal, the new window appears behind the terminal window. The fix (as suggested on the Emacs on Mac mailing list) was a script like this:

#!/bin/sh

# script to force Aquamacs to open in front of terminal
open -a Aquamacs\ Emacs
/Applications/Aquamacs\ Emacs.app/Contents/MacOS/bin/emacsclient "$@"
# Now make sure the focus goes back to the terminal when we are done
open -a Terminal

which ensures the editor window opens in front of the terminal and also makes sure the terminal gets the focus after the editor window closes.

I saved this script as ~/bin/emacs-mail and set my mutt editor to point to the script. Works like a charm. One slight weakness is that if your mouse pointer is over a different terminal window when the editor window closes, that other terminal will get the focus instead of the terminal running mutt. Haven't thought of a fix for that yet.

Another improvement I still need to make is instead of just blindly running emacsclient to edit a message, I need to do two things:

  1. Check if emacs is already running and launch it if not.
  2. Check if you are running in a graphical environment and launch a text-mode editor if not.

Number 2 isn't terribly important on the mac unless you ssh in to the system. Otherwise you can pretty much always assume you've got a GUI.

Note there are a few issues with post.el that need to be worked out:

First, the 'check if message contained the string attach and ask user for attachment' functionality is broken. If this is triggered in a message, you get an error message when attempting to close the window with C-cC-c. It looks like the problem in post.el is here:

   ;; "13 occurences" instead of a number, 13.
  (let ((total-attach (string-to-int (how-many post-attachment-regexp))))
    ;; And this mess is just to catch the unlikely false alarm of
    ;; "attach" being in the signature, but not in the body.
    (if (> total-attach 0)
        (progn (post-goto-signature)
               (> total-attach (string-to-int (how-many
                                               post-attachment-regexp)))))))

Specifically the call the string-to-int seems to actually get a number instead of a string so it bombs out. The fix is this patch to post.el:

--- post.el.orig        2005-12-15 23:04:03.000000000 -0500
+++ post.el     2005-12-15 23:09:49.000000000 -0500
@@ -1083,15 +1083,14 @@
   "Check if attach appears in the body."
   (post-goto-body)

-  ;; Aargh it's annoying that how-many returns a string,
-  ;; "13 occurences" instead of a number, 13.
-  (let ((total-attach (string-to-int (how-many post-attachment-regexp))))
+  ;; how-many apparently used to return a string but now it
+  ;; returns an int so we don't need string-to-int.
+  (let ((total-attach (how-many post-attachment-regexp)))
     ;; And this mess is just to catch the unlikely false alarm of
     ;; "attach" being in the signature, but not in the body.
     (if (> total-attach 0)
        (progn (post-goto-signature)
-              (> total-attach (string-to-int (how-many
-                                              post-attachment-regexp)))))))
+              (> total-attach (how-many post-attachment-regexp))))))

 (defun post-prompt-for-attachment ()
   "Prompt for an attachment."

Or you can disable the check for attachments in post.el:

(post-should-prompt-for-attachment (quote Never))

Second, the default underline display in Aquamacs is broken just as it is in XEmacs and all other Emacsen I've ever seen: the underline gets drawn through the characters instead of under them. Supposedly this is due to some font weirdness in X11, etc. Anyway, I changed the underline to a nice sunken box instead with this .emacs change:

(post-underline-face ((((class color) (background dark)) (:box (:line-width 1 :color "grey75" :style released-button)))))

Note that the default underline in Aquamacs in general has the same problem so I also added this:

(underline ((t (:box (:line-width 1 :color "grey75" :style released-button)))))

Third, emacs uses the tempfile name to determine whether to turn on post mode. This gets confused by two things:

  1. Even the latest post.el can't quite understand mutt-ng tempfile names. Regular mutt just uses the system name plus the pid plus a counter to construct the name. Mutt-ng adds several other numbers, presumably to make tempfile handling more secure. The lazy fix for this is the patch to muttlib.c above. The better fix would be to work with the post.el maintainer and fix the regex.
  2. If you are on a cable mode or dsl, you might have a system name like abc-100-43-56-33.comcast.net, i.e. your system name contains your ip address. The extra numbers break the post.el regex.

I fixed number two by forcing my system name to something sensible. I changed three items:

  1. Under system preferences->sharing, you can set the system name. Unfortunately this doesn't change the results of the hostname call and that is what mutt users.
  2. I created an /etc/rc.local and added one line: /bin/hostname sysname. This changes the hostname on boot. However I think it still might break when running on dhcp.
  3. Finally I also edited /etc/hostconfig and added the line HOSTNAME=sysname. That was suggested on the net, but its not clear if this mechanism still works in Mac OS 10.4.

Anyway after all that now my system name is always the same, and it doesn't confuse post.el.

Sending Mail

Mutt doesn't come with any mail transfer agent functionality. That is, it doesn't know how to actually send mail. Mutt assumes some other program on the system will take care of that little detail. This makes sense in the unix world because unix machines typically have an MTA like sendmail installed.

There are several options:

  1. Use the Postfix mailer that comes with Mac OS.

    • Seems like overkill if you just want to send mail from one program.
  2. Use muttng and link to the libesmtp library, which will give mutt the ability to send mail itself.

    • I couldn't get libesmtp or esmtp to build under Mac OS 10.4.
  3. Use a standalone outgoing MTA like esmtp, msmtp, or nullmailer

I had used libesmtp under Mac OS 10.3.9 but I couldn't get it built under 10.4. Thus I went looking for an alternative and found msmtp. Seems to offer similar features to esmtp, including various authentication and encryption options. This is important as I want to use mutt for my work mail and I have to authenticate with that server.

I built msmtp 1.4.4 with the standard configure & make & make install. Then I updated my .muttngrc to call it:

set sendmail="/usr/local/bin/msmtp"

I also needed to configure my ~/.mstmp with my mail server, username, and password. After that mutt was sending mail with no problems.


CategoryGeekStuff

CategoryMacStuff



Our Founder
ToolboxClick to hide/show