@Override public void create() { try { imapHostManager.createPrivateMailAccount(this); } catch (FolderException e) { throw new IllegalStateException("Can not create user" + this, e); } }
@Override public void delete() { try { imapHostManager.deleteMailbox(this, ImapConstants.INBOX_NAME); } catch (FolderException | AuthorizationException e) { throw new IllegalStateException("Can not delete user " + this, e); } }
/** * @return null if no need to wait. Otherwise caller must call wait() on the returned object */ public synchronized CountDownLatch createAndAddNewWaitObject(int emailCount) { final int existingCount = imapHostManager.getAllMessages().size(); if (existingCount >= emailCount) { return new CountDownLatch(0); // Requires no count down, therefore not added to notification list } CountDownLatch latch = new CountDownLatch(emailCount - existingCount); notifyList.add(latch); return latch; }
@Override public void setQuotaSupported(boolean isEnabled) { managers.getImapHostManager().getStore().setQuotaSupported(isEnabled); }
@Override public void deliver(MimeMessage msg) { try { imapHostManager.getInbox(this).store(msg); } catch (Exception e) { throw new IllegalStateException("Can not deliver " + msg + " for user " + this, e); } }
protected MailFolder getMailbox(String mailboxName, ImapSession session, boolean mustExist) throws FolderException { return session.getHost().getFolder(session.getUser(), mailboxName, mustExist); }
@Override protected Collection<MailFolder> doList(ImapSession session, String searchPattern) throws FolderException { return session.getHost().listSubscribedMailboxes(session.getUser(), searchPattern); } }
protected Collection<MailFolder> doList(ImapSession session, String searchPattern) throws FolderException { return session.getHost().listMailboxes(session.getUser(), searchPattern); }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException, AuthorizationException { String mailboxName = parser.mailbox(request); parser.endLine(request); session.getHost().createMailbox(session.getUser(), mailboxName); session.unsolicitedResponses(response); response.commandComplete(this); } }
@Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException, AuthorizationException { String existingName = parser.mailbox(request); String newName = parser.mailbox(request); parser.endLine(request); session.getHost().renameMailbox(session.getUser(), existingName, newName); session.unsolicitedResponses(response); response.commandComplete(this); } }
@Override public void purgeEmailFromAllMailboxes() throws FolderException { ImapHostManager imaphost = getManagers().getImapHostManager(); InMemoryStore store = (InMemoryStore) imaphost.getStore(); Collection<MailFolder> mailboxes = store.listMailboxes("*"); for (MailFolder folder : mailboxes) { folder.deleteAllMessages(); } }
@Override public void deliver(MovingMessage msg) { try { imapHostManager.getInbox(this).store(msg); } catch (Exception e) { throw new IllegalStateException("Can not deliver " + msg + " for user " + this, e); } }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) throws ProtocolException, FolderException, AuthorizationException { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } String root = parser.mailbox(request); // NAME root (name usage limit) Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); for(Quota q: quota) { StringBuilder buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); }
public void authenticate(String pass) throws UserException, FolderException { if (user == null) throw new UserException("No user selected"); user.authenticate(pass); inbox = imapHostManager.getInbox(user); }
@Override public MimeMessage[] getReceivedMessages() { List<StoredMessage> msgs = managers.getImapHostManager().getAllMessages(); MimeMessage[] ret = new MimeMessage[msgs.size()]; for (int i = 0; i < msgs.size(); i++) { StoredMessage storedMessage = msgs.get(i); ret[i] = storedMessage.getMimeMessage(); } return ret; }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException, AuthorizationException { String mailboxName = parser.mailbox(request); parser.endLine(request); MailFolder folder = getMailbox(mailboxName, session, true); if (session.getSelected() != null && folder.getFullName().equals(session.getSelected().getFullName())) { session.deselect(); } session.getHost().deleteMailbox(session.getUser(), mailboxName); session.unsolicitedResponses(response); response.commandComplete(this); } }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) throws ProtocolException, FolderException, AuthorizationException { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } String root = parser.mailbox(request); // QUOTAROOT mailbox Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); StringBuilder buf = new StringBuilder("QUOTAROOT "); buf.append(root); for (Quota q : quota) { buf.append(' '); appendQuotaRootName(q, buf); } response.untaggedResponse("QUOTAROOT "+root); for (Quota q : quota) { buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); } }
@Override public MimeMessage[] getReceivedMessagesForDomain(String domain) { List<StoredMessage> msgs = managers.getImapHostManager().getAllMessages(); List<MimeMessage> ret = new ArrayList<>(); try { for (StoredMessage msg : msgs) { String tos = GreenMailUtil.getAddressList(msg.getMimeMessage().getAllRecipients()); if (tos.toLowerCase().contains(domain)) { ret.add(msg.getMimeMessage()); } } } catch (MessagingException e) { throw new RuntimeException(e); } return ret.toArray(new MimeMessage[ret.size()]); }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException { parser.endLine(request); if( session.getHost().getStore().isQuotaSupported()) { response.untaggedResponse(CAPABILITY_RESPONSE + SP + "QUOTA"); } else { response.untaggedResponse(CAPABILITY_RESPONSE); } session.unsolicitedResponses(response); response.commandComplete(this); } }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } try { String root = parser.mailbox(request); Quota quota = new Quota(root); parser.consumeChar(request, ' '); parser.consumeChar(request, '('); quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); char c =request.nextWordChar(); if(')' != c) { quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); } parser.consumeChar(request, ')'); session.getHost().getStore().setQuota( quota, session.getUser().getQualifiedMailboxName()); response.commandComplete(this); } catch (ProtocolException e) { response.commandFailed(this, "Can not parse command"+e.getMessage()); } } }