@Test public void importMessage() throws IOException { MailContainerResource resource = new MailContainerResource(null, Collections.singletonList(MESSAGE_MODEL)); ImportResult result = googleMailImporter.importItem(JOB_ID, null, resource); // Getting list of labels from Google verify(labelsList).execute(); // Importing message ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class); verify(messages).insert(eq(GoogleMailImporter.USER), messageArgumentCaptor.capture()); assertThat(messageArgumentCaptor.getValue().getRaw()).isEqualTo(MESSAGE_RAW); // TODO(olsona): test labels } }
results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds()));
private MimeMessage convertFromMessageToMimeMessage(Message message) throws MessagingException { byte[] emailBytes = BaseEncoding.base64Url().decode(message.getRaw()); // While we are not actually sending or receiving an email, a session is required so there will be strict parsing // of address headers when we create a MimeMessage. We are also passing in empty properties where we are expected to // supply some values because we are not actually sending or receiving any email. Session session = Session.getInstance(new Properties()); return new MimeMessage(session, new ByteArrayInputStream(emailBytes)); }
/** * Directly inserts a message into only this user's mailbox similar to IMAP APPEND, bypassing most * scanning and classification. Does not send a message. * * Create a request for the method "messages.insert". * * This request holds the parameters needed by the the gmail server. After setting any optional * parameters, call the {@link Insert#execute()} method to invoke the remote operation. <p> {@link * Insert#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must * be called to initialize this instance immediately after invoking the constructor. </p> * * @param userId The user's email address. The special value me can be used to indicate the authenticated user. * [default: me] * @param content the {@link com.google.api.services.gmail.model.Message} * @since 1.13 */ protected Insert(java.lang.String userId, com.google.api.services.gmail.model.Message content) { super(Gmail.this, "POST", REST_PATH, content, com.google.api.services.gmail.model.Message.class); this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified."); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getRaw(), "Message.getRaw()"); }
/** * Sends the specified message to the recipients in the To, Cc, and Bcc headers. * * Create a request for the method "messages.send". * * This request holds the parameters needed by the the gmail server. After setting any optional * parameters, call the {@link Send#execute()} method to invoke the remote operation. <p> {@link * Send#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must be * called to initialize this instance immediately after invoking the constructor. </p> * * @param userId The user's email address. The special value me can be used to indicate the authenticated user. * [default: me] * @param content the {@link com.google.api.services.gmail.model.Message} * @since 1.13 */ protected Send(java.lang.String userId, com.google.api.services.gmail.model.Message content) { super(Gmail.this, "POST", REST_PATH, content, com.google.api.services.gmail.model.Message.class); this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified."); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getRaw(), "Message.getRaw()"); }