You are not logged in.

#1 2008-11-22 16:43:56

kant1
Member
Registered: 2006-11-28
Posts: 57

mutt, IMAP, and Exchange (patch)

Just wanted to let anyone interested know that I was able to get mutt working with an Exchange server over IMAP.

You can find out more here: http://mychael.gotdns.com/blog/2008/11/ … -exchange/

I've already put the package for libntlm out on AUR.  Here is the patch to the mutt package (ie. extract the mutt tarball and apply this patch):

diff -Naur mutt_orig/PKGBUILD mutt_patched/PKGBUILD
--- mutt_orig/PKGBUILD    2008-11-22 08:34:40.000000000 -0800
+++ mutt_patched/PKGBUILD    2008-11-22 08:34:09.000000000 -0800
@@ -10,18 +10,24 @@
 depends=('slang' 'openssl>=0.9.8e' 'gdbm' 'mime-types' 'zlib' 'libsasl' 'gpgme')
 makedepends=('gnupg')
 install=${pkgname}.install
-source=(ftp://ftp.mutt.org/mutt/devel/${pkgname}-${pkgver}.tar.gz)
-md5sums=('27c30037120189b9f9c0d3e76361b8f8')
+source=(ftp://ftp.mutt.org/mutt/devel/${pkgname}-${pkgver}.tar.gz ntlm.patch)
+md5sums=('27c30037120189b9f9c0d3e76361b8f8'
+         '2f808cabc5f1e48dbc5de000672fba9e')
 url="http://www.mutt.org/"
 
 build() {
   cd ${startdir}/src/${pkgname}-${pkgver}
-  ./configure --prefix=/usr --sysconfdir=/etc \
+
+  patch -p1 < ../ntlm.patch
+
+  ./prepare --prefix=/usr --sysconfdir=/etc \
     --enable-pop --enable-imap --enable-smtp \
     --with-sasl --with-ssl=/usr --without-idn \
     --enable-hcache --enable-pgp --enable-inodesort \
      --enable-compressed --with-regex \
-     --enable-gpgme --with-slang=/usr
+     --enable-gpgme --with-slang=/usr \
+     --with-ntlm=/usr
+
   make || return 1
   make DESTDIR=${startdir}/pkg install
   rm -f ${startdir}/pkg/usr/bin/{flea,muttbug}
diff -Naur mutt_orig/ntlm.patch mutt_patched/ntlm.patch
--- mutt_orig/ntlm.patch    1969-12-31 16:00:00.000000000 -0800
+++ mutt_patched/ntlm.patch    2008-11-22 08:34:14.000000000 -0800
@@ -0,0 +1,222 @@
+diff -Naur mutt-1.5.18_orig/configure.ac mutt-1.5.18/configure.ac
+--- mutt-1.5.18_orig/configure.ac    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/configure.ac    2008-11-20 12:06:22.000000000 -0800
+@@ -610,6 +610,34 @@
+ 
+ dnl -- imap dependencies --
+ 
++AC_ARG_WITH(ntlm, AC_HELP_STRING([--with-ntlm[=PFX]], [Compile in NTLM authentication for IMAP]), 
++      [
++      if test "$with_ntlm" != "no"
++      then
++    if test "$need_imap" = "yes"
++    then
++      if test "$with_ntlm" != "yes"
++      then
++        CPPFLAGS="$CPPFLAGS -I$with_ntlm/include"
++        LDFLAGS="$LDFLAGS -L$with_ntlm/lib"
++      fi
++
++      saved_LIBS="$LIBS"
++      AC_CHECK_LIB(ntlm, buildSmbNtlmAuthResponse,,
++        AC_MSG_ERROR([could not find libntlm which is needed for ntlm authentication]))
++      LIBS="$saved_LIBS"
++      MUTTLIBS="$MUTTLIBS -lntlm"
++      AC_DEFINE([USE_NTLM], 1, [ Define if you want support for NTLM. ])
++
++      need_ntlm=yes
++
++    else
++      AC_MSG_WARN([NTLM was requested but IMAP is not enabled])
++    fi
++      fi
++])
++AM_CONDITIONAL(USE_NTLM, test x$need_ntlm = xyes)
++
+ AC_ARG_WITH(gss, AC_HELP_STRING([--with-gss[=PFX]], [Compile in GSSAPI authentication for IMAP]), 
+     gss_prefix="$withval", gss_prefix="no")
+ if test "$gss_prefix" != "no"
+diff -Naur mutt-1.5.18_orig/imap/Makefile.am mutt-1.5.18/imap/Makefile.am
+--- mutt-1.5.18_orig/imap/Makefile.am    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/imap/Makefile.am    2008-11-20 12:06:22.000000000 -0800
+@@ -9,12 +9,12 @@
+ endif
+ 
+ if USE_SASL
+-AUTHENTICATORS = auth_sasl.c
++AUTHENTICATORS = auth_ntlm.c auth_sasl.c
+ else
+-AUTHENTICATORS = auth_anon.c auth_cram.c
++AUTHENTICATORS = auth_anon.c auth_cram.c auth_ntlm.c
+ endif
+ 
+-EXTRA_DIST = BUGS README TODO auth_anon.c auth_cram.c auth_gss.c auth_sasl.c
++EXTRA_DIST = BUGS README TODO auth_anon.c auth_cram.c auth_gss.c auth_ntlm.c auth_sasl.c
+ 
+ AM_CPPFLAGS = -I$(top_srcdir) -I../intl
+ 
+diff -Naur mutt-1.5.18_orig/imap/auth.c mutt-1.5.18/imap/auth.c
+--- mutt-1.5.18_orig/imap/auth.c    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/imap/auth.c    2008-11-20 12:06:22.000000000 -0800
+@@ -29,6 +29,9 @@
+ #include "auth.h"
+ 
+ static imap_auth_t imap_authenticators[] = {
++#ifdef USE_NTLM
++  { imap_auth_ntlm, NULL },
++#endif
+ #ifdef USE_SASL
+   { imap_auth_sasl, NULL },
+ #else
+diff -Naur mutt-1.5.18_orig/imap/auth.h mutt-1.5.18/imap/auth.h
+--- mutt-1.5.18_orig/imap/auth.h    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/imap/auth.h    2008-11-20 12:06:22.000000000 -0800
+@@ -48,6 +48,9 @@
+ #ifdef USE_GSS
+ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const char* method);
+ #endif
++#ifdef USE_NTLM
++imap_auth_res_t imap_auth_ntlm (IMAP_DATA* idata, const char* method);
++#endif
+ #ifdef USE_SASL
+ imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata, const char* method);
+ #endif
+diff -Naur mutt-1.5.18_orig/imap/auth_ntlm.c mutt-1.5.18/imap/auth_ntlm.c
+--- mutt-1.5.18_orig/imap/auth_ntlm.c    1969-12-31 16:00:00.000000000 -0800
++++ mutt-1.5.18/imap/auth_ntlm.c    2008-11-20 12:06:22.000000000 -0800
+@@ -0,0 +1,113 @@
++/* NTLM login/authentication code */
++
++#if HAVE_CONFIG_H
++# include "config.h"
++#endif
++
++#include "mutt.h"
++#include "imap_private.h"
++#include "auth.h"
++
++#include <ntlm.h>
++
++imap_auth_res_t imap_auth_ntlm (IMAP_DATA* idata, const char* method)
++{
++  char buf[LONG_STRING];
++  int len, rc;
++  tSmbNtlmAuthRequest   request;              
++  tSmbNtlmAuthChallenge challenge;
++  tSmbNtlmAuthResponse  response;
++
++  if (!mutt_bit_isset (idata->capabilities, ANTLM))
++    return IMAP_AUTH_UNAVAIL;
++
++  mutt_message _("Authenticating (NTLM)...");
++
++  /* get auth info */
++  if (mutt_account_getlogin (&idata->conn->account))
++    return IMAP_AUTH_FAILURE;
++  if (mutt_account_getpass (&idata->conn->account))
++    return IMAP_AUTH_FAILURE;
++
++  imap_cmd_start (idata, "AUTHENTICATE NTLM");
++
++  do
++    rc = imap_cmd_step (idata);
++  while (rc == IMAP_CMD_CONTINUE);
++  
++  if (rc != IMAP_CMD_RESPOND)
++  {
++    dprint (1, (debugfile, "Invalid response from server: %s\n", idata->buf));
++    goto bail;
++  }
++
++  /* Need to handle the case where Exchange incorrectly returns +\r\n instead
++   * of + \r\n? */
++
++  buildSmbNtlmAuthRequest(&request, idata->conn->account.user, "AMERICAS");
++
++#ifdef DEBUG
++  if (debuglevel > 0)
++    dumpSmbNtlmAuthRequest(debugfile, &request);
++#endif  
++
++  memset(buf, 0, sizeof buf);
++  mutt_to_base64((unsigned char*)buf, (unsigned char*)&request,
++    SmbLength(&request), sizeof (buf) - 2);
++  safe_strcat (buf, sizeof buf, "\r\n");
++
++  mutt_socket_write (idata->conn, buf);
++
++  do
++    rc = imap_cmd_step (idata);
++  while (rc == IMAP_CMD_CONTINUE);
++
++  if (rc != IMAP_CMD_RESPOND)
++  {
++    dprint (1, (debugfile, "Invalid response from server: %s\n", idata->buf));
++    goto bail;
++  }
++
++  if ((idata->buf[0] != '+') || (idata->buf[1] != ' '))
++    goto bail;
++
++  len = mutt_from_base64((char*)&challenge, idata->buf+2);
++
++#ifdef DEBUG
++  if (debuglevel > 0)
++    dumpSmbNtlmAuthChallenge(debugfile, &challenge);
++#endif
++ 
++  buildSmbNtlmAuthResponse(&challenge, &response, idata->conn->account.user,
++    idata->conn->account.pass);
++ 
++#ifdef DEBUG
++  if (debuglevel > 0)
++    dumpSmbNtlmAuthResponse(debugfile, &response);
++#endif
++   
++  memset(buf, 0, sizeof buf);
++  mutt_to_base64((unsigned char*)buf, (unsigned char*)&response, SmbLength(&response),
++    sizeof (buf) - 2);
++  safe_strcat (buf, sizeof buf, "\r\n");
++ 
++  mutt_socket_write (idata->conn, buf);
++
++  do
++    rc = imap_cmd_step (idata);
++  while (rc == IMAP_CMD_CONTINUE);
++
++  if (rc != IMAP_CMD_OK)
++  {
++    dprint (1, (debugfile, "Error receiving server response.\n"));
++    goto bail;
++  }
++
++  if (imap_code (idata->buf))
++    return IMAP_AUTH_SUCCESS;
++
++ bail:
++  mutt_error _("NTLM authentication failed.");
++  mutt_sleep (2);
++  return IMAP_AUTH_FAILURE;
++}
+diff -Naur mutt-1.5.18_orig/imap/command.c mutt-1.5.18/imap/command.c
+--- mutt-1.5.18_orig/imap/command.c    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/imap/command.c    2008-11-20 12:06:22.000000000 -0800
+@@ -58,6 +58,7 @@
+   "NAMESPACE",
+   "AUTH=CRAM-MD5",
+   "AUTH=GSSAPI",
++  "AUTH=NTLM", 
+   "AUTH=ANONYMOUS",
+   "STARTTLS",
+   "LOGINDISABLED",
+diff -Naur mutt-1.5.18_orig/imap/imap_private.h mutt-1.5.18/imap/imap_private.h
+--- mutt-1.5.18_orig/imap/imap_private.h    2008-11-20 12:06:15.000000000 -0800
++++ mutt-1.5.18/imap/imap_private.h    2008-11-20 12:06:22.000000000 -0800
+@@ -107,6 +107,7 @@
+   NAMESPACE,                       /* RFC 2342: IMAP4 Namespace */
+   ACRAM_MD5,            /* RFC 2195: CRAM-MD5 authentication */
+   AGSSAPI,            /* RFC 1731: GSSAPI authentication */
++  ANTLM,                        /* AUTH=NTLM for MS Exchange Server */
+   AUTH_ANON,            /* AUTH=ANONYMOUS */
+   STARTTLS,            /* RFC 2595: STARTTLS */
+   LOGINDISABLED,        /*           LOGINDISABLED */

Hope that helps someone!

Offline

#2 2008-11-25 20:16:43

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: mutt, IMAP, and Exchange (patch)

This looks very promising; i would love to get my work and google mail all though mutt.

one comment though:

on your site, under your Gmail settings you have

set record='+[Gmail]/Sent Mail'

i've see this same setting in every single mutt/gmail sample config on the internet.

google's smtp server automatically saves a copy to "Sent Mail"; with this setting you'd end up with duplicate copies all through your "Sent Mail" folder (i did).  to prevent this behavior i use this setting in stead:

unset record

Offline

#3 2008-11-25 20:42:33

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: mutt, IMAP, and Exchange (patch)

Thanks for your constructive comment!

I just checked, and strangely, I don't have duplicates in my Sent Mail folder.  I wonder why the difference?...

Offline

#4 2008-11-25 21:33:48

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: mutt, IMAP, and Exchange (patch)

interesting indeed:

from http://mail.google.com/support/bin/answ … opic=12920

Google Help wrote:

Sending:
    * Do NOT save sent messages on the server. If your client is sending mail through Gmail's SMTP server, your sent messages will be automatically copied to the [Gmail]/Sent Mail folder.

as well as my own experience i can't imagine why you (and all the other tuturial writers out there) aren't having the same problem.

oh well, more to the point; i'm excited for exchange support smile !

Last edited by brisbin33 (2008-11-25 21:34:54)

Offline

#5 2008-11-25 22:26:35

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: mutt, IMAP, and Exchange (patch)

Good point.  If you want to make a comment posting at the site above, that would be great.  If not, no sweat.  But it looks like you do have a very valid point, and the documentation to back it!

I'd be interested if the instructions help you or if anything is unclear.

My current set up is really slick, and much better than the fetchmail+mutt solution I've had for the past couple years.  I hope you'll like it too!

Offline

#6 2008-11-25 22:50:05

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: mutt, IMAP, and Exchange (patch)

yeah, i definitely plan on looking into it shortly; i've never patched a program before but i hear it's not hard.  i need to check with IT and see if our exchange server supports IMAP; my last job did not.

i've bookmarked you're site and i'll comment if i can get it going.  thanks again for the info.

EDIT: my company blocks external IMAP connections too sad

Last edited by brisbin33 (2008-11-26 14:44:46)

Offline

#7 2008-11-26 09:30:13

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: mutt, IMAP, and Exchange (patch)

PKGBUILD for teh lazy ones:

pkgname=mutt-exchange
pkgver=1.5.18
pkgrel=1
pkgdesc="A small but very powerful text-based mail client"
arch=(i686 x86_64)
license=('GPL')
url="http://www.mutt.org/"
depends=('slang' 'openssl>=0.9.8e' 'gdbm' 'mime-types' 'zlib' 'libsasl' 'gpgme' 'libntlm')
makedepends=('gnupg')
conflicts=('mutt')
install='mutt.install'
source=(ftp://ftp.mutt.org/mutt/devel/mutt-${pkgver}.tar.gz http://mychael.gotdns.com/static/ntlm.patch.txt)
md5sums=('27c30037120189b9f9c0d3e76361b8f8'
         '2f808cabc5f1e48dbc5de000672fba9e')
url="http://www.mutt.org/"

build() {
  cd ${startdir}/src/mutt-${pkgver}
  patch -p1 < ../ntlm.patch.txt
  ./configure --prefix=/usr --sysconfdir=/etc \
    --enable-pop --enable-imap --enable-smtp \
    --with-sasl --with-ssl=/usr --without-idn \
    --enable-hcache --enable-pgp --enable-inodesort \
     --enable-compressed --with-regex \
     --enable-gpgme --with-slang=/usr --with-ntlm
  make || return 1
  make DESTDIR=${startdir}/pkg install
  rm -f ${startdir}/pkg/usr/bin/{flea,muttbug}
  rm -f $startdir/pkg/usr/share/man/man1/{flea,muttbug}.1
  rm -f ${startdir}/pkg/etc/mime.types*
  install -Dm644 contrib/gpg.rc ${startdir}/pkg/etc/Muttrc.gpg.dist
}

+ uploaded libntlm 1.0 (stable) to AUR

cant test it cause it seems like our company has IMAP disabled on our exchange sad

kant1: can you add "  provides=('libntlm')  " to your libntlm-git PKGBUILD?

Last edited by robmaloy (2008-11-26 09:30:38)


☃ Snowman ☃

Offline

Board footer

Powered by FluxBB