If you just query Yahoo's messages you won't get the content of emails, so you should use a query that looks more like this. Please note that this will query all of an account's messages, including read or archived ones.
select
message.subject,
message.receivedDate,
message.from,
message.to,
message.cc,
message.bcc,
message.part.text
from ymail.msgcontent
where (fid,mids) in (
select
folder.folderInfo.fid,
mid
from ymail.messages
)
Once you have that you just need to use the JSON pick element features described in Play's documentation. It should look something like this:
import java.util._
case class EmailMessage(
subject : String,
receivedDate : Date,
body : String,
sender : String,
recipients : List[String]
)
def yahooToEmailMessage(json:JsValue) = {
val subject = json / "result" / "message" / "subject"
val body = json / "result" / "message" / "part" / "text"
val ts = (json / "result" / "message" / "receivedDate").toLong
val receivedDate = new Date(ts * 1000L)
val sender = getRecipient(json / "result" / "message" / "to")
val to = getRecipients(json / "result" / "message" / "to")
val cc = getRecipients(json / "result" / "message" / "cc")
val bcc = getRecipients(json / "result" / "message" / "bcc")
val recipients = to ::: cc ::: bcc
EmailMessage(
subject,
receivedDate,
body,
sender,
recipients
)
}
def getRecipient(recipient:JsValue):List[String] = {
val name = recipient / "name"
val email = recipient / "email"
name + " <" + email + ">"
}
def getRecipients(array:JsArray):List[String] = {
array.foldLeft(List[String]()) {
(list,recipient) => list ::: List(getRecipient(recipient))
}
}