You are not logged in.
Pages: 1
Topic closed
I recently started using offlineimap/mutt to keep track of three email accounts. I wanted notifications when new email arrived so I tried some notification programs that worked with Maildir but didn't find any that I liked. So I came up with this script:
#!/bin/sh
MAILDIR1=$HOME/Email/maildir1/INBOX/new
MAILDIR2=$HOME/Email/maildir2/INBOX/new
MAILDIR3=$HOME/Email/maildir3/Inbox/new
echo "Watching $MAILDIR1"
while MAILNAME1=$(inotifywait -qe MOVED_TO --format '%f' $MAILDIR1)
do
echo $MAILNAME1
mailpop $MAILDIR1/$MAILNAME1
done&
echo "Watching $MAILDIR2"
while MAILNAME2=$(inotifywait -qe MOVED_TO --format '%f' $MAILDIR2)
do
echo $MAILNAME2
mailpop $MAILDIR2/$MAILNAME2
done&
echo "Watching $MAILDIR3"
while MAILNAME3=$(inotifywait -qe MOVED_TO --format '%f' $MAILDIR3)
do
echo $MAILNAME3
mailpop $MAILDIR3/$MAILNAME3
done
I modified a script for procmail notifications I found here http://miek.nl/posts/2008/Jun/09/a-popu … rocmailrc/ for nicely formatted notifications and added two lines to speak the notification as well.
mailpop
#!/bin/bash
# popup a small notification with 'notify-send'
from=`formail -X From: < $1`
sub=`formail -X Subject: < $1`
# tweaks < > are special
from=${from//</\(}
from=${from//>/\)}
from=${from//&/\.}
sub=${sub//</\(}
sub=${sub//>/\)}
sub=${sub//&/\.}
sub=${sub:0:200}
from=${from:0:75}
TM=2000
/usr/bin/notify-send -u normal -t $TM "$from" "$sub"
while pgrep speech2 > /dev/null; do sleep 1; done
speech2 New Email ${from%(*}, With $sub, has arrived
#echo "New Email $from, With $sub has arrived" | festival --tts
At first I used festival for speech, but Google's voice sounded so much better. This script will speak up to 100 characters, just requires mplayer:
speech2
#!/bin/bash
say() { local IFS=+;/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=en&q=$*"; }
say $*
For messages with longer subjects: http://danfountain.com/2013/03/raspberr … to-speech/
Anyone else have a script/program they like for maildir notifications? Also I would be interested in making these work as a systemd user service.
Offline
eml(){
maildirs="$HOME/Mail/*/INBOX/new/"
ml="$(find $maildirs -type f | wc -l)"
if (( ml > 0 )); then
echo -en "\x03$ml\x01"
else
echo "0"
fi
}
Prints to my statusbar...
Offline
eml(){ maildirs="$HOME/Mail/*/INBOX/new/" ml="$(find $maildirs -type f | wc -l)" if (( ml > 0 )); then echo -en "\x03$ml\x01" else echo "0" fi }
Prints to my statusbar...
Nice, I'm going to use that if I can figure how to append it to i3status.
Offline
For any other i3 users, jasonwryan script works great with i3status and i3bar useing the example from i3status manual:
i3status | while :
do
read line
echo "Email: $(eml) | $line" || exit 1
done
Edit: This is better, works with colors:
i3status | (read line && echo $line && read line && echo $line && while :
do
read line
dat=$(eml)
dat="[{ \"full_text\": \"Email: ${dat}\" },"
echo "${line/[/$dat}" || exit 1
done)
Last edited by kristopher004 (2015-03-01 18:19:00)
Offline
Using inotify would prevent needing a timed loop that either eats the cpu due to looping too fast or lags due to looping to slow. I think inotify watches can be set up in bash, but I've only used it in C.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I used inotify watches in mine, the while loops only run when inotifywait returns a value.
EDIT: I'm no bash wizard though, I'm sure there are better ways to use inotifywait, I just went by the examples I saw in the man page.
Last edited by kristopher004 (2015-03-01 17:21:02)
Offline
Oops! I need to learn to read more carefully. That looks good.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Is it possible to remove the e-mail adress from the notification and just have the name?
Offline
Yes. Did you make any attempt to do so? It's also possible to start a new thread for a completely unrelated question as opposed to necrobumping something from 2 and a half years ago.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yes. Did you make any attempt to do so? It's also possible to start a new thread for a completely unrelated question as opposed to necrobumping something from 2 and a half years ago.
Yes, but libnotify didn't really work that well with sed. `s/From://` worked, but `s/(.*)//` didn't? Completely unrelated would be asking about this in a thread about trains. And I understand that bumping old threads can sometimes be a bad idea, but I fail to see why I would be a bad idea now.
Last edited by Hund (2017-10-08 11:49:54)
Offline
Your question is simply about string manipulation in the shell. The fact that the string you want to extract from came from an email is irrelevant. There are not special tools for extracting a substring from when the source string came from an email rather than somewhere else. There are just shell commans for extracting substrings (${source% <*}).
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
It's also possible to start a new thread for a completely unrelated question as opposed to necrobumping something from 2 and a half years ago.
This. Please don't necrobump Hund.
Closing.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Pages: 1
Topic closed