package com.cm.common.utils.email;
/**
 * 发送邮件需要使用的基本信息
 *
 * @author FH QQ 313596790[青苔]
 * 修改时间：2015年7月27日
 * @version 2.0
 */

import java.util.Arrays;
import java.util.Properties;

public class MailSenderInfo {
    /**
     * 发送邮件的服务器的IP和端口
     */
    private String mailServerHost;
    private Integer mailServerPort = 25;
    /**
     * 邮件发送者的地址
     */
    private String fromAddress;
    /**
     * 邮件接收者的地址
     */
    private String toAddress;
    /**
     * 抄送人
     */
    private String toCc;
    /**
     * 登陆邮件发送服务器的用户名和密码
     */
    private String userName;
    private String password;
    /**
     * 是否需要身份验证
     */
    private boolean validate = false;
    /**
     * 邮件主题
     */
    private String subject;
    /**
     * 邮件的文本内容
     */
    private String content;
    /**
     * 邮件附件的文件名
     */
    private String[] attachFileNames;

    /**
     * 获得邮件会话属性
     */
    public Properties getProperties() {
        Properties properties = new Properties();
        properties.put("mail.smtp.host", this.mailServerHost);
        properties.put("mail.smtp.port", this.mailServerPort);
        properties.put("mail.smtp.auth", validate ? "true" : "false");
        return properties;
    }

    public String getMailServerHost() {
        return mailServerHost == null ? "" : mailServerHost.trim();
    }

    public void setMailServerHost(String mailServerHost) {
        this.mailServerHost = mailServerHost;
    }

    public Integer getMailServerPort() {
        return mailServerPort;
    }

    public void setMailServerPort(Integer mailServerPort) {
        this.mailServerPort = mailServerPort;
    }

    public String getFromAddress() {
        return fromAddress == null ? "" : fromAddress.trim();
    }

    public void setFromAddress(String fromAddress) {
        this.fromAddress = fromAddress;
    }

    public String getToAddress() {
        return toAddress == null ? "" : toAddress.trim();
    }

    public void setToAddress(String toAddress) {
        this.toAddress = toAddress;
    }

    public String getToCc() {
        return toCc == null ? "" : toCc.trim();
    }

    public void setToCc(String toCc) {
        this.toCc = toCc;
    }

    public String getUserName() {
        return userName == null ? "" : userName.trim();
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password == null ? "" : password.trim();
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isValidate() {
        return validate;
    }

    public void setValidate(boolean validate) {
        this.validate = validate;
    }

    public String getSubject() {
        return subject == null ? "" : subject.trim();
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getContent() {
        return content == null ? "" : content.trim();
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String[] getAttachFileNames() {
        return attachFileNames;
    }

    public void setAttachFileNames(String[] attachFileNames) {
        this.attachFileNames = attachFileNames;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"mailServerHost\":")
                .append("\"").append(mailServerHost).append("\"");
        sb.append(",\"mailServerPort\":")
                .append("\"").append(mailServerPort).append("\"");
        sb.append(",\"fromAddress\":")
                .append("\"").append(fromAddress).append("\"");
        sb.append(",\"toAddress\":")
                .append("\"").append(toAddress).append("\"");
        sb.append(",\"toCc\":")
                .append("\"").append(toCc).append("\"");
        sb.append(",\"userName\":")
                .append("\"").append(userName).append("\"");
        sb.append(",\"password\":")
                .append("\"").append(password).append("\"");
        sb.append(",\"validate\":")
                .append(validate);
        sb.append(",\"subject\":")
                .append("\"").append(subject).append("\"");
        sb.append(",\"content\":")
                .append("\"").append(content).append("\"");
        sb.append(",\"attachFileNames\":")
                .append(Arrays.toString(attachFileNames));
        sb.append('}');
        return sb.toString();
    }
}
