You are not logged in.

#1 2011-04-13 14:32:49

Markus00000
Member
Registered: 2011-03-27
Posts: 318

Mutt & OfflineIMAP: Handling new emails

I've run into two issues with Mutt and OfflineIMAP. I'm wondering how those zillions of Mutt/OfflineIMAP users are keeping up with their new emails.

1) How do I execute a command (like xmessage or aplay) when I receive an email? Do I need one of those (seemingly) complicated message-hooks?

2) Is Mutt's mailbox view the only way to get an overview of all mailboxes and their new emails? How do I make it refresh automatically (without pressing "yy")?

Offline

#2 2011-04-13 18:22:30

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Mutt & OfflineIMAP: Handling new emails

1. You can set mutt to beep on new message - this translates to an urgency hint that you can have most window managers pick up: or leave your speaker on.

2. You can write a simple script to display the number of new mails in your boxes. There is also a mutt-sidebar in AUR if that is what you are after. If by refresh, you mean check for new mail, you can runs a script from cron - see brisbin33's primer


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2011-04-13 18:28:45

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: Mutt & OfflineIMAP: Handling new emails

You could also use the inotify-tools package and listen for filesystem changes in your mail spool/inbox.

Offline

#4 2011-04-13 18:53:57

Markus00000
Member
Registered: 2011-03-27
Posts: 318

Re: Mutt & OfflineIMAP: Handling new emails

Thanks for your answers! I just found this nice script: http://www.toxahost.ru/projects.html
That's all I need for notifications.

Concerning the refreshing of the mailbox view (the one that opens with "y"). I've set Mutt to check my OfflineIMAP mailboxes frequently but no "N" flag will ever appear. Reopening the view with "yy" instantly shows the correct "N" flags. (Therefore it's not OfflineIMAP that is frozen.)

Offline

#5 2011-04-13 22:58:02

Markus00000
Member
Registered: 2011-03-27
Posts: 318

Re: Mutt & OfflineIMAP: Handling new emails

The script I linked simply counts files in the mailbox folder. If you mark a message as read and receive a message between two checks, you won't get notified. I came up with the following unpolished script:

#!/bin/sh

boxes=("$HOME/mail/a" "$HOME/mail/b")
names=("Mailbox A:" "Mailbox B:")
text=""
new_mail=false
first_check=true

while true; do
    for i in {0..1}; do
        if $first_check; then
            new=`find ${boxes[i]}/inbox/new/ -type f -print | wc -l`
        else
            new=`find ${boxes[i]}/inbox/new/ -type f -cmin -1 -print | wc -l`
        fi
        text="${text}${names[i]}\t$new\n"
        if [ $new -gt 0 ];then
            new_mail=true
        fi
    done
    if $new_mail; then
        aplay -q $HOME/notify.wav &
        echo -e "$text" | zenity --text-info --width 180 --height 170
    fi
    text=""
    new_mail=false
    first_check=false
    sleep 60
done

One issue is that a mail could arrive between "sleep 60" and "find ... -cmin -1". I guess that happens not all that often. Also if you receive 10 new emails while being away from your computer, you probably end up with ten dialogs to close...

There is also "mailcheck" in AUR: https://aur.archlinux.org/packages.php? … 7&detail=0

"inotify" could also be worth a look: http://en.wikipedia.org/wiki/Inotify (or see pyinotify: https://github.com/seb-m/pyinotify)

Last edited by Markus00000 (2011-04-13 23:13:00)

Offline

#6 2011-04-20 07:39:41

Markus00000
Member
Registered: 2011-03-27
Posts: 318

Re: Mutt & OfflineIMAP: Handling new emails

A slightly less annoying and slightly more polished notification script:

#!/bin/sh

## Time between checks
interval=60

## Mailboxes to check
boxes=("$HOME/mail/gmail1" "$HOME/mail/gmail2")

## Number of mailboxes
box_count=${#boxes[@]}

new_mail=false

## Notify upon new mail
notify () {
    if [[ $new_mail == true ]]; then
        echo -e "You have new mail!" | zenity --text-info --width 170 &
        pid=$!
        aplay -q $HOME/alarm.wav &
        new_mail=false
    fi
}

## Find the highest message ID for each mailbox
## This allows marking old messages new without notification
last_mail () {
    for (( i = 0; i < $box_count; i++ )); do
        last_cur=`ls -lr ${boxes[i]}/inbox/cur | sed -n 2p | awk -F , '{ print $2 }' | cut -c 3-`
        last_new=`ls -lr ${boxes[i]}/inbox/new | sed -n 2p | awk -F , '{ print $2 }' | cut -c 3-`
        if [[ $last_new == "" ]]; then
            last_new=0
        fi
        if [[ $last_cur -gt $last_new ]]; then
            last[i]=$last_cur
        else
            last[i]=$last_new
        fi
    done
}

last_mail

## First check: Notify if any new mail is found
for (( i = 0; i < $box_count; i++ )); do
    new=`find ${boxes[i]}/inbox/new/ -type f -print | wc -l`
    if [[ $new -gt 0 ]]; then
        new_mail=true
    fi
done
notify

## Check 2..n: Notify if a new mail (higher ID) is found and there are no previous notification windows
while true; do
    sleep $interval
    ## Check if previous notification window still open
    kill -0 $pid
    running=$?
    ## 1: closed, 0: open
    if [[ $running = "1" ]]; then
        last_previous=("${last[@]}")
        last_mail
        for (( i = 0; i < $box_count; i++ )); do
            if [[ ${last[i]} -gt ${last_previous[i]} ]]; then
                new_mail=true
            fi
        done
        notify
    else
        last_mail
    fi
done

Offline

#7 2011-07-18 18:37:19

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Mutt & OfflineIMAP: Handling new emails

Nicolas: I'm going to split the last three posts of yours out into a separate (new) thread in Community Contributions as this is really stand-alone now.

https://bbs.archlinux.org/viewtopic.php?id=122789


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB