use of jakarta.mail.Store in project spring-integration by spring-projects.
the class ImapMailReceiverTests method testAttachmentsGuts.
private Folder testAttachmentsGuts(final ImapMailReceiver receiver) throws MessagingException, IOException {
Store store = mock(Store.class);
Folder folder = mock(Folder.class);
given(folder.exists()).willReturn(true);
given(folder.isOpen()).willReturn(true);
Message message = new MimeMessage(null, new ClassPathResource("test.mail").getInputStream());
given(folder.search(Mockito.any())).willReturn(new Message[] { message });
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER));
DirectFieldAccessor df = new DirectFieldAccessor(receiver);
df.setPropertyValue("store", store);
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
return folder;
}
use of jakarta.mail.Store in project spring-integration by spring-projects.
the class MailReceiverTests method testStoreConnect.
@Test
public void testStoreConnect() throws Exception {
AbstractMailReceiver receiver = new AbstractMailReceiver() {
@Override
protected Message[] searchForNewMessages() {
return null;
}
};
Properties props = new Properties();
Session session = Session.getInstance(props);
receiver.setSession(session);
receiver.setProtocol("imap");
Store store = session.getStore("imap");
store = spy(store);
new DirectFieldAccessor(receiver).setPropertyValue("store", store);
when(store.isConnected()).thenReturn(false);
Folder folder = mock(Folder.class);
when(folder.exists()).thenReturn(true);
when(folder.isOpen()).thenReturn(false);
doReturn(folder).when(store).getFolder((URLName) null);
doNothing().when(store).connect();
receiver.openFolder();
receiver.openFolder();
verify(store, times(2)).connect();
}
use of jakarta.mail.Store in project exist by eXist-db.
the class MailStoreFunctions method getMailStore.
private Sequence getMailStore(Sequence[] args, Sequence contextSequence) throws XPathException {
Store store;
// was a session handle specified?
if (args[0].isEmpty()) {
throw (new XPathException(this, "Session handle not specified"));
}
// get the Session
long sessionHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Session session = MailModule.retrieveSession(context, sessionHandle);
if (session == null) {
throw (new XPathException(this, "Invalid Session handle specified"));
}
try {
String password = session.getProperty("mail." + session.getProperty("mail.store.protocol") + ".password");
if (password == null) {
password = session.getProperty("mail.password");
}
store = session.getStore();
store.connect(null, null, password);
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to open mail store", me));
}
return (new IntegerValue(MailModule.storeStore(context, store)));
}
use of jakarta.mail.Store in project exist by eXist-db.
the class MailStoreFunctions method closeMailStore.
private Sequence closeMailStore(Sequence[] args, Sequence contextSequence) throws XPathException {
// was a store handle specified?
if (args[0].isEmpty()) {
throw (new XPathException(this, "Store handle not specified"));
}
// get the Store
long storeHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Store store = MailModule.retrieveStore(context, storeHandle);
if (store == null) {
throw (new XPathException(this, "Invalid Store handle specified"));
}
try {
store.close();
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to close mail store", me));
} finally {
MailModule.removeStore(context, storeHandle);
}
return (Sequence.EMPTY_SEQUENCE);
}
use of jakarta.mail.Store in project exist by eXist-db.
the class MailFolderFunctions method getMailFolder.
private Sequence getMailFolder(Sequence[] args, Sequence contextSequence) throws XPathException {
Folder folder;
// was a store handle specified?
if (args[0].isEmpty() || args[1].isEmpty()) {
throw (new XPathException(this, "Store handle and/or folder name not specified"));
}
// get the Store
long storeHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Store store = MailModule.retrieveStore(context, storeHandle);
if (store == null) {
throw (new XPathException(this, "Invalid Store handle specified"));
}
// get the Folder Name
String name = args[1].getStringValue();
try {
folder = store.getFolder(name);
folder.open(Folder.READ_WRITE);
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to open mail folder", me));
}
return (new IntegerValue(MailModule.storeFolder(context, folder)));
}
Aggregations