List<History> histories = historyResponse.getHistory();
for (History history : histories){
if (history.getMessages() == null)
continue;
for (Message messageStub : history.getMessages()){
Message message = invokeGetMessage(gmail, email, messageStub.getId());
if (message == null)
continue;
if (historyId.compareTo(message.getHistoryId()) < 0)
historyId = message.getHistoryId();
byte[] emailBytes = Base64.decodeBase64(message.getRaw());
MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));
if (flushEntry(updateInfo, email, mimeMessage, CallLogEntryFacet.class) == null){
throw new Exception("Could not persist Call log");
}
}
}
} while (historyResponse.getNextPageToken() != null);
}
if (historyId == null){
ListMessagesResponse listResponse = null;
do{
listResponse = invokeList(gmail,email,callLogLabel.getId(),listResponse == null ? null : listResponse.getNextPageToken());
if (listResponse.getMessages() == null){
continue;
}
for (Message messageStub : listResponse.getMessages()){
Message message = invokeGetMessage(gmail, email, messageStub.getId());
if (message == null)
continue;
if (historyId == null || historyId.compareTo(message.getHistoryId()) < 0)
historyId = message.getHistoryId();
byte[] emailBytes = Base64.decodeBase64(message.getRaw());
MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));
if (flushEntry(updateInfo, email, mimeMessage, CallLogEntryFacet.class) == null){
throw new Exception("Could not persist Call log");
}