You are not logged in.

#1 2012-06-21 08:29:35

devil_kc
Member
Registered: 2008-09-14
Posts: 93

[SOLVED]maildrop notifications

Hello, could you please help me with my maildrop notifications?
i user procmail + maildrop + mutt combo and it worked great on debain, i moved my configs to arch(got back to arch after few months on deb)
the thing is  i need .mailfilter to call mail-notify script that uses notify-send to notify me about new mails.

.mailfilter part:

...
  `/home/user/bin/mail-notify`
to $INBOX

/home/user/bin/mail-notify:

#!/bin/bash

while read line
do
	echo $line
	if [ $(echo $line | grep -Ec "^Subject: ") -eq 1 ]
	then
		subject=$(echo $line | sed -r 's/^Subject: //')
	fi

	if [ $(echo $line | grep -Ec "^From: ") -eq 1 ]
	then
		from=$(echo $line | sed -r 's/^From: //')
	fi
done

fromname=$(echo $from | cut -d"<" -f1 | sed -r 's/[ ]*$//')
fromaddr=$(echo $from | cut -d"<" -f2 | sed -r 's/>$//')

if ([[ "$1" == "nagios" ]] && [[ $(echo $subject | grep -Evc "^PROBLEM") -eq 1 ]])
then
	exit
fi

export DISPLAY=":0"

notify-send -t 10000 "<span color=\"#0000FF\">You've got mail!</span>" "$(echo -e "<b>From:</b> $fromname\n<b>Address:</b> $fromaddr\n<b>Subject:</b> $subject")" &>/dev/null

% echo $DISPLAY
:0


% cat .xinitrc
numlockx on &
urxvtd -q -o -f &
setxkbmap hr &
synclient TouchpadOff=1 &
exec ck-launch-session dbus-launch awesome

could you please help?
i have whole xorg package bundle isntalled, starting X with startx. tried with slim, modified DISPLAY to :0.0 but nothing.

Last edited by devil_kc (2012-06-21 11:24:49)

Offline

#2 2012-06-21 08:31:28

devil_kc
Member
Registered: 2008-09-14
Posts: 93

Re: [SOLVED]maildrop notifications

one more thing
if i test it from terminal via
cat mail | /home/user/bin/mail-notify - it works. but looks like .mailfilter cannot call it for some reason

Offline

#3 2012-06-21 08:39:12

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [SOLVED]maildrop notifications

I don't use maildrop (going to go and look up what it is*), but di use procmail.
I get procmail to notify me of incoming mail. If that seems like a good workaround, or preferable to getting maildrop to do it, I'll post the relevant bits of my procmailrc here.


EDIT* - okay, courier maildrop? Do you need it *and* procmail? I assume you do, but it does see, to do the same thing.

Last edited by skanky (2012-06-21 08:43:04)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#4 2012-06-21 08:42:06

devil_kc
Member
Registered: 2008-09-14
Posts: 93

Re: [SOLVED]maildrop notifications

skanky, please post procmailrc, and a way how it notifys you so i can try it.

btw i tested it and maildro/.mailfiter starts mail-notify script but notify-send fails without any error.

Offline

#5 2012-06-21 08:50:24

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [SOLVED]maildrop notifications

Here's what I use:

# Used later for notifications
DISPLAY=:0
XAUTHORITY=$HOME/.Xauthority
#ONSCREEN="osd_cat --color=#fff5f2 -p middle -A center --wait --delay=5 --shadow=2 --font=lucidasans-14  -l 5 -"
ONSCREEN="notify-send --urgency=normal --app-name=mail"

I used to use osd_cat until recently when I started using dunst, so switched to using notify-send. The DISPLAY and XAUTHORITY are (I think not needed if not using osd_cat - otherwise they are needed as procmail clears the environment for security reasons. There are other ways to get round it). The osd_cat was nicked from the web - the biggest issue is that multiple incoming mail causes lots of notifications to pile up.

I then use it like this:

# Display on screen
:0 c
* ^Subject:.*\/.*
{
    SUBJECT=$MATCH
    
    :0 ih
    * ^From: .*\/[^<]*
    | $ONSCREEN  "$SUBJECT from $MATCH"  
}

# Example
:0 
* ^From: .*@(exampe.net|example.co.uk)
saved/suppliers/example/

This announces all the incoming mail, and passes the mail on to further recipes below, eg example.

EDIT:

*) put junk filter rules above the notification if you don't want to be told about stuff that's deleted.
*) I nicked it from here: http://bethesignal.org/dotfiles/procmailrc.html

Last edited by skanky (2012-06-21 09:57:38)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#6 2012-06-21 10:49:35

devil_kc
Member
Registered: 2008-09-14
Posts: 93

Re: [SOLVED]maildrop notifications

looks like it is a problem with notify-send. it wont work from console. from terminal it is ok, but from console doesn't work
strange:(
any ideas?

Offline

#7 2012-06-21 11:00:49

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [SOLVED]maildrop notifications

I might be misunderstanding you, but libnotify requires X, so I expect it needs a running X environment to work.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#8 2012-06-21 11:07:43

devil_kc
Member
Registered: 2008-09-14
Posts: 93

Re: [SOLVED]maildrop notifications

ofc, i run X but if i go to tty1(or any other) and try expord DISPLAY=:0 and then notify-send something it doesn't work - exit status is 0 but nothing is displayed on desktop

Offline

#9 2012-06-21 11:24:34

devil_kc
Member
Registered: 2008-09-14
Posts: 93

Re: [SOLVED]maildrop notifications

got it to work with xfce4-notifyd. it is ugly but it works smile

Offline

#10 2012-06-21 12:10:48

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [SOLVED]maildrop notifications

That's good. smile


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#11 2013-10-09 07:10:41

xing
Member
Registered: 2013-10-09
Posts: 1

Re: [SOLVED]maildrop notifications

maildrop sets up it's own environment variables and DISPLAY is not one of them. to fix this, simply export DISPLAY in your script and all should be fine (it is not enough to just set DISPLAY, you need to export it). e.g.:

file: $HOME/bin/mail-notify

#!/bin/sh

# maildrop doesn't have $DISPLAY set
export DISPLAY=:0;
notify-send --app-name=mail --expire-time 8000 "$( cat - | reformail -X From: -X Subject: )"
#                                                          ---------
#                                                               \
#                                                         comes with maildrop

and in your .mailfilter rules add something like this:

# to notify about all incoming mail, add this early in the file
exception {
	cc "| $HOME/bin/mail-notify"
}

# as part of a given filter
if( /^From.*@example.com/:h )
{
	exception {
		cc "|$HOME/bin/mail-notify"
	}
	to $DEFAULT/example/
}

Last edited by xing (2013-10-09 07:45:56)

Offline

Board footer

Powered by FluxBB