@Override public int getMsn(long uid) throws FolderException { synchronized (mailMessages) { if (mailMessages.containsKey(uid)) { int i = 1; for (Long messageUid : mailMessages.keySet()) { if (messageUid.equals(uid)) { return i; } i++; } } throw new FolderException("No such message."); } }
/** * Template methods for handling command processing. This method reads * argument values (validating them), and checks the request for correctness. * If correct, the command processing is delegated to the specific command * implementation. * * @see ImapCommand#process */ @Override public void process(ImapRequestLineReader request, ImapResponse response, ImapSession session) { try { doProcess(request, response, session); } catch (FolderException e) { log.warn("Error processing command", e); response.commandFailed(this, e.getResponseCode(), e.getMessage()); } catch (AuthorizationException e) { log.warn("Error processing command due to authentication", e); String msg = "Authorization error: Lacking permissions to perform requested operation."; response.commandFailed(this, msg); } catch (ProtocolException e) { String msg = e.getMessage() + " Command should be '" + getExpectedMessage() + '\''; log.warn("Error processing command: {}", msg, e); response.commandError(msg); } }
toFolder = getMailbox(mailboxName, session, true); } catch (FolderException e) { e.setResponseCode("TRYCREATE"); throw e;
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException { String mailboxName = appendCommandParser.mailbox(request); Flags flags = appendCommandParser.optionalAppendFlags(request); if (flags == null) { flags = new Flags(); } Date receivedDate = appendCommandParser.optionalDateTime(request); if (receivedDate == null) { receivedDate = new Date(); } MimeMessage message = appendCommandParser.mimeMessage(request); appendCommandParser.endLine(request); MailFolder folder; try { folder = getMailbox(mailboxName, session, true); } catch (FolderException e) { e.setResponseCode("TRYCREATE"); throw e; } long uid = folder.appendMessage(message, flags, receivedDate); session.unsolicitedResponses(response); response.commandComplete(this, "APPENDUID" + SP + folder.getUidValidity() + SP + uid); }
@Override public MailFolder getFolder(GreenMailUser user, String mailboxName, boolean mustExist) throws FolderException { MailFolder folder = getFolder(user, mailboxName); if (mustExist && (folder == null)) { throw new FolderException("No such folder : "+mailboxName); } return folder; }
@Override public int getMsn(long uid) throws FolderException { synchronized (mailMessages) { for (int i = 0; i < mailMessages.size(); i++) { StoredMessage message = mailMessages.get(i); if (message.getUid() == uid) { return i + 1; } } } throw new FolderException("No such message."); }
@Override public MailFolder createMailbox(MailFolder parent, String mailboxName, boolean selectable) throws FolderException { if (mailboxName.indexOf(HIERARCHY_DELIMITER_CHAR) != -1) { throw new FolderException("Invalid mailbox name "+mailboxName); } HierarchicalFolder castParent = (HierarchicalFolder) parent; HierarchicalFolder child = castParent.createChild(mailboxName); child.setSelectable(selectable); return child; }
@Override public void deleteMailbox(MailFolder folder) throws FolderException { HierarchicalFolder toDelete = (HierarchicalFolder) folder; if (toDelete.hasChildren()) { throw new FolderException("Cannot delete mailbox with children."); } if (toDelete.getMessageCount() != 0) { throw new FolderException("Cannot delete non-empty mailbox"); } HierarchicalFolder parent = toDelete.getParent(); parent.removeChild(toDelete); }
@Override public int getMsn(long uid) throws FolderException { long[] uids = folder.getMessageUids(); for (int i = 0; i < uids.length; i++) { long messageUid = uids[i]; if (uid == messageUid) { return i + 1; } } throw new FolderException("No such message with uid " + uid + " in folder " + folder.getName()); }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes all messages with this flag. */ @Override protected void expungeInternal() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet()) { imapService.expungeMessage(entry.getValue()); } }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes all messages with this flag. */ @Override protected void expungeInternal() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet()) { imapService.expungeMessage(entry.getValue()); } }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes the message with current uid */ @Override protected void expungeInternal(long uid) throws Exception { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } FileInfo messageFileInfo = searchMails().get(uid); imapService.expungeMessage(messageFileInfo); }
String qualifiedName = getQualifiedMailboxName(user, mailboxName); if (store.getMailbox(qualifiedName) != null) { throw new FolderException("Mailbox already exists."); throw new FolderException("Cannot create store at namespace level."); MailFolder folder = store.getMailbox(namespaceRoot); if (folder == null) { throw new FolderException("Invalid namespace " + namespaceRoot);
/** * Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag. */ @Override public void deleteAllMessagesInternal() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't delete all - Permission denied"); } for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet()) { imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true); // comment out to physically remove content. // fileFolderService.delete(fileInfo.getNodeRef()); } }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes the message with current uid */ @Override protected void expungeInternal(long uid) throws Exception { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } FileInfo messageFileInfo = searchMails().get(uid); imapService.expungeMessage(messageFileInfo); }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes all messages with this flag. */ public void expunge() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } CommandCallback<Object> command = new CommandCallback<Object>() { public Object command() throws Throwable { expungeInternal(); return null; } }; command.runFeedback(); }
/** * Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag. */ @Override public void deleteAllMessagesInternal() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't delete all - Permission denied"); } for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet()) { imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true); // comment out to physically remove content. // fileFolderService.delete(fileInfo.getNodeRef()); } }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes the messages with current uid */ public void expunge(final long uid) throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } CommandCallback<Object> command = new CommandCallback<Object>() { public Object command() throws Throwable { expungeInternal(uid); return null; } }; command.runFeedback(); }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes all messages with this flag. */ public void expunge() throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } CommandCallback<Object> command = new CommandCallback<Object>() { public Object command() throws Throwable { expungeInternal(); return null; } }; command.runFeedback(); }
/** * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes the messages with current uid */ public void expunge(final long uid) throws FolderException { if (isReadOnly()) { throw new FolderException("Can't expunge - Permission denied"); } CommandCallback<Object> command = new CommandCallback<Object>() { public Object command() throws Throwable { expungeInternal(uid); return null; } }; command.runFeedback(); }