FileDocCategorySizeDatePackage
MessageInfo.javaAPI DocGlassfish v2 API8962Mon Oct 17 14:54:30 BST 2005demo

MessageInfo

public class MessageInfo extends Object
Used to store message information.

Fields Summary
private Message
message
Constructors Summary
Methods Summary
private java.lang.StringformatAddresses(javax.mail.Address[] addrs)
Utility method for formatting msg header addresses.

        if (addrs == null)
            return "";
        StringBuffer strBuf = new StringBuffer(getDisplayAddress(addrs[0]));
        for (int i = 1; i < addrs.length; i++) {
            strBuf.append(", ").append(getDisplayAddress(addrs[i]));
        }
        return strBuf.toString();
    
public java.lang.StringgetBcc()
Returns the bcc field.

        return formatAddresses(
            message.getRecipients(Message.RecipientType.BCC));
    
public java.lang.StringgetBody()
Returns the body of the message (if it's plain text).

        Object content = message.getContent();
        if (message.isMimeType("text/plain")) {
            return (String)content;
        } else if (message.isMimeType("multipart/alternative")) {
	    Multipart mp = (Multipart)message.getContent();
            int numParts = mp.getCount();
            for (int i = 0; i < numParts; ++i) {
                if (mp.getBodyPart(i).isMimeType("text/plain"))
                    return (String)mp.getBodyPart(i).getContent();
            }
            return "";   
        } else if (message.isMimeType("multipart/*")) { 
	    Multipart mp = (Multipart)content;
            if (mp.getBodyPart(0).isMimeType("text/plain"))
                return (String)mp.getBodyPart(0).getContent();
            else
                return "";
        } else
            return "";
    
public java.lang.StringgetCc()
Returns the cc field.

        return formatAddresses(
            message.getRecipients(Message.RecipientType.CC));
    
public java.lang.StringgetDate()
Returns the date the message was sent (or received if the sent date is null.

        Date date;
        SimpleDateFormat df = new SimpleDateFormat("EE M/d/yy");
        if ((date = message.getSentDate()) != null)
            return (df.format(date));
        else if ((date = message.getReceivedDate()) != null)
            return (df.format(date));
        else
            return "";
     
private java.lang.StringgetDisplayAddress(javax.mail.Address a)
Utility method which returns a string suitable for msg header display.

        String pers = null;
        String addr = null;
        if (a instanceof InternetAddress &&
           ((pers = ((InternetAddress)a).getPersonal()) != null)) {
	    addr = pers + "  "+"<"+((InternetAddress)a).getAddress()+">";
        } else 
            addr = a.toString();
        return addr;
    
public java.lang.StringgetFrom()
Returns the from field.

        return formatAddresses(message.getFrom());
    
public MessagegetMessage()
Returns the javax.mail.Message object.

        return message;
    
public java.lang.StringgetNum()
Returns the message number.

        return (Integer.toString(message.getMessageNumber()));
    
public java.lang.StringgetReceivedDate()
Returns the received date field.

        if (hasReceivedDate())
            return (message.getReceivedDate().toString());
        else
            return "";
    
public java.lang.StringgetReplyTo()
Returns the address to reply to.

	Address[] a = message.getReplyTo();
	if (a.length > 0)
	    return ((InternetAddress)a[0]).getAddress();
	else
	    return "";
    
public java.lang.StringgetSentDate()
Returns the sent date field.

        if (hasSentDate())
            return (message.getSentDate().toString()); 
        else
            return "";
    
public java.lang.StringgetSubject()
Returns the subject field.

        if (hasSubject())
            return message.getSubject();
        else
            return "";
    
public java.lang.StringgetTo()
Returns the to field.

        return formatAddresses(
            message.getRecipients(Message.RecipientType.TO));
    
public booleanhasAttachments()
Method for checking if the message has attachments.

        boolean hasAttachments = false;
        if (message.isMimeType("multipart/*")) {
	    Multipart mp = (Multipart)message.getContent();
            if (mp.getCount() > 1)
                hasAttachments = true;
        }
            
        return hasAttachments;
    
public booleanhasBcc()
Method for checking if the message has a bcc field.

        return (message.getRecipients(Message.RecipientType.BCC) != null);
    
public booleanhasCc()
Method for checking if the message has a cc field.

        return (message.getRecipients(Message.RecipientType.CC) != null);
    
public booleanhasDate()
Method for checking if the message has a date field.

        return (hasSentDate() || hasReceivedDate());
    
public booleanhasFrom()
Method for checking if the message has a from field.

        return (message.getFrom() != null);
    
public booleanhasMimeType(java.lang.String mimeType)
Method for checking if the message has the desired mime type.

        return message.isMimeType(mimeType);
    
public booleanhasReceivedDate()
Method for checking if the message has a received date field.

        return (message.getReceivedDate() != null);
    
public booleanhasSentDate()
Method for checking if the message has a sent date field.

        return (message.getSentDate() != null);
    
public booleanhasSubject()
Method for checking if the message has a subject field.

        return (message.getSubject() != null);
    
public booleanhasTo()
Method for checking if the message has a to field.

        return (message.getRecipients(Message.RecipientType.TO) != null);
    
public voidsetMessage(Message message)
Method for mapping a message to this MessageInfo class.

        this.message = message;