1 20 21 package org.jdesktop.jdic.desktop.internal.impl; 22 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 26 import org.jdesktop.jdic.desktop.Message; 27 import org.jdesktop.jdic.desktop.internal.LaunchFailedException; 28 import org.jdesktop.jdic.desktop.internal.MailerService; 29 30 35 public class GnomeEvoMailer implements MailerService { 36 private String evoLocation; 38 39 42 public GnomeEvoMailer() { 43 evoLocation = "evolution"; 44 } 45 46 49 public GnomeEvoMailer(String location) { 50 evoLocation = location; 51 } 52 53 58 public void open(Message msg) throws LaunchFailedException { 59 String [] cmdArray = new String [2]; 60 cmdArray[0] = evoLocation; 61 cmdArray[1] = "mailto:?"; 62 63 cmdArray[1] += constructMailto(msg.getToAddrs(), msg.getCcAddrs(), msg.getBccAddrs(), msg.getSubject(), msg.getBody(), msg.getAttachments()); 64 65 try { 66 Runtime.getRuntime().exec(cmdArray); 67 Thread.sleep(2000); 68 } catch (IOException e1) { 69 throw new LaunchFailedException("Cannot launch Evolution composer via commandline:" + e1); 70 } catch (InterruptedException iE) {} 71 } 72 73 78 public void open() throws LaunchFailedException { 79 String [] cmdArray = new String [2]; 80 cmdArray[0] = evoLocation; 81 cmdArray[1] = "mailto:?"; 82 83 try { 84 Runtime.getRuntime().exec(cmdArray); 85 Thread.sleep(2000); 86 } catch (IOException e2) { 87 throw new LaunchFailedException("Cannot launch Evolution composer via commandline:" + e2); 88 } catch (InterruptedException iE) {} 89 } 90 91 96 private String constructMailto(Iterator to, Iterator cc, Iterator bcc, String subject, String body, Iterator attach) { 97 String mailto = new String (); 98 99 if(to != null) { 100 while(to.hasNext()) { 101 mailto = mailto + "to=" + ((String )to.next()) + "&"; 102 } 103 } 104 105 if(cc != null) { 106 while(cc.hasNext()) { 107 mailto = mailto + "cc=" + ((String )cc.next()) + "&"; 108 } 109 } 110 111 if(bcc != null) { 112 while (bcc.hasNext()) { 113 mailto = mailto + "bcc=" + ((String )bcc.next()) + "&"; 114 } 115 } 116 117 if(subject != null) 118 mailto = mailto + "subject=" + URLUTF8Encoder.encode(subject) + "&"; 119 if(body != null) 120 mailto = mailto + "body=" + URLUTF8Encoder.encode(body) + "&"; 121 122 if(attach != null) { 123 while(attach.hasNext()) { 124 mailto = mailto + "attach=" + ((String )attach.next()) + "&"; 125 } 126 } 127 128 return mailto; 129 } 130 } 131 132 | Popular Tags |