Tuesday, September 05, 2006

Gnus works with fetchmail

In the past, I always use only gnus to receive and send mails. However, minor defect in an otherwise prefect thing is that, when it receives many, especially, more than tens of letters, whole of emacs will seem to be suspended and have no response, unless you press C-g to interrupt current gnus process. Gnus is totally written with elisp and elisp is parsed by emacs, whereby it is not a program with multi-process. Then, when gnus receives or sends mails, emacs will wait it util its job ends.

Recently, this situation took places so frequently that I can not suffer from it. Thus, I plan to distinguish my MDA and MTA. Gnus is a nice tool as MUA, such as mutt, but more powerful than mutt, which can orgnize mails and newsgroups easily and conveniently. Besides, gnus can also play a role of MTA like sendmail, which can send mails by smtpmail.el. Gnus can also take the place of MDA like fetchmail, while orgnizing newsgroup is its outstanding job, which has several style to store messages. The two most frequent styles are nnfolder and nnml, the former of which is to store messages into a whole file as the format mbox, the latter into several files for each in a directory. The nnml format is the fastest format to read and search, so as that I prefer the latter one. The more details exists in gnus manuals.

Now, Gnus will act as MUA and MTA, to orgnize mails and send mails. Correspondingly, fetchmail will play as MDA, instead of some functions of gnus before. Here is the method to configure fetchmail:

Firestly, touch a file named ~/.fetchmailrc, whose content is so simple:

poll MAIL_SERVER_IP protocol POP3 uidl
     username MAIL_USERNAME password MAIL_PASSWORD keep
mda "procmail -d %T"

Here is some selective explanation:

  • uidl: Only fetch newer messages.
  • keep: Leave messages on the pop3 server.
  • mda "procmail -d %T": This statement can bo omitted, which means to use procmail as the mail filter.

Important: When using fetchmail in Gentoo Linux and I omitted the statement which contains procmail, some similar errors occur:

1 message for  at  (923 octets).
reading message 1 of 1 (923 octets) fetchmail: SMTP connect to localhost failed
fetchmail: SMTP transaction error while fetching from 
fetchmail: Query status=10 (SMTP)

If you use procmail to categorze and filter mails rather than gnus, you need set rules in ~/.procmailrc:

MAILDIR=$HOME/Mail
DEFAULT=$MAILDIR/mbox
LOGFILE=$MAILDIR/from-log
LOCKFILE=$MAILDIR/.lock

:0
! FORWARD-NAME@FORWARD-SERVER.COM

After :0, you can create your filter rules, even with regular expressions, in which the symbol "!" above means to forward all mails received into the mailbox FORWARD-NAME@FORWARD-SERVER.COM, whereby procmail is enough powerful.

Important: In Gentoo Linux, I have to add "DEFAULT=$MAILDIR/mbox" into ~/.procmailrc, otherwise, procmail will automatically deliver messages into ~/.maildir as format maildir, which is used with nnmldir. When I do this, the messages will not be stored at default directory /var/mail/USERNAME. Then, we also should change nnml-spool-directory and others to ~/Mail/mbox accordingly.

Now, run fetchmail by command:

fetchmail -d 300
which means run fetchmail as a daemon, and receive mails from remote server every 5 minutes. If everything is ok, you can write it into cron or into startup scripts. All mails will be stored into the local mail spools, usually which exists in /var/mail/USERNAME, when it run at Gentoo Linux or FreeBSD.

Then, configure the ~/.gnus, to which we write some simple lisp code:

(setq
 user-full-name "Myfirstname Mylastname"
 user-mail-address "mymail@mycompany.com"
 nnmail-spool-file "/var/mail/USERNAME"
 display-time-mail-file "/var/mail/USERNAME"
 message-default-charset `utf-8
 nnml-directory "~/Mail/"
 gnus-select-method '(nnml ""))

Start emacs and open gnus. Gnus will automaticly move and orgnize messages from /var/mail/USERNAME into the nnml-directory with the program "movemail". If there is no rules to say how to orgnize mails in the ~/.gnus, all mails will be moved to the default directory ~/Mail/mail/misc.

Then, step into the Group buffer in the gnus, if the group mail.misc is invisible, then press "L"(gnus-group-list-all-groups). If the group mail.misc does not exist, press "G m"(gnus-group-make-group) to create a new group named mail.misc with the method "nnml:", or press "^" (gnus-enter-server-mode), then enter "{nnml:}(open)" to check whether you have missed some groups.

If you wanna make the group mail.misc always visible, then press "G c"(gnus-group-customize) to complete more customed details.

When go here, gnus and fetchmail will work together, and you will not be boring of gnus receiving mails and fetchmail takes the place of it at background.

1 comment:

keebler said...

Thank you very much.