FileDocCategorySizeDatePackage
MessageContext.javaAPI DocGlassfish v2 API4293Mon May 14 15:28:48 BST 2007javax.mail

MessageContext

public class MessageContext extends Object
The context in which a piece of Message content is contained. A MessageContext object is returned by the getMessageContext method of the MessageAware interface. MessageAware is typically implemented by DataSources to allow a DataContentHandler to pass on information about the context in which a data content object is operating.
see
javax.mail.MessageAware
see
javax.activation.DataSource
see
javax.activation.DataContentHandler
since
JavaMail 1.1

Fields Summary
private Part
part
Constructors Summary
public MessageContext(Part part)
Create a MessageContext object describing the context of the given Part.

	this.part = part;
    
Methods Summary
public MessagegetMessage()
Return the Message that contains the content. Follows the parent chain up through containing Multipart objects until it comes to a Message object, or null.

return
the containing Message, or null if not known

	try {
	    return getMessage(part);
	} catch (MessagingException ex) {
	    return null;
	}
    
private static MessagegetMessage(javax.mail.Part p)
Return the Message containing an arbitrary Part. Follows the parent chain up through containing Multipart objects until it comes to a Message object, or null.

return
the containing Message, or null if none
see
javax.mail.BodyPart#getParent
see
javax.mail.Multipart#getParent

	while (p != null) {
	    if (p instanceof Message)
		return (Message)p;
	    BodyPart bp = (BodyPart)p;
	    Multipart mp = bp.getParent();
	    if (mp == null)	// MimeBodyPart might not be in a MimeMultipart
		return null;
	    p = mp.getParent();
	}
	return null;
    
public javax.mail.PartgetPart()
Return the Part that contains the content.

return
the containing Part, or null if not known

	return part;
    
public javax.mail.SessiongetSession()
Return the Session we're operating in.

return
the Session, or null if not known

	Message msg = getMessage();
	return msg != null ? msg.session : null;