首页

分享apache的commons-email源码包基于HtmlEmail邮件功能的主要源码实现分析

标签:HtmlEmail,commons-email,apache,javax.mail     发布时间:2018-02-23   

一、前言

基于apachecommons-email源码包中的org.apache.commons.mail.Email、org.apache.commons.mail.HtmlEmail、org.apache.commons.mail.MultiPartEmail类,实现发送HTML邮件内容功能的支持,详情参见源码部分说明

二、源码说明

1.Email抽象类

package org.apache.commons.mail;@b@@b@import java.io.UnsupportedEncodingException;@b@import java.nio.charset.Charset;@b@import java.util.ArrayList;@b@import java.util.Collection;@b@import java.util.Date;@b@import java.util.HashMap;@b@import java.util.List;@b@import java.util.Map;@b@import java.util.Map.Entry;@b@import java.util.Properties;@b@import javax.mail.Authenticator;@b@import javax.mail.Message.RecipientType;@b@import javax.mail.MessagingException;@b@import javax.mail.Session;@b@import javax.mail.Store;@b@import javax.mail.Transport;@b@import javax.mail.internet.AddressException;@b@import javax.mail.internet.InternetAddress;@b@import javax.mail.internet.MimeMessage;@b@import javax.mail.internet.MimeMultipart;@b@import javax.mail.internet.MimeUtility;@b@import javax.naming.Context;@b@import javax.naming.InitialContext;@b@import javax.naming.NamingException;@b@@b@public abstract class Email@b@{@b@@b@  @Deprecated@b@  public static final String SENDER_EMAIL = "sender.email";@b@@b@  @Deprecated@b@  public static final String SENDER_NAME = "sender.name";@b@@b@  @Deprecated@b@  public static final String RECEIVER_EMAIL = "receiver.email";@b@@b@  @Deprecated@b@  public static final String RECEIVER_NAME = "receiver.name";@b@@b@  @Deprecated@b@  public static final String EMAIL_SUBJECT = "email.subject";@b@@b@  @Deprecated@b@  public static final String EMAIL_BODY = "email.body";@b@@b@  @Deprecated@b@  public static final String CONTENT_TYPE = "content.type";@b@@b@  @Deprecated@b@  public static final String ATTACHMENTS = "attachments";@b@@b@  @Deprecated@b@  public static final String FILE_SERVER = "file.server";@b@@b@  @Deprecated@b@  public static final String KOI8_R = "koi8-r";@b@@b@  @Deprecated@b@  public static final String ISO_8859_1 = "iso-8859-1";@b@@b@  @Deprecated@b@  public static final String US_ASCII = "us-ascii";@b@@b@  @Deprecated@b@  public static final String MAIL_DEBUG = "mail.debug";@b@@b@  @Deprecated@b@  public static final String MAIL_HOST = "mail.smtp.host";@b@@b@  @Deprecated@b@  public static final String MAIL_PORT = "mail.smtp.port";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_FROM = "mail.smtp.from";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_USER = "mail.smtp.user";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_PASSWORD = "mail.smtp.password";@b@@b@  @Deprecated@b@  public static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol";@b@@b@  @Deprecated@b@  public static final String SMTP = "smtp";@b@@b@  @Deprecated@b@  public static final String TEXT_HTML = "text/html";@b@@b@  @Deprecated@b@  public static final String TEXT_PLAIN = "text/plain";@b@@b@  @Deprecated@b@  public static final String MAIL_TRANSPORT_TLS = "mail.smtp.starttls.enable";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_SOCKET_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_SOCKET_FACTORY_CLASS = "mail.smtp.socketFactory.class";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "mail.smtp.socketFactory.port";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout";@b@@b@  @Deprecated@b@  public static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";@b@  protected MimeMessage message;@b@  protected String charset;@b@  protected InternetAddress fromAddress;@b@  protected String subject;@b@  protected MimeMultipart emailBody;@b@  protected Object content;@b@  protected String contentType;@b@  protected boolean debug;@b@  protected Date sentDate;@b@  protected Authenticator authenticator;@b@  protected String hostName;@b@  protected String smtpPort;@b@  protected String sslSmtpPort;@b@  protected List<InternetAddress> toList;@b@  protected List<InternetAddress> ccList;@b@  protected List<InternetAddress> bccList;@b@  protected List<InternetAddress> replyList;@b@  protected String bounceAddress;@b@  protected Map<String, String> headers;@b@  protected boolean popBeforeSmtp;@b@  protected String popHost;@b@  protected String popUsername;@b@  protected String popPassword;@b@@b@  @Deprecated@b@  protected boolean tls;@b@@b@  @Deprecated@b@  protected boolean ssl;@b@  protected int socketTimeout;@b@  protected int socketConnectionTimeout;@b@  private boolean startTlsEnabled;@b@  private boolean startTlsRequired;@b@  private boolean sslOnConnect;@b@  private boolean sslCheckServerIdentity;@b@  private boolean sendPartial;@b@  private Session session;@b@@b@  public Email()@b@  {@b@    this.smtpPort = "25";@b@@b@    this.sslSmtpPort = "465";@b@@b@    this.toList = new ArrayList();@b@@b@    this.ccList = new ArrayList();@b@@b@    this.bccList = new ArrayList();@b@@b@    this.replyList = new ArrayList();@b@@b@    this.headers = new HashMap();@b@@b@    this.socketTimeout = 60000;@b@@b@    this.socketConnectionTimeout = 60000;@b@  }@b@@b@  public void setDebug(boolean d)@b@  {@b@    this.debug = d;@b@  }@b@@b@  public void setAuthentication(String userName, String password)@b@  {@b@    setAuthenticator(new DefaultAuthenticator(userName, password));@b@  }@b@@b@  public void setAuthenticator(Authenticator newAuthenticator)@b@  {@b@    this.authenticator = newAuthenticator;@b@  }@b@@b@  public void setCharset(String newCharset)@b@  {@b@    Charset set = Charset.forName(newCharset);@b@    this.charset = set.name();@b@  }@b@@b@  public void setContent(MimeMultipart aMimeMultipart)@b@  {@b@    this.emailBody = aMimeMultipart;@b@  }@b@@b@  public void setContent(Object aObject, String aContentType)@b@  {@b@    this.content = aObject;@b@    updateContentType(aContentType);@b@  }@b@@b@  public void updateContentType(String aContentType)@b@  {@b@    if (EmailUtils.isEmpty(aContentType))@b@    {@b@      this.contentType = null;@b@    }@b@    else@b@    {@b@      this.contentType = aContentType;@b@@b@      String strMarker = "; charset=";@b@      int charsetPos = aContentType.toLowerCase().indexOf("; charset=");@b@@b@      if (charsetPos != -1)@b@      {@b@        charsetPos += "; charset=".length();@b@        int intCharsetEnd = aContentType.toLowerCase().indexOf(" ", charsetPos);@b@@b@        if (intCharsetEnd != -1)@b@        {@b@          this.charset = aContentType.substring(charsetPos, intCharsetEnd);@b@        }@b@        else@b@        {@b@          this.charset = aContentType.substring(charsetPos);@b@        }@b@@b@      }@b@      else if ((this.contentType.startsWith("text/")) && (EmailUtils.isNotEmpty(this.charset)))@b@      {@b@        StringBuffer contentTypeBuf = new StringBuffer(this.contentType);@b@        contentTypeBuf.append("; charset=");@b@        contentTypeBuf.append(this.charset);@b@        this.contentType = contentTypeBuf.toString();@b@      }@b@    }@b@  }@b@@b@  public void setHostName(String aHostName)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.hostName = aHostName;@b@  }@b@@b@  @Deprecated@b@  public void setTLS(boolean withTLS)@b@  {@b@    setStartTLSEnabled(withTLS);@b@  }@b@@b@  public Email setStartTLSEnabled(boolean startTlsEnabled)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.startTlsEnabled = startTlsEnabled;@b@    this.tls = startTlsEnabled;@b@    return this;@b@  }@b@@b@  public Email setStartTLSRequired(boolean startTlsRequired)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.startTlsRequired = startTlsRequired;@b@    return this;@b@  }@b@@b@  public void setSmtpPort(int aPortNumber)@b@  {@b@    checkSessionAlreadyInitialized();@b@@b@    if (aPortNumber < 1)@b@    {@b@      throw new IllegalArgumentException("Cannot connect to a port number that is less than 1 ( " + aPortNumber + " )");@b@    }@b@@b@    this.smtpPort = Integer.toString(aPortNumber);@b@  }@b@@b@  public void setMailSession(Session aSession)@b@  {@b@    EmailUtils.notNull(aSession, "no mail session supplied");@b@@b@    Properties sessionProperties = aSession.getProperties();@b@    String auth = sessionProperties.getProperty("mail.smtp.auth");@b@@b@    if ("true".equalsIgnoreCase(auth))@b@    {@b@      String userName = sessionProperties.getProperty("mail.smtp.user");@b@      String password = sessionProperties.getProperty("mail.smtp.password");@b@@b@      if ((EmailUtils.isNotEmpty(userName)) && (EmailUtils.isNotEmpty(password)))@b@      {@b@        this.authenticator = new DefaultAuthenticator(userName, password);@b@        this.session = Session.getInstance(sessionProperties, this.authenticator);@b@      }@b@      else@b@      {@b@        this.session = aSession;@b@      }@b@    }@b@    else@b@    {@b@      this.session = aSession;@b@    }@b@  }@b@@b@  public void setMailSessionFromJNDI(String jndiName)@b@    throws NamingException@b@  {@b@    if (EmailUtils.isEmpty(jndiName))@b@    {@b@      throw new IllegalArgumentException("JNDI name missing");@b@    }@b@    Context ctx = null;@b@    if (jndiName.startsWith("java:"))@b@    {@b@      ctx = new InitialContext();@b@    }@b@    else@b@    {@b@      ctx = (Context)new InitialContext().lookup("java:comp/env");@b@    }@b@@b@    setMailSession((Session)ctx.lookup(jndiName));@b@  }@b@@b@  public Session getMailSession()@b@    throws EmailException@b@  {@b@    if (this.session == null)@b@    {@b@      Properties properties = new Properties(System.getProperties());@b@      properties.setProperty("mail.transport.protocol", "smtp");@b@@b@      if (EmailUtils.isEmpty(this.hostName))@b@      {@b@        this.hostName = properties.getProperty("mail.smtp.host");@b@      }@b@@b@      if (EmailUtils.isEmpty(this.hostName))@b@      {@b@        throw new EmailException("Cannot find valid hostname for mail session");@b@      }@b@@b@      properties.setProperty("mail.smtp.port", this.smtpPort);@b@      properties.setProperty("mail.smtp.host", this.hostName);@b@      properties.setProperty("mail.debug", String.valueOf(this.debug));@b@@b@      properties.setProperty("mail.smtp.starttls.enable", (isStartTLSEnabled()) ? "true" : "false");@b@@b@      properties.setProperty("mail.smtp.starttls.required", (isStartTLSRequired()) ? "true" : "false");@b@@b@      properties.setProperty("mail.smtp.sendpartial", (isSendPartial()) ? "true" : "false");@b@@b@      properties.setProperty("mail.smtps.sendpartial", (isSendPartial()) ? "true" : "false");@b@@b@      if (this.authenticator != null)@b@      {@b@        properties.setProperty("mail.smtp.auth", "true");@b@      }@b@@b@      if (isSSLOnConnect())@b@      {@b@        properties.setProperty("mail.smtp.port", this.sslSmtpPort);@b@        properties.setProperty("mail.smtp.socketFactory.port", this.sslSmtpPort);@b@        properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");@b@        properties.setProperty("mail.smtp.socketFactory.fallback", "false");@b@      }@b@@b@      if ((((isSSLOnConnect()) || (isStartTLSEnabled()))) && (isSSLCheckServerIdentity()))@b@      {@b@        properties.setProperty("mail.smtp.ssl.checkserveridentity", "true");@b@      }@b@@b@      if (this.bounceAddress != null)@b@      {@b@        properties.setProperty("mail.smtp.from", this.bounceAddress);@b@      }@b@@b@      if (this.socketTimeout > 0)@b@      {@b@        properties.setProperty("mail.smtp.timeout", Integer.toString(this.socketTimeout));@b@      }@b@@b@      if (this.socketConnectionTimeout > 0)@b@      {@b@        properties.setProperty("mail.smtp.connectiontimeout", Integer.toString(this.socketConnectionTimeout));@b@      }@b@@b@      this.session = Session.getInstance(properties, this.authenticator);@b@    }@b@    return this.session;@b@  }@b@@b@  public Email setFrom(String email)@b@    throws EmailException@b@  {@b@    return setFrom(email, null);@b@  }@b@@b@  public Email setFrom(String email, String name)@b@    throws EmailException@b@  {@b@    return setFrom(email, name, this.charset);@b@  }@b@@b@  public Email setFrom(String email, String name, String charset)@b@    throws EmailException@b@  {@b@    this.fromAddress = createInternetAddress(email, name, charset);@b@    return this;@b@  }@b@@b@  public Email addTo(String email)@b@    throws EmailException@b@  {@b@    return addTo(email, null);@b@  }@b@@b@  public Email addTo(String[] emails)@b@    throws EmailException@b@  {@b@    if ((emails == null) || (emails.length == 0))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    String[] arr$ = emails; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { String email = arr$[i$];@b@@b@      addTo(email, null);@b@    }@b@@b@    return this;@b@  }@b@@b@  public Email addTo(String email, String name)@b@    throws EmailException@b@  {@b@    return addTo(email, name, this.charset);@b@  }@b@@b@  public Email addTo(String email, String name, String charset)@b@    throws EmailException@b@  {@b@    this.toList.add(createInternetAddress(email, name, charset));@b@    return this;@b@  }@b@@b@  public Email setTo(Collection<InternetAddress> aCollection)@b@    throws EmailException@b@  {@b@    if ((aCollection == null) || (aCollection.isEmpty()))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    this.toList = new ArrayList(aCollection);@b@    return this;@b@  }@b@@b@  public Email addCc(String email)@b@    throws EmailException@b@  {@b@    return addCc(email, null);@b@  }@b@@b@  public Email addCc(String[] emails)@b@    throws EmailException@b@  {@b@    if ((emails == null) || (emails.length == 0))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    String[] arr$ = emails; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { String email = arr$[i$];@b@@b@      addCc(email, null);@b@    }@b@@b@    return this;@b@  }@b@@b@  public Email addCc(String email, String name)@b@    throws EmailException@b@  {@b@    return addCc(email, name, this.charset);@b@  }@b@@b@  public Email addCc(String email, String name, String charset)@b@    throws EmailException@b@  {@b@    this.ccList.add(createInternetAddress(email, name, charset));@b@    return this;@b@  }@b@@b@  public Email setCc(Collection<InternetAddress> aCollection)@b@    throws EmailException@b@  {@b@    if ((aCollection == null) || (aCollection.isEmpty()))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    this.ccList = new ArrayList(aCollection);@b@    return this;@b@  }@b@@b@  public Email addBcc(String email)@b@    throws EmailException@b@  {@b@    return addBcc(email, null);@b@  }@b@@b@  public Email addBcc(String[] emails)@b@    throws EmailException@b@  {@b@    if ((emails == null) || (emails.length == 0))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    String[] arr$ = emails; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { String email = arr$[i$];@b@@b@      addBcc(email, null);@b@    }@b@@b@    return this;@b@  }@b@@b@  public Email addBcc(String email, String name)@b@    throws EmailException@b@  {@b@    return addBcc(email, name, this.charset);@b@  }@b@@b@  public Email addBcc(String email, String name, String charset)@b@    throws EmailException@b@  {@b@    this.bccList.add(createInternetAddress(email, name, charset));@b@    return this;@b@  }@b@@b@  public Email setBcc(Collection<InternetAddress> aCollection)@b@    throws EmailException@b@  {@b@    if ((aCollection == null) || (aCollection.isEmpty()))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    this.bccList = new ArrayList(aCollection);@b@    return this;@b@  }@b@@b@  public Email addReplyTo(String email)@b@    throws EmailException@b@  {@b@    return addReplyTo(email, null);@b@  }@b@@b@  public Email addReplyTo(String email, String name)@b@    throws EmailException@b@  {@b@    return addReplyTo(email, name, this.charset);@b@  }@b@@b@  public Email addReplyTo(String email, String name, String charset)@b@    throws EmailException@b@  {@b@    this.replyList.add(createInternetAddress(email, name, charset));@b@    return this;@b@  }@b@@b@  public Email setReplyTo(Collection<InternetAddress> aCollection)@b@    throws EmailException@b@  {@b@    if ((aCollection == null) || (aCollection.isEmpty()))@b@    {@b@      throw new EmailException("Address List provided was invalid");@b@    }@b@@b@    this.replyList = new ArrayList(aCollection);@b@    return this;@b@  }@b@@b@  public void setHeaders(Map<String, String> map)@b@  {@b@    this.headers.clear();@b@@b@    for (Map.Entry entry : map.entrySet())@b@    {@b@      addHeader((String)entry.getKey(), (String)entry.getValue());@b@    }@b@  }@b@@b@  public void addHeader(String name, String value)@b@  {@b@    if (EmailUtils.isEmpty(name))@b@    {@b@      throw new IllegalArgumentException("name can not be null or empty");@b@    }@b@    if (EmailUtils.isEmpty(value))@b@    {@b@      throw new IllegalArgumentException("value can not be null or empty");@b@    }@b@@b@    this.headers.put(name, value);@b@  }@b@@b@  public Email setSubject(String aSubject)@b@  {@b@    this.subject = aSubject;@b@    return this;@b@  }@b@@b@  public Email setBounceAddress(String email)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.bounceAddress = email;@b@    return this;@b@  }@b@@b@  public abstract Email setMsg(String paramString)@b@    throws EmailException;@b@@b@  public void buildMimeMessage()@b@    throws EmailException@b@  {@b@    if (this.message != null)@b@    {@b@      throw new IllegalStateException("The MimeMessage is already built.");@b@    }@b@@b@    try@b@    {@b@      this.message = createMimeMessage(getMailSession());@b@@b@      if (EmailUtils.isNotEmpty(this.subject))@b@      {@b@        if (EmailUtils.isNotEmpty(this.charset))@b@        {@b@          this.message.setSubject(this.subject, this.charset);@b@        }@b@        else@b@        {@b@          this.message.setSubject(this.subject);@b@        }@b@@b@      }@b@@b@      updateContentType(this.contentType);@b@@b@      if (this.content != null)@b@      {@b@        if (("text/plain".equalsIgnoreCase(this.contentType)) && (this.content instanceof String))@b@        {@b@          this.message.setText(this.content.toString(), this.charset);@b@        }@b@        else@b@        {@b@          this.message.setContent(this.content, this.contentType);@b@        }@b@      }@b@      else if (this.emailBody != null)@b@      {@b@        if (this.contentType == null)@b@        {@b@          this.message.setContent(this.emailBody);@b@        }@b@        else@b@        {@b@          this.message.setContent(this.emailBody, this.contentType);@b@        }@b@@b@      }@b@      else {@b@        this.message.setText("");@b@      }@b@@b@      if (this.fromAddress != null)@b@      {@b@        this.message.setFrom(this.fromAddress);@b@      }@b@      else if (this.session.getProperty("mail.smtp.from") == null)@b@      {@b@        throw new EmailException("From address required");@b@      }@b@@b@      if (this.toList.size() + this.ccList.size() + this.bccList.size() == 0)@b@      {@b@        throw new EmailException("At least one receiver address required");@b@      }@b@@b@      if (this.toList.size() > 0)@b@      {@b@        this.message.setRecipients(Message.RecipientType.TO, toInternetAddressArray(this.toList));@b@      }@b@@b@      if (this.ccList.size() > 0)@b@      {@b@        this.message.setRecipients(Message.RecipientType.CC, toInternetAddressArray(this.ccList));@b@      }@b@@b@      if (this.bccList.size() > 0)@b@      {@b@        this.message.setRecipients(Message.RecipientType.BCC, toInternetAddressArray(this.bccList));@b@      }@b@@b@      if (this.replyList.size() > 0)@b@      {@b@        this.message.setReplyTo(toInternetAddressArray(this.replyList));@b@      }@b@@b@      if (this.headers.size() > 0)@b@      {@b@        for (Map.Entry entry : this.headers.entrySet())@b@        {@b@          String foldedValue = createFoldedHeaderValue((String)entry.getKey(), entry.getValue());@b@          this.message.addHeader((String)entry.getKey(), foldedValue);@b@        }@b@      }@b@@b@      if (this.message.getSentDate() == null)@b@      {@b@        this.message.setSentDate(getSentDate());@b@      }@b@@b@      if (this.popBeforeSmtp)@b@      {@b@        Store store = this.session.getStore("pop3");@b@        store.connect(this.popHost, this.popUsername, this.popPassword);@b@      }@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@  }@b@@b@  public String sendMimeMessage()@b@    throws EmailException@b@  {@b@    EmailUtils.notNull(this.message, "MimeMessage has not been created yet");@b@    try@b@    {@b@      Transport.send(this.message);@b@      return this.message.getMessageID();@b@    }@b@    catch (Throwable t)@b@    {@b@      String msg = "Sending the email to the following server failed : " + getHostName() + ":" + getSmtpPort();@b@@b@      throw new EmailException(msg, t);@b@    }@b@  }@b@@b@  public MimeMessage getMimeMessage()@b@  {@b@    return this.message;@b@  }@b@@b@  public String send()@b@    throws EmailException@b@  {@b@    buildMimeMessage();@b@    return sendMimeMessage();@b@  }@b@@b@  public void setSentDate(Date date)@b@  {@b@    if (date != null)@b@    {@b@      this.sentDate = new Date(date.getTime());@b@    }@b@  }@b@@b@  public Date getSentDate()@b@  {@b@    if (this.sentDate == null)@b@    {@b@      return new Date();@b@    }@b@    return new Date(this.sentDate.getTime());@b@  }@b@@b@  public String getSubject()@b@  {@b@    return this.subject;@b@  }@b@@b@  public InternetAddress getFromAddress()@b@  {@b@    return this.fromAddress;@b@  }@b@@b@  public String getHostName()@b@  {@b@    if (this.session != null)@b@    {@b@      return this.session.getProperty("mail.smtp.host");@b@    }@b@    if (EmailUtils.isNotEmpty(this.hostName))@b@    {@b@      return this.hostName;@b@    }@b@    return null;@b@  }@b@@b@  public String getSmtpPort()@b@  {@b@    if (this.session != null)@b@    {@b@      return this.session.getProperty("mail.smtp.port");@b@    }@b@    if (EmailUtils.isNotEmpty(this.smtpPort))@b@    {@b@      return this.smtpPort;@b@    }@b@    return null;@b@  }@b@@b@  public boolean isStartTLSRequired()@b@  {@b@    return this.startTlsRequired;@b@  }@b@@b@  public boolean isStartTLSEnabled()@b@  {@b@    return ((this.startTlsEnabled) || (this.tls));@b@  }@b@@b@  @Deprecated@b@  public boolean isTLS()@b@  {@b@    return isStartTLSEnabled();@b@  }@b@@b@  protected InternetAddress[] toInternetAddressArray(List<InternetAddress> list)@b@  {@b@    return ((InternetAddress[])list.toArray(new InternetAddress[list.size()]));@b@  }@b@@b@  public void setPopBeforeSmtp(boolean newPopBeforeSmtp, String newPopHost, String newPopUsername, String newPopPassword)@b@  {@b@    this.popBeforeSmtp = newPopBeforeSmtp;@b@    this.popHost = newPopHost;@b@    this.popUsername = newPopUsername;@b@    this.popPassword = newPopPassword;@b@  }@b@@b@  @Deprecated@b@  public boolean isSSL()@b@  {@b@    return isSSLOnConnect();@b@  }@b@@b@  public boolean isSSLOnConnect()@b@  {@b@    return ((this.sslOnConnect) || (this.ssl));@b@  }@b@@b@  @Deprecated@b@  public void setSSL(boolean ssl)@b@  {@b@    setSSLOnConnect(ssl);@b@  }@b@@b@  public Email setSSLOnConnect(boolean ssl)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.sslOnConnect = ssl;@b@    this.ssl = ssl;@b@    return this;@b@  }@b@@b@  public boolean isSSLCheckServerIdentity()@b@  {@b@    return this.sslCheckServerIdentity;@b@  }@b@@b@  public Email setSSLCheckServerIdentity(boolean sslCheckServerIdentity)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.sslCheckServerIdentity = sslCheckServerIdentity;@b@    return this;@b@  }@b@@b@  public String getSslSmtpPort()@b@  {@b@    if (this.session != null)@b@    {@b@      return this.session.getProperty("mail.smtp.socketFactory.port");@b@    }@b@    if (EmailUtils.isNotEmpty(this.sslSmtpPort))@b@    {@b@      return this.sslSmtpPort;@b@    }@b@    return null;@b@  }@b@@b@  public void setSslSmtpPort(String sslSmtpPort)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.sslSmtpPort = sslSmtpPort;@b@  }@b@@b@  public boolean isSendPartial()@b@  {@b@    return this.sendPartial;@b@  }@b@@b@  public Email setSendPartial(boolean sendPartial)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.sendPartial = sendPartial;@b@    return this;@b@  }@b@@b@  public List<InternetAddress> getToAddresses()@b@  {@b@    return this.toList;@b@  }@b@@b@  public List<InternetAddress> getCcAddresses()@b@  {@b@    return this.ccList;@b@  }@b@@b@  public List<InternetAddress> getBccAddresses()@b@  {@b@    return this.bccList;@b@  }@b@@b@  public List<InternetAddress> getReplyToAddresses()@b@  {@b@    return this.replyList;@b@  }@b@@b@  public int getSocketConnectionTimeout()@b@  {@b@    return this.socketConnectionTimeout;@b@  }@b@@b@  public void setSocketConnectionTimeout(int socketConnectionTimeout)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.socketConnectionTimeout = socketConnectionTimeout;@b@  }@b@@b@  public int getSocketTimeout()@b@  {@b@    return this.socketTimeout;@b@  }@b@@b@  public void setSocketTimeout(int socketTimeout)@b@  {@b@    checkSessionAlreadyInitialized();@b@    this.socketTimeout = socketTimeout;@b@  }@b@@b@  protected MimeMessage createMimeMessage(Session aSession)@b@  {@b@    return new MimeMessage(aSession);@b@  }@b@@b@  private String createFoldedHeaderValue(String name, Object value)@b@  {@b@    String result;@b@    if (EmailUtils.isEmpty(name))@b@    {@b@      throw new IllegalArgumentException("name can not be null or empty");@b@    }@b@    if ((value == null) || (EmailUtils.isEmpty(value.toString())))@b@    {@b@      throw new IllegalArgumentException("value can not be null or empty");@b@    }@b@@b@    try@b@    {@b@      result = MimeUtility.fold(name.length() + 2, MimeUtility.encodeText(value.toString(), this.charset, null));@b@    }@b@    catch (UnsupportedEncodingException e)@b@    {@b@      result = value.toString();@b@    }@b@@b@    return result;@b@  }@b@@b@  private InternetAddress createInternetAddress(String email, String name, String charsetName)@b@    throws EmailException@b@  {@b@    InternetAddress address = null;@b@    try@b@    {@b@      address = new InternetAddress(email);@b@@b@      if (EmailUtils.isNotEmpty(name))@b@      {@b@        if (EmailUtils.isEmpty(charsetName))@b@        {@b@          address.setPersonal(name);@b@        }@b@        else@b@        {@b@          Charset set = Charset.forName(charsetName);@b@          address.setPersonal(name, set.name());@b@        }@b@@b@      }@b@@b@      address.validate();@b@    }@b@    catch (AddressException e)@b@    {@b@      throw new EmailException(e);@b@    }@b@    catch (UnsupportedEncodingException e)@b@    {@b@      throw new EmailException(e);@b@    }@b@    return address;@b@  }@b@@b@  private void checkSessionAlreadyInitialized()@b@  {@b@    if (this.session != null)@b@    {@b@      throw new IllegalStateException("The mail session is already initialized");@b@    }@b@  }@b@}

