use of com.google.api.services.gmail.model.Message in project camel by apache.
the class GmailUsersThreadsIntegrationTest method testList.
@Test
public void testList() throws Exception {
Message m1 = createThreadedTestEmail(null);
Message m2 = createThreadedTestEmail(m1.getThreadId());
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
com.google.api.services.gmail.model.ListThreadsResponse result = requestBodyAndHeaders("direct://LIST", CURRENT_USERID, headers);
assertNotNull("list result", result);
assertTrue(result.getThreads().size() > 0);
LOG.debug("list: " + result);
headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", m1.getThreadId());
requestBodyAndHeaders("direct://DELETE", null, headers);
}
use of com.google.api.services.gmail.model.Message in project wildfly-camel by wildfly-extras.
the class GoogleMailIntegrationTest method createThreadedMessage.
private static Message createThreadedMessage(String previousThreadId, String subject, ProducerTemplate template) throws MessagingException, IOException {
Message message = createMessage(template, subject);
if (previousThreadId != null) {
message.setThreadId(previousThreadId);
}
Map<String, Object> headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is com.google.api.services.gmail.model.Message
headers.put("CamelGoogleMail.content", message);
return template.requestBodyAndHeaders("google-mail://messages/send", null, headers, Message.class);
}
use of com.google.api.services.gmail.model.Message in project wildfly-camel by wildfly-extras.
the class GoogleMailIntegrationTest method createMessage.
private static Message createMessage(ProducerTemplate template, String subject) throws MessagingException, IOException {
Profile profile = template.requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID, Profile.class);
Session session = Session.getDefaultInstance(new Properties(), null);
MimeMessage mm = new MimeMessage(session);
mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
mm.setSubject(subject);
mm.setContent(//
"Camel rocks!\n" + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + //
"\n" + "user: " + System.getProperty("user.name"), "text/plain");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mm.writeTo(baos);
String encodedEmail = Base64.getUrlEncoder().encodeToString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
use of com.google.api.services.gmail.model.Message in project wildfly-camel by wildfly-extras.
the class GoogleMailIntegrationTest method messages.
@Test
public void messages() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
GoogleMailComponent gMailComponent = camelctx.getComponent("google-mail", GoogleMailComponent.class);
GoogleApiEnv.configure(gMailComponent.getConfiguration(), getClass(), LOG);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
final String pathPrefix = "messages";
// test route for attachments
from("direct://ATTACHMENTS").to("google-mail://" + pathPrefix + "/attachments");
// test route for delete
from("direct://DELETE").to("google-mail://" + pathPrefix + "/delete");
// test route for get
from("direct://GET").to("google-mail://" + pathPrefix + "/get");
// test route for gmailImport
from("direct://GMAILIMPORT").to("google-mail://" + pathPrefix + "/gmailImport");
// test route for gmailImport
from("direct://GMAILIMPORT_1").to("google-mail://" + pathPrefix + "/gmailImport");
// test route for insert
from("direct://INSERT").to("google-mail://" + pathPrefix + "/insert");
// test route for insert
from("direct://INSERT_1").to("google-mail://" + pathPrefix + "/insert");
// test route for list
from("direct://LIST").to("google-mail://" + pathPrefix + "/list?inBody=userId");
// test route for modify
from("direct://MODIFY").to("google-mail://" + pathPrefix + "/modify");
// test route for send
from("direct://SEND").to("google-mail://" + pathPrefix + "/send");
// test route for send
from("direct://SEND_1").to("google-mail://" + pathPrefix + "/send");
// test route for trash
from("direct://TRASH").to("google-mail://" + pathPrefix + "/trash");
// test route for untrash
from("direct://UNTRASH").to("google-mail://" + pathPrefix + "/untrash");
}
});
try {
camelctx.start();
ProducerTemplate template = camelctx.createProducerTemplate();
// ==== Send test email ====
final String subject = getClass().getSimpleName() + ".messages " + UUID.randomUUID().toString();
Message testEmail = createMessage(template, subject);
Map<String, Object> headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is com.google.api.services.gmail.model.Message
headers.put("CamelGoogleMail.content", testEmail);
Message result = template.requestBodyAndHeaders("direct://SEND", null, headers, Message.class);
Assert.assertNotNull("send result", result);
String testEmailId = result.getId();
// ==== Search for message we just sent ====
headers = new HashMap<>();
headers.put("CamelGoogleMail.q", "subject:\"" + subject + "\"");
// using String message body for single parameter "userId"
ListMessagesResponse listOfMessages = template.requestBody("direct://LIST", CURRENT_USERID, ListMessagesResponse.class);
Assert.assertTrue(idInList(testEmailId, listOfMessages));
// ===== trash it ====
headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
template.requestBodyAndHeaders("direct://TRASH", null, headers);
// ==== Search for message we just trashed ====
headers = new HashMap<>();
headers.put("CamelGoogleMail.q", "subject:\"" + subject + "\"");
// using String message body for single parameter "userId"
listOfMessages = template.requestBody("direct://LIST", CURRENT_USERID, ListMessagesResponse.class);
Assert.assertFalse(idInList(testEmailId, listOfMessages));
// ===== untrash it ====
headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
template.requestBodyAndHeaders("direct://UNTRASH", null, headers);
// ==== Search for message we just untrashed ====
headers = new HashMap<>();
headers.put("CamelGoogleMail.q", "subject:\"" + subject + "\"");
// using String message body for single parameter "userId"
listOfMessages = template.requestBody("direct://LIST", CURRENT_USERID, ListMessagesResponse.class);
Assert.assertTrue(idInList(testEmailId, listOfMessages));
// ===== permanently delete it ====
headers = new HashMap<>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
template.requestBodyAndHeaders("direct://DELETE", null, headers);
// ==== Search for message we just deleted ====
headers = new HashMap<>();
headers.put("CamelGoogleMail.q", "subject:\"" + subject + "\"");
// using String message body for single parameter "userId"
listOfMessages = template.requestBody("direct://LIST", CURRENT_USERID, ListMessagesResponse.class);
Assert.assertFalse(idInList(testEmailId, listOfMessages));
} finally {
camelctx.stop();
}
}
use of com.google.api.services.gmail.model.Message in project syndesis-qe by syndesisio.
the class GMailUtils method modifyMessage.
/**
* Modify the labels a message is associated with.
*
* @param userId User's email address. The special value "me"
* can be used to indicate the authenticated user.
* @param messageId ID of Message to Modify.
* @param labelsToAdd List of label ids to add.
* @param labelsToRemove List of label ids to remove.
* @throws IOException when something goes wrong
*/
public void modifyMessage(String userId, String messageId, List<String> labelsToAdd, List<String> labelsToRemove) throws IOException {
ModifyMessageRequest mods = new ModifyMessageRequest().setAddLabelIds(labelsToAdd).setRemoveLabelIds(labelsToRemove);
Message message = getClient().users().messages().modify(userId, messageId, mods).execute();
log.info("Message with id: " + message.getId() + "was modified");
log.debug(message.toPrettyString());
}
Aggregations