You are not logged in.

#1 2008-11-09 10:40:22

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Hotmail. new unread mail script

There are a lot of gmail scripts to show new unread mails, i have one in my dwm status bar to show the number of new mails, but i use one hotmail account not so often, and i was looking for a way to find/make an script to behave like my gmail script, that only shows the number of unread mails in the account...

so far i configured GetLive, and with a "GetLive --config-file .getliverc" i get the complete output of the program, so i add grep and awk, and now the output is this

[aleyscha@aleyscha 12 ~ 08:20]$ get_hotmail 
0/0
0/0
0/0
0/0

but i only need the total amount of new unread mails, so i only need the sum of the numbers after the "/"

The bash script:

#!/bin/bash
GetLive --config-file .getliverc | grep Messages/Unread | awk '{print $1}'

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-11-09 14:34:58

Cene
Member
From: Laukaa, Finland
Registered: 2008-11-06
Posts: 16
Website

Re: Hotmail. new unread mail script

I believe the output you want to parse is something like

6/2 Messages/Unread
something else
20/1 Messages/Unread
something else
2/4 Messages/Unread
something else
2/1 Messages/Unread
something else

If so, then all it takes is just a little awk magic.. wink

Try this:

GetLive --config-file .getliverc|awk 'BEGIN{a=0}{if($0 ~ /Messages\/Unread/){a+=sprintf("%d",gensub(/[0-9]+\/([0-9]+)/,"\\1","g",$1))}}END{printf("%d",a)}'

Last edited by Cene (2008-11-09 14:36:00)

Offline

#3 2008-11-09 19:52:11

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: Hotmail. new unread mail script

it's Perfect!! the only thing is that the output is this now...

[aleyscha@aleyscha 8 ~ 17:16]$ GetLive --config-file .getliverc|awk 'BEGIN{a=0}{if($0 ~ /Messages\/Unread/){a+=sprintf("%d",gensub(/[0-9]+\/([0-9]+)/,"\\1","g",$1))}}ED{printf("%d",a)}'
Wide character in print at /usr/bin/GetLive line 1236.
1You have new mail in /var/spool/mail/aleyscha

and i don't know if there's a problem with the "You have new mail in /var/spool/mail/aleyscha" line, if i put it in an script where i only need a number


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#4 2008-11-09 20:50:33

Cene
Member
From: Laukaa, Finland
Registered: 2008-11-06
Posts: 16
Website

Re: Hotmail. new unread mail script

AFAIK the "You have new mail" message comes from your shell, not from any other script.

The warning message about "wide character in print" is given by Perl and tells that you're using print (or any other output function for that matter) on a string that contains non-ASCII UTF-8 characters (> 255). With your grep solution it is filtered by grep, but awk seems to print piped STDERR right away without processing it.

The real solution would be to tell the creator of GetLive to fix his program. A quick workaround could be to redirect STDERR to somewhere else:

GetLive --config-file .getliverc 2>/dev/null|awk 'BEGIN{a=0}{if($0 ~ /Messages\/Unread/){a+=sprintf("%d",gensub(/[0-9]+\/([0-9]+)/,"\\1","g",$1))}}END{printf("%d",a)}'

or to add no warnings 'utf8'; to GetLive script.

Last edited by Cene (2008-11-09 20:52:36)

Offline

#5 2008-11-10 10:25:16

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: Hotmail. new unread mail script

Thankyou! you're a genius tongue the only thing is that "You have new mail in /var/spool/mail/USER" line... do you know what can i do to get rid of it? is that something i'd made it to do before? or something in the default installation?


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#6 2008-11-10 12:25:28

Cene
Member
From: Laukaa, Finland
Registered: 2008-11-06
Posts: 16
Website

Re: Hotmail. new unread mail script

On default settings, some programs like fetchmail output the fetched mail to /var/spool/mail/youruser or cron mails status reports if there were any errors. If you don't want this, find out what program does this, and disable it from its configuration (or with cron, AFAIK redirecting STDERR to somewhere else should work fine).

You can read the unread mail with the command mail (..or if you're just interested in getting the message away, you could do rm -f /var/spool/mail/youruser).

Offline

#7 2008-11-10 22:38:50

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: Hotmail. new unread mail script

thank you! smile i now get it to work perfectly big_smile


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#8 2008-11-30 10:47:46

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: Hotmail. new unread mail script

ironj221 wrote:

http://www.usernameslist.com

That site has a PHP cURL script that will get the number of unread messages in your hotmail inbox.

buy now U$S19.95... neutral


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

Board footer

Powered by FluxBB