.execute(); LOGGER.fine("==Fetched message "+fetched.getId()); HashMap<String, MessagePart> toDownload = new HashMap<>();
/** * Gets the specified message. * * Create a request for the method "messages.get". * * This request holds the parameters needed by the gmail server. After setting any optional * parameters, call the {@link Get#execute()} method to invoke the remote operation. * * @param userId The user's email address. The special value me can be used to indicate the authenticated user. * [default: me] * @param id The ID of the message to retrieve. * @return the request */ public Get get(java.lang.String userId, java.lang.String id) throws java.io.IOException { Get result = new Get(userId, id); initialize(result); return result; }
/** * 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; }
@Before public void setup() throws IOException { googleMailExporter = new GoogleMailExporter(googleCredentialFactory, gmail); when(gmail.users()).thenReturn(users); when(users.messages()).thenReturn(messages); when(messages.list(Matchers.anyString())).thenReturn(messageListRequest); when(messageListRequest.setMaxResults(Matchers.anyLong())).thenReturn(messageListRequest); when(messages.get(Matchers.anyString(), Matchers.anyString())).thenReturn(get); when(get.setFormat(Matchers.anyString())).thenReturn(get); verifyZeroInteractions(googleCredentialFactory); }
/** * Sets up a response with a single message */ private void setUpSingleMessageResponse() throws IOException { messageListResponse = new ListMessagesResponse() .setMessages(Collections.singletonList(INITIAL_MESSAGE)); when(messageListRequest.execute()).thenReturn(messageListResponse); when(get.execute()).thenReturn(FULL_MESSAGE); } }