@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."); } }
@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); }
/** * 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(); }
/** * Returns message sequence number in the folder by its UID. * * @param uid - message UID. * @return message sequence number. * @throws FolderException if no message with given UID. */ @Override public int getMsn(long uid) throws FolderException { NavigableMap<Long, FileInfo> messages = searchMails(); if (!messages.containsKey(uid)) { throw new FolderException("No such message."); } return messages.headMap(uid, true).size(); }
private boolean selectMailbox(String mailboxName, ImapSession session, boolean readOnly) throws FolderException { MailFolder folder = getMailbox(mailboxName, session, true); if (!folder.isSelectable()) { throw new FolderException("Non selectable mailbox " + mailboxName); } session.setSelected(folder, readOnly); return readOnly; } }
/** * Returns message sequence number in the folder by its UID. * * @param uid - message UID. * @return message sequence number. * @throws FolderException if no message with given UID. */ @Override public int getMsn(long uid) throws FolderException { NavigableMap<Long, FileInfo> messages = searchMails(); if (!messages.containsKey(uid)) { throw new FolderException("No such message."); } return messages.headMap(uid, true).size(); }
@Override public long copyMessage(long uid, MailFolder toFolder) throws FolderException { StoredMessage originalMessage = getMessage(uid); MimeMessage newMime; try { newMime = new MimeMessage(originalMessage.getMimeMessage()); } catch (MessagingException e) { throw new FolderException("Can not copy message " + uid + " to folder " + toFolder, e); } return toFolder.appendMessage(newMime, originalMessage.getFlags(), originalMessage.getReceivedDate()); }
/** * Unsubscribes from a given mailbox. <p/> This method serves UNSUBSCRIBE command of the IMAP protocol. * * @param user User making the request * @param mailbox String representation of a mailbox name. */ public void unsubscribe(GreenMailUser user, String mailbox) throws FolderException { try { AlfrescoImapUser alfrescoUser = new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()); imapService.unsubscribe(alfrescoUser, getUnqualifiedMailboxPattern(alfrescoUser, mailbox)); } catch (Throwable e) { logger.debug(e.getMessage(), e); throw new FolderException(e.getMessage()); } }