package myBean.mail;

import javax.mail.*;  
import javax.mail.internet.*;  
import java.util.*;
import java.rmi.*;
import javax.activation.*;
import java.io.*;
import myBean.mail.*;

public class Mails {
	private int unReaded;
	private int total;
	private Vector mails = new Vector();
	
	public Mails(Folder folder) {
		try {
			folder.open(Folder.READ_WRITE);
			
			unReaded = folder.getUnreadMessageCount();
			total = folder.getMessageCount();
			
			Message []msg = folder.getMessages();
			
			for(int i=0; i<msg.length; i++) {
				Mail mail = new Mail(msg[i]);
				
				mails.add(mail);
			}
			
			folder.close(true);
		}catch(MessagingException e) {
			System.err.println("myBean.Mails()" +e.getMessage());
		}
	}
	
	public Mail getMail(int i) {
		if(i<0 || i>=mails.size())
			return null;
		else
			return (Mail)mails.get(i);
	}
	
	public int getUnreadedMessageCount() {
		return unReaded;
	}
	
	public int getMessageCount() {
		return total;
	}
}