try { getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute(); } catch (IOException e) { return new ExportResult<>(e);
private void markMessageAsRead(Message messageStub) throws IOException { ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest() .setRemoveLabelIds(Collections.singletonList("UNREAD")); service.users().messages().modify(username, messageStub.getId(), modifyMessageRequest).execute(); }
@Override public void onSuccess( Message message, HttpHeaders responseHeaders) throws IOException { System.out.format("Successfully added labels %s to %s\n", missingLabelIds.stream() .map(labelIdToNameMap::get) .collect(Collectors.joining(", ")), message.getId()); } });
@Override public void onFailure( GoogleJsonError e, HttpHeaders responseHeaders) throws IOException { System.err.format("For message: %s, got error: %s\n", message.getId(), e.toPrettyString()); }
/** * Retrieves the registration key among the unread emails * with {@code courseId} and {@code courseName} sent to the Gmail inbox. * * <p>After retrieving, marks the email as read. * * <p>If multiple emails of the same course are in the inbox, return the registration key presented in one of them. * * @return registration key (null if cannot be found). */ public String getRegistrationKeyFromUnreadEmails(String courseName, String courseId) throws IOException, MessagingException { List<Message> messageStubs = getListOfUnreadEmailOfUser(); for (Message messageStub : messageStubs) { Message message = service.users().messages().get(username, messageStub.getId()).setFormat("raw") .execute(); MimeMessage email = convertFromMessageToMimeMessage(message); if (isStudentCourseJoinRegistrationEmail(email, courseName, courseId)) { String body = getTextFromEmail(email); markMessageAsRead(messageStub); return getKey(body); } } return null; }
@Override public void onSuccess( ListMessagesResponse response, HttpHeaders responseHeaders) throws IOException { if (!response.isEmpty()) { results.putAll(localMessage, response.getMessages()); System.err.println( "For " + localMessage.getMessageId() + " got:"); response.getMessages().stream().forEach(message -> System.err.println(" message id: " + message.getId())); } } });
@Override public void onSuccess( Message responseMessage, HttpHeaders responseHeaders) throws IOException { Preconditions.checkState( message.getId().equals(responseMessage.getId()), "Message ids must be equal"); List<String> gmailMessageIds = responseMessage.getLabelIds() == null ? ImmutableList.of() : responseMessage.getLabelIds(); System.out.format("For message %s, got labels: %s\n", responseMessage.getId(), gmailMessageIds.stream() .map(id -> labelsById.getOrDefault( id, new Label().setName(id))) .map(Label::getName) .collect(Collectors.joining(", "))); message.setLabelIds(gmailMessageIds); } });
@Override public void onFailure( GoogleJsonError e, HttpHeaders responseHeaders) throws IOException { System.err.format("For message: %s, got error: %s\n", message.getId(), e.toPrettyString()); if (e.getCode() == TOO_MANY_CONCURRENT_REQUESTS_FOR_USER) { request.queue(batches.nextBatch, this); } }
.modify(user.getEmailAddress(), message.getId(), new ModifyMessageRequest() .setAddLabelIds(labelIdsToAdd)
String singleFilename = ""; Message fetched = gmailService.users().messages().get("me", message.getId()) .execute(); LOGGER.fine("==Fetched message "+fetched.getId()); HashMap<String, MessagePart> toDownload = new HashMap<>(); scanParts(fetched.getPayload().getParts(), toDownload); if(!destination.exists()){ byte[] data = entry.getValue().getBody().getAttachmentId() != null ? gmailService.users().messages().attachments().get("me", message.getId(), entry.getValue().getBody().getAttachmentId()).execute().decodeData() : entry.getValue().getBody().decodeData(); Puzzle puzzle = singleFilename.endsWith("jpz") ? puzzle.setDate(date); puzzle.setSource(source); puzzle.setSourceUrl("gmail://" + fetched.getId()); puzzle.setUpdatable(false); date = getSentDate(fetched.getPayload().getHeaders());
gmail.users().messages().get(user.getEmailAddress(), message.getId()) .setFields("id,labelIds") .queue(batch, new JsonBatchCallback<Message>() {