Last active
August 29, 2015 13:57
-
-
Save wookietreiber/9435529 to your computer and use it in GitHub Desktop.
Checks your IMAP folders for new and unread messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd "$(dirname "$0")" | |
[[ ! -d lib ]] && | |
mkdir lib | |
[[ ! -e lib/java-mail.jar ]] && | |
wget -q -O lib/java-mail.jar http://search.maven.org/remotecontent?filepath=com/sun/mail/javax.mail/1.5.1/javax.mail-1.5.1.jar | |
export JAVA_OPTS="-Xms64M -Xmx64M" | |
export DISPLAY=:0 | |
exec scala -classpath 'lib/*' -savecompiled "$(basename "$0")" "$@" | |
!# | |
import util.Properties._ | |
import util.Try | |
import sys.process._ | |
import javax.mail._ | |
val confSource = io.Source.fromFile(s"""$userHome/.scala-imap-inbox-check""") | |
val conf = confSource.getLines | |
val host = conf.next | |
val user = conf.next | |
val pass = conf.next | |
val folders = conf.toList | |
confSource.close() | |
val icon = "/usr/share/icons/gnome/32x32/status/mail-unread.png" | |
val acoustic = Seq("canberra-gtk-play","-i","message") | |
val session = Session.getDefaultInstance(System.getProperties, null) | |
for (name <- folders.par) { | |
val store = session.getStore("imaps") | |
try { | |
store.connect(host, user, pass) | |
val folder = store.getFolder(name) | |
folder.open(Folder.READ_ONLY) | |
val hasNew = folder.hasNewMessages | |
val unread = folder.getUnreadMessageCount | |
if (hasNew) { | |
val newcount = folder.getNewMessageCount | |
val visual = Seq("notify-send","-i",icon,"-u","critical","-t","5000","new mail",s"""$newcount new messages in $name""") | |
acoustic.run() | |
visual.run() | |
} | |
if (unread > 0) { | |
val visual = Seq("notify-send","-i",icon,"-u","normal","-t","5000","unread mail",s"""$unread unread messages in $name""") | |
acoustic.run() | |
visual.run() | |
} | |
folder.close(false) | |
} catch { | |
case e: Exception => | |
Seq("notify-send","-i",icon,e.getClass.getSimpleName,e.getMessage).run() | |
} finally { | |
store.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment