Archive

Archive for August, 2009

Windows developement environment, part 1

August 21st, 2009 Comments off

This is the first post (out of 3) about setting up a development environment to build the user interface of Manitou-Mail on Windows. In this part, we’re installing the compiler (GCC packaged by MinGW), the MSYS environment, and the autotools (autoconf and automake).
In the second part, we’ll build Qt itself and the PostgreSQL client libraries from source. In the third part, we’ll build manitou.exe from the sources off the subversion repository.

MinGW (compiler) installation

The current version is 5.1.4 is available here: MingW-5.1.4 installer on sourceforge.net.
Let’s run the installer and choose “Download and install”:
MinGW install start

After accepting the license, we get to choose the destination directory. Let’s install into c:\mingw, the default choice.

MinGW destination directory

We want the “current” version:
MinGW version's choice

The next screen is about choosing the components.
We need to check the following ones:

  • MinGW base tools
  • g++ compiler
  • MinGW Make

MinGW components

After that, a rapid succession of screens appear, that show the packages that are being downloaded and installed.
MinGW packages getting installed

Then the install finished and we end up with a c:\mingw directory containing about 60MB of programs. It turns out that in my case, I’m also finding .tar.gz archives of the compiler packages on my desktop (from which I launched the installer), so let’s delete them.
Remaining files

MSYS (shell environment) installation

MSYS stands for minimal system. It’s a light unix-like environment with a shell and enough capabilities to support the autotools.

Like MingW, MSYS has a base system and packages, except that it has a lot more packages. We need only a half-dozen of them.
The current version of the MSYS base is available at:

MSYS-1.0.11 installer on sourceforge.net

Let’s select the default directory: c:\msys\1.0
MSys destination directory
At the end of the installation, a post-installer script running in a CMD window “will try to normalize” with MingW, so we just accept what it suggests and type the path of our mingw directory as told (c:/mingw)
MSYS post-install

Once the installation is done, we have this icon on the desktop to launch an MSYS shell :
MSYS shortcut

Autotools installation

MSYS has an MSYS Developer Toolkit in the form of a .EXE that installs automake, autoconf and the perl interpreter they depend on, but unfortunately their versions are too old for manitou’s configure script. It installs autoconf version 2.56 and automake 1.7.1 that date back from 2002, while we need at least autoconf version 2.60. Perl is version 5.6.1.

Still, let’s install that package, if just to have Perl, and upgrade separately automake and autoconf.

We install MSYS DTK into the recommended location
MSYS Developer Toolkit install

Now, following the advice from the MSYS wiki, we get the source archives for autoconf and automake directly off the main GNU FTP server (so it’s the baseline, not modified versions for MSYS).
The current sources are autoconf-2.64.tar.bz2 and automake-1.11.tar.bz2.

Let’s download these archives into c:/tmp/ and unpack them (all the subsequent commands are run inside the MSYS shell)

$ cd c:/tmp
$ tar xjf autoconf-2.64.tar.bz2
$ tar xjf automake-1.11.tar.bz2

The MSYS wiki says it’s important to compile into separate build directories so we do as told:

$ mkdir build-autoconf
$ cd build-autoconf
$ ../autoconf-2.64/configure --prefix=/mingw 
$ make
$ make install

Same thing for automake:

$ mkdir build-automake
$ cd build-automake
$ ../automake-1.11/configure --prefix=/mingw 
$ make
$ make install

Now that they’re both installed, autoconf --version displays:

$ autoconf --version
autoconf (GNU Autoconf) 2.64
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

And automake –version:

$ automake --version
automake (GNU automake) 1.11
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey 
       and Alexandre Duret-Lutz .

Conclusion of part 1

With MinGW and MSYS, we have an environment that is good enough to build programs on Windows the same way that they are on unix (basically: configure && make && make install)
With autotools we can regenerate the configure script and the Makefile.in files, which is something we need to add new source files to the project or modify the configure.in script.
Also, we’re ready to compile Qt and a PostgreSQL client, which will be done in the next part.

Categories: Development Tags:

Indexing HTML parts

August 15th, 2009 Comments off

While HTML integration is improving in Manitou-Mail, the current version (0.9.12) does not index the contents of HTML parts. This is generally not a problem because messages tend to carry a text version inside a multipart/alternative MIME construct, and that version gets indexed so that the message can still be retrieved by the words it contains. But still, some people send HTML-only messages, in which case we want to automatically extract the text from the HTML and pass it to the indexer.

It’s relatively easy to write a manitou-mdx Perl plugin that does just that, by using a CPAN module to do the HTML to text conversion: HTML::FormatText

Apart from the usual init and process functions that are described in the mdx plugins reference, we need to provide two functions: one that recursively descends the MIME tree to find the html parts, and another that extracts them to text and pass them to the indexer.

sub index_contents {
  my ($fh, $ctxt)=@_;
  my $html;
  my $text;
  {
    local $/;
    $html = $fh->getline();
  }
 
  if (defined $html) {
    my $tree = HTML::TreeBuilder->new;
    $tree->parse_content($html);
    my $formatter = HTML::FormatText->new(leftmargin=>0, rightmargin=>78);
    $text = $formatter->format($tree);
  }
  if (defined $text) {
    Manitou::Words::index_words($ctxt->{'dbh'}, $ctxt->{'mail_id'}, \$text);
  }
}
 
sub process_parts {
  my ($obj,$ctxt) = @_;;
  if ($obj->is_multipart) {
    foreach my $subobj ($obj->parts) {
      process_parts($subobj, $ctxt);    # recurse
    }
  }
  else {
    my $type=$obj->effective_type;
    if ($type eq "text/html") {
      my $io = $obj->bodyhandle->open("r");
      index_contents($io, $ctxt);
      $io->close;
    }
  }
}

The full source code and download link are available on the wiki

Categories: Development Tags: , ,