/*
 * blanco Framework
 * Copyright (C) 2004-2007 IGA Tosiki
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 */
package blanco.mail.core.mobilephone;

import java.io.IOException;
import java.net.ConnectException;

import blanco.mail.core.BlancoMailSenderFactory;
import blanco.mail.core.BlancoMailSettingFactory;
import blanco.mail.core.valueobject.BlancoMailAddress;
import blanco.mail.core.valueobject.BlancoMailMessage;
import blanco.mail.core.valueobject.BlancoMailMessageAttachment;
import blanco.mail.core.valueobject.BlancoMailSetting;

/**
 * 文字化けパターンその1。
 */
public class BlancoMailMobilePhoneTestSender002 {
    public static void main(final String[] args) throws ConnectException,
            IOException {
        final BlancoMailSetting setting = BlancoMailSettingFactory
                .getInstance();
        if (true) {
            // 設定値は BlancoMailSetting.properties から取得します。
        } else {
            // setting.setSendHost("smtp.gmail.com");
            // setting.setSendPort(465);
        }

        final BlancoMailMessage message = new BlancoMailMessage();
        final BlancoMailAddress from = new BlancoMailAddress();
        from.setAddress(BlancoMailMobilePhoneTestConstants.MAIL_SEND_FROM_ADDR);
        from
                .setPersonal(BlancoMailMobilePhoneTestConstants.MAIL_SEND_FROM_ADDR_PERSONAL);
        message.setFrom(from);

        final BlancoMailAddress to1 = new BlancoMailAddress();
        to1.setAddress(BlancoMailMobilePhoneTestConstants.MAIL_SEND_TO_ADDR);
        to1
                .setPersonal(BlancoMailMobilePhoneTestConstants.MAIL_SEND_TO_ADDR_PERSONAL);
        message.getTo().add(to1);

        message.setSubject("[blanco](No.002) 本文末尾強制改行OFF, 添付ファイルあり");
        message
                .setText(BlancoMailMobilePhoneTestConstants.MAIL_SEND_TO_ADDR_PERSONAL
                        + "さん。"
                        + BlancoMailMobilePhoneTestConstants.MAIL_SEND_FROM_ADDR_PERSONAL
                        + "です。\n"
                        + "これは「JavaMail＋日本メール環境」固有の問題に対する試験です。\n"
                        + "本文末尾強制改行なし (SEND_FORTH_NEWLINE_AFTER_MESSAGE_TEXT): false→文字化けする端末があることが知られています。\n"
                        + "添付ファイル付き。");

        // 本文末尾強制改行あり
        setting.setSendForthNewlineAfterMessageText(false);

        // 添付ファイル版
        final BlancoMailMessageAttachment attachment = new BlancoMailMessageAttachment();
        attachment.setData("添付ファイル".getBytes());
        attachment.setFileName("aaa.txt");
        message.getAttachmentList().add(attachment);

        System.out.println(message.getSubject() + ": " + to1.toString());

        BlancoMailSenderFactory.getInstance().send(setting, message);
    }
}