2.MultiPartEmail实现类

package org.apache.commons.mail;@b@@b@import java.io.File;@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.io.UnsupportedEncodingException;@b@import java.net.URL;@b@import javax.activation.DataHandler;@b@import javax.activation.DataSource;@b@import javax.activation.FileDataSource;@b@import javax.activation.URLDataSource;@b@import javax.mail.BodyPart;@b@import javax.mail.MessagingException;@b@import javax.mail.internet.MimeBodyPart;@b@import javax.mail.internet.MimeMultipart;@b@import javax.mail.internet.MimePart;@b@import javax.mail.internet.MimeUtility;@b@@b@public class MultiPartEmail extends Email@b@{@b@  private MimeMultipart container;@b@  private BodyPart primaryBodyPart;@b@  private String subType;@b@  private boolean initialized;@b@  private boolean boolHasAttachments;@b@@b@  public void setSubType(String aSubType)@b@  {@b@    this.subType = aSubType;@b@  }@b@@b@  public String getSubType()@b@  {@b@    return this.subType;@b@  }@b@@b@  public Email addPart(String partContent, String partContentType)@b@    throws EmailException@b@  {@b@    BodyPart bodyPart = createBodyPart();@b@    try@b@    {@b@      bodyPart.setContent(partContent, partContentType);@b@      getContainer().addBodyPart(bodyPart);@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@@b@    return this;@b@  }@b@@b@  public Email addPart(MimeMultipart multipart)@b@    throws EmailException@b@  {@b@    try@b@    {@b@      return addPart(multipart, getContainer().getCount());@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@  }@b@@b@  public Email addPart(MimeMultipart multipart, int index)@b@    throws EmailException@b@  {@b@    BodyPart bodyPart = createBodyPart();@b@    try@b@    {@b@      bodyPart.setContent(multipart);@b@      getContainer().addBodyPart(bodyPart, index);@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@@b@    return this;@b@  }@b@@b@  protected void init()@b@  {@b@    if (this.initialized)@b@    {@b@      throw new IllegalStateException("Already initialized");@b@    }@b@@b@    this.container = createMimeMultipart();@b@    super.setContent(this.container);@b@@b@    this.initialized = true;@b@  }@b@@b@  public Email setMsg(String msg)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(msg))@b@    {@b@      throw new EmailException("Invalid message supplied");@b@    }@b@    try@b@    {@b@      BodyPart primary = getPrimaryBodyPart();@b@@b@      if ((primary instanceof MimePart) && (EmailUtils.isNotEmpty(this.charset)))@b@      {@b@        ((MimePart)primary).setText(msg, this.charset);@b@      }@b@      else@b@      {@b@        primary.setText(msg);@b@      }@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@    return this;@b@  }@b@@b@  public void buildMimeMessage()@b@    throws EmailException@b@  {@b@    try@b@    {@b@      if (this.primaryBodyPart != null)@b@      {@b@        BodyPart body = getPrimaryBodyPart();@b@        try@b@        {@b@          body.getContent();@b@        }@b@        catch (IOException e)@b@        {@b@        }@b@@b@      }@b@@b@      if (this.subType != null)@b@      {@b@        getContainer().setSubType(this.subType);@b@      }@b@@b@      super.buildMimeMessage();@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@  }@b@@b@  public MultiPartEmail attach(File file)@b@    throws EmailException@b@  {@b@    String fileName = file.getAbsolutePath();@b@    try@b@    {@b@      if (!(file.exists()))@b@      {@b@        throw new IOException("\"" + fileName + "\" does not exist");@b@      }@b@@b@      FileDataSource fds = new FileDataSource(file);@b@@b@      return attach(fds, file.getName(), null, "attachment");@b@    }@b@    catch (IOException e)@b@    {@b@      throw new EmailException("Cannot attach file \"" + fileName + "\"", e);@b@    }@b@  }@b@@b@  public MultiPartEmail attach(EmailAttachment attachment)@b@    throws EmailException@b@  {@b@    MultiPartEmail result = null;@b@@b@    if (attachment == null)@b@    {@b@      throw new EmailException("Invalid attachment supplied");@b@    }@b@@b@    URL url = attachment.getURL();@b@@b@    if (url == null)@b@    {@b@      String fileName = null;@b@      try@b@      {@b@        fileName = attachment.getPath();@b@        File file = new File(fileName);@b@        if (!(file.exists()))@b@        {@b@          throw new IOException("\"" + fileName + "\" does not exist");@b@        }@b@        result = attach(new FileDataSource(file), attachment.getName(), attachment.getDescription(), attachment.getDisposition());@b@      }@b@      catch (IOException e)@b@      {@b@        throw new EmailException("Cannot attach file \"" + fileName + "\"", e);@b@      }@b@    }@b@    else@b@    {@b@      result = attach(url, attachment.getName(), attachment.getDescription(), attachment.getDisposition());@b@    }@b@@b@    return result;@b@  }@b@@b@  public MultiPartEmail attach(URL url, String name, String description)@b@    throws EmailException@b@  {@b@    return attach(url, name, description, "attachment");@b@  }@b@@b@  public MultiPartEmail attach(URL url, String name, String description, String disposition)@b@    throws EmailException@b@  {@b@    InputStream is;@b@    try@b@    {@b@      is = url.openStream();@b@      is.close();@b@    }@b@    catch (IOException e)@b@    {@b@      throw new EmailException("Invalid URL set:" + url, e);@b@    }@b@@b@    return attach(new URLDataSource(url), name, description, disposition);@b@  }@b@@b@  public MultiPartEmail attach(DataSource ds, String name, String description)@b@    throws EmailException@b@  {@b@    try@b@    {@b@      InputStream is = (ds != null) ? ds.getInputStream() : null;@b@      if (is != null)@b@      {@b@        is.close();@b@      }@b@@b@      if (is == null)@b@      {@b@        throw new EmailException("Invalid Datasource");@b@      }@b@    }@b@    catch (IOException e)@b@    {@b@      throw new EmailException("Invalid Datasource", e);@b@    }@b@@b@    return attach(ds, name, description, "attachment");@b@  }@b@@b@  public MultiPartEmail attach(DataSource ds, String name, String description, String disposition)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(name))@b@    {@b@      name = ds.getName();@b@    }@b@    BodyPart bodyPart = createBodyPart();@b@    try@b@    {@b@      bodyPart.setDisposition(disposition);@b@      bodyPart.setFileName(MimeUtility.encodeText(name));@b@      bodyPart.setDescription(description);@b@      bodyPart.setDataHandler(new DataHandler(ds));@b@@b@      getContainer().addBodyPart(bodyPart);@b@    }@b@    catch (UnsupportedEncodingException uee)@b@    {@b@      throw new EmailException(uee);@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@    setBoolHasAttachments(true);@b@@b@    return this;@b@  }@b@@b@  protected BodyPart getPrimaryBodyPart()@b@    throws MessagingException@b@  {@b@    if (!(this.initialized))@b@    {@b@      init();@b@    }@b@@b@    if (this.primaryBodyPart == null)@b@    {@b@      this.primaryBodyPart = createBodyPart();@b@      getContainer().addBodyPart(this.primaryBodyPart, 0);@b@    }@b@@b@    return this.primaryBodyPart;@b@  }@b@@b@  protected MimeMultipart getContainer()@b@  {@b@    if (!(this.initialized))@b@    {@b@      init();@b@    }@b@    return this.container;@b@  }@b@@b@  protected BodyPart createBodyPart()@b@  {@b@    return new MimeBodyPart();@b@  }@b@@b@  protected MimeMultipart createMimeMultipart()@b@  {@b@    return new MimeMultipart();@b@  }@b@@b@  public boolean isBoolHasAttachments()@b@  {@b@    return this.boolHasAttachments;@b@  }@b@@b@  public void setBoolHasAttachments(boolean b)@b@  {@b@    this.boolHasAttachments = b;@b@  }@b@@b@  protected boolean isInitialized()@b@  {@b@    return this.initialized;@b@  }@b@@b@  protected void setInitialized(boolean b)@b@  {@b@    this.initialized = b;@b@  }@b@}

3.HtmlEmail实现类

package org.apache.commons.mail;@b@@b@import java.io.File;@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.io.UnsupportedEncodingException;@b@import java.net.MalformedURLException;@b@import java.net.URL;@b@import java.util.HashMap;@b@import java.util.List;@b@import java.util.Locale;@b@import java.util.Map;@b@import javax.activation.DataHandler;@b@import javax.activation.DataSource;@b@import javax.activation.FileDataSource;@b@import javax.activation.URLDataSource;@b@import javax.mail.BodyPart;@b@import javax.mail.MessagingException;@b@import javax.mail.internet.MimeBodyPart;@b@import javax.mail.internet.MimeMultipart;@b@@b@public class HtmlEmail extends MultiPartEmail@b@{@b@  public static final int CID_LENGTH = 10;@b@  private static final String HTML_MESSAGE_START = "<html><body><pre>";@b@  private static final String HTML_MESSAGE_END = "</pre></body></html>";@b@  protected String text;@b@  protected String html;@b@@b@  @Deprecated@b@  protected List<InlineImage> inlineImages;@b@  protected Map<String, InlineImage> inlineEmbeds;@b@@b@  public HtmlEmail()@b@  {@b@    this.inlineEmbeds = new HashMap();@b@  }@b@@b@  public HtmlEmail setTextMsg(String aText)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(aText))@b@    {@b@      throw new EmailException("Invalid message supplied");@b@    }@b@@b@    this.text = aText;@b@    return this;@b@  }@b@@b@  public HtmlEmail setHtmlMsg(String aHtml)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(aHtml))@b@    {@b@      throw new EmailException("Invalid message supplied");@b@    }@b@@b@    this.html = aHtml;@b@    return this;@b@  }@b@@b@  public Email setMsg(String msg)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(msg))@b@    {@b@      throw new EmailException("Invalid message supplied");@b@    }@b@@b@    setTextMsg(msg);@b@@b@    StringBuffer htmlMsgBuf = new StringBuffer(msg.length() + "<html><body><pre>".length() + "</pre></body></html>".length());@b@@b@    htmlMsgBuf.append("<html><body><pre>").append(msg).append("</pre></body></html>");@b@@b@    setHtmlMsg(htmlMsgBuf.toString());@b@@b@    return this;@b@  }@b@@b@  public String embed(String urlString, String name)@b@    throws EmailException@b@  {@b@    try@b@    {@b@      return embed(new URL(urlString), name);@b@    }@b@    catch (MalformedURLException e)@b@    {@b@      throw new EmailException("Invalid URL", e);@b@    }@b@  }@b@@b@  public String embed(URL url, String name)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(name))@b@    {@b@      throw new EmailException("name cannot be null or empty");@b@    }@b@@b@    if (this.inlineEmbeds.containsKey(name))@b@    {@b@      InlineImage ii = (InlineImage)this.inlineEmbeds.get(name);@b@      URLDataSource urlDataSource = (URLDataSource)ii.getDataSource();@b@@b@      if (url.toExternalForm().equals(urlDataSource.getURL().toExternalForm()))@b@      {@b@        return ii.getCid();@b@      }@b@@b@      throw new EmailException("embedded name '" + name + "' is already bound to URL " + urlDataSource.getURL() + "; existing names cannot be rebound");@b@    }@b@@b@    InputStream is = null;@b@    try@b@    {@b@      is = url.openStream();@b@    }@b@    catch (IOException e)@b@    {@b@    }@b@    finally@b@    {@b@      try@b@      {@b@        if (is != null)@b@        {@b@          is.close();@b@        }@b@      }@b@      catch (IOException ioe)@b@      {@b@      }@b@    }@b@    return embed(new URLDataSource(url), name);@b@  }@b@@b@  public String embed(File file)@b@    throws EmailException@b@  {@b@    String cid = EmailUtils.randomAlphabetic(10).toLowerCase(Locale.ENGLISH);@b@    return embed(file, cid);@b@  }@b@@b@  public String embed(File file, String cid)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(file.getName()))@b@    {@b@      throw new EmailException("file name cannot be null or empty");@b@    }@b@@b@    String filePath = null;@b@    try@b@    {@b@      filePath = file.getCanonicalPath();@b@    }@b@    catch (IOException ioe)@b@    {@b@      throw new EmailException("couldn't get canonical path for " + file.getName(), ioe);@b@    }@b@@b@    if (this.inlineEmbeds.containsKey(file.getName()))@b@    {@b@      InlineImage ii = (InlineImage)this.inlineEmbeds.get(file.getName());@b@      FileDataSource fileDataSource = (FileDataSource)ii.getDataSource();@b@@b@      String existingFilePath = null;@b@      try@b@      {@b@        existingFilePath = fileDataSource.getFile().getCanonicalPath();@b@      }@b@      catch (IOException ioe)@b@      {@b@        throw new EmailException("couldn't get canonical path for file " + fileDataSource.getFile().getName() + "which has already been embedded", ioe);@b@      }@b@@b@      if (filePath.equals(existingFilePath))@b@      {@b@        return ii.getCid();@b@      }@b@@b@      throw new EmailException("embedded name '" + file.getName() + "' is already bound to file " + existingFilePath + "; existing names cannot be rebound");@b@    }@b@@b@    if (!(file.exists()))@b@    {@b@      throw new EmailException("file " + filePath + " doesn't exist");@b@    }@b@    if (!(file.isFile()))@b@    {@b@      throw new EmailException("file " + filePath + " isn't a normal file");@b@    }@b@    if (!(file.canRead()))@b@    {@b@      throw new EmailException("file " + filePath + " isn't readable");@b@    }@b@@b@    return embed(new FileDataSource(file), file.getName(), cid);@b@  }@b@@b@  public String embed(DataSource dataSource, String name)@b@    throws EmailException@b@  {@b@    if (this.inlineEmbeds.containsKey(name))@b@    {@b@      InlineImage ii = (InlineImage)this.inlineEmbeds.get(name);@b@@b@      if (dataSource.equals(ii.getDataSource()))@b@      {@b@        return ii.getCid();@b@      }@b@@b@      throw new EmailException("embedded DataSource '" + name + "' is already bound to name " + ii.getDataSource().toString() + "; existing names cannot be rebound");@b@    }@b@@b@    String cid = EmailUtils.randomAlphabetic(10).toLowerCase();@b@    return embed(dataSource, name, cid);@b@  }@b@@b@  public String embed(DataSource dataSource, String name, String cid)@b@    throws EmailException@b@  {@b@    if (EmailUtils.isEmpty(name))@b@    {@b@      throw new EmailException("name cannot be null or empty");@b@    }@b@@b@    MimeBodyPart mbp = new MimeBodyPart();@b@    try@b@    {@b@      cid = EmailUtils.encodeUrl(cid);@b@@b@      mbp.setDataHandler(new DataHandler(dataSource));@b@      mbp.setFileName(name);@b@      mbp.setDisposition("inline");@b@      mbp.setContentID("<" + cid + ">");@b@@b@      InlineImage ii = new InlineImage(cid, dataSource, mbp);@b@      this.inlineEmbeds.put(name, ii);@b@@b@      return cid;@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@    catch (UnsupportedEncodingException uee)@b@    {@b@      throw new EmailException(uee);@b@    }@b@  }@b@@b@  public void buildMimeMessage()@b@    throws EmailException@b@  {@b@    try@b@    {@b@      build();@b@    }@b@    catch (MessagingException me)@b@    {@b@      throw new EmailException(me);@b@    }@b@    super.buildMimeMessage();@b@  }@b@@b@  private void build()@b@    throws MessagingException, EmailException@b@  {@b@    MimeMultipart rootContainer = getContainer();@b@    MimeMultipart bodyEmbedsContainer = rootContainer;@b@    MimeMultipart bodyContainer = rootContainer;@b@    MimeBodyPart msgHtml = null;@b@    MimeBodyPart msgText = null;@b@@b@    rootContainer.setSubType("mixed");@b@@b@    if ((EmailUtils.isNotEmpty(this.html)) && (this.inlineEmbeds.size() > 0))@b@    {@b@      bodyEmbedsContainer = new MimeMultipart("related");@b@      bodyContainer = bodyEmbedsContainer;@b@      addPart(bodyEmbedsContainer, 0);@b@@b@      if (EmailUtils.isNotEmpty(this.text))@b@      {@b@        bodyContainer = new MimeMultipart("alternative");@b@        BodyPart bodyPart = createBodyPart();@b@        try@b@        {@b@          bodyPart.setContent(bodyContainer);@b@          bodyEmbedsContainer.addBodyPart(bodyPart, 0);@b@        }@b@        catch (MessagingException me)@b@        {@b@          throw new EmailException(me);@b@        }@b@      }@b@    }@b@    else if ((EmailUtils.isNotEmpty(this.text)) && (EmailUtils.isNotEmpty(this.html)))@b@    {@b@      bodyContainer = new MimeMultipart("alternative");@b@      addPart(bodyContainer, 0);@b@    }@b@@b@    if (EmailUtils.isNotEmpty(this.html))@b@    {@b@      msgHtml = new MimeBodyPart();@b@      bodyContainer.addBodyPart(msgHtml, 0);@b@@b@      msgHtml.setText(this.html, this.charset, "html");@b@@b@      for (InlineImage image : this.inlineEmbeds.values())@b@      {@b@        bodyEmbedsContainer.addBodyPart(image.getMbp());@b@      }@b@    }@b@@b@    if (EmailUtils.isNotEmpty(this.text))@b@    {@b@      msgText = new MimeBodyPart();@b@      bodyContainer.addBodyPart(msgText, 0);@b@@b@      msgText.setText(this.text, this.charset);@b@    }@b@  }@b@@b@  private static class InlineImage@b@  {@b@    private final String cid;@b@    private final DataSource dataSource;@b@    private final MimeBodyPart mbp;@b@@b@    public InlineImage(String cid, DataSource dataSource, MimeBodyPart mbp)@b@    {@b@      this.cid = cid;@b@      this.dataSource = dataSource;@b@      this.mbp = mbp;@b@    }@b@@b@    public String getCid()@b@    {@b@      return this.cid;@b@    }@b@@b@    public DataSource getDataSource()@b@    {@b@      return this.dataSource;@b@    }@b@@b@    public MimeBodyPart getMbp()@b@    {@b@      return this.mbp;@b@    }@b@@b@    public boolean equals(Object obj)@b@    {@b@      if (this == obj)@b@      {@b@        return true;@b@      }@b@      if (!(obj instanceof InlineImage))@b@      {@b@        return false;@b@      }@b@@b@      InlineImage that = (InlineImage)obj;@b@@b@      return this.cid.equals(that.cid);@b@    }@b@@b@    public int hashCode()@b@    {@b@      return this.cid.hashCode();@b@    }@b@  }@b@}




<<热门下载>>