List of usage examples for javax.mail FolderClosedException FolderClosedException
public FolderClosedException(Folder folder, String message)
From source file:com.sun.mail.pop3.POP3Folder.java
/** * Prefetch information about POP3 messages. * If the FetchProfile contains <code>UIDFolder.FetchProfileItem.UID</code>, * POP3 UIDs for all messages in the folder are fetched using the POP3 * UIDL command./* www . j a v a 2s. co m*/ * If the FetchProfile contains <code>FetchProfile.Item.ENVELOPE</code>, * the headers and size of all messages are fetched using the POP3 TOP * and LIST commands. */ public synchronized void fetch(Message[] msgs, FetchProfile fp) throws MessagingException { checkReadable(); if (!doneUidl && fp.contains(UIDFolder.FetchProfileItem.UID)) { /* * Since the POP3 protocol only lets us fetch the UID * for a single message or for all messages, we go ahead * and fetch UIDs for all messages here, ignoring the msgs * parameter. We could be more intelligent and base this * decision on the number of messages fetched, or the * percentage of the total number of messages fetched. */ String[] uids = new String[message_cache.size()]; try { if (!port.uidl(uids)) return; } catch (EOFException eex) { close(false); throw new FolderClosedException(this, eex.toString()); } catch (IOException ex) { throw new MessagingException("error getting UIDL", ex); } for (int i = 0; i < uids.length; i++) { if (uids[i] == null) continue; POP3Message m = (POP3Message) getMessage(i + 1); m.uid = uids[i]; } doneUidl = true; // only do this once } if (fp.contains(FetchProfile.Item.ENVELOPE)) { for (int i = 0; i < msgs.length; i++) { try { POP3Message msg = (POP3Message) msgs[i]; // fetch headers msg.getHeader(""); // fetch message size msg.getSize(); } catch (MessageRemovedException mex) { // should never happen, but ignore it if it does } } } }
From source file:com.sun.mail.pop3.POP3Folder.java
/** * Return the unique ID string for this message, or null if * not available. Uses the POP3 UIDL command. * * @return unique ID string/*from ww w . j av a2s. c o m*/ * @exception MessagingException */ public synchronized String getUID(Message msg) throws MessagingException { checkOpen(); POP3Message m = (POP3Message) msg; try { if (m.uid == POP3Message.UNKNOWN) m.uid = port.uidl(m.getMessageNumber()); return m.uid; } catch (EOFException eex) { close(false); throw new FolderClosedException(this, eex.toString()); } catch (IOException ex) { throw new MessagingException("error getting UIDL", ex); } }
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
@Test public void testIdleReconnects() throws Exception { ImapMailReceiver receiver = spy(new ImapMailReceiver("imap:foo")); receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet();//from ww w . ja v a 2 s. co m IMAPFolder folder = mock(IMAPFolder.class); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); given(folder.isOpen()).willReturn(false).willReturn(true); given(folder.exists()).willReturn(true); given(folder.hasNewMessages()).willReturn(true); Field storeField = AbstractMailReceiver.class.getDeclaredField("store"); storeField.setAccessible(true); Store store = mock(Store.class); given(store.isConnected()).willReturn(false); given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder); storeField.set(receiver, store); ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(receiver); Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class)); new DirectFieldAccessor(adapter).setPropertyValue("logger", logger); willDoNothing().given(logger).warn(anyString(), any(Throwable.class)); willAnswer(i -> { i.callRealMethod(); throw new FolderClosedException(folder, "test"); }).given(receiver).waitForNewMessages(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.initialize(); adapter.setTaskScheduler(taskScheduler); adapter.setReconnectDelay(50); adapter.afterPropertiesSet(); final CountDownLatch latch = new CountDownLatch(3); adapter.setApplicationEventPublisher(e -> { latch.countDown(); }); adapter.start(); assertTrue(latch.await(60, TimeUnit.SECONDS)); verify(store, atLeast(3)).connect(); taskScheduler.shutdown(); }