How to display email subjects in an fvwm menu.

I got tired of opening and email client everytime i got new mail just to have it be SPAM. So i wrote up alittle something that will display the subject of all your new and/or old mail in a your mail box. The only requirement is that your mail box be in maildir format ( new cur tmp).

Heres what you have to add to your .fvwm2rc file. Edit the path to the file. The default location is /home/$USER/.fvwm/scripts/

AddToMenu FvwmNewMailMenu
+ DynamicPopupAction Function FvwmNewMailMenu

DestroyFunc FvwmNewMailMenu
AddToFunc FvwmNewMailMenu
+ I DestroyMenu recreate FvwmNewMailMenu
+ I AddToMenu FvwmNewMailMenu
+ I PipeRead '/home/$USER/.fvwm/scripts/ new'

AddToMenu FvwmOldMailMenu
+ DynamicPopupAction Function FvwmOldMailMenu

DestroyFunc FvwmOldMailMenu
AddToFunc FvwmOldMailMenu
+ I DestroyMenu recreate FvwmOldMailMenu
+ I AddToMenu FvwmOldMailMenu
+ I PipeRead '/home/$USER/.fvwm/scripts/ old'

DestroyMenu MenuFvwmMail
AddToMenu   MenuFvwmMail
+ "New Mails" Popup FvwmNewMailMenu
+ "Old Mails" Popup FvwmOldMailMenu

Then add this to your root menu

+ "Check Mails" Popup MenuFvwmMail

And heres the bash script. You need to edit the mail_path so that it points to your maildir. Default is /home/$USER/Mail.

case $1 in
	for new in `ls $mail_path/new/*` 
			echo "+ \"`cat $new|grep Subject:| fold -w 35 | head -n 1`\" Nop" 
		done ;;
	old) for cur in `ls $mail_path/cur/*` 
			echo "+ \"`cat $cur|grep Subject:| fold -w 35 | head -n 1`\" Nop"
		done ;;

The only problem i have with it is i havent been able figure out how to shorten the subject down so its only a few words long. Eventually i plan on rewriting it in perl and haveing the option to read either mbox or maildir and make it an fvwm module. That will be my first major perl script. Hope you all enjoy it.


I suppose you could do something like this:

echo "+ \"`cat $new|grep Subject:`| fold -w 8 | head -n 1\" Nop"

Where “8”, above, depicts the length. There’s 1001 other ways to achieve the same thing. :slight_smile:

– Thomas Adam

Thanks ThomasAdam that works great i edited my post to add that.


You can create also a copy of each mail in your procmailrc:

:0 c * |

and pipe it to a perlscript:

[code]#!/usr/bin/perl -w

use strict;
use MIME::Parser;

my $FvwmCommand = “FvwmCommand”;
my $FvwmFunction = “MailPopup”;
my $maxlength = 60;

sub prep_string {
my $s = shift;
chomp $s;
$s = substr($s, 0, $maxlength - 1);
$s =~ s/\/\\\\/g;
$s =~ s/"/\\\"/g;
$s =~ s/$/$$/g;
return $s;

my $parser = new MIME::Parser;


my $entity = eval { $parser->parse(*STDIN) };
my $error = ($@ || $parser->last_error);

my $head = $entity->head;

my $subject = prep_string($head->get(‘Subject’));
my $from = prep_string($head->get(‘From’));
my $to = prep_string($head->get(‘To’));

my $command = “$FvwmFunction “$subject” “$from” “$to””;

open(FD, “|$FvwmCommand -c”);
print FD $command;

I use a similar script to display a menu for 20 seconds and to change an icon in my FvwmButtons Module:

btw, the MIME::Parser decodes RFC-1522 MIME headers like:

Wow Sascha that is really cool. Does it automaticly popup when you recive new mail?


Yes… I pipe every incoming mail through procmail and thus the script processes every mail as soon as it arrives…
Of course, my “real” configuration first checks where I’m logged in and then executes FvwmCommand on this hosts… But this part is very environment specific. Therefore the script only demonstrats how to parse a mail…



After seeing the shot of Sascha I though the same thing would be nice!

And I did it! It took me some time because I use a bash script and no a perl script (my knowledge is already bad in bash and zero in perl…).

So Here is the bash script:


FVWM=ps -ef|grep '[f]vwm -s'

make sure we are running fvwm

if [ -n “$FVWM” ]
exit 0


cat > $tmp_mail

to=grep -v "\-To" < $tmp_mail |grep -m 1 "To:"|tr " " "_"
subject=grep -m 1 "Subject:" < $tmp_mail |tr " " "_"
from=grep -m 1 "From:" < $tmp_mail |tr " " "_"

rm $tmp_mail

fvwmfunction=‘MailPopup’\ “$from”\ “$subject”\ “$to”

echo “$fvwmfunction”|FvwmCommand -c[/code]

In procmailrc:

[code]# where the fvwm script is

Parse every incoming mail to a bash script

displaying a mailpopup when running fvwm

:0 c


In my fvwm config:


MailPopup function

Purpose: popup a FvwmButtons instance when a new mail arrives.

A bash script is responsible for the retriving of the From, Subject and

To headers of the mail. This part is higly environment dependent.


DestroyFunc MailPopup
AddToFunc MailPopup

  • I DestroyModuleConfig FvwmMail: *
  • I PipeRead “echo *FvwmMail: Geometry 350x60-70+$[StrutTop]”
  • I *FvwmMail: Columns 5
  • I *FvwmMail: Font “Shadow=0 1 SE:xft:Sans:pixelsize=11”
  • I *FvwmMail: Colorset 8
  • I *FvwmMail: Frame 0
  • I *FvwmMail: Padding 0 0
  • I *FvwmMail: Rows 3
  • I *FvwmMail: (1x3, Frame 0, Icon mail_big.png, Action (Mouse 1) Exec exec aterm -tr -bg black -fg white -trsb -sh 30 +sb -T '.: M u t t :.' -e mutt, Action (Mouse 3) Exec exec aterm -tr -bg black -fg white -trsb -sh 30 +sb -T '.: M u t t :.' -e mutt -y)
  • I *FvwmMail: (4x1, Title(Side) $0)
  • I *FvwmMail: (4x1, Title(Side) $1)
  • I *FvwmMail: (4x1, Title(Side) $2)
  • I Module FvwmButtons FvwmMail
  • I Schedule 20000 KillModule FvwmButtons FvwmMail


And you’ll get something like:



ps: the bash script might need additional debugging but it works quite well, as well as my IconBox

Hummm the test part in the bash script is creating matters! Also please notice that fvwm is run under debian with the “-s” option, so adapt.

Here is the last version of the beginning of the script, I hope this one is fine.


FVWM=ps -ef|grep '[f]vwm -s'|tr " " "_"

make sure we are running fvwm

if [ -z “$FVWM” ]
exit 0


I someone has some idea for improving it, you’re welcome!


I use fetchmail myself!

In such a case, it parses the emails and displays for 1-2 seconds, not much.

A locking mechanism seems to be hard to implement… Maybe a “+ I KillModule FvwmButtons FvwmMail” at first can be a good thing.


Since I first saw this, I’ve thought it was a brilliant idea, and Sasha’s and Bricem’s variants are just too impressive.

Anyway, here’s my take on this, which includes From: and To: headers as well as the subject.

Screenshot with no e-mails:

Screenshot with e-mails received:

[code]#! /bin/bash


Script to print mail header info in an Fvwm menu


for MMF in ls -v --color=none ${MYMAILDIR}
grep -m 1 “^From: " “${MYMAILDIR}/${MMF}” | sed 's/”/\"/g;s/^/+ %mail.png%"/;s/$/"/’
grep -m 1 “^Subject: " “${MYMAILDIR}/${MMF}” | sed 's/”/\"/g;s/^/+ “/;s/$/”/’
grep -m 1 “^To: " “${MYMAILDIR}/${MMF}” | sed 's/”/\"/g;s/^/+ “/;s/$/”/’
echo “+ “” Nop”

if [ ls ${MYMAILDIR} | wc -l -ne 0 ]
echo “Test (x + %mail_edit.png%“sylpheed-claws” Exec exec”
echo “+ %no.png%“no new e-mails””
echo “+ “” Nop”
echo “Test (x + %mail_edit.png%“sylpheed-claws” Exec exec”

Add the following chunks to your .fvwm2rc:

[code]AddToMenu MenuFvwmNewMail

  • DynamicPopupAction Function MenuFvwmNewMail

DestroyFunc MenuFvwmNewMail
AddToFunc MenuFvwmNewMail

  • I DestroyMenu recreate MenuFvwmNewMail
  • I AddToMenu MenuFvwmNewMail
  • I AddToMenu MenuFvwmNewMail “new e-mails” Title
  • I PipeRead ‘/home/$USER/bin/’


AddToMenu Scripts “scripts” Title
Test (x bash) + %mail_mailbox.png%“new e-mails” Popup MenuFvwmNewMail[/code] (this runs your e-mail client, sylpheed-claws in my case, and clears down the headers copied into ~/.newmailcount/)

[code]#! /bin/bash

Script to clear mail headers copied into ~/.newmailcount/


sylpheed-claws &

if [ -d $HOME/.newmailcount ]
if [ -e $HOME/.newmailcount/1 ]
rm -f $HOME/.newmailcount/*
exit 0
mkdir $HOME/.newmailcount

exit 0[/code]

And the following entry at the top of your .procmailrc will copy the headers of all received mail into ~/.newmailcount/

:0 ch * $HOME/.newmailcount/.

I hope you find this useful.



Wow thanks PainlessRob. that is really slick. I wish i had half the scripting abilitys as you guys. Im adding this to my config asap.


I’d like to use one of these scripts but I have one problem with all of them.

I do not recieve my mail on my computer automatically.
I have a few emailadresses (all available via imap or pop3). Is there a way to get these mails in my local inbox as soon as a mail arrives on the mailserver? or should I periodically check for new mail or something? how do you guys do this?

thanks in advance


I use fetchmail to get my email off of my pop accounts. Then i set up a cron job to check for new mail every 10 mins. Id suggest checking in to fetchmail to recieve mail. Is really easy to setup and is pretty configurealbe.


Hi Johan,

As well as fetchmail for getting mail, I use procmail to pre-sort all received mail into the correct sub-directories. You can sort by almost any criteria: the subject, who the mail is from, who it is addressed to, country of origin, attachment type, etc. And I also use procmail to copy the header of each newly received mail to a special folder (~/.newmailcount/ mentioned above) for counting new mails.