View Single Post
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#1389
Originally Posted by Whispering Weasel View Post
Thanks, it is almost working now, I had issues with wget due to @ in the password, solved it..
Now it is only displaying the mailbox_empty.png but it does update the mailcount, simply pasting the command in the script doesn't let it return the correct state?
My programming skills are ehm.. at noob level so i got this far:

PHP Code:
if [ "$QBW_EXEC_REASON== "QBW_TIMER_UPDATE" ]; then
# get the new mail info
wget -t 1 -T 3 ---user=myusername --password=myp@ssword -'https://mail.google.com/mail/feed/atom' --no-check-certificate awk 'BEGIN{m=2}/<fullcount>.+<\/fullcount>/{gsub(/<[^>]*>/,"",$0);print $1 " New";if($1>0)m=1;else m=0}END{exit m}'
fi;

if [ 
"$QBW_EXEC_REASON== "QBW_CLICK" ]; then
# start claws-mail 
/usr/bin/dbus-send --dest=com.nokia.HildonDesktop.AppMgr /com/nokia/HildonDesktop/AppMgr com.nokia.HildonDesktop.AppMgr.LaunchApplication string:claws-mail
fi

We have a couple of issues here:
First "if block" is missing a piece because awk statement "if($1>0)m=1;else m=0}END{exit m}" just returns the exit code to the calling script... I'd add an explicit exit statement before the fi;

Second "if block" is missing a further check and an exit status; behavior here would be that for every click the beecon will launch the mail program but return a 0 exit and whatever output the dbus-send is issuing to stdout (= always mailbox_empty.png and possibly "" number of messages)

See below for a possible improvement:
PHP Code:
if [ "$QBW_EXEC_REASON== "QBW_TIMER_UPDATE" ]; then
# get the new mail info
wget -t 1 -T 3 ---user=myusername --password=myp@ssword -'https://mail.google.com/mail/feed/atom' --no-check-certificate awk 'BEGIN{m=2}/<fullcount>.+<\/fullcount>/{gsub(/<[^>]*>/,"",$0);print $1 " New";if($1>0)m=1;else m=0}END{exit m}'
exit $?
fi;

if [ 
"$QBW_EXEC_REASON== "QBW_CLICK" ]; then
# start claws-mail 
/usr/bin/dbus-send --dest=com.nokia.HildonDesktop.AppMgr /com/nokia/HildonDesktop/AppMgr com.nokia.HildonDesktop.AppMgr.LaunchApplication string:claws-mail
# get the new mail info
wget -t 1 -T 3 ---user=myusername --password=myp@ssword -'https://mail.google.com/mail/feed/atom' --no-check-certificate awk 'BEGIN{m=2}/<fullcount>.+<\/fullcount>/{gsub(/<[^>]*>/,"",$0);print $1 " New";if($1>0)m=1;else m=0}END{exit m}'
exit $?
fi
Further, you might want to manage possible error conditions from the wget command inside your awk 1-liner
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras
 

The Following 2 Users Say Thank You to No!No!No!Yes! For This Useful Post: