MIME was
designed mainly for Internet email, and it was specifically organized
so that it would be backward compatible with existing protocols and
software. Therefore, a typical Internet email message is in fact a
MIME message. The only concrete subclass of
Message
in the JavaMail API is
javax.mail.internet.MimeMessage
:
public class MimeMessage extends Message implements MimePart
This class declares almost seventy public and protected methods.
However, with the natural exception of the constructors, almost all
of these either override methods from the Message
superclass or implement methods declared by the
Part
interface. The only new methods are a
baker’s dozen declared in the MimePart
interface, a subinterface of Part
:
public interface MimePart extends Part
Most of these methods are very similar to
either methods in Part
or methods in
Message
. However, they have features that are
unlikely to be found in non-MIME messages. For instance, a MIME part
may have an MD5 digest, which would be encoded as an extra header
inside the part. Thus, the MimePart
interface
declares and the MimeMessage
class implements two
methods to set and get this digest:
public String getContentMD5( ) throws MessagingException public void setContentMD5(String md5) throws MessagingException, IllegalWriteException, IllegalStateException
The addHeaderLine( )
method adds a string of text to
the header of the message. It’s up to you to make sure that
this string will actually make sense in the header:
public void addHeaderLine(String line) throws MessagingException, IllegalWriteException, IllegalStateException
The getHeader( )
method returns the value of every
header in the message with the given name. If there are multiple
headers with this name, then the string separates the values of the
different headers with the specified delimiter
string:
public String getHeader(String name, String delimiter) throws MessagingException
The getAllHeaderLines( )
method returns a
java.util.Enumeration
containing every header in
the message. The Enumeration
contains
String
objects, one per header. Each
String
contains the full name and value; for
example, “Subject: Re: Java 2 support”. It is not divided
into a separate name and value:
public Enumeration getAllHeaderLines( ) throws MessagingException
The getMatchingHeaderLines( )
method returns all header lines
whose names are given in the names
argument array.
The getNonMatchingHeaderLines( )
method does the
same thing except that it returns all those header lines with a name
not mentioned in the names
argument:
public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException
The getEncoding( )
method returns the encoding of
this MIME part as a String
as given by the
Content-transfer-encoding: header. The typical encoding for a
plain-text email is 7-bit or perhaps 8-bit or quoted-printable. The
typical encoding for a file attachment is Base64:
public String getEncoding( ) throws MessagingException
The getContentID( )
method returns a string that
uniquely identifies this part as given by the part’s
Content-ID: field. A typical ID looks like
<[email protected]>
.
It returns null if the part doesn’t have a content ID:
public String getContentID( ) throws MessagingException IllegalWriteException, IllegalStateException
The getContentLanguage( )
method returns the value of the
Content-language: header. This is a comma-separated list of two (or
more) letter abbreviations for languages as defined by RFC 1766. For
example, English is “en” and French is “fr”.
It returns null if the part doesn’t have a Content-language:
header.
public String[] getContentLanguage( ) throws MessagingException
There’s also a setContentLanguage( )
method that you might use when
sending a message:
public void setContentLanguage(String[] languages) throws MessagingException, IllegalWriteException, IllegalStateException
Finally, the two setText( )
methods set the content of the part
with the MIME type text/plain. The second setText( )
method also lets you specify the character set; for
example, us-ascii or ISO 8859-1:
public void setText(String text) throws MessagingException public void setText(String text, String charset) throws MessagingException
18.188.40.207