Package org.apache.james.mailbox

Examples of org.apache.james.mailbox.MailboxSession


    /**
     * Close system session and shutdown system repository.
     */
    @After
    public void tearDown() throws BadCredentialsException, MailboxException {
        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
        session.close();
        repository.shutdown();
        new File(JACKRABBIT_HOME).delete();
    }
View Full Code Here


    }
   
    @After
    public void tearDown() {
        MailboxSession session = mailboxManager.createSystemSession("test", LoggerFactory.getLogger("Test"));
        session.close();
        repository.shutdown();
        new File(JACKRABBIT_HOME).delete();
    }
View Full Code Here

    public void testStessTest() throws InterruptedException, MailboxException {
      
        final CountDownLatch latch = new CountDownLatch(APPEND_OPERATIONS);
        final ExecutorService pool = Executors.newFixedThreadPool(APPEND_OPERATIONS/2);
       
        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
        getMailboxManager().startProcessingRequest(session);
        final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, "username", "INBOX");
        getMailboxManager().createMailbox(path, session);
        getMailboxManager().endProcessingRequest(session);
        getMailboxManager().logout(session, false);
        final AtomicBoolean fail = new AtomicBoolean(false);
        final ConcurrentHashMap<Long, Object> uids = new ConcurrentHashMap<Long, Object>();
       
        // fire of 1000 append operations
        for (int i = 0 ; i < APPEND_OPERATIONS; i++) {
            pool.execute(new Runnable() {
               
                public void run() {
                    if (fail.get()){
                        latch.countDown();
                        return;
                    }
                   

                    try {
                        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));

                        getMailboxManager().startProcessingRequest(session);
                        MessageManager m = getMailboxManager().getMailbox(path, session);
                        Long uid =  m.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
                        System.out.println("Append message with uid=" + uid);
View Full Code Here

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

            }
            try {
                List<Long> uidList = (List<Long>) session.getState().get(POP3Session.UID_LIST);
                List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);

                MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
                Long uid = uidList.get(num - 1);
                if (deletedUidList.contains(uid) == false) {
                    FetchGroupImpl fetchGroup = new FetchGroupImpl(FetchGroup.BODY_CONTENT);
                    fetchGroup.or(FetchGroup.HEADERS);
                    Iterator<MessageResult> results = session.getUserMailbox().getMessages(MessageRange.one(uid), fetchGroup, mailboxSession);
View Full Code Here

            }
            try {
                List<Long> uidList = (List<Long>) session.getState().get(POP3Session.UID_LIST);
                List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);

                MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
                Long uid = uidList.get(num - 1);
                if (deletedUidList.contains(uid) == false) {
                    Iterator<MessageResult> results = session.getUserMailbox().getMessages(MessageRange.one(uid), new FetchGroupImpl(FetchGroup.FULL_CONTENT), mailboxSession);
                    MessageStream stream = new MessageStream();
                    OutputStream out = stream.getOutputStream();
View Full Code Here

                        // username
                        if (mailServer.supportVirtualHosting()) {
                            user = user + "@" + host;
                        }

                        final MailboxSession session = mailboxManager.createSystemSession(user, new MailetLog());

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

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

                        if (destination == null || "".equals(destination)) {
                            destination = "INBOX";
                        }
                        if (destination.startsWith(MailboxConstants.DEFAULT_DELIMITER_STRING))
                            destination = destination.substring(1);
                        final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, destination);
                        try {
                            if ("INBOX".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 (IOException e) {
                            throw new MessagingException("Failed to write mail message", e);
                        } finally {
                            session.close();
                            mailboxManager.logout(session, true);

                            // stop processing request
                            mailboxManager.endProcessingRequest(session);
                        }
View Full Code Here

            SMTPResponse response;
           
            try {
               
                MailboxSession mailboxSession = mailboxManager.createSystemSession(username, session.getLogger());
                MailboxPath inbox = MailboxPath.inbox(username);
               
                mailboxManager.startProcessingRequest(mailboxSession);
               
                // create inbox if not exist
View Full Code Here

     *
     * @param recipient the recipient to check
     */   
    protected long getUsed(MailAddress recipient, Mail _) throws MessagingException {
        long size = 0;
        MailboxSession session = manager.createSystemSession(getPrimaryName(recipient.getLocalPart()), new Log() {

      public void debug(Object arg0) {
        // just consume        
      }

      public void debug(Object arg0, Throwable arg1) {
        // just consume
      }

      public void error(Object arg0) {
        log(arg0.toString());

      }

      public void error(Object arg0, Throwable arg1) {
        log(arg0.toString(),arg1);
      }

      public void fatal(Object arg0) {
        log(arg0.toString());
      }

      public void fatal(Object arg0, Throwable arg1) {
        log(arg0.toString(), arg1);       
      }

      public void info(Object arg0) {
        log(arg0.toString());
      }

      public void info(Object arg0, Throwable arg1) {
        log(arg0.toString(), arg1);
       
      }

      public boolean isDebugEnabled() {
        return false;
      }

      public boolean isErrorEnabled() {
        return true;
      }

      public boolean isFatalEnabled() {
        return true;
      }

      public boolean isInfoEnabled() {
        return true;
      }

      public boolean isTraceEnabled() {
        return false;
      }

      public boolean isWarnEnabled() {
        return true;
      }

      public void trace(Object arg0) {
        // just consume        
      }

      public void trace(Object arg0, Throwable arg1) {
        // just consume        
      }

      public void warn(Object arg0) {
        log(arg0.toString());
      }

      public void warn(Object arg0, Throwable arg1) {
        log(arg0.toString(), arg1);
      }
         
        });
        manager.startProcessingRequest(session);
        MessageManager mailbox = manager.getMailbox(new MailboxPath(MailboxConstants.USER_NAMESPACE,
                                            session.getUser().getUserName(), "INBOX"),
                                            session);
        Iterator<MessageResult> results = mailbox.getMessages(MessageRange.all(), new FetchGroupImpl(FetchGroup.MINIMAL), session);
       
        while (results.hasNext()) {
          size += results.next().getSize();
View Full Code Here

                    // username
                    if (mailServer.supportVirtualHosting()) {
                        user = user + "@" + host;
                    }

                    final MailboxSession session = mailboxManager.createSystemSession(user, new MailetLog());

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

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

                    if (destination == null || "".equals(destination)) {
                        destination = "INBOX";
                    }
                    if (destination.startsWith(MailboxConstants.DEFAULT_DELIMITER_STRING))
                        destination = destination.substring(1);
                    final MailboxPath path = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, destination);
                    try {
                        if ("INBOX".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);
                    } finally {
                        session.close();
                        mailboxManager.logout(session, true);

                        // stop processing request
                        mailboxManager.endProcessingRequest(session);
                       
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.