Examples of EmailAddress


Examples of com.ericdaugherty.mail.server.info.EmailAddress

    private void handleRcptTo( String inputString ) {

        String toAddress = parseAddress( inputString.substring( 8 ) );

        try {
            EmailAddress address = new EmailAddress( toAddress );
            //Check the address to see if we can deliver it.
            DeliveryService deliveryService = DeliveryService.getDeliveryService();
            if( deliveryService.acceptAddress( address, clientIp, message.getFromAddress() ) ) {
                // Check to see if it is a local user.  If so, ask to
                // user object for the delivery addresses.
                User localUser = configurationManager.getUser( address );
                if( localUser!= null ) {
                    EmailAddress[] addresses = localUser.getDeliveryAddresses();
                    for( int index = 0; index < addresses.length; index++ ) {
                        message.addToAddress( addresses[index] );
                    }
                }
                // Otherwise, just add the address.
                else {
                    message.addToAddress( address );
                }
                write( MESSAGE_OK );
                if( log.isDebugEnabled() ) { log.debug( "RCTP TO: " + address.getAddress() + " accepted." ); }
            }
            else {
                if( log.isInfoEnabled() ) log.info( "Invalid delivery address for incoming mail: " + toAddress + " from client: " + clientIp + " / " + message.getFromAddress() );
                throw new InvalidAddressException();
            }
View Full Code Here

Examples of com.ericdaugherty.mail.server.info.EmailAddress

    private void deliver( SMTPMessage message ) {

        List toAddresses = message.getToAddresses();
        int numAddress = toAddresses.size();
        Vector failedAddress = new Vector();
        EmailAddress address = null;

        // If the next scheduled delivery attempt is still in the future, skip.
        if( message.getScheduledDelivery().getTime() > System.currentTimeMillis() )
        {
            if( log.isDebugEnabled() ) log.debug( "Skipping delivery of message " + message.getMessageLocation().getName() + " because the scheduled delivery time is still in the future: " + message.getScheduledDelivery() );
            return;
        }

        for( int index = 0; index < numAddress; index++ ) {
            try {
                address = (EmailAddress) toAddresses.get( index );
                if( log.isDebugEnabled()) { log.debug( "Attempting to deliver message from: " + message.getFromAddress().getAddress() + " to: " + address ); }

                DeliveryService deliveryService = DeliveryService.getDeliveryService();

                try {
                    if( deliveryService.isLocalAddress( address ) ) {
                        deliverLocalMessage( address, message );
                    }
                    else {
                        deliverRemoteMessage( address, message );
                    }
                }
                catch (NotFoundException e) {
                    log.info( "Delivery attempted to unknown user: " + address.getAddress() );
                    //The addressee does not exist.  Notify the sender of the error.
                    bounceMessage( address, message );
                }

                if( log.isInfoEnabled() ) { log.info( "Delivery complete for message " + message.getMessageLocation().getName() + " to: " + address ); }
            }
            catch( Throwable throwable ) {
                log.error( "Delivery failed for message from: " + message.getFromAddress().getAddress() + " to: " + address + " - " + throwable, throwable );
                failedAddress.addElement( toAddresses.get( index ) );
            }
        }

        // If all addresses were successful, remove the message from the spool
        if( failedAddress.size() == 0 ) {
            // Log an error if the delete fails.  This will cause the message to get
            // delivered again, but it is too late to roll back the delivery.
            if( !message.getMessageLocation().delete() )
            {
                log.error( "Error removed SMTP message after delivery!  This message may be redelivered. " + message.getMessageLocation().getName() );
            }
        }
        // Update the message with any changes.
        else {

            message.setToAddresses( failedAddress );
            int deliveryAttempts = message.getDeliveryAttempts();


            // If the message is a bounced email, just give up and move it to the failed directory.
            if(message.getFromAddress().getUsername().equalsIgnoreCase("MAILER_DAEMON"))
            {
                try {
                    log.info( "Delivery of message from MAILER_DAEMON failed, moving to failed folder." );
                    message.moveToFailedFolder();
                }
                catch (Exception e) {
                    log.error( "Unable to move failed message to 'failed' folder." );
                }
            }
            // If we have not passed the maximum delivery count, calculate the
            // next delivery time and save the message.
            else ifdeliveryAttempts < configurationManager.getDeliveryAttemptThreshold() )
            {
                message.setDeliveryAttempts( deliveryAttempts + 1 );

                // Reschedule later, 1 min, 2 min, 4 min, 8 min, ... 2^n
                // Cap delivery interval at 2^10 minutes. (about 17 hours)
                if( deliveryAttempts > 10 )
                {
                    deliveryAttempts = 10;
                }
                long offset = (long)Math.pow( 2, deliveryAttempts);
                Date schedTime = new Date(System.currentTimeMillis() + offset*60*1000);
                message.setScheduledDelivery( schedTime );

                try {
                    message.save();
                }
                catch( Exception exception ) {
                    log.error( "Error updating spooled message for next delivery.  Message may be re-delivered.", exception );
                }
            }
            // All delivery attempts failed, bounce message.
            else
            {
                // Send a bounce message to all failed addresses.
                for( int index = 0; index < failedAddress.size(); index++ ) {
                    try {
                        EmailAddress bounce_address = (EmailAddress)( failedAddress.elementAt(index) );
                        bounceMessage(bounce_address, message);
                    }
                    catch(Exception e) {
                        log.error( "Problem bouncing message. " + message.getMessageLocation().getName() );
                    }
View Full Code Here

Examples of com.ericdaugherty.mail.server.info.EmailAddress

        {
            log.debug( "User not found, checking for default delivery options" );
            //Check to see if a default delivery mailbox exists, and if so, deliver it.
            //Otherwise, just throw the NotFoundException to bounce the email.
            if( configurationManager.isDefaultUserEnabled() ) {
                EmailAddress defaultAddress = configurationManager.getDefaultUser();
                //If this throws a NotFoundException, go ahead and let it bounce.
                user = configurationManager.getUser( defaultAddress );
                if( user == null ) throw new NotFoundException();
                if( log.isDebugEnabled() ) { log.info( "Delivering message addressed to: " + address + " to default user: " + defaultAddress ); }
            }
View Full Code Here

Examples of com.ericdaugherty.mail.server.info.EmailAddress

        if( log.isInfoEnabled() ) { log.info( "Bouncing Messsage from " + message.getFromAddress().getAddress() + " to " + address.getAddress() ); }

        SMTPMessage bounceMessage = new SMTPMessage();

        //Set the from address as mailserver@ the first (default) local domain.
        EmailAddress fromAddress = new EmailAddress( "MAILER_DAEMON", configurationManager.getLocalDomains()[0] );

        bounceMessage.setFromAddress( fromAddress );
        bounceMessage.addToAddress( message.getFromAddress() );
        bounceMessage.addDataLine( "From: Mail Delivery Subsystem <MAILER-DAEMON@" + configurationManager.getLocalDomains()[0] + ">" );
        bounceMessage.addDataLine( "To: " + message.getFromAddress().getAddress() );
View Full Code Here

Examples of com.ericdaugherty.mail.server.info.EmailAddress

        // Load default user info
        String defaultUserString = properties.getProperty( DEFAULT_USER, "" ).trim();;
        if( defaultUserString.length() > 0 )
        {
            try {
                defaultUser = new EmailAddress( defaultUserString );
                defaultUserEnabled = true;
            }
            catch (InvalidAddressException e) {
                throw new RuntimeException( "Invalid address for default user: " + defaultUserString );
            }
View Full Code Here

Examples of com.ericdaugherty.mail.server.info.EmailAddress

     * @param properties the properties that contain the user parameters.
     * @return a new User instance.
     */
    private User loadUser( String fullAddress, Properties properties ) throws InvalidAddressException
    {
        EmailAddress address = new EmailAddress( fullAddress );
        User user = new User( address );

        // Load the password
        String password = properties.getProperty( USER_DEF_PREFIX + fullAddress );
        // If the password is not hashed, hash it now.
        if( password.length() != 60 ) {
            password = PasswordManager.encryptPassword( password );
            properties.setProperty( USER_DEF_PREFIX + fullAddress, password );
            if( password == null ) {
                log.error( "Error encrypting plaintext password from user.conf for user " + fullAddress );
                throw new RuntimeException( "Error encrypting password for user: " + fullAddress );
            }
            userConfModified = true;
        }
        user.setPassword( password );

        // Load the 'forward' addresses.
        String forwardAddressesString = properties.getProperty( USER_PROPERTY_PREFIX + fullAddress + USER_FILE_FORWARDS );
        String[] forwardAddresses = new String[0];
        if( forwardAddressesString != null && forwardAddressesString.trim().length() >= 0 )
        {
            forwardAddresses = tokenize( forwardAddressesString );
        }
        ArrayList addressList = new ArrayList( forwardAddresses.length );
        for( int index = 0; index < forwardAddresses.length; index++ ) {
            try {
                addressList.add( new EmailAddress( forwardAddresses[index] ) );
            }
            catch (InvalidAddressException e) {
                log.warn( "Forward address: " + forwardAddresses[index] + " for user " + user.getFullUsername() + " is invalid and will be ignored." );
            }
        }
View Full Code Here

Examples of com.googlecode.gmail4j.EmailAddress

    @Override
    public EmailAddress getFrom() {
        if (from == null) {
            final SyndPerson author = (SyndPerson) rssEntry.getAuthors().get(0);
            from = new EmailAddress(author.getName(), author.getEmail());
        }
        return from;
    }
View Full Code Here

Examples of com.googlecode.gmail4j.EmailAddress

    private List<EmailAddress> getAddresses(final RecipientType type)
            throws MessagingException {
        final List<EmailAddress> addresses = new ArrayList<EmailAddress>();
        for (final Address addr : source.getRecipients(type)) {
            final InternetAddress temp = (InternetAddress) addr;
            addresses.add(new EmailAddress(temp.getPersonal(), temp.getAddress()));
        }
        return addresses;
    }
View Full Code Here

Examples of com.googlecode.gmail4j.EmailAddress

        }
        client.setConnection(connection);
        GmailMessage msg = new JavaMailGmailMessage();
        msg.setSubject("Test mail subject. Unicode: ąžuolėlį");
        msg.setContentText("Test mail content. Unicode: ąžuolėlį");
        msg.addTo(new EmailAddress(conf.getTestRecipient()));
        client.send(msg);
    }
View Full Code Here

Examples of com.googlecode.gmail4j.EmailAddress

    @Override
    public EmailAddress getFrom() {
        if (from == null) {
            try {
                final InternetAddress f = (InternetAddress) source.getFrom()[0];
                from = new EmailAddress(f.getPersonal(), f.getAddress());
            } catch (final Exception e) {
                throw new GmailException("Failed getting from address", e);
            }
        }
        return from;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.