Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I use alpine as my primary mail reader. While I spend most of my day in the terminal or emacs, it would still be nice to get pretty notification of new mail using notify-bin. Is there any way I can configure alpine to run a custom command when new mail is recieved?

share|improve this question

4 Answers 4

up vote 6 down vote accepted

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.

share|improve this answer
    
nice solution :-) –  echox Oct 2 '10 at 20:02
    
Awesome. I wrote a small shell script to do essentially the same thing. –  Steven D Oct 2 '10 at 20:12
    
@steven: I'd vote for it if you'd be kind enough to share it. :-) –  Bruce Connor Aug 18 '11 at 13:58
    
Nevermind, I ended up writing one as well. –  Bruce Connor Aug 18 '11 at 17:44

Can't you use a specialized mail-notification tool like Gnubiff, mail-notification or kbiff?

share|improve this answer

It is not possible to customize the "new mail notification" of alpine.

There is no such option mentioned in the configuration documentation.

Also here is a quote from the mailinglist from Eduardo Chappa:

I've noticed that alpine gives a visual alert in gnome terminal by flashing the screen, when a new mail arrives. Is there any way to customise the alert, so that, for instance, it plays a sound or something?

[..]

Alpine, as you can guess now, will only beep. In Web Alpine it is possible to send a file to be played (to the browser) for new mail notification. There is no such feature in Unix, Mac or Windows Alpine.

Your options are now:

And to quote the developer of my favorit mail client:

All mailclients suck...

:-)

share|improve this answer

Update:
I wasn't satisfied with my previous answer, so I improved the script a lot and made a github page 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.

share|improve this answer
    
Bruce, thanks for sharing the script! Now I know how to read and process messages from FIFO while keeping it open in shell. Could not figure it out while setting up a notifier for myself :) –  Linulin Sep 21 '11 at 23:13
    
@Linulin Cool. =) Unfortunately the filters I used for setting content and name are a little buggy in some cases., which is a little silly since they're the reason I posted the answer at all. =P –  Bruce Connor Sep 22 '11 at 13:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.