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 received?
4 Answers
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.
-
-
Awesome. I wrote a small shell script to do essentially the same thing.– Steven DOct 2, 2010 at 20:12
-
1
-
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.
-
1Bruce, 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 :)– LinulinSep 21, 2011 at 23:13
-
@Linulin Cool. =) Unfortunately the filters I used for setting
content
andname
are a little buggy in some cases., which is a little silly since they're the reason I posted the answer at all. =P Sep 22, 2011 at 13:15 -
It is awesome to see shell used so well. Thanks for posting it on github. Bravo!– chicksMar 18, 2015 at 5:21
Can't you use a specialized mail-notification tool like Gnubiff, mail-notification or kbiff?
-
I would like to use mail-notification to achieve something similar, however I cannot find any documentation on how to customize the mail-notification new-mail command. Jun 23, 2016 at 15:14
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:
- write a feature request to the alpine-info mailinglist
- get the sources and write a patch
- use an external tool like Mail Notification
And to quote the developer of my favorit mail client:
All mailclients suck...
:-)