Search in sources :

Example 1 with Messages

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));
}
Also used : ListMessagesResponse(com.google.api.services.gmail.model.ListMessagesResponse) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Messages(com.google.api.services.gmail.Gmail.Users.Messages) Message(com.google.api.services.gmail.model.Message) ArrayList(java.util.ArrayList) MailModelWrapper(org.dataportabilityproject.dataModels.mail.MailModelWrapper) MailMessageModel(org.dataportabilityproject.dataModels.mail.MailMessageModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Aggregations

Messages (com.google.api.services.gmail.Gmail.Users.Messages)1 ListMessagesResponse (com.google.api.services.gmail.model.ListMessagesResponse)1 Message (com.google.api.services.gmail.model.Message)1 ArrayList (java.util.ArrayList)1 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)1 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)1 MailMessageModel (org.dataportabilityproject.dataModels.mail.MailMessageModel)1 MailModelWrapper (org.dataportabilityproject.dataModels.mail.MailModelWrapper)1 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)1