private int expunge(MessageManager mailbox, MessageRange range, ImapSession session, MailboxSession mailboxSession) throws MailboxException { final Iterator<Long> it = mailbox.expunge(range, mailboxSession); final SelectedMailbox selected = session.getSelected(); int expunged = 0; if (mailboxSession != null) { while (it.hasNext()) { final long uid = it.next(); selected.removeRecent(uid); expunged++; } } return expunged; }
private int expunge(MessageManager mailbox, MessageRange range, ImapSession session, MailboxSession mailboxSession) throws MailboxException { final Iterator<MessageUid> it = mailbox.expunge(range, mailboxSession); final SelectedMailbox selected = session.getSelected(); int expunged = 0; if (mailboxSession != null) { while (it.hasNext()) { final MessageUid uid = it.next(); selected.removeRecent(uid); expunged++; } } return expunged; }
@Override public void remove(String... uids) throws IOException { List<MessageUid> uidList = Arrays.stream(uids) .map(uid -> MessageUid.of(Long.valueOf(uid))) .collect(Guavate.toImmutableList()); List<MessageRange> ranges = MessageRange.toRanges(uidList); try { mailboxManager.startProcessingRequest(session); for (MessageRange range : ranges) { manager.setFlags(new Flags(Flags.Flag.DELETED), MessageManager.FlagsUpdateMode.ADD, range, session); manager.expunge(range, session); } } catch (MailboxException e) { throw new IOException("Unable to remove messages for ranges " + ranges); } finally { mailboxManager.endProcessingRequest(session); } }
protected void doProcess(CloseRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { MessageManager mailbox = getSelectedMailbox(session); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) { mailbox.expunge(MessageRange.all(), mailboxSession); session.deselect(); // Don't send HIGHESTMODSEQ when close. Like correct in the ERRATA of RFC5162 // // See http://www.rfc-editor.org/errata_search.php?rfc=5162 okComplete(command, tag, responder); } } catch (MailboxException e) { if (session.getLog().isInfoEnabled()) { session.getLog().info("Close failed for mailbox " + session.getSelected().getPath() , e); } no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } } }
@Override protected void doProcess(CloseRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { MessageManager mailbox = getSelectedMailbox(session); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) { mailbox.expunge(MessageRange.all(), mailboxSession); session.deselect(); // Don't send HIGHESTMODSEQ when close. Like correct in the ERRATA of RFC5162 // // See http://www.rfc-editor.org/errata_search.php?rfc=5162 okComplete(command, tag, responder); } } catch (MailboxException e) { LOGGER.error("Close failed for mailbox {}", session.getSelected().getPath(), e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
MessageRange range = MessageRange.one(toBeRemoved.get(i)); mailbox.setFlags(new Flags(Flags.Flag.DELETED), true, false, range, mailboxSession); mailbox.expunge(range, mailboxSession);
@Test public void testRetrievalOverMaxStorage() throws Exception { QuotaSize maxQuotaSize = QuotaSize.size(15 * MockMail.MAIL_TEXT_PLAIN.getBytes(StandardCharsets.UTF_8).length + 1); maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), maxQuotaSize); try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // We are here over quota } messageManager.expunge(MessageRange.all(), session); // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown. resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build()); }
@Test public void testRetrievalOverMaxMessage() throws Exception { QuotaCount maxMessageCount = QuotaCount.count(15L); maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), maxMessageCount); try { resources.fillMailbox(); } catch (OverQuotaException overQuotaException) { // We are here over quota } messageManager.expunge(MessageRange.all(), session); // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown. resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build()); }