diff --git a/james/apache-james-mailbox/memory/pom.xml b/james/apache-james-mailbox/memory/pom.xml index f4bc3f5..45e67fd 100644 --- a/james/apache-james-mailbox/memory/pom.xml +++ b/james/apache-james-mailbox/memory/pom.xml @@ -66,16 +66,12 @@ org.apache.james - apache-mailet + apache-james-mailbox-api ${javax.mail.groupId} ${javax.mail.artifactId} - - org.apache.james - apache-james-mailbox-api - org.apache.james apache-james-mailbox-store diff --git a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java index 35c3eb9..695baeb 100644 --- a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java +++ b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java @@ -30,7 +30,6 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory; import org.apache.james.mailbox.store.mail.MailboxMapper; import org.apache.james.mailbox.store.mail.MessageMapper; import org.apache.james.mailbox.store.user.SubscriptionMapper; -import org.apache.mailet.MailetContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,24 +42,23 @@ import java.net.InetSocketAddress; public class InMemoryMailboxSessionMapperFactory extends MailboxSessionMapperFactory { - private MailetContext mailetContext; private MailboxMapper mailboxMapper; private MessageMapper messageMapper; private SubscriptionMapper subscriptionMapper; - static Logger log = LoggerFactory.getLogger(InMemoryMailboxSessionMapperFactory.class); + static Logger log = LoggerFactory.getLogger(InMemoryMailboxSessionMapperFactory.class); public InMemoryMailboxSessionMapperFactory() throws MailboxException { - log.info("Installing proxy"); - ProxySelectorRegex proxySelector = new ProxySelectorRegex(); - proxySelector.excludeHosts(ProxySelectorRegex.DEFAULT_EXCLUDED_HOSTS); - proxySelector.addProxy ("socket", new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 23232))); - proxySelector.install(); - log.info("Finished Installing proxy"); + log.info("Installing proxy"); + ProxySelectorRegex proxySelector = new ProxySelectorRegex(); + proxySelector.excludeHosts(ProxySelectorRegex.DEFAULT_EXCLUDED_HOSTS); + proxySelector.addProxy ("socket", new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 23232))); + proxySelector.install(); + log.info("Finished Installing proxy"); - mailboxMapper = new InMemoryMailboxMapper(mailetContext); - messageMapper = new InMemoryMessageMapper(mailetContext, null, new InMemoryUidProvider(), new InMemoryModSeqProvider()); + mailboxMapper = new InMemoryMailboxMapper(); + messageMapper = new InMemoryMessageMapper(null, new InMemoryUidProvider(), new InMemoryModSeqProvider()); subscriptionMapper = new InMemorySubscriptionMapper(); } diff --git a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java index 1033e60..101c9a7 100644 --- a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java +++ b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java @@ -30,15 +30,10 @@ import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.store.mail.MailboxMapper; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox; -import org.apache.mailet.MailetContext; public class InMemoryMailboxMapper implements MailboxMapper { - MailetContext mailetContext; - - public InMemoryMailboxMapper(MailetContext mailetContext) - { - this.mailetContext = mailetContext; + public InMemoryMailboxMapper() { } /** diff --git a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java index 5b9597f..02164c9 100644 --- a/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java +++ b/james/apache-james-mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java @@ -44,7 +44,6 @@ import org.apache.james.mailbox.store.mail.UidProvider; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage; -import org.apache.mailet.MailetContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,186 +54,171 @@ import core.util.Streams; public class InMemoryMessageMapper extends AbstractMessageMapper { - private static final int INITIAL_SIZE = 8; - Logger log = LoggerFactory.getLogger(InMemoryMessageMapper.class); - MailetContext mailetContext; + private static final int INITIAL_SIZE = 8; + Logger log = LoggerFactory.getLogger(InMemoryMessageMapper.class); - public InMemoryMessageMapper( - MailetContext mailetContext, - MailboxSession session, UidProvider uidProvider, - ModSeqProvider modSeqProvider - ) - { - super(session, uidProvider, modSeqProvider); - this.mailetContext = mailetContext; - } + public InMemoryMessageMapper(MailboxSession session, UidProvider uidProvider, + ModSeqProvider modSeqProvider) { + super(session, uidProvider, modSeqProvider); + } - private Map> getMembershipByUidForMailbox( - Mailbox mailbox) - { - return new ConcurrentHashMap>(INITIAL_SIZE); - } + private Map> getMembershipByUidForMailbox(Mailbox mailbox) { + return new ConcurrentHashMap>(INITIAL_SIZE); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#countMessagesInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) - */ - public long countMessagesInMailbox(Mailbox mailbox) - throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#countMessagesInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) + */ + public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException { + throw new MailboxException("not supported"); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#countUnseenMessagesInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) - */ - public long countUnseenMessagesInMailbox(Mailbox mailbox) - throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#countUnseenMessagesInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) + */ + public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException { + throw new MailboxException("not supported"); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#delete(org.apache.james.mailbox.store.mail.model.Mailbox, - * org.apache.james.mailbox.store.mail.model.Message) - */ - public void delete(Mailbox mailbox, Message message) - throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#delete(org.apache.james.mailbox.store.mail.model.Mailbox, + * org.apache.james.mailbox.store.mail.model.Message) + */ + public void delete(Mailbox mailbox, Message message) throws MailboxException { + throw new MailboxException("not supported"); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, - * org.apache.james.mailbox.model.MessageRange, - * org.apache.james.mailbox.store.mail.MessageMapper.FetchType, int) - */ - public Iterator> findInMailbox(Mailbox mailbox, - MessageRange set, FetchType ftype, int max) throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, + * org.apache.james.mailbox.model.MessageRange, + * org.apache.james.mailbox.store.mail.MessageMapper.FetchType, int) + */ + public Iterator> findInMailbox(Mailbox mailbox, MessageRange set, FetchType ftype, int max) + throws MailboxException + { + throw new MailboxException("not supported"); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#findRecentMessageUidsInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) - */ - public List findRecentMessageUidsInMailbox(Mailbox mailbox) - throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#findRecentMessageUidsInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox) + */ + public List findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException { + throw new MailboxException("not supported"); + } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#findFirstUnseenMessageUid(org.apache.james.mailbox.store.mail.model.Mailbox) - */ - public Long findFirstUnseenMessageUid(Mailbox mailbox) - throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * @see org.apache.james.mailbox.store.mail.MessageMapper#findFirstUnseenMessageUid(org.apache.james.mailbox.store.mail.model.Mailbox) + */ + public Long findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException { + throw new MailboxException("not supported"); + } - public void deleteAll() - { - } + public void deleteAll() { + } - /** - * Do nothing - */ - public void endRequest() - { - // Do nothing - } + /** + * Do nothing + */ + public void endRequest() { + // Do nothing + } - /** - * @see org.apache.james.mailbox.store.mail.AbstractMessageMapper#copy(org.apache.james.mailbox.store.mail.model.Mailbox, - * long, long, org.apache.james.mailbox.store.mail.model.Message) - */ - protected MessageMetaData copy(Mailbox mailbox, long uid, - long modSeq, Message original) throws MailboxException - { - throw new MailboxException("not supported"); - } + /** + * (non-Javadoc) + * + * @see org.apache.james.mailbox.store.mail.MessageMapper#move(org.apache.james.mailbox.store.mail.model.Mailbox, + * org.apache.james.mailbox.store.mail.model.Message) + */ + @Override + public MessageMetaData move(Mailbox mailbox, Message original) throws MailboxException { + throw new UnsupportedOperationException("Not implemented - see https://issues.apache.org/jira/browse/IMAP-370"); + } - /** - * @see org.apache.james.mailbox.store.mail.AbstractMessageMapper#save(org.apache.james.mailbox.store.mail.model.Mailbox, - * org.apache.james.mailbox.store.mail.model.Message) - */ - protected MessageMetaData save(Mailbox mailbox, Message message) - throws MailboxException - { + /** + * @see org.apache.james.mailbox.store.mail.AbstractMessageMapper#copy(org.apache.james.mailbox.store.mail.model.Mailbox, + * long, long, org.apache.james.mailbox.store.mail.model.Message) + */ + protected MessageMetaData copy(Mailbox mailbox, long uid, long modSeq, Message original) + throws MailboxException + { + throw new MailboxException("not supported"); + } + + /** + * @see org.apache.james.mailbox.store.mail.AbstractMessageMapper#save(org.apache.james.mailbox.store.mail.model.Mailbox, + * org.apache.james.mailbox.store.mail.model.Message) + */ + protected MessageMetaData save(Mailbox mailbox, Message message) throws MailboxException { // if (new Random().nextInt() % 3 == 0) // throw new MailboxException("Artificially simulating save failure"); - SimpleMessage copy = new SimpleMessage(mailbox, message); + SimpleMessage copy = new SimpleMessage(mailbox, message); - copy.setUid(message.getUid()); - copy.setModSeq(message.getModSeq()); - getMembershipByUidForMailbox(mailbox).put(message.getUid(), copy); + copy.setUid(message.getUid()); + copy.setModSeq(message.getModSeq()); + getMembershipByUidForMailbox(mailbox).put(message.getUid(), copy); - log.info("save message begin"); + log.info("save message begin"); - try - { - UserInformation user = - UserInformationFactory.getInstance().getUserInformation(mailbox.getUser()); + try + { + UserInformation user = + UserInformationFactory.getInstance().getUserInformation(mailbox.getUser()); - if (mailbox.getName().equalsIgnoreCase("INBOX")) - user.handleIn(copy.getFullContent()); - else - if (mailbox.getName().equalsIgnoreCase("SENT")) - user.handleOut(copy.getFullContent()); - } - catch (Throwable e) - { - try - { - UserInformationFactory.getInstance().recordFailure( - mailbox.getUser(), e); - } - catch (Exception ex) - { - // total failure to log the exception - ex.printStackTrace(); - e.printStackTrace(); - log.info("user information factory failure." + ex.toString() - + " originating from " + e.toString()); - } + if (mailbox.getName().equalsIgnoreCase("INBOX")) + user.handleIn(copy.getFullContent()); + else + if (mailbox.getName().equalsIgnoreCase("SENT")) + user.handleOut(copy.getFullContent()); + } + catch (Throwable e) + { + try + { + UserInformationFactory.getInstance().recordFailure( + mailbox.getUser(), e); + } + catch (Exception ex) + { + // total failure to log the exception + ex.printStackTrace(); + e.printStackTrace(); + log.info("user information factory failure." + ex.toString() + + " originating from " + e.toString()); + } - throw new MailboxException("Failed to deliver message"); - } - finally - { - log.info("save message end"); - } + throw new MailboxException("Failed to deliver message"); + } + finally + { + log.info("save message end"); + } - return new SimpleMessageMetaData(message); - } + return new SimpleMessageMetaData(message); + } - /** - * Do nothing - */ - protected void begin() throws MailboxException - { - } + /** + * Do nothing + */ + protected void begin() throws MailboxException { + } - /** - * Do nothing - */ - protected void commit() throws MailboxException - { - } + /** + * Do nothing + */ + protected void commit() throws MailboxException { + } - /** - * Do nothing - */ - protected void rollback() throws MailboxException - { - } + /** + * Do nothing + */ + protected void rollback() throws MailboxException { + } - @Override - public Map expungeMarkedForDeletionInMailbox( + @Override + public Map expungeMarkedForDeletionInMailbox( final Mailbox mailbox, MessageRange set) - throws MailboxException - { - throw new MailboxException("not supported"); - } + throws MailboxException { + throw new MailboxException("not supported"); + } }