use of com.google.api.services.gmail.Gmail.Users.Messages in project data-transfer-project by google.
the class GoogleMailService method export.
// This currently exports each message with associated labels
@Override
public MailModelWrapper export(ExportInformation exportInformation) throws IOException {
Messages.List request = gmail.users().messages().list(USER).setMaxResults(MAX_RESULTS_PER_REQUEST);
if (exportInformation.getPaginationInformation().isPresent()) {
request.setPageToken(((StringPaginationToken) exportInformation.getPaginationInformation().get()).getId());
}
ListMessagesResponse response = request.execute();
List<MailMessageModel> results = new ArrayList<>(response.getMessages().size());
// as we can't store all the mail messagess in memory at once.
for (Message listMessage : response.getMessages()) {
Message getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute();
// TODO: note this doesn't transfer things like labels
results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds()));
}
PaginationInformation pageInfo = null;
if (response.getNextPageToken() != null) {
pageInfo = new StringPaginationToken(response.getNextPageToken());
}
// TODO: export by label or by message?
return new MailModelWrapper(null, results, new ContinuationInformation(null, pageInfo));
}
Aggregations