Package org.apache.james.mailbox

Examples of org.apache.james.mailbox.MessageManager


                    log.error("Mailbox " + i + " with path=" + mailboxPath.toString() + " already exists.", e);
                }
                dstMailboxManager.endProcessingRequest(dstMailboxSession);

                srcMailboxManager.startProcessingRequest(srcMailboxSession);
                MessageManager srcMessageManager = srcMailboxManager.getMailbox(mailboxPath, srcMailboxSession);
                srcMailboxManager.endProcessingRequest(srcMailboxSession);

                dstMailboxManager.startProcessingRequest(dstMailboxSession);
                MessageManager dstMessageManager = dstMailboxManager.getMailbox(mailboxPath, dstMailboxSession);
                dstMailboxManager.endProcessingRequest(dstMailboxSession);

                int j=0;
                Iterator<MessageResult> messageResultIterator = srcMessageManager.getMessages(MessageRange.all(), FetchGroupImpl.FULL_CONTENT, srcMailboxSession);
               
                while (messageResultIterator.hasNext()) {

                    MessageResult messageResult = messageResultIterator.next();
                    InputStreamContent content = (InputStreamContent) messageResult.getFullContent();

                    dstMailboxManager.startProcessingRequest(dstMailboxSession);
                    dstMessageManager.appendMessage(content.getInputStream(), messageResult.getInternalDate(), dstMailboxSession, messageResult.getFlags().contains(Flag.RECENT), messageResult.getFlags());
                    dstMailboxManager.endProcessingRequest(dstMailboxSession);
                    log.info("Message #" + j + " appended in destination mailbox with path=" + mailboxPath.toString());
                    j++;

                }
View Full Code Here


                    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();
View Full Code Here

            // 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()) {
                    size += results.next().getSize();
                }
            }
View Full Code Here

        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);
View Full Code Here

            } catch (MailboxExistsException e) {
                // Do nothing, the mailbox already exists.
            }
            mailboxManager.endProcessingRequest(mailboxSession);

            MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);

            while (mailRepositoryIterator.hasNext()) {
                Mail mail = mailRepository.retrieve(mailRepositoryIterator.next());
                mailboxManager.startProcessingRequest(mailboxSession);
                messageManager.appendMessage(new MimeMessageInputStream(mail.getMessage()), new Date(), mailboxSession, isRecent, flags);
                mailboxManager.endProcessingRequest(mailboxSession);
            }

        }
View Full Code Here

        final Flags flags = request.getFlags();
        try {

            final MailboxPath mailboxPath = buildFullPath(session, mailboxName);
            final MailboxManager mailboxManager = getMailboxManager();
            final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session));
            appendToMailbox(messageIn, datetime, flags, session, tag, command, mailbox, responder, mailboxPath);
        } catch (MailboxNotFoundException e) {
            // consume message on exception
            consume(messageIn);
View Full Code Here

        super(ExpungeRequest.class, next, mailboxManager, factory);
    }

    protected void doProcess(ExpungeRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) {
        try {
            final MessageManager mailbox = getSelectedMailbox(session);
            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);

            if (!mailbox.isWriteable(mailboxSession)) {
                no(command, tag, responder, HumanReadableText.MAILBOX_IS_READ_ONLY);
            } else {
                IdRange[] ranges = request.getUidSet();
                if (ranges == null) {
                    expunge(mailbox, MessageRange.all(), session, mailboxSession);
View Full Code Here

        } else {
            replace = true;
            value = true;
        }
        try {
            final MessageManager mailbox = getSelectedMailbox(session);
            for (int i = 0; i < idSet.length; i++) {
                final SelectedMailbox selected = session.getSelected();
                MessageRange messageSet = messageRange(selected, idSet[i], useUids);
                if (messageSet != null) {
                    final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
                    final Map<Long, Flags> flagsByUid = mailbox.setFlags(flags, value, replace, messageSet, mailboxSession);
                    // As the STORE command is allowed to create a new "flag/keyword", we need to send a FLAGS and PERMANENTFLAGS response before the FETCH response
                    // if some new flag/keyword was used
                    // See IMAP-303
                    if (selected.hasNewApplicableFlags()) {
                        flags(responder, selected);
                        permanentFlags(responder, mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT), selected);
                        selected.resetNewApplicableFlags();
                    }
                   
                    if (!silent) {
    
View Full Code Here

        final boolean useUids = request.isUseUids();
        List<SearchResultOption> resultOptions = operation.getResultOptions();

        try {

            final MessageManager mailbox = getSelectedMailbox(session);

            final SearchQuery query = toQuery(searchKey, session);

            final Collection<Long> results = findIds(useUids, session, mailbox, query);
            final long[] ids = toArray(results);
View Full Code Here

    private void addFlagsResponses(final ImapSession session, final SelectedMailbox selected, final ImapProcessor.Responder responder, boolean useUid) {
      
       
        try {
            final MessageManager mailbox = getMailbox(session, selected);
            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);

            // Check ifwe need to send a FLAGS and PERMANENTFLAGS response before the FETCH response
            // This is the case if some new flag/keyword was used
            // See IMAP-303
            if (selected.hasNewApplicableFlags()) {
                flags(responder, selected);
                permanentFlags(responder, mailbox.getMetaData(false, mailboxSession,  MessageManager.MetaData.FetchGroup.NO_COUNT), selected);
                selected.resetNewApplicableFlags();
            }
           
            final Collection<Long> flagUpdateUids = selected.flagUpdateUids();
            if (!flagUpdateUids.isEmpty()) {
View Full Code Here

TOP

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

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.