title: Accessing New messages from Yahoo Mail using YQL
body: <p>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: <a href="http://developer.yahoo.com/yql/console/" rel="nofollow">http://developer.yahoo.com/yql/console/</a> I can replicate the same results using my webapp/oauth.</p>
  
  <ul>
  <li>To</li>
  <li>FromEmail</li>
  <li>FromName</li>
  <li>Subject</li>
  <li>Message</li>
  <li>Date</li>
  <li>MID</li>
  </ul>
  
  <p>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:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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' 
  </code></pre>
  
  <p>However, this Yields 'null' as a result.  In order to debug this I just run the sub select and come up with this:</p>
  
  <pre><code>SELECT folder.folderInfo.fid, mid
  FROM ymail.messages
  WHERE numMid=10
  AND startMid=0 
  AND messageInfo.flags.isRead=0
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>SELECT folder.folderInfo.fid, messageInfo.mid
  FROM ymail.messages
  WHERE numMid=10
  AND startMid=0 
  AND messageInfo.flags.isRead=0
  </code></pre>
  
  <p>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.</p>
  
  <p>So the question is, has any one done this? Is YQL just broke / not maintained or am I doing something wrong?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT</strong>: 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.</p>