Package org.apache.james.core

Examples of org.apache.james.core.MailImpl


        // if headers do not contains minimum REQUIRED headers fields throw Exception
        if ( !headers.isValid() ) {
            throw new MessagingException( "Some REQURED header field is missing. Invalid Message" );
        }
        ByteArrayInputStream headersIn = new ByteArrayInputStream( headers.toByteArray() );
        sendMail( new MailImpl( getId(), sender, recipients, new SequenceInputStream( headersIn, msg ) ) );
    }
View Full Code Here


     * @throws MessagingException if an exception is caught while placing the mail
     *                            on the spool
     */
    public void sendMail( Mail mail ) throws MessagingException
    {
        MailImpl mailimpl = ( MailImpl ) mail;
        try {
            spool.store( mailimpl );
        }
        catch ( Exception e ) {
            try {
                spool.remove( mailimpl );
            }
            catch ( Exception ignored ) {
            }
            throw new MessagingException( "Exception spooling message: " + e.getMessage(), e );
        }
        if ( getLogger().isDebugEnabled() ) {
            StringBuffer logBuffer =
                    new StringBuffer( 64 )
                    .append( "Mail " )
                    .append( mailimpl.getName() )
                    .append( " pushed in spool" );
            getLogger().debug( logBuffer.toString() );
        }
    }
View Full Code Here

        if ( useIMAPstorage ) {
            ImapMailbox mbox = null;
            try {
                user = ( JamesUser ) localusers.getUserByName( username );
                mbox = imapHost.getInbox( user );
                MailImpl mail = new MailImpl( message );
                mbox.store( mail );
                getLogger().info( "Message " + message.getMessageID() +
                                  " stored in " +
                                  mbox.getFullName() );
                mbox = null;
            }
            catch ( Exception e ) {
                getLogger().error( "Exception storing mail: " + e );
                e.printStackTrace();
                if ( mbox != null ) {
                    mbox = null;
                }
                throw new RuntimeException( "Exception storing mail: " + e );
            }
        }
        else {
            Collection recipients = new HashSet();
            recipients.add( recipient );
            MailImpl mailImpl = new MailImpl( getId(), sender, recipients, message );
            MailRepository userInbox = getUserInbox( username );
            if ( userInbox == null ) {
                StringBuffer errorBuffer =
                        new StringBuffer( 128 )
                        .append( "The inbox for user " )
View Full Code Here

     * @throws MessagingException if an exception is caught while placing the mail
     *                            on the spool
     */
    public void sendMail(MailAddress sender, Collection recipients, MimeMessage message, String state)
            throws MessagingException {
        MailImpl mail = new MailImpl(getId(), sender, recipients, message);
        mail.setState(state);
        sendMail(mail);
    }
View Full Code Here

        // if headers do not contains minimum REQUIRED headers fields throw Exception
        if (!headers.isValid()) {
            throw new MessagingException("Some REQURED header field is missing. Invalid Message");
        }
        ByteArrayInputStream headersIn = new ByteArrayInputStream(headers.toByteArray());
        sendMail(new MailImpl(getId(), sender, recipients, new SequenceInputStream(headersIn, msg)));
    }
View Full Code Here

     *
     * @throws MessagingException if an exception is caught while placing the mail
     *                            on the spool
     */
    public void sendMail(Mail mail) throws MessagingException {
        MailImpl mailimpl = (MailImpl)mail;
        try {
            spool.store(mailimpl);
        } catch (Exception e) {
            try {
                spool.remove(mailimpl);
            } catch (Exception ignored) {
            }
            throw new MessagingException("Exception spooling message: " + e.getMessage(), e);
        }
        if (getLogger().isDebugEnabled()) {
            StringBuffer logBuffer =
                new StringBuffer(64)
                        .append("Mail ")
                        .append(mailimpl.getName())
                        .append(" pushed in spool");
            getLogger().debug(logBuffer.toString());
        }
    }
View Full Code Here

            }
        }

        Collection recipients = new HashSet();
        recipients.add(recipient);
        MailImpl mailImpl = new MailImpl(getId(), sender, recipients, message);
        MailRepository userInbox = getUserInbox(username);
        if (userInbox == null) {
            StringBuffer errorBuffer =
                new StringBuffer(128)
                    .append("The inbox for user ")
View Full Code Here

    private void stat() {
        userMailbox = new Vector();
        userMailbox.addElement(DELETED);
        for (Iterator it = userInbox.list(); it.hasNext(); ) {
            String key = (String) it.next();
            MailImpl mc = userInbox.retrieve(key);
            // Retrieve can return null if the mail is no longer in the store.
            // In this case we simply continue to the next key
            if (mc == null) {
                continue;
            }
View Full Code Here

        if (state == TRANSACTION) {
            long size = 0;
            int count = 0;
            try {
                for (Enumeration e = userMailbox.elements(); e.hasMoreElements(); ) {
                    MailImpl mc = (MailImpl) e.nextElement();
                    if (mc != DELETED) {
                        size += mc.getMessageSize();
                        count++;
                    }
                }
                StringBuffer responseBuffer =
                    new StringBuffer(32)
View Full Code Here

            if (argument == null) {
                long size = 0;
                int count = 0;
                try {
                    for (Enumeration e = userMailbox.elements(); e.hasMoreElements(); ) {
                        MailImpl mc = (MailImpl) e.nextElement();
                        if (mc != DELETED) {
                            size += mc.getMessageSize();
                            count++;
                        }
                    }
                    StringBuffer responseBuffer =
                        new StringBuffer(32)
                                .append(OK_RESPONSE)
                                .append(" ")
                                .append(count)
                                .append(" ")
                                .append(size);
                    responseString = responseBuffer.toString();
                    writeLoggedFlushedResponse(responseString);
                    count = 0;
                    for (Enumeration e = userMailbox.elements(); e.hasMoreElements(); count++) {
                        MailImpl mc = (MailImpl) e.nextElement();
                        if (mc != DELETED) {
                            responseBuffer =
                                new StringBuffer(16)
                                        .append(count)
                                        .append(" ")
                                        .append(mc.getMessageSize());
                            out.println(responseBuffer.toString());
                        }
                    }
                    out.println(".");
                    out.flush();
                } catch (MessagingException me) {
                    responseString = ERR_RESPONSE;
                    writeLoggedFlushedResponse(responseString);
                }
            } else {
                int num = 0;
                try {
                    num = Integer.parseInt(argument);
                    MailImpl mc = (MailImpl) userMailbox.elementAt(num);
                    if (mc != DELETED) {
                        StringBuffer responseBuffer =
                            new StringBuffer(64)
                                    .append(OK_RESPONSE)
                                    .append(" ")
                                    .append(num)
                                    .append(" ")
                                    .append(mc.getMessageSize());
                        responseString = responseBuffer.toString();
                        writeLoggedFlushedResponse(responseString);
                    } else {
                        StringBuffer responseBuffer =
                            new StringBuffer(64)
View Full Code Here

TOP

Related Classes of org.apache.james.core.MailImpl

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.