package cn.aposoft.framework.mail;

import java.io.UnsupportedEncodingException;
import java.util.Collection;

import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

public class MailClientImpl implements MailClient {

	private InternetAddress createAddress(MailContact contact) throws AddressException, UnsupportedEncodingException {
		return new InternetAddress(MimeUtility.encodeWord(contact.getName()) + " <" + contact.getEmailAddress() + ">");
	}

	private Session session;

	public MailClientImpl(Session session) {
		this.session = session;
	}

	@Override
	public void send(MailContact from, MailRecipient to, String subject, String content)
			throws AddressException, UnsupportedEncodingException, MessagingException {
		Message msg = new MimeMessage(session);
		msg.setFrom(createAddress(from));
		RecipientType type = getRecipientType(to);
		msg.setRecipient(type, createAddress(to));
	}

	private RecipientType getRecipientType(MailRecipient to) {

		return null;
	}

	@Override
	public void send(MailContact from, MailRecipient to, MailMessage message) {
		// TODO Auto-generated method stub

	}

	@Override
	public void send(MailContact from, Collection<MailRecipient> tos, MailMessage message) {
		// TODO Auto-generated method stub

	}

	@Override
	public void send(MailContact from, Collection<MailRecipient> tos, Collection<MailRecipient> ccs,
			MailMessage message) {
		// TODO Auto-generated method stub

	}

	@Override
	public void send(MailContact from, Collection<MailRecipient> tos, Collection<MailRecipient> ccs,
			Collection<MailRecipient> scs, MailMessage message) {
		// TODO Auto-generated method stub

	}

}

@@ -159,23 +159,20 @@
 ssag
-e.RecipientType
+ingException
 ;%0Aim
@@ -183,39 +183,28 @@
  javax.mail.
-M
+S
 ess
-agingExcept
 ion;%0Aimport 
@@ -206,39 +206,41 @@
 port javax.mail.
-Session
+Transport
 ;%0Aimport javax.m
@@ -1039,53 +1039,8 @@
 ));%0A
-%09%09RecipientType type = getRecipientType(to);%0A
 %09%09ms
@@ -1055,19 +1055,27 @@
 ipient(t
+o.getT
 ype
+()
 , create
@@ -1093,85 +1093,109 @@
 );%0A%09
-%7D%0A%0A%09private RecipientType getRecipientType(MailRecipient to) %7B%0A%0A%09%09return null
+%09msg.setSubject(subject);%0A%09%09msg.setContent(content, %22text/html;charset=UTF-8%22);%0A%09%09Transport.send(msg)
 ;%0A%09%7D

完成简单的 String subject,String content的实现