1 package net.suberic.pooka; 2 import javax.mail.*; 3 import javax.mail.internet.*; 4 5 9 public class OutgoingFolderInfo extends FolderInfo { 10 URLName transportURL; 11 Thread sendMailThread = new net.suberic.util.thread.ActionThread(Pooka.getProperty("SendMailThread.name", "Send Mail Thread")); 12 boolean online = true; 13 14 17 public OutgoingFolderInfo(StoreInfo parent, String fname, URLName outgoingURL) { 18 super(parent, fname); 19 transportURL = outgoingURL; 20 } 21 22 25 public void sendAll() throws javax.mail.MessagingException { 26 27 Transport sendTransport = Pooka.getDefaultSession().getTransport(transportURL); 28 try { 29 sendTransport.connect(); 30 31 Message[] msgs = getFolder().getMessages(); 32 33 try { 34 for (int i = 0; i < msgs.length; i++) { 35 Message m = msgs[i]; 36 if (! m.isSet(Flags.Flag.DRAFT)) { 37 sendTransport.sendMessage(m, m.getAllRecipients()); 38 m.setFlag(Flags.Flag.DELETED, true); 39 } 40 } 41 } finally { 42 getFolder().expunge(); 43 } 44 } finally { 45 sendTransport.close(); 46 } 47 } 48 49 55 public void sendMessage(NewMessageInfo nmi, boolean connect) throws javax.mail.MessagingException { 56 this.appendMessages(new MessageInfo[] { nmi }); 57 if (online) 58 sendAll(); 59 else if (connect || Pooka.getProperty("Message.sendImmediately", "false").equalsIgnoreCase("true")) { 60 try { 61 connect(); 62 if (online) 63 sendAll(); 64 } catch (MessagingException me) { 65 System.err.println("me is a " + me); 66 online = false; 67 } 68 } 69 } 70 71 75 public void sendMessage(NewMessageInfo nmi) throws javax.mail.MessagingException { 76 sendMessage(nmi, false); 77 } 78 79 82 public void connect() { 83 online=true; 85 } 86 } 87 | Popular Tags |