/**
 * <h1>TestRetrieveMail</h1>
 * <p>
 * Copyright 2009-2010, Res Interactive, LLC.
 * </p>
 * <p>
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * </p>
 * <p>
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * </p>
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * </p>
 * 
 * @author theys
 */

package org.starhope.appius.test;

import java.io.*;

import javax.servlet.jsp.JspWriter;

import org.starhope.appius.game.AppiusClaudiusCaecus;
import org.starhope.appius.user.User;

/**
 * WRITEME
 * 
 * @author theys
 */
public class TestRetrieveMail {
	/**
	 * @param out WRITEME
	 */
	public static void getMailFromFile (final JspWriter out) {
		System.out.println ("Running");
		final File input = new File ("/etc/appius/newUsers.txt");
		BufferedReader reader = null;
		try {
			reader = new BufferedReader (
					new FileReader (input));
			System.out.println ("Trying");

			String line = null;

			while (null != (line = reader.readLine ())) {
				System.out.println ("Looping");
				final int id = Integer.parseInt (line.trim ());
				final String mail = User.getByID (id)
				.getResponsibleMail ();
				if (null != mail) {
					out.println (mail + "\n");
				}
			}
			reader.close ();
			reader = null;

		} catch (final FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace ();
		} catch (final IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace ();
		} finally {
			try {
				if (null != reader) {
					reader.close ();
					reader = null;
				}
			} catch (final IOException e) {
				AppiusClaudiusCaecus.reportBug (
						"Caught a IOException in getMailFromFile", e);
			}
		}
		System.out.println ("Ending");

	}
}
