本文整理了Java中javax.mail.Store.getFolder()
方法的一些代码示例,展示了Store.getFolder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Store.getFolder()
方法的具体详情如下:
包路径:javax.mail.Store
类名称:Store
方法名:getFolder
[英]Return the Folder object corresponding to the given name. Note that a Folder object is returned even if the named folder does not physically exist on the Store. The exists()
method on the folder object indicates whether this folder really exists.
Folder objects are not cached by the Store, so invoking this method on the same name multiple times will return that many distinct Folder objects.
[中]返回与给定名称对应的文件夹对象。请注意,即使指定的文件夹实际上不存在于存储中,也会返回文件夹对象。folder对象上的exists()
方法指示此文件夹是否确实存在。
存储区不会缓存文件夹对象,因此对同一名称多次调用此方法将返回许多不同的文件夹对象。
代码示例来源:origin: oblac/jodd
/**
* Just returns a folder, w/o opening.
*/
public Folder getFolder(final String folder) {
try {
return getService().getFolder(folder);
} catch (MessagingException e) {
throw new MailException("Folder not found: " + folder, e);
}
}
代码示例来源:origin: stackoverflow.com
Properties props = new Properties();
//IMAPS protocol
props.setProperty(“mail.store.protocol”, “imaps”);
//Set host address
props.setProperty(“mail.imaps.host”, imaps.gmail.com);
//Set specified port
props.setProperty(“mail.imaps.port”, “993″);
//Using SSL
props.setProperty(“mail.imaps.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”);
props.setProperty(“mail.imaps.socketFactory.fallback”, “false”);
//Setting IMAP session
Session imapSession = Session.getInstance(props);
Store store = imapSession.getStore(“imaps”);
//Connect to server by sending username and password.
//Example mailServer = imap.gmail.com, username = abc, password = abc
store.connect(mailServer, account.username, account.password);
//Get all mails in Inbox Forlder
inbox = store.getFolder(“Inbox”);
inbox.open(Folder.READ_ONLY);
//Return result to array of message
Message[] result = inbox.getMessages();
代码示例来源:origin: oblac/jodd
/**
* Opens new folder and closes previously opened folder.
*
* @param folderName Folder to open
*/
public void useFolder(final String folderName) {
closeFolderIfOpened(folder);
try {
this.folderName = folderName;
this.folder = getService().getFolder(folderName);
try {
folder.open(Folder.READ_WRITE);
} catch (final MailException ignore) {
folder.open(Folder.READ_ONLY);
}
} catch (final MessagingException msgexc) {
throw new MailException("Failed to connect to folder: " + folderName, msgexc);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Returns all subfolders of the folder folder
*
* @param folder
* target folder
* @return sub folders
*/
public String[] returnAllFolders( String folder ) throws KettleException {
Folder dfolder = null;
String[] retval = null;
try {
if ( Utils.isEmpty( folder ) ) {
// Default folder
dfolder = getStore().getDefaultFolder();
} else {
dfolder = getStore().getFolder( folder );
}
retval = returnAllFolders( dfolder );
} catch ( Exception e ) {
// Ignore errors
} finally {
try {
if ( dfolder != null ) {
dfolder.close( false );
}
} catch ( Exception e ) { /* Ignore */
}
}
return retval;
}
代码示例来源:origin: spring-projects/spring-integration
private Folder obtainFolderInstance() throws MessagingException {
return this.store.getFolder(this.url);
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected Folder getInbox() throws MessagingException {
return getStore().getFolder("INBOX");
}
代码示例来源:origin: com.sun.mail/javax.mail
protected Folder getInbox() throws MessagingException {
return getStore().getFolder("INBOX");
}
代码示例来源:origin: camunda/camunda-bpm-platform
return store.getFolder(url);
代码示例来源:origin: com.sun.mail/javax.mail
return store.getFolder(url);
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testStoreConnect() throws Exception {
AbstractMailReceiver receiver = new AbstractMailReceiver() {
@Override
protected Message[] searchForNewMessages() throws MessagingException {
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();
}
代码示例来源:origin: spring-projects/spring-integration
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;
}
代码示例来源:origin: spring-projects/spring-integration
given(folder.isOpen()).willReturn(true);
given(folder.search(Mockito.any())).willReturn(new Message[] { });
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER));
代码示例来源:origin: spring-projects/spring-integration
Store store = mock(Store.class);
given(store.isConnected()).willReturn(false);
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
storeField.set(receiver, store);
代码示例来源:origin: spring-projects/spring-integration
Store store = mock(Store.class);
given(store.isConnected()).willReturn(true);
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
storeField.set(receiver, store);
代码示例来源:origin: spring-projects/spring-integration
Store store = mock(Store.class);
given(store.isConnected()).willReturn(true);
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
storeField.set(receiver, store);
代码示例来源:origin: stackoverflow.com
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("<impap_address>","<mail ID> ", "<Password>");
inbox = store.getFolder("Inbox");
System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
inbox.open(Folder.READ_ONLY);
/* Get the messages which is unread in the Inbox*/
Message messages[] = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
代码示例来源:origin: webx/citrus
inbox = store.getFolder(getFolder());
inbox.open(Folder.READ_WRITE);
代码示例来源:origin: webx/citrus
inbox = store.getFolder(getFolder());
inbox.open(Folder.READ_WRITE);
代码示例来源:origin: org.jodd/jodd-mail
/**
* Just returns a folder, w/o opening.
*/
public Folder getFolder(final String folder) {
try {
return getService().getFolder(folder);
} catch (MessagingException e) {
throw new MailException("Folder not found: " + folder, e);
}
}
代码示例来源:origin: org.xbib.malva/malva
public void create(String folderName) throws Exception {
WithContext<Object> action = ctx -> {
Folder folder = ctx.store.getFolder(folderName);
if (!folder.exists()) {
folder.create(Folder.HOLDS_MESSAGES | Folder.READ_WRITE);
}
folder.close(false);
return null;
};
performWithContext(action);
}
内容来源于网络,如有侵权,请联系作者删除!