Java Network Programming (3rd ed) [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Java Network Programming (3rd ed) [Electronic resources] - نسخه متنی

Harold, Elliotte Rusty

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








19.10 MIME Messages


MIME was
designed mainly for Internet email and specifically organized to 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 70 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 methods in
Part or 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, 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 5
support". It is not divided into a separate name and
value:

public Enumeration getAllHeaderLines( ) throws MessagingException

The getMatchingHeaderLines() method returns all header
lines with names given in the names argument
array. The getNonMatchingHeaderLines(
)
method does the reverse;
it returns the 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 seven-bit or perhaps eight-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 might look like
<Pine.LNX.4.
10.9912290930220.8058@akbar.nevex.com>
. 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 setfor example, us-ascii or ISO 8859-1:

public void setText(String text) throws MessagingException
public void setText(String text, String charset)
throws MessagingException


/ 164