Page 1 of 2

Display new mails count of any mailbox

Posted: May 28th, 2016, 3:04 pm
by mistic100
Hello

Here is a simple trick to display the number of new mails in your Gmail, Outlook, IMAP, etc. mailboxes.
It is based on https://nylas.com cloud API (which can be hosted on your own server if you care about absolute privacy).
  1. Register on Nylas Developer Program https://developer.nylas.com/register
  2. On the "Accounts" tab of the developer console, add your mail account, any big provider is supported as well as any IMAP account
  3. You will be given an access token store it preciously, you won't be able to get it later (unless deleting the account)
  4. Now simply use the WebParser plugin with basic auth to get the mail count

Code: Select all

[mMailCount]
Measure=Plugin
Plugin=WebParser
UpdateRate=60
URL=https://YOUR_TOKEN@api.nylas.com/threads?in=inbox&view=count&unread=true
RegExp=(?siU)"count": ([0-9]+)
StringIndex=1
Have fun

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 1:00 pm
by mistic100
Yesterday it was working well, but today I systematically get an error in WebParser dump :

Code: Select all

{
  "message": "Could not verify access credential.",
  "type": "invalid_request_error"
}
though it works when I access the API with Firefox.

Perhaps the Rainmeter User-Agent got blacklisted.

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 1:03 pm
by jsmorley
mistic100 wrote:Yesterday it was working well, but today I systematically get an error in WebParser dump :

Code: Select all

{
  "message": "Could not verify access credential.",
  "type": "invalid_request_error"
}
though it works when I access the API with Firefox.

Perhaps the Rainmeter User-Agent got blacklisted.
Perhaps, or you might have overrun some hourly/daily/monthly limit on calls to the API during your testing.

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 1:09 pm
by mistic100
I don't think so, it still works from the browser or curl

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 1:17 pm
by jsmorley
You might be able to actually use cURL.exe with the RunCommand plugin and get the information that way. Either directly from STDOUT with RunCommand and RegExpSubstitute, or by downloading the XML to a file and using WebParser to parse the local file created. I believe in cURL you can set any User Agent string you want.

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 1:21 pm
by mistic100
Interesting, I'll try, thank you.

I also contacted Nylas support to know if there was any changes in the BasicAuth process.

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 2:53 pm
by mistic100
Working measure with curl :

Code: Select all

[mMailCountTick]
Measure=Calc
UpdateDivider=60
OnUpdateAction=[!CommandMeasure mMailCount "Run"]

[mMailCount]
Measure=Plugin
Plugin=RunCommand
Parameter=curl -s "https://#Token#@api.nylas.com/threads?in=inbox&view=count&unread=true"
OutputType=ANSI
RegExpSubstitute=1
Substitute='"count": ':"","{":"","}":""," ":"","#CRLF#":""

Re: Display new mails count of any mailbox

Posted: May 29th, 2016, 3:00 pm
by jsmorley
Cool beans...

Re: Display new mails count of any mailbox

Posted: June 1st, 2016, 1:39 pm
by jsmorley
FYI, we have added the capability to set a custom User Agent String to WebParser, so you won't need to us cURL for this purpose going forward.

https://forum.rainmeter.net/viewtopic.php?p=124153#p124153

Re: Display new mails count of any mailbox

Posted: June 1st, 2016, 2:17 pm
by mistic100
I'm not 100% sure the problem is the user agent but a redirection with cookie auth.