01: /***
02: * jwma Java WebMail
03: * Copyright (c) 2000-2003 jwma team
04: *
05: * jwma is free software; you can distribute and use this source
06: * under the terms of the BSD-style license received along with
07: * the distribution.
08: ***/package dtw.webmail.model;
09:
10: import javax.mail.*;
11: import javax.mail.event.*;
12:
13: import org.apache.log4j.Logger;
14: import dtw.webmail.*;
15:
16: import java.util.Date;
17:
18: /**
19: * Class that implements a <tt>Transport</tt> wrapper.
20: * <p>
21: *
22: * @author Dieter Wimberger
23: * @version 0.9.7 07/02/2003
24: */
25: public class JwmaTransportImpl {
26:
27: private static final Logger log = Logger
28: .getLogger(JwmaTransportImpl.class);
29:
30: private Transport m_Transport;
31: private URLName m_URLName;
32: private JwmaAuthenticator m_Authenticator;
33:
34: private JwmaTransportImpl(Transport trans, JwmaAuthenticator auth) {
35: m_Transport = trans;
36: m_URLName = trans.getURLName();
37: m_Authenticator = auth;
38: }//JwmaTransportImpl
39:
40: public void sendMessage(Message msg) throws MessagingException {
41: if (!m_Transport.isConnected()) {
42: m_Transport.connect(m_URLName.getHost(), m_URLName
43: .getPort(), m_Authenticator.getUserName(),
44: m_Authenticator.getPassword());
45: log.debug("Connected to transport:" + m_URLName.toString());
46: }
47: //ensure that a sent date is set
48: msg.setSentDate(new Date());
49: m_Transport.sendMessage(msg, msg.getAllRecipients());
50: }//sendMessage
51:
52: public static JwmaTransportImpl createJwmaTransportImpl(
53: Transport trans, JwmaAuthenticator auth) {
54: return new JwmaTransportImpl(trans, auth);
55: }//createJwmaTransportImpl
56:
57: class TransportHandler extends TransportAdapter {
58:
59: }//inner class TransportHandler
60:
61: }//class JwmaTransportImpl
|