/*
 * 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;

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

import blanco.mail.core.valueobject.BlancoMailMessage;
import blanco.mail.core.valueobject.BlancoMailSetting;

public class BlancoMailReceiverSample {
    /**
     * blancoMailCoreを用いたメール受信サンプル。
     * 
     * @param args
     *            入力パラメータ。
     * @throws ConnectException
     *             接続例外が発生した場合。
     * @throws IOException
     *             メール受信中に例外が発生した場合。
     */
    public static void main(final String[] args) throws ConnectException,
            IOException {
        final BlancoMailSetting setting = BlancoMailSettingFactory
                .getInstance();
        if (true) {
            // 設定値は BlancoMailSetting.properties から取得します。
        } else {
            setting.setReceiveHost("pop.gmail.com");
            setting.setReceivePort(995);
            setting.setReceiveUseSsl(true);
            setting.setReceiveUserName("受信者○○○@gmail.com");
            setting.setReceivePassword("password");
            // setting.setSessionLogDirectorySuccess("./log");
            // setting.setSessionLogDirectoryError("./log.err");
        }

        final BlancoMailReceiver receiver = BlancoMailReceiverFactory
                .getInstance();
        final BlancoMailMessage message = receiver.receive(setting);
        if (message != null) {
            System.out.println(message.getSubject());
            System.out.println(message.toString());
        }
    }
}
