junit tests

This commit is contained in:
Ralph Soika 2023-10-05 22:55:40 +02:00
parent d8c87df5cf
commit 2de39f4e9f
5 changed files with 671 additions and 123 deletions

View file

@ -1,7 +1,11 @@
package com.alexanderlogistics; package com.alexanderlogistics;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.Store; import javax.mail.Store;
@ -12,6 +16,8 @@ import org.imixs.workflow.ItemCollection;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import com.sun.mail.imap.IMAPFolder;
import junit.framework.Assert; import junit.framework.Assert;
/** /**
@ -22,13 +28,15 @@ import junit.framework.Assert;
*/ */
public class TestIMAPAuhtenticators { public class TestIMAPAuhtenticators {
private final static Logger logger = Logger.getLogger(TestIMAPAuhtenticators.class.getName());
/** /**
* Test IMAP connect via OAuth * Test IMAP connect via OAuth for email address imixs@alexander-logistics.com
* *
* https://techcommunity.microsoft.com/t5/exchange/javamail-connecting-to-office-365-xoauth2-for-imap/m-p/1505026 * https://techcommunity.microsoft.com/t5/exchange/javamail-connecting-to-office-365-xoauth2-for-imap/m-p/1505026
*/ */
@Test @Test
public void testOutlookAuthenticator() { public void testOutlookAuthenticator_ImixsAGL() {
IMAPOutlookAuthenticator auth = new IMAPOutlookAuthenticator(); IMAPOutlookAuthenticator auth = new IMAPOutlookAuthenticator();
@ -41,10 +49,62 @@ public class TestIMAPAuhtenticators {
Properties sourceOptions = new Properties(); Properties sourceOptions = new Properties();
sourceOptions.put("microsoft.tenantid", "51e2f038-0a96-41be-801d-bb4118aa018e"); sourceOptions.put("microsoft.tenantid", "51e2f038-0a96-41be-801d-bb4118aa018e");
sourceOptions.put("microsoft.clientid", "39e9eec5-6939-47dc-9729-3438a9898e63"); sourceOptions.put("microsoft.clientid", "39e9eec5-6939-47dc-9729-3438a9898e63");
logger.info("Connect started....");
try {
Store store = auth.openMessageStore(source, sourceOptions);
Assert.assertNotNull(store);
Assert.assertTrue(store.isConnected());
logger.info("Connect OK");
// test open INBOX
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// test messages
Message[] messages = inbox.getMessages();
logger.log(Level.INFO, "... {0} new messages found", messages.length);
} catch (MessagingException e) {
e.printStackTrace();
Assert.fail();
}
}
/**
* Test IMAP connect via OAuth for email address imixs@alexander-logistics.com
*
* https://techcommunity.microsoft.com/t5/exchange/javamail-connecting-to-office-365-xoauth2-for-imap/m-p/1505026
*/
@Test
public void testOutlookAuthenticator_Imixs_bhvAGL() {
IMAPOutlookAuthenticator auth = new IMAPOutlookAuthenticator();
ItemCollection source = new ItemCollection();
source.setItemValue(DocumentImportService.SOURCE_ITEM_SERVER, "outlook.office365.com");
source.setItemValue(DocumentImportService.SOURCE_ITEM_PORT, "993");
source.setItemValue(DocumentImportService.SOURCE_ITEM_USER, "Imixs_bhv@alexander-logistics.com");
source.setItemValue(DocumentImportService.SOURCE_ITEM_PASSWORD, "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL");
Properties sourceOptions = new Properties();
sourceOptions.put("microsoft.tenantid", "51e2f038-0a96-41be-801d-bb4118aa018e");
sourceOptions.put("microsoft.clientid", "39e9eec5-6939-47dc-9729-3438a9898e63");
logger.info("Connect started....");
try { try {
Store store = auth.openMessageStore(source, sourceOptions); Store store = auth.openMessageStore(source, sourceOptions);
Assert.assertNotNull(store); Assert.assertNotNull(store);
Assert.assertTrue(store.isConnected());
logger.info("Connect OK");
// test open INBOX
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// test messages
Message[] messages = inbox.getMessages();
logger.log(Level.INFO, "... {0} new messages found", messages.length);
} catch (MessagingException e) { } catch (MessagingException e) {
e.printStackTrace(); e.printStackTrace();
Assert.fail(); Assert.fail();

View file

@ -10,6 +10,7 @@ import java.util.Properties;
import javax.mail.Folder; import javax.mail.Folder;
import javax.mail.Message; import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session; import javax.mail.Session;
import javax.mail.Store; import javax.mail.Store;
@ -29,6 +30,7 @@ import com.sun.mail.imap.IMAPFolder;
import junit.framework.Assert; import junit.framework.Assert;
/** /**
* This test shows how to access outlook via oauth2 * This test shows how to access outlook via oauth2
* *
@ -39,12 +41,78 @@ import junit.framework.Assert;
*/ */
public class TestIMAPOutlookOAuth { public class TestIMAPOutlookOAuth {
@Test private static final String TENANT_ID = "51e2f038-0a96-41be-801d-bb4118aa018e";
public void imapAccess2() { private static final String CLIENT_ID = "39e9eec5-6939-47dc-9729-3438a9898e63";
private static final String CLIENT_SECRET = "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL";
@Test
public void TestMailboxImixs() {
Store store = null;
String token = null;
try {
// try to connect...
token = getAuthToken();
Assert.assertNotNull(token);
store = connect(token, "imixs@alexander-logistics.com");
Assert.assertNotNull(store);
if (!store.isConnected()) {
// not connected!
} else {
// read inbox....
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail();
} catch (MessagingException e) {
e.printStackTrace();
Assert.fail();
}
}
@Test
public void TestMailboxImixsBHV() {
Store store = null;
String token = null;
try {
// try to connect...
token = getAuthToken();
Assert.assertNotNull(token);
store = connect(token, "Imixs_bhv@alexander-logistics.com");
Assert.assertNotNull(store);
if (!store.isConnected()) {
// not connected!
} else {
// read inbox....
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail();
} catch (MessagingException e) {
e.printStackTrace();
Assert.fail();
}
}
/**
* This method returns a connection to an javax.mail.store
*/
public Store connect(String oauth2AccessToken, String userEmailId) {
String userEmailId = "imixs@alexander-logistics.com";
try { try {
String oauth2AccessToken = getAuthToken();
String host = "outlook.office365.com"; String host = "outlook.office365.com";
String port = "993"; String port = "993";
@ -56,7 +124,6 @@ public class TestIMAPOutlookOAuth {
props.put("mail.imaps.ssl.enable", "true"); props.put("mail.imaps.ssl.enable", "true");
props.put("mail.imaps.sasl.enable", "true"); props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.port", port); props.put("mail.imaps.port", port);
props.put("mail.imaps.auth.mechanisms", "XOAUTH2"); props.put("mail.imaps.auth.mechanisms", "XOAUTH2");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2"); props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
@ -67,6 +134,10 @@ public class TestIMAPOutlookOAuth {
props.setProperty("mail.imaps.socketFactory.fallback", "false"); props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.socketFactory.port", port); props.setProperty("mail.imaps.socketFactory.port", port);
props.setProperty("mail.imaps.starttls.enable", "true"); props.setProperty("mail.imaps.starttls.enable", "true");
// optional set imap user?
// props.put("mail.imap.user", userEmailId);
props.put("mail.imaps.auth.plain.disable", "true"); props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.debug", "true"); props.put("mail.debug", "true");
props.put("mail.debug.auth", "true"); props.put("mail.debug.auth", "true");
@ -80,18 +151,12 @@ public class TestIMAPOutlookOAuth {
+ port + ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken); + port + ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken);
store.connect(host, userEmailId, oauth2AccessToken); store.connect(host, userEmailId, oauth2AccessToken);
System.out.println("IMAP connected with system properties to Host:" + host + ", Port: " + port
+ ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken);
if (store.isConnected()) { if (store.isConnected()) {
System.out.println("Connection Established using imap protocol successfully !"); System.out.println("Connection Established using imap protocol successfully !");
return store;
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
} }
System.out.println("Store.Connect failed!");
} catch (Exception e) { } catch (Exception e) {
System.out.println("Store.Connect failed with the errror: " + e.getMessage()); System.out.println("Store.Connect failed with the errror: " + e.getMessage());
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
@ -101,70 +166,8 @@ public class TestIMAPOutlookOAuth {
Assert.fail(); Assert.fail();
} }
} return null;
/**
* Tests the Imap access
*
* https://stackoverflow.com/questions/73463357/cannot-authenticate-to-imap-on-office365-using-javamail
*
* mail.store.protocol="imap" mail.imap.host="outlook.office365.com"
* mail.imap.port="993" mail.imap.ssl.enable="true"
* mail.imap.starttls.enable="true" mail.imap.auth="true"
* mail.imap.auth.mechanisms="XOAUTH2" mail.imap.user="<email box>"
*/
@Test
public void imapAccess3() {
Properties props = new Properties();
props.put("mail.store.protocol", "imap");
props.put("mail.imap.host", "outlook.office365.com");
props.put("mail.imap.port", "993");
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imap.starttls.enable", "true");
props.put("mail.imap.auth", "true");
props.put("mail.imap.auth.mechanisms", "XOAUTH2");
props.put("mail.imap.user", "imixs@alexander-logistics.com");
// props.put("mail.imaps.auth.plain.disable","true");
props.put("mail.debug", "true");
props.put("mail.debug.auth", "true");
try {
String token = getAuthToken();
Session session = Session.getInstance(props);
session.setDebug(true);
System.out.println("info: properties: " + session.getProperties().toString());
Store store = session.getStore("imap");
store.connect("outlook.office365.com", "imixs@alexander-logistics.com", token);
// IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
// inbox.open(Folder.READ_WRITE);
// Message[] messages = inbox.getMessages();
// System.out.println("..." + messages.length + " new messages found");
// messages[0].getSubject();
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
/**
* Test the getToken method
*/
@Test
public void testGetToken() {
try {
String token = getAuthToken();
System.out.println("....access token = " + token);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
} }
/** /**
@ -182,45 +185,6 @@ public class TestIMAPOutlookOAuth {
* "ClientSecret": "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL" * "ClientSecret": "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL"
* *
* } * }
*
*
*
*
*
* Hallo Herr Soika,
*
*
*
* ich habe eine neue App angelegt und hier die Berechtigungen neu gesetzt.
*
*
*
* Hier die Daten dazu:
*
*
*
* "OAuth2": {
*
* "Authority":
* https://login.microsoftonline.com/51e2f038-0a96-41be-801d-bb4118aa018e/v2.0,
*
* "ClientId": "39e9eec5-6939-47dc-9729-3438a9898e63",
*
* "ClientSecret": "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL"
*
* }
*
*
*
* Hier noch der Link zu einem Video, welches ganz gut erklärt wie das ganze
* eingebunden werden muss.
*
* Anhand dieser Anleitung bin ich ebefalls vorgegangen.
*
*
*
* https://www.youtube.com/watch?v=bMYA-146dmM&t=356s
*
* *
* *
* @return * @return
@ -229,11 +193,8 @@ public class TestIMAPOutlookOAuth {
*/ */
public String getAuthToken() throws ClientProtocolException, IOException { public String getAuthToken() throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpClient client = HttpClients.createDefault();
String tanantId = "51e2f038-0a96-41be-801d-bb4118aa018e";
String clientId = "39e9eec5-6939-47dc-9729-3438a9898e63";
String client_secret = "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL";
HttpPost loginPost = new HttpPost("https://login.microsoftonline.com/" + tanantId + "/oauth2/v2.0/token"); HttpPost loginPost = new HttpPost("https://login.microsoftonline.com/" + TENANT_ID + "/oauth2/v2.0/token");
String scopes = "https://outlook.office365.com/.default"; String scopes = "https://outlook.office365.com/.default";
// scopes="https://outlook.office365.com/IMAP.AccessAsUser.All"; // scopes="https://outlook.office365.com/IMAP.AccessAsUser.All";
// scopes="https://graph.microsoft.com/.default"; // scopes="https://graph.microsoft.com/.default";
@ -241,7 +202,7 @@ public class TestIMAPOutlookOAuth {
// https://outlook.office365.com/POP.AccessAsUser.All // https://outlook.office365.com/POP.AccessAsUser.All
// https://outlook.office365.com/IMAP.AccessAsUser.All"; // https://outlook.office365.com/IMAP.AccessAsUser.All";
String encodedBody = "client_id=" + clientId + "&scope=" + scopes + "&client_secret=" + client_secret String encodedBody = "client_id=" + CLIENT_ID + "&scope=" + scopes + "&client_secret=" + CLIENT_SECRET
+ "&grant_type=client_credentials"; + "&grant_type=client_credentials";
loginPost.setEntity(new StringEntity(encodedBody, ContentType.APPLICATION_FORM_URLENCODED)); loginPost.setEntity(new StringEntity(encodedBody, ContentType.APPLICATION_FORM_URLENCODED));
@ -261,7 +222,14 @@ public class TestIMAPOutlookOAuth {
return result; return result;
} }
public static byte[] readAllBytes(InputStream inputStream) throws IOException { /**
* Helper method to read bytes from strem
*
* @param inputStream
* @return
* @throws IOException
*/
private static byte[] readAllBytes(InputStream inputStream) throws IOException {
final int bufLen = 4 * 0x400; // 4KB final int bufLen = 4 * 0x400; // 4KB
byte[] buf = new byte[bufLen]; byte[] buf = new byte[bufLen];
int readLen; int readLen;

View file

@ -0,0 +1,382 @@
package com.alexanderlogistics;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.junit.Test;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.mail.imap.IMAPFolder;
import junit.framework.Assert;
/**
* This test shows how to access outlook via oauth2
*
* See: https://www.java-forum.org/thema/javamail-mit-oauth2-an-o365.199133/
*
* @author rsoika
*
*/
public class TestIMAPOutlookOAuth {
@Test
public void TestMailboxImixs() {
Store store = null;
String token = null;
try {
// try to connect...
token = getAuthToken();
Assert.assertNotNull(token);
store = connect(token, "imixs@alexander-logistics.com");
Assert.assertNotNull(store);
if (!store.isConnected()) {
// not connected!
} else {
// read inbox....
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail();
} catch (MessagingException e) {
e.printStackTrace();
Assert.fail();
}
}
@Test
public void TestMailboxImixsBHV() {
Store store = null;
String token = null;
try {
// try to connect...
token = getAuthToken();
Assert.assertNotNull(token);
store = connect(token, "Imixs_bhv@alexander-logistics.com");
Assert.assertNotNull(store);
if (!store.isConnected()) {
// not connected!
} else {
// read inbox....
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail();
} catch (MessagingException e) {
e.printStackTrace();
Assert.fail();
}
}
@Test
public void imapAccess2() {
String userEmailId = "imixs@alexander-logistics.com";
try {
String oauth2AccessToken = getAuthToken();
String host = "outlook.office365.com";
String port = "993";
Store store = null;
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties props = new Properties();
props.put("mail.imaps.ssl.enable", "true");
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.port", port);
props.put("mail.imaps.auth.mechanisms", "XOAUTH2");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put("mail.imaps.auth.login.disable", "true");
props.put("mail.imaps.auth.plain.disable", "true");
props.setProperty("mail.imaps.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.socketFactory.port", port);
props.setProperty("mail.imaps.starttls.enable", "true");
props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.debug", "true");
props.put("mail.debug.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
store = session.getStore("imaps");
System.out.println("OAUTH2 IMAP trying to connect with system properties to Host:" + host + ", Port: "
+ port + ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken);
store.connect(host, userEmailId, oauth2AccessToken);
System.out.println("IMAP connected with system properties to Host:" + host + ", Port: " + port
+ ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken);
if (store.isConnected()) {
System.out.println("Connection Established using imap protocol successfully !");
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
// fetches all messages from the INBOX...
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
}
} catch (Exception e) {
System.out.println("Store.Connect failed with the errror: " + e.getMessage());
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
System.out.println(exceptionAsString);
Assert.fail();
}
}
/**
* Tests the Imap access
*
* https://stackoverflow.com/questions/73463357/cannot-authenticate-to-imap-on-office365-using-javamail
*
* mail.store.protocol="imap" mail.imap.host="outlook.office365.com"
* mail.imap.port="993" mail.imap.ssl.enable="true"
* mail.imap.starttls.enable="true" mail.imap.auth="true"
* mail.imap.auth.mechanisms="XOAUTH2" mail.imap.user="<email box>"
*/
@Test
public void imapAccess3() {
Properties props = new Properties();
String mail_bhv = "Imixs_bhv@alexander-logistics.com";
String mail_imixs = "imixs@alexander-logistics.com";
props.put("mail.store.protocol", "imap");
props.put("mail.imap.host", "outlook.office365.com");
props.put("mail.imap.port", "993");
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imap.starttls.enable", "true");
props.put("mail.imap.auth", "true");
props.put("mail.imap.auth.mechanisms", "XOAUTH2");
props.put("mail.imap.user", mail_bhv);
// props.put("mail.imaps.auth.plain.disable","true");
props.put("mail.debug", "true");
props.put("mail.debug.auth", "true");
try {
String token = getAuthToken();
Session session = Session.getInstance(props);
session.setDebug(true);
System.out.println("info: properties: " + session.getProperties().toString());
Store store = session.getStore("imap");
store.connect("outlook.office365.com", mail_imixs, token);
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
System.out.println("..." + messages.length + " new messages found");
messages[0].getSubject();
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
/**
* Test the getToken method
*/
@Test
public void testGetToken() {
try {
String token = getAuthToken();
System.out.println("....access token = " + token);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
/**
* This method returns a connection to an javax.mail.store
*/
public Store connect(String oauth2AccessToken, String userEmailId) {
try {
String host = "outlook.office365.com";
String port = "993";
Store store = null;
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties props = new Properties();
props.put("mail.imaps.ssl.enable", "true");
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.port", port);
props.put("mail.imaps.auth.mechanisms", "XOAUTH2");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put("mail.imaps.auth.login.disable", "true");
props.put("mail.imaps.auth.plain.disable", "true");
props.setProperty("mail.imaps.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.socketFactory.port", port);
props.setProperty("mail.imaps.starttls.enable", "true");
// optional set imap user?
// props.put("mail.imap.user", userEmailId);
props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.debug", "true");
props.put("mail.debug.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
store = session.getStore("imaps");
System.out.println("OAUTH2 IMAP trying to connect with system properties to Host:" + host + ", Port: "
+ port + ", userEmailId: " + userEmailId + ", AccessToken: " + oauth2AccessToken);
store.connect(host, userEmailId, oauth2AccessToken);
if (store.isConnected()) {
System.out.println("Connection Established using imap protocol successfully !");
return store;
}
System.out.println("Store.Connect failed!");
} catch (Exception e) {
System.out.println("Store.Connect failed with the errror: " + e.getMessage());
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
System.out.println(exceptionAsString);
Assert.fail();
}
return null;
}
/**
* Helper method to receive a Microsoft access Token
*
* https://jwt.ms/
*
* "OAuth2": {
*
* "Authority":
* https://login.microsoftonline.com/51e2f038-0a96-41be-801d-bb4118aa018e/v2.0,
*
* "ClientId": "39e9eec5-6939-47dc-9729-3438a9898e63",
*
* "ClientSecret": "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL"
*
* }
*
*
* @return
* @throws IOException
* @throws ClientProtocolException
*/
public String getAuthToken() throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault();
String tanantId = "51e2f038-0a96-41be-801d-bb4118aa018e";
String clientId = "39e9eec5-6939-47dc-9729-3438a9898e63";
String client_secret = "A6x8Q~EWVUyt~gfyTHtIJf4ig.F9tajUpEEXMaCL";
HttpPost loginPost = new HttpPost("https://login.microsoftonline.com/" + tanantId + "/oauth2/v2.0/token");
String scopes = "https://outlook.office365.com/.default";
// scopes="https://outlook.office365.com/IMAP.AccessAsUser.All";
// scopes="https://graph.microsoft.com/.default";
// scopes="openid profile offline_access https://outlook.office365.com/SMTP.Send
// https://outlook.office365.com/POP.AccessAsUser.All
// https://outlook.office365.com/IMAP.AccessAsUser.All";
String encodedBody = "client_id=" + clientId + "&scope=" + scopes + "&client_secret=" + client_secret
+ "&grant_type=client_credentials";
loginPost.setEntity(new StringEntity(encodedBody, ContentType.APPLICATION_FORM_URLENCODED));
loginPost.addHeader(new BasicHeader("cache-control", "no-cache"));
CloseableHttpResponse loginResponse = client.execute(loginPost);
InputStream inputStream = loginResponse.getEntity().getContent();
byte[] response = readAllBytes(inputStream);
ObjectMapper objectMapper = new ObjectMapper();
JavaType type = objectMapper.constructType(
objectMapper.getTypeFactory().constructParametricType(Map.class, String.class, String.class));
Map<String, String> parsed = new ObjectMapper().readValue(response, type);
String result = parsed.get("access_token");
System.out.println("....access token = " + result);
return result;
}
public static byte[] readAllBytes(InputStream inputStream) throws IOException {
final int bufLen = 4 * 0x400; // 4KB
byte[] buf = new byte[bufLen];
int readLen;
IOException exception = null;
try {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
while ((readLen = inputStream.read(buf, 0, bufLen)) != -1)
outputStream.write(buf, 0, readLen);
return outputStream.toByteArray();
}
} catch (IOException e) {
exception = e;
throw e;
} finally {
if (exception == null)
inputStream.close();
else
try {
inputStream.close();
} catch (IOException e) {
exception.addSuppressed(e);
}
}
}
}

View file

@ -0,0 +1,54 @@
....access token = eyJ0eXAiOiJKV1QiLCJub25jZSI6InFSUG1IX3JneHBfdWh5UWtOTFF3T2s4SVNDRG5JdmhvRFRRRjctSlp2RjgiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzUxZTJmMDM4LTBhOTYtNDFiZS04MDFkLWJiNDExOGFhMDE4ZS8iLCJpYXQiOjE2OTY1MzczMzksIm5iZiI6MTY5NjUzNzMzOSwiZXhwIjoxNjk2NTQxMjM5LCJhaW8iOiJFMkZnWUVqTGNyZm9tYWZtZXlVc3lKVy9TMWtIQUE9PSIsImFwcF9kaXNwbGF5bmFtZSI6IklNSVhTIElNQVAiLCJhcHBpZCI6IjM5ZTllZWM1LTY5MzktNDdkYy05NzI5LTM0MzhhOTg5OGU2MyIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzUxZTJmMDM4LTBhOTYtNDFiZS04MDFkLWJiNDExOGFhMDE4ZS8iLCJvaWQiOiIxOTE3MDE0MS05ZTdiLTQ0NTgtYWQ2MC05N2E4OWNjODNiYzUiLCJyaCI6IjAuQVR3QU9QRGlVWllLdmtHQUhidEJHS29CamdJQUFBQUFBUEVQemdBQUFBQUFBQUE4QUFBLiIsInJvbGVzIjpbIklNQVAuQWNjZXNzQXNBcHAiXSwic2lkIjoiNDhmYzA2NmYtNGE5Mi00NWRkLWI2ZWQtZDNhZGM4YTRiOTg4Iiwic3ViIjoiMTkxNzAxNDEtOWU3Yi00NDU4LWFkNjAtOTdhODljYzgzYmM1IiwidGlkIjoiNTFlMmYwMzgtMGE5Ni00MWJlLTgwMWQtYmI0MTE4YWEwMThlIiwidXRpIjoiYkl6V05NSk8xRW1USHdISERfb0JBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiMDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl19.EGrkEK5sD6bWYBnaRM0zlrRdDRYb9sjCiW--6sifJcs49NXCQKeuKe6eJuhwdeDqTpHSyan92mb0encA2WvGzszclGrmCdO3eAr-2VWW34nnixeBXFGtFiib23L4iLISLJLHQz7eCcpmSXCeXuQudSgtrry7KU8S7dGZ31N_4-n5OUUVY96dVCOWBRClxCnRU_UQ7-ESQOtCdzLj6mSvThHSmao8G7dqvdSGJeOw78qJaD-JARrSYMH8jy4b2Mbj1ZncwlO8aC7hv6c2EwaUgLySXlUoOKqBgfzc1qxJTTRUeS_7Jw7alSwd43LcUhPWW5KcYrgwyp_c724nDmdTjQ
DEBUG: JavaMail version 1.6.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable STARTTLS
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: closeFoldersOnStoreFailure
OAUTH2 IMAP trying to connect with system properties to Host:outlook.office365.com, Port: 993, userEmailId: imixs@alexander-logistics.com, AccessToken: eyJ0eXAiOiJKV1QiLCJub25jZSI6InFSUG1IX3JneHBfdWh5UWtOTFF3T2s4SVNDRG5JdmhvRFRRRjctSlp2RjgiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzUxZTJmMDM4LTBhOTYtNDFiZS04MDFkLWJiNDExOGFhMDE4ZS8iLCJpYXQiOjE2OTY1MzczMzksIm5iZiI6MTY5NjUzNzMzOSwiZXhwIjoxNjk2NTQxMjM5LCJhaW8iOiJFMkZnWUVqTGNyZm9tYWZtZXlVc3lKVy9TMWtIQUE9PSIsImFwcF9kaXNwbGF5bmFtZSI6IklNSVhTIElNQVAiLCJhcHBpZCI6IjM5ZTllZWM1LTY5MzktNDdkYy05NzI5LTM0MzhhOTg5OGU2MyIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzUxZTJmMDM4LTBhOTYtNDFiZS04MDFkLWJiNDExOGFhMDE4ZS8iLCJvaWQiOiIxOTE3MDE0MS05ZTdiLTQ0NTgtYWQ2MC05N2E4OWNjODNiYzUiLCJyaCI6IjAuQVR3QU9QRGlVWllLdmtHQUhidEJHS29CamdJQUFBQUFBUEVQemdBQUFBQUFBQUE4QUFBLiIsInJvbGVzIjpbIklNQVAuQWNjZXNzQXNBcHAiXSwic2lkIjoiNDhmYzA2NmYtNGE5Mi00NWRkLWI2ZWQtZDNhZGM4YTRiOTg4Iiwic3ViIjoiMTkxNzAxNDEtOWU3Yi00NDU4LWFkNjAtOTdhODljYzgzYmM1IiwidGlkIjoiNTFlMmYwMzgtMGE5Ni00MWJlLTgwMWQtYmI0MTE4YWEwMThlIiwidXRpIjoiYkl6V05NSk8xRW1USHdISERfb0JBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiMDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl19.EGrkEK5sD6bWYBnaRM0zlrRdDRYb9sjCiW--6sifJcs49NXCQKeuKe6eJuhwdeDqTpHSyan92mb0encA2WvGzszclGrmCdO3eAr-2VWW34nnixeBXFGtFiib23L4iLISLJLHQz7eCcpmSXCeXuQudSgtrry7KU8S7dGZ31N_4-n5OUUVY96dVCOWBRClxCnRU_UQ7-ESQOtCdzLj6mSvThHSmao8G7dqvdSGJeOw78qJaD-JARrSYMH8jy4b2Mbj1ZncwlO8aC7hv6c2EwaUgLySXlUoOKqBgfzc1qxJTTRUeS_7Jw7alSwd43LcUhPWW5KcYrgwyp_c724nDmdTjQ
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [RgBSADQAUAAyADgAMQBDAEEAMAAwADIAMAAuAEQARQBVAFAAMgA4ADEALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, user=imixs@alexander-logistics.com, password=<non-null>
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: SASL client XOAUTH2
DEBUG IMAPS: SASL callback length: 2
DEBUG IMAPS: SASL callback 0: javax.security.auth.callback.NameCallback@5f683daf
DEBUG IMAPS: SASL callback 1: javax.security.auth.callback.PasswordCallback@78ffe6dc
A1 AUTHENTICATE XOAUTH2 dXNlcj1pbWl4c0BhbGV4YW5kZXItbG9naXN0aWNzLmNvbQFhdXRoPUJlYXJlciBleUowZVhBaU9pSktWMVFpTENKdWIyNWpaU0k2SW5GU1VHMUlYM0puZUhCZmRXaDVVV3RPVEZGM1QyczRTVk5EUkc1SmRtaHZSRlJSUmpjdFNscDJSamdpTENKaGJHY2lPaUpTVXpJMU5pSXNJbmcxZENJNklpMUxTVE5ST1c1T1VqZGlVbTltZUcxbFdtOVljV0pJV2tkbGR5SXNJbXRwWkNJNklpMUxTVE5ST1c1T1VqZGlVbTltZUcxbFdtOVljV0pJV2tkbGR5SjkuZXlKaGRXUWlPaUpvZEhSd2N6b3ZMMjkxZEd4dmIyc3ViMlptYVdObE16WTFMbU52YlNJc0ltbHpjeUk2SW1oMGRIQnpPaTh2YzNSekxuZHBibVJ2ZDNNdWJtVjBMelV4WlRKbU1ETTRMVEJoT1RZdE5ERmlaUzA0TURGa0xXSmlOREV4T0dGaE1ERTRaUzhpTENKcFlYUWlPakUyT1RZMU16Y3pNemtzSW01aVppSTZNVFk1TmpVek56TXpPU3dpWlhod0lqb3hOamsyTlRReE1qTTVMQ0poYVc4aU9pSkZNa1puV1VWcVRHTnlabTl0WVdadFpYbFZjM2xLVnk5VE1XdElRVUU5UFNJc0ltRndjRjlrYVhOd2JHRjVibUZ0WlNJNklrbE5TVmhUSUVsTlFWQWlMQ0poY0hCcFpDSTZJak01WlRsbFpXTT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S1U4UzdkR1ozMU5fNC1uNU9VVVZZOTZkVkNPV0JSQ2x4Q25SVV9VUTctRVNRT3RDZHpMajZtU3ZUaEhTbWFvOEc3ZHF2ZFNHSmVPdzc4cUphRC1KQVJyU1lNSDhqeTRiMk1iajFabmN3bE84YUM3aHY2YzJFd2FVZ0x5U1hsVW9PS3FCZ2Z6YzFxeEpUVFJVZVNfN0p3N2FsU3dkNDNMY1VoUFdXNUtjWXJnd3lwX2M3MjRuRG1kVGpRAQE=
A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed.
Connection Established using imap protocol successfully !
DEBUG IMAPS: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed.
DEBUG IMAPS: connection available -- size: 1
A5 SELECT INBOX
* 0 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UIDVALIDITY 14] UIDVALIDITY value
* OK [UIDNEXT 167594] The next unique identifier value
A5 OK [READ-WRITE] SELECT completed.
...0 new messages found

View file

@ -0,0 +1,84 @@
....access token = eyJ0eXAiOiJKV1QiLCJub25jZSI6ImVlQzNBUmx2SENia2NCczA2QmRacm9zNWlkWXlvc3ljNDdiUjZNMGRZeXMiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ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z0AbmZJ8XBV8KJ3q7Zm912xTy-bfEjMu-lTUSRZW5_sKIXXgEmoePjDwEbvlDLSsOoz2rGf00irI7uJMotCb7d-Ob4CCGb6m32ls5TaPTT1LfbV9oUcJ1EWOG8rDf7gml-A3y9lcbJBceHn2sR2Y2mW-JV6nII0O_Mts443lPHxiwG_fwuPkgrnntb-3ZfCfgbdLQ931lvtaZKI_7Nic5xn6o-ndlbEHpezqzF_WFSF67pRrq7iN2XKg
DEBUG: JavaMail version 1.6.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable STARTTLS
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: closeFoldersOnStoreFailure
OAUTH2 IMAP trying to connect with system properties to Host:outlook.office365.com, Port: 993, userEmailId: Imixs_bhv@alexander-logistics.com, AccessToken: eyJ0eXAiOiJKV1QiLCJub25jZSI6ImVlQzNBUmx2SENia2NCczA2QmRacm9zNWlkWXlvc3ljNDdiUjZNMGRZeXMiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzUxZTJmMDM4LTBhOTYtNDFiZS04MDFkLWJiNDExOGFhMDE4ZS8iLCJpYXQiOjE2OTY1Mzcz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Mts443lPHxiwG_fwuPkgrnntb-3ZfCfgbdLQ931lvtaZKI_7Nic5xn6o-ndlbEHpezqzF_WFSF67pRrq7iN2XKg
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [RgBSADIAUAAyADgAMQBDAEEAMAAxADcAMwAuAEQARQBVAFAAMgA4ADEALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, user=Imixs_bhv@alexander-logistics.com, password=<non-null>
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: SASL client XOAUTH2
DEBUG IMAPS: SASL callback length: 2
DEBUG IMAPS: SASL callback 0: javax.security.auth.callback.NameCallback@5f683daf
DEBUG IMAPS: SASL callback 1: javax.security.auth.callback.PasswordCallback@78ffe6dc
A1 AUTHENTICATE XOAUTH2 dXNlcj1JbWl4c19iaHZAYWxleGFuZGVyLWxvZ2lzdGljcy5jb20BYXV0aD1CZWFyZXIgZXlKMGVYQWlPaUpLVjFRaUxDSnViMjVqWlNJNkltVmxRek5CVW14MlNFTmlhMk5DY3pBMlFtUmFjbTl6Tldsa1dYbHZjM2xqTkRkaVVqWk5NR1JaZVhNaUxDSmhiR2NpT2lKU1V6STFOaUlzSW5nMWRDSTZJaTFMU1ROUk9XNU9VamRpVW05bWVHMWxXbTlZY1dKSVdrZGxkeUlzSW10cFpDSTZJaTFMU1ROUk9XNU9VamRpVW05bWVHMWxXbTlZY1dKSVdrZGxkeUo5LmV5SmhkV1FpT2lKb2RIUndjem92TD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1XSmxMVGd3TVdRdFltSTBNVEU0WVdFd01UaGxJaXdpZFhScElqb2lhV0ZDWldkQlZ6ZGZWVEpYVms5UU5IWk1jVk5CUVNJc0luWmxjaUk2SWpFdU1DSXNJbmRwWkhNaU9sc2lNRGs1TjJFeFpEQXRNR1F4WkMwMFlXTmlMV0kwTURndFpEVmpZVGN6TVRJeFpUa3dJbDE5LllZOC0zTFN0b0FPQWZMZmZ3VV9GcGhROHNuMjZ6dVJCWUVLRlp0ZllNejhTemVtUmdEQVZwRjRjR05sYURNNUxhYmxOcXBhM1VnMU5aME90MVpkdXJ3SmRKYnFlQmx6MEFibVpKOFhCVjhLSjNxN1ptOTEyeFR5LWJmRWpNdS1sVFVTUlpXNV9zS0lYWGdFbW9lUGpEd0VidmxETFNzT296MnJHZjAwaXJJN3VKTW90Q2I3ZC1PYjRDQ0diNm0zMmxzNVRhUFRUMUxmYlY5b1VjSjFFV09HOHJEZjdnbWwtQTN5OWxjYkpCY2VIbjJzUjJZMm1XLUpWNm5JSTBPX010czQ0M2xQSHhpd0dfZnd1UGtncm5udGItM1pmQ2ZnYmRMUTkzMWx2dGFaS0lfN05pYzV4bjZvLW5kbGJFSHBlenF6Rl9XRlNGNjdwUnJxN2lOMlhLZwEB
A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed.
Connection Established using imap protocol successfully !
DEBUG IMAPS: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed.
DEBUG IMAPS: connection available -- size: 1
A5 SELECT INBOX
A5 BAD User is authenticated but not connected.
A6 LOGOUT
* BYE Microsoft Exchange Server IMAP4 server signing off.
A6 OK LOGOUT completed.
javax.mail.MessagingException: A5 BAD User is authenticated but not connected.;
nested exception is:
com.sun.mail.iap.BadCommandException: A5 BAD User is authenticated but not connected.
at com.sun.mail.imap.IMAPFolder.logoutAndThrow(IMAPFolder.java:1180)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:1087)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:1001)
at com.alexanderlogistics.TestIMAPOutlookOAuth.TestMailboxImixsBHV(TestIMAPOutlookOAuth.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: com.sun.mail.iap.BadCommandException: A5 BAD User is authenticated but not connected.
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:439)
at com.sun.mail.imap.protocol.IMAPProtocol.select(IMAPProtocol.java:1252)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:1058)
... 24 more