How can I customize new mail notification in alpine?

There is "NewMail FIFO Path" configuration option in alpine. Quoting the help:

You may have Alpine create a FIFO special file (also called a named pipe) where it will send a one-line message each time a new message is received in the current folder, the INBOX, or any open Stayopen Folders. To protect against two different Alpines both writing to the same FIFO, Alpine will only create the FIFO and write to it if it doesn't already exist.

So, I set the option to '/tmp/alpine.fifo', and wrote simple utility to read messages from the FIFO and invoke 'notify-send':

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#define FIFO_NAME "/tmp/alpine.fifo"

int main(void)
{   
    char s[512];
    char cmd[512];
    int num;
    int fd = open(FIFO_NAME, O_RDONLY);
    do {
        if ((num = read(fd, s, 300)) == -1)
            perror("read");
        else {
            s[num] = '\0';
            sprintf(cmd, "notify-send -t 0 'New mail:' '%s'", s);
            system(cmd);
        }
    } while (num > 0);

    return 0;
}

Save it to alpine-notifier.c, and compile with 'gcc alpine-notifier.c -o alpine-notifier' command. Start 'alpine-notifier' after alpine is started. Enjoy pop-up notifications.


Update:
I wasn't satisfied with my previous answer, so I improved the script a lot and made a github repo for it.

Now you don't have to start the script after starting alpine, the script will take care of everything for you. The core of the script is mostly the same (I only improved parsing a little):

#! /bin/bash
while read L; do
    n=$(($n + 1))  
    if [[ n -gt 3 ]]; then      
        name=`echo "$L"  | sed 's/  \+/\t/g;s/^\(+ \)\?\([^\t]*\)\t\([^\t]*\)[\t ].*/\2/'`
        subject=`echo "$L"  | sed 's/  \+/\t/g;s/^\([^\t]*\)\t\(Re: \?\)\?\([^\t]*\)[\t ].*/\3/'`
        box=`echo "$L"  | sed 's/  \+/\t/g;s/^\([^\t]*\)\t\([^\t]*\)[\t ]\([^\t]*\).*/\3/'`
        notify-send -t 10000 $iconcommand "Mail from $name" "$subject\n-\nIn your $box."
    fi
done < <(cat alpine.fifo)

The rest of it is a little large to post here, so anyone who's interested can just get it at the repo.