whomba
whomba

Reputation: 387

Accessing New messages from Yahoo Mail using YQL

I am currently writing a JAVA application in which I need to access the following information from users Yahoo email messages (to display back to them). YQL looked like a 'quick easy way' to do this, however it's proving to be more difficult. All tests I ran were done here: http://developer.yahoo.com/yql/console/ I can replicate the same results using my webapp/oauth.

I am having trouble getting this all in to 1 query call (or even 2, although I have not invested as much time researching that as a solution). Here is the short of it, currently I have the following YQL:

SELECT folder.unread, message FROM ymail.msgcontent
    WHERE (fid,mids )
    IN
        (SELECT folder.folderInfo.fid, mid
        FROM ymail.messages
        WHERE numMid=2
        AND startMid=0)
        AND fid='Inbox' 
        AND message.flags.isRead=0;

This works the best out of all the solutions I have, however there is one major crippling flaw. If we have 10 emails, E1 - E10 and they are all unread with the exception of E2,E3 then after running that query, the result set will show E1, not E1, E4. Obviously this is not good. So I tried plugging the "AND message.flags.isRead=0" in the sub select:

SELECT folder.unread, message FROM ymail.msgcontent
    WHERE (fid,mids )
    IN
        (SELECT folder.folderInfo.fid, mid
        FROM ymail.messages
        WHERE numMid=10
        AND startMid=0 
        AND message.flags.isRead=0)
        AND fid='Inbox' 

However, this Yields 'null' as a result. In order to debug this I just run the sub select and come up with this:

SELECT folder.folderInfo.fid, mid
FROM ymail.messages
WHERE numMid=10
AND startMid=0 
AND messageInfo.flags.isRead=0

This query returns 10, unfortunately after further review, it does not filter out the read VS unread. After some more toying around I change the select statement to the following query:

SELECT folder.folderInfo.fid, messageInfo.mid
FROM ymail.messages
WHERE numMid=10
AND startMid=0 
AND messageInfo.flags.isRead=0

Finally, this works! EXCEPT 47 emails are returned instead of just 10. and to make things more interesting, I know for a fact I have 207 (unread) emails in my inbox, so why 47?? I have changed the 'numMid' (think of this as how many to show) from 0 - 300 and startMid (how many emails in to start, like an offset) from 0 - 300 and neither change the result set count. Of course when i change the select statement back from 'messageInfo.mid' to 'mid' the numMid / startMid 'work' again, however the filtering fromt he isRead no longer works. I know there are other solutions where I set numMid=50000 or something along those lines, however YQL is a bit slow to begin with, and I can only imagine that this will slow it down significantly.

So the question is, has any one done this? Is YQL just broke / not maintained or am I doing something wrong?

Thank you!

EDIT: Apparently this '47' that shows up is from the top 50 emails I have, 3 of which are read. I have yet to figure out how to 'trick' the YQL to allow me to override this 50 limit.

Upvotes: 4

Views: 912

Answers (1)

Karan Ashar
Karan Ashar

Reputation: 1400

Bit late but I think I have the answer to your question.

Your query is query is almost correct except for the numInfo query parameter. Try changing the query to

SELECT * FROM ymail.messages WHERE numMid=75 AND startMid=0 AND numInfo=75 AND messageInfo.flags.isRead=0

Notice the numInfo=75. This should get you the last 75 unread messages. To read more about different query parameters refer to official documentation here

EDIT 1
The table ymail.messages should return unread messages by default. There is a GroupBy parameter which you should use if you want to get unread messages. Find documentation here

Upvotes: 0

Related Questions