/** * Use the IMAP IDLE command (see * <A HREF="http://www.ietf.org/rfc/rfc2177.txt">RFC 2177</A>), * if supported by the server, to enter idle mode so that the server * can send unsolicited notifications of new messages arriving, etc. * without the need for the client to constantly poll the server. * Use an appropriate listener to be notified of new messages or * other events. When another thread (e.g., the listener thread) * needs to issue an IMAP comand for this folder, the idle mode will * be terminated and this method will return. Typically the caller * will invoke this method in a loop. <p> * * The mail.imap.minidletime property enforces a minimum delay * before returning from this method, to ensure that other threads * have a chance to issue commands before the caller invokes this * method again. The default delay is 10 milliseconds. * * @exception MessagingException if the server doesn't support the * IDLE extension * @exception IllegalStateException if the folder isn't open * * @since JavaMail 1.4.1 */ public void idle() throws MessagingException { idle(false); }
logger.fine("force folder to close"); f.forceClose(); } else { logger.fine("close folder"); f.close(false);
/** * Expunge all messages marked as DELETED. */ public synchronized Message[] expunge() throws MessagingException { return expunge(null); }
/** * Get the type of this folder. */ public synchronized int getType() throws MessagingException { if (opened) { // never throw FolderNotFoundException if folder is open if (attributes == null) exists(); // try to fetch attributes } else { checkExists(); } return type; }
checkOpened(); Message[] rmsgs = new MimeMessage[msgs.length]; AppendUID[] uids = appendUIDMessages(msgs); for (int i = 0; i < uids.length; i++) { AppendUID auid = uids[i]; if (auid.uidvalidity == uidvalidity) { try { rmsgs[i] = getMessageByUID(auid.uid); } catch (MessagingException mex) {
checkOpened(); fetch(msgs, fp); doExpungeNotification = false; // We do this ourselves later try { IMAPProtocol p = getProtocol(); if (msgs != null) p.uidexpunge(Utility.toUIDSet(msgs)); else p.expunge(); } catch (CommandFailedException cfx) { "Cannot expunge READ_ONLY folder: " + fullName); else throw new MessagingException(cfx.getMessage(), cfx); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex); } finally { doExpungeNotification = true; uidTable.remove(Long.valueOf(uid)); notifyMessageRemovedListeners(true, rmsgs); return rmsgs;
checkExists(); // verify that self exists m.getSize() > maxsize ? 0 : maxsize); } catch (IOException ex) { throw new MessagingException( "IOException while appending messages", ex); } catch (MessageRemovedException mrex) { doCommand(new ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException {
checkOpened(); throw new MessagingException( move ? "can't moveUIDMessages to a different store" : fetch(msgs, fp); IMAPProtocol p = getProtocol(); CopyUID cuid; if (move) cuid = p.moveuid(ms, folder.getFullName()); else cuid = p.copyuid(ms, folder.getFullName()); Message[] srcmsgs = getMessagesByUID(srcuids); AppendUID[] result = new AppendUID[msgs.length]; for (int i = 0; i < msgs.length; i++) { ); else throw new MessagingException(cfx.getMessage(), cfx); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (ProtocolException pex) { throw new MessagingException(pex.getMessage(), pex);
/** * Delete this folder. */ public synchronized boolean delete(boolean recurse) throws MessagingException { checkClosed(); // insure that this folder is closed. if (recurse) { // Delete all subfolders. Folder[] f = list(); for (int i = 0; i < f.length; i++) f[i].delete(recurse); // ignore intermediate failures } // Attempt to delete this folder Object ret = doCommandIgnoreFailure(new ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { p.delete(fullName); return Boolean.TRUE; } }); if (ret == null) // Non-existent folder/No permission ?? return false; // DELETE succeeded. exists = false; attributes = null; // Notify listeners on self and our Store notifyFolderListeners(FolderEvent.DELETED); return true; }
protected MoveMessageResult executeInternal(MoveMessage action, ExecutionContext context) throws ActionException { User user = getUser(); try { IMAPStore store = cache.get(user); IMAPFolder folder = (IMAPFolder)store.getFolder(action.getOldFolder().getFullName()); if (folder.isOpen() == false) { folder.open(Folder.READ_WRITE); } Message m = folder.getMessageByUID(action.getMessageUid()); Message[] mArray = new Message[] {m}; folder.copyMessages(mArray, store.getFolder(action.getNewFolder().getFullName())); folder.setFlags(mArray, new Flags(Flags.Flag.DELETED), true); try { folder.expunge(mArray); folder.close(false); } catch (MessagingException e) { // prolly UID expunge is not supported folder.close(true); } return new MoveMessageResult(); } catch (MessagingException e) { logger.error("Error while moving message " + action.getMessageUid() + " from folder " + action.getOldFolder() + " to " + action.getNewFolder(),e); throw new ActionException(e); } }
.getFolder(folder.getFullName()); if (f.isOpen() == false) { f.open(com.sun.mail.imap.IMAPFolder.READ_WRITE); MimeMessage message = (MimeMessage) f.getMessageByUID(uid); MessageDetails mDetails = mimeToDetails(message, f.getFullName(), uid); f.setFlags(new Message[] { message }, new Flags(Flag.SEEN), true); if (f != null && f.isOpen()) { try { f.close(false); } catch (MessagingException e) {
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) protected List getAttachments(ReplyMessage action) throws MessagingException, ActionException { List<?> items = new ArrayList(); IMAPStore store = cache.get(getUser()); IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName()); if (folder.isOpen() == false) { folder.open(Folder.READ_ONLY); } // Only original inline images have to be added to the list Message msg = folder.getMessageByUID(action.getReplyMessageUid()); try { items = MessageUtils.extractInlineImages(logger, msg.getContent()); if (items.size() > 0) logger.debug("Replying a message, extracted: " + items.size() + " inline image from"); } catch (IOException e) { e.printStackTrace(); } // Put into the list the attachments uploaded by the user items.addAll(super.getAttachments(action)); return items; }
c = getSeparator(); final char sep = c; Object ret = doCommandIgnoreFailure(new ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { boolean retb = exists(); // set exists, type, and attributes if (retb) // Notify listeners on self and our Store notifyFolderListeners(FolderEvent.CREATED); return retb;
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.RECENT)); given(folder.isOpen()).willReturn(false).willReturn(true); given(folder.exists()).willReturn(true); Thread.sleep(1000); return null; }).given(folder).idle();
logger.fine("IMAPStore cleanup, not connected"); return; connectionFailed = false; if (logger.isLoggable(Level.FINE)) logger.fine("IMAPStore cleanup, force " + force); f.forceClose(); } else { logger.fine("close folder"); f.close(false);
@Override protected RawMessageResult executeInternal(RawMessage action, ExecutionContext context) throws ActionException { User user = getUser(); long uid = action.getUid(); org.apache.hupa.shared.data.IMAPFolder folder = action.getFolder(); try { IMAPStore store = cache.get(user); IMAPFolder f = (IMAPFolder) store.getFolder(folder.getFullName()); if (f.isOpen() == false) { f.open(Folder.READ_ONLY); } Message m = f.getMessageByUID(action.getUid()); ByteArrayOutputStream out = new ByteArrayOutputStream(); m.writeTo(out); if (f.isOpen()) { f.close(false); } return new RawMessageResult(out.toString()); } catch (Exception e) { logger.error("Unable to get raw content of msg for user " + user + " in folder " + folder + " with uid " + uid, e); throw new ActionException("Unable to et raw content of msg for user " + user + " in folder " + folder + " with uid " + uid); } }
receiver.afterPropertiesSet(); 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); willAnswer(i -> { i.callRealMethod(); throw new FolderClosedException(folder, "test"); }).given(receiver).waitForNewMessages(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
/** * Close this folder without waiting for the server. * * @exception MessagingException for failures */ public synchronized void forceClose() throws MessagingException { close(false, true); }
/** * Open this folder in the given mode. */ public synchronized void open(int mode) throws MessagingException { open(mode, null); }