001package votorola.g.mail; // Copyright 2007, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import javax.mail.*;
004import votorola.g.lang.*;
005
006
007/** Message utilities.
008  */
009public final @ThreadSafe class MessageX
010{
011
012    private MessageX() {}
013
014
015
016    /** Returns the address of the first header sender (From).
017      *
018      *     @return address of header sender, or null if none exists
019      */
020    public static Address getFirstFrom( final Message message ) throws MessagingException
021    {
022        Address a = null; // till proven otherwise
023        final Address[] aArray = message.getFrom();
024        if( aArray != null && aArray.length > 0 ) a = aArray[0];
025
026        return a;
027    }
028
029
030
031    /** Returns the address of the first recipient of the specified type. Never tested.
032      *
033      *     @return address of recipient, or null if no such recipient exists
034      */
035    public static Address getFirstRecipient(
036        final Message message, final Message.RecipientType type ) throws MessagingException
037    {
038        Address a = null; // till proven otherwise
039        final Address[] aArray = message.getRecipients( type );
040        if( aArray != null && aArray.length > 0 ) a = aArray[0];
041
042        return a;
043    }
044
045
046
047}