#!/bin/bash # File: mail_check-led.sh # check remote email accounts via SSL/TLS, turn on keyboard LED's if new mail # Important: this script is not for standard POP over port 110 # turn on all 3 keyboard LED's if there is any mail # turn them all off when no mail # run from cron every so often. # I run this from a headless Artigo (pico) box when my main box is off/asleep # Pete Nesbitt 2012 ########################## # !!! IMPORTANT !!! # # you will need to edit lines indicated below (near lines 42 & 71). ########################## ##################################################################### # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ##################################################################### ############### # Vars # EDIT the next 3 items! # Use space separated list for more than one email account # example: # SERVER=(popserver.domain1.com mail.myisp.com pop.gmail.com) # ACCOUNT=(emailname@domain1.com user1@myisp.com mymail@gmail.com) # PASSWORD=(password1 password2 password3) SERVER=() ACCOUNT=() PASSWORD=() # file to save status data in TEMP_FILE="/tmp/mailtemp.txt" # need to send led flags via a real console. We can use this to fake it. CONSOLE="/dev/console" # accounts are all ssl port 995 so can use openssl cmd PORT=995 NUM_MESSAGES=0 # initial value ############ # check status of each account for ACCT in `seq 1 ${#SERVER[*]}` do # diff servers have diff sequesnces :( # EDIT STRING_1 & STRING_2 as needed # use the section following this 'if statement' as a guide or # telnet to the server in order to see the interaction sequence. # may need to add one or more sections. Use 'elif' (commented out) below if [ ${ACCT} -eq 1 ];then #first server (strings work @ webnames.ca) STRING_1="sleep 2" STRING_2="+OK [0-9]\+ messages ([0-9]\+ bytes)" # elif [ ${ACCT} -eq 2 ];then #2 is 2nd in server list # STRING_1="" # STRING_2="" else # this works for gmail and others STRING_1='expect "+OK Welcome."' STRING_2="+OK [0-9]\+ [0-9]\+" fi let NUM=${ACCT}-1 expect << EOPOP > ${TEMP_FILE} spawn openssl s_client -connect ${SERVER[${NUM}]}:${PORT} expect "+OK" send "USER ${ACCOUNT[${NUM}]}\r" expect "+OK" send "PASS ${PASSWORD[${NUM}]}\r" ${STRING_1} send "stat\r" expect "+OK " send "quit\r" EOPOP let NUM_MESSAGES=${NUM_MESSAGES}+`grep -o "${STRING_2}" ${TEMP_FILE}|cut -d' ' -f2` done ############ # check status if [ ${NUM_MESSAGES} -ne 0 ];then setleds -D +num < ${CONSOLE} setleds -D +caps < ${CONSOLE} setleds -D +scroll < ${CONSOLE} else setleds -D -num < ${CONSOLE} setleds -D -caps < ${CONSOLE} setleds -D -scroll < ${CONSOLE} fi rm ${TEMP_FILE} exit #EOF