Package org.apache.james.mailbox

Examples of org.apache.james.mailbox.MailboxSession


            final boolean isRelative;

            final List<MailboxMetaData> results;

            final String user = ImapSessionUtils.getUserName(session);
            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);

            if (mailboxName.length() == 0) {
                // An empty mailboxName signifies a request for the hierarchy
                // delimiter and root name of the referenceName argument

                String referenceRoot;
                if (referenceName.length() > 0 && referenceName.charAt(0) == MailboxConstants.NAMESPACE_PREFIX_CHAR) {
                    // A qualified reference name - get the root element
                    isRelative = false;
                    int firstDelimiter = referenceName.indexOf(mailboxSession.getPathDelimiter());
                    if (firstDelimiter == -1) {
                        referenceRoot = referenceName;
                    } else {
                        referenceRoot = referenceName.substring(0, firstDelimiter);
                    }
                    referenceRoot = CharsetUtil.decodeModifiedUTF7(referenceRoot);
                } else {
                    // A relative reference name, return "" to indicate it is
                    // non-rooted
                    referenceRoot = "";
                    isRelative = true;
                }
                // Get the mailbox for the reference name.
                final MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
                results = new ArrayList<MailboxMetaData>(1);
                results.add(new MailboxMetaData() {

                    /**
                     * @see org.apache.james.mailbox.MailboxMetaData#inferiors()
                     */
                    public Children inferiors() {
                        return Children.CHILDREN_ALLOWED_BUT_UNKNOWN;
                    }

                    /**
                     * @see org.apache.james.mailbox.MailboxMetaData#getSelectability()
                     */
                    public Selectability getSelectability() {
                        return Selectability.NOSELECT;
                    }

                    /**
                     * @see org.apache.james.mailbox.MailboxMetaData#getHierarchyDelimiter()
                     */
                    public char getHierarchyDelimiter() {
                        return mailboxSession.getPathDelimiter();
                    }

                    /**
                     * (non-Javadoc)
                     * @see org.apache.james.mailbox.MailboxMetaData#getPath()
                     */
                    public MailboxPath getPath() {
                        return rootPath;
                    }
                   
                });
            } else {
                // If the mailboxPattern is fully qualified, ignore the
                // reference name.
                String finalReferencename = referenceName;
                if (mailboxName.charAt(0) == MailboxConstants.NAMESPACE_PREFIX_CHAR) {
                    finalReferencename = "";
                }
                // Is the interpreted (combined) pattern relative?
                isRelative = ((finalReferencename + mailboxName).charAt(0) != MailboxConstants.NAMESPACE_PREFIX_CHAR);

                finalReferencename = CharsetUtil.decodeModifiedUTF7(finalReferencename);

                MailboxPath basePath = null;
                if (isRelative) {
                    basePath = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, finalReferencename);
                } else {
                    basePath = buildFullPath(session, finalReferencename);
                }

                results = getMailboxManager().search(new MailboxQuery(basePath, CharsetUtil.decodeModifiedUTF7(mailboxName), mailboxSession.getPathDelimiter()), mailboxSession);
            }

            for (final MailboxMetaData metaData : results) {
                processResult(responder, isRelative, metaData, getMailboxType(session, mailboxTyper, metaData.getPath()));
            }
View Full Code Here


    protected void doProcess(final IdleRequest message, final ImapSession session, final String tag, final ImapCommand command, final Responder responder) {

        try {
         
            final MailboxManager mailboxManager = getMailboxManager();
            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
            final SelectedMailbox sm = session.getSelected();
            final MailboxListener idleListener;
            if (sm != null) {
                idleListener = new IdleMailboxListener(session, responder);
                mailboxManager.addListener(sm.getPath(), idleListener , mailboxSession);
View Full Code Here

     */
    public void copyMailboxes(MailboxManager srcMailboxManager, MailboxManager dstMailboxManager) throws MailboxException, IOException {
       
        Calendar start = Calendar.getInstance();

        MailboxSession srcMailboxSession;
        MailboxSession dstMailboxSession;

        List<MailboxPath> mailboxPathList = null;

        srcMailboxSession = srcMailboxManager.createSystemSession("manager", log);
        srcMailboxManager.startProcessingRequest(srcMailboxSession);
View Full Code Here

            StoreMailboxManager<Integer> manager = new StoreMailboxManager<Integer>(mf, null, new JVMMailboxPathLocker());
   
            manager.init();
   
            String user = "test@localhost";
            MailboxSession session = manager.createSystemSession(user, LoggerFactory.getLogger("Test"));
            manager.createMailbox(new MailboxPath(MailboxConstants.USER_NAMESPACE, user, "Trash"), session);
            manager.createMailbox(new MailboxPath(MailboxConstants.USER_NAMESPACE, user, "INBOX.testfolder"), session);
           
            // this threw NPE
            manager.getMailbox(MailboxPath.inbox(session), session).appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
View Full Code Here

     * @throws BadCredentialsException
     */
    @After
    public void tearDown() throws BadCredentialsException, MailboxException {
        deleteAllMailboxes();
        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
        session.close();
        entityManagerFactory.close();
    }
View Full Code Here

        deleteAllMailboxes();
       
    }
   
    private void deleteAllMailboxes() throws BadCredentialsException, MailboxException {
        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
        try {
            ((OpenJPAMailboxManager) mailboxManager).deleteEverything(session);
        } catch (MailboxException e) {
            e.printStackTrace();
        }
        session.close();
    }
View Full Code Here

     * @throws MailboxException
     * @throws BadCredentialsException
     */
    private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException {
       
        MailboxSession mailboxSession = mailboxManager.createSystemSession("manager", LoggerFactory.getLogger("src-mailbox-copier"));       
        mailboxManager.startProcessingRequest(mailboxSession);

        List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession);
       
        Assert.assertEquals(MockMailboxManager.EXPECTED_MAILBOXES_COUNT, mailboxPathList.size());
View Full Code Here

        manager.close();
    }
   
    @After
    public void tearDown() {
        MailboxSession session = mailboxManager.createSystemSession("test", LoggerFactory.getLogger("Test"));
        try {
            mailboxManager.deleteEverything(session);
        } catch (MailboxException e) {
            e.printStackTrace();
        }
        session.close();
    }
View Full Code Here

               
                String user = "user" + j + "@localhost" + i;
               
                String folderName = "INBOX";

                MailboxSession mailboxSession = getMockMailboxManager().createSystemSession(user, LoggerFactory.getLogger("mailboxmanager-test"));
                mailboxPath = new MailboxPath("#private", user, folderName);
                createMailbox(mailboxSession, mailboxPath);
               
                for (int k=0; k < SUB_MAILBOXES_COUNT; k++) {
                   
View Full Code Here

     * Process the {@link Event} and update the index if something relevant is received
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public void event(Event event) {
        final MailboxSession session = event.getSession();

        try {
            if (event instanceof MessageEvent) {
                if (event instanceof AddedImpl) {
                    AddedImpl added = (AddedImpl) event;
                    final Mailbox<Id> mailbox = added.getMailbox();
                    Iterator<Long> uids = added.getUids().iterator();

                    while (uids.hasNext()) {
                        long next = uids.next();
                        factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.one(next), FetchType.Full, new MessageCallback<Id>() {

                            @Override
                            public void onMessages(List<Message<Id>> list) throws MailboxException {
                                for (int i = 0; i < list.size(); i++) {
                                    Message<Id> message = list.get(i);
                                    try {
                                        add(session, mailbox, message);
                                    } catch (MailboxException e) {
                                        session.getLog().debug("Unable to index message " + message.getUid() + " for mailbox " + mailbox, e);
                                    }
                                }
                            }
                        });

                    }
                } else if (event instanceof ExpungedImpl) {
                    ExpungedImpl expunged = (ExpungedImpl) event;
                    final Mailbox<Id> mailbox = expunged.getMailbox();
                    List<Long> uids = expunged.getUids();
                    List<MessageRange> ranges = MessageRange.toRanges(uids);
                    for (int i = 0; i < ranges.size(); i++) {
                        MessageRange range = ranges.get(i);
                        try {
                            delete(session, mailbox, range);
                        } catch (MailboxException e) {
                            session.getLog().debug("Unable to deleted range " + range.toString() + " from index for mailbox " + mailbox, e);
                        }
                    }
                } else if (event instanceof FlagsUpdatedImpl) {
                    FlagsUpdatedImpl flagsUpdated = (FlagsUpdatedImpl) event;
                    final Mailbox<Id> mailbox = flagsUpdated.getMailbox();

                    Iterator<UpdatedFlags> flags = flagsUpdated.getUpdatedFlags().iterator();
                    while(flags.hasNext()) {
                        UpdatedFlags uFlags = flags.next();
                        try {
                            update(session, mailbox, MessageRange.one(uFlags.getUid()), uFlags.getNewFlags());
                        } catch (MailboxException e) {
                            session.getLog().debug("Unable to update flags for message " + uFlags.getUid() + " in index for mailbox " + mailbox, e);
                        }
                    }
                }
            } else if (event instanceof MailboxDeletionImpl) {
                // delete all indexed messages for the mailbox
                delete(session, ((MailboxDeletionImpl) event).getMailbox(), MessageRange.all());
            }
        } catch (MailboxException e) {
            session.getLog().debug("Unable to update index", 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.