Package org.apache.james.mailbox

Examples of org.apache.james.mailbox.MailboxSession


                        }
                    } catch (UsersRepositoryException e) {
                        throw new MessagingException("Unable to accessUsersRepository", e);
                    }

                    MailboxSession session;
                    try {
                        session = mailboxManager.createSystemSession(user, new MailetContextLog(getMailetContext()));
                    } catch (BadCredentialsException e) {
                        throw new MessagingException("Unable to authenticate to mailbox", e);
                    } catch (MailboxException e) {
                        throw new MessagingException("Can not access mailbox", e);
                    }

                    // Start processing request
                    mailboxManager.startProcessingRequest(session);

                    // This allows Sieve scripts to use a standard delimiter
                    // regardless of mailbox implementation
                    String destination = urlPath.replace('/', session.getPathDelimiter());

                    if (destination == null || "".equals(destination)) {
                        destination = this.folder;
                    }
                    if (destination.startsWith(session.getPathDelimiter() + ""))
                        destination = destination.substring(1);

                    // Use the MailboxSession to construct the MailboxPath - See
                    // JAMES-1326
                    final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, destination);
                    try {
                        if (this.folder.equalsIgnoreCase(destination) && !(mailboxManager.mailboxExists(path, session))) {
                            mailboxManager.createMailbox(path, session);
                        }
                        final MessageManager mailbox = mailboxManager.getMailbox(path, session);
                        if (mailbox == null) {
                            final String error = "Mailbox for user " + user + " was not found on this server.";
                            throw new MessagingException(error);
                        }

                        mailbox.appendMessage(new MimeMessageInputStream(mail), new Date(), session, true, null);

                    } catch (MailboxException e) {
                        throw new MessagingException("Unable to access mailbox.", e);
                    } finally {
                        session.close();
                        try {
                            mailboxManager.logout(session, true);
                        } catch (MailboxException e) {
                            throw new MessagingException("Can logout from mailbox", e);
                        }
View Full Code Here


        POP3MessageInfo[] list = pop3Client.listUniqueIdentifiers();
        assertEquals("Found unexpected messages", 0, list.length);

        pop3Client.disconnect();
        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo", "INBOX");
        MailboxSession session = mailboxManager.login("foo", "bar", LoggerFactory.getLogger("Test"));
        if (!mailboxManager.mailboxExists(mailboxPath, session)) {
            mailboxManager.createMailbox(mailboxPath, session);
        }
        setupTestMails(session, mailboxManager.getMailbox(mailboxPath, session));
View Full Code Here

        pop3Client.connect("127.0.0.1", pop3Port);

        usersRepository.addUser("foo2", "bar2");

        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX");
        MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test"));

        if (!mailboxManager.mailboxExists(mailboxPath, session)) {
            mailboxManager.createMailbox(mailboxPath, session);
        }
View Full Code Here

        pop3Client.connect("127.0.0.1", pop3Port);

        usersRepository.addUser("foo2", "bar2");

        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX");
        MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test"));

        if (!mailboxManager.mailboxExists(mailboxPath, session)) {
            mailboxManager.createMailbox(mailboxPath, session);
        }
View Full Code Here

        pop3Client.connect("127.0.0.1", pop3Port);

        usersRepository.addUser("foo2", "bar2");

        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX");
        MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test"));

        if (!mailboxManager.mailboxExists(mailboxPath, session)) {
            mailboxManager.createMailbox(mailboxPath, session);
        }
View Full Code Here

        pop3Client = new POP3Client();
        pop3Client.connect("127.0.0.1", pop3Port);

        usersRepository.addUser("foo6", "bar6");
        MailboxSession session = mailboxManager.login("foo6", "bar6", LoggerFactory.getLogger("Test"));

        MailboxPath mailboxPath = MailboxPath.inbox(session);

        mailboxManager.startProcessingRequest(session);
        if (!mailboxManager.mailboxExists(mailboxPath, session)) {
View Full Code Here

     *            the recipient to check
     */
    @Override
    protected long getUsed(MailAddress recipient, Mail _) throws MessagingException {
        long size = 0;
        MailboxSession session;
        try {
            String username;
            try {
                // see if we need use the full email address as username or not.
                // See JAMES-1197
                if (localUsers.supportVirtualHosting()) {
                    username = recipient.toString().toLowerCase(Locale.US);
                }
                else {
                    username = recipient.getLocalPart().toLowerCase(Locale.US);
                }
            }
            catch (UsersRepositoryException e) {
                throw new MessagingException("Unable to access UsersRepository", e);
            }
            session = manager.createSystemSession(username, log);
            manager.startProcessingRequest(session);

            // get all mailboxes for the user to calculate the size
            // TODO: See JAMES-1198
            List<MailboxMetaData> mList = manager.search(
                    new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session);
            for (MailboxMetaData aMList : mList) {
                MessageManager mailbox = manager.getMailbox(aMList.getPath(), session);
                Iterator<MessageResult> results = mailbox.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL,
                        session);
                while (results.hasNext()) {
View Full Code Here

            }
        } catch (UsersRepositoryException e) {
            throw new MessagingException(e.getMessage());
        }

        final MailboxSession session;
        try {
            session = mailboxManager.createSystemSession(username, new MailetContextLog(getMailetContext()));
        } catch (BadCredentialsException e) {
            throw new MessagingException("Unable to authenticate to mailbox", e);
        } catch (MailboxException e) {
            throw new MessagingException("Can not access mailbox", e);
        }

        mailboxManager.startProcessingRequest(session);

        final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, username, this.folder);
       
        try {
       
            if (this.folder.equalsIgnoreCase(folder) && !(mailboxManager.mailboxExists(path, session))) {
                mailboxManager.createMailbox(path, session);
            }
            final MessageManager mailbox = mailboxManager.getMailbox(path, session);
            if (mailbox == null) {
                final String error = "Mailbox for username " + username + " was not found on this server.";
                throw new MessagingException(error);
            }

            mailbox.appendMessage(new MimeMessageInputStream(mail.getMessage()), new Date(), session, true, null);

            log("Local delivery with ToSenderFolder mailet for mail " + mail.getName() + " with sender " + sender.toString() + " in folder " + this.folder);
       
        } catch (MailboxException e) {
            throw new MessagingException("Unable to access mailbox.", e);
        } finally {
            session.close();
            try {
                mailboxManager.logout(session, true);
            } catch (MailboxException e) {
                throw new MessagingException("Can logout from mailbox", e);
            }
View Full Code Here

    /**
     * @see org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#deleteMailboxes(java.lang.String)
     */
    public boolean deleteMailboxes(String username) {
        MailboxSession session = null;
        try {
            session = mailboxManager.createSystemSession(username, log);
            mailboxManager.startProcessingRequest(session);
            List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session);
            for (MailboxMetaData aMList : mList) {
                mailboxManager.deleteMailbox(aMList.getPath(), session);
            }
            return true;
        } catch (MailboxException e) {
View Full Code Here

     * org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#listMailboxes
     * (java.lang.String)
     */
    public List<String> listMailboxes(String username) {
        List<String> boxes = new ArrayList<String>();
        MailboxSession session = null;
        try {
            session = mailboxManager.createSystemSession(username, log);
            mailboxManager.startProcessingRequest(session);
            List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session);
            for (MailboxMetaData aMList : mList) {
                boxes.add(aMList.getPath().getName());
            }
            Collections.sort(boxes);
        } catch (MailboxException e) {
View Full Code Here

TOP

Related Classes of org.apache.james.mailbox.MailboxSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.