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 31 37 public class WinMozMailer implements MailerService { 38 private String mozLocation; 40 41 44 public WinMozMailer() { 45 mozLocation = "C:\\Program Files\\mozilla.org\\Mozilla\\mozilla.exe"; 46 } 47 48 51 public WinMozMailer(String location) { 52 mozLocation = location; 53 } 54 55 60 public void open(Message msg) throws LaunchFailedException { 61 String [] cmdArray = new String [3]; 62 63 64 cmdArray[0] = mozLocation; 65 cmdArray[1] = "-compose"; 66 cmdArray[2] = constructArgs(msg.getToAddrs(), msg.getCcAddrs(), msg.getBccAddrs(), msg.getSubject(), msg.getBody(), msg.getAttachments()); 67 68 try { 69 Runtime.getRuntime().exec(cmdArray); 70 } catch (IOException e) { 71 throw new LaunchFailedException("Cannot launch Mozilla composer via -compose commandline:" + e.getMessage()); 72 } 73 } 74 75 80 public void open() throws LaunchFailedException { 81 String [] cmdArray = { mozLocation, "-compose" }; 82 try { 83 Runtime.getRuntime().exec(cmdArray); 84 } catch (IOException e) { 85 throw new LaunchFailedException("Cannot launch Mozilla composer via -compose commandline:" + e.getMessage()); 86 } 87 } 88 89 98 private String constructArgs(Iterator to, Iterator cc, Iterator bcc, String subject, String body, Iterator attach) { 99 Iterator iter; 100 String argString = ""; 101 String tmp = ""; 102 103 if(to != null) { 104 while(to.hasNext()) { 105 tmp = tmp + ((String )to.next()) + ","; 106 } 107 argString = "to='" + tmp + "',"; 108 } 109 110 if(cc != null) { 111 tmp = ""; 112 while(cc.hasNext()) { 113 tmp = tmp + ((String )cc.next()) + ","; 114 } 115 argString = argString + "cc='" + tmp + "',"; 116 } 117 118 if(bcc != null) { 119 tmp = ""; 120 while(bcc.hasNext()) { 121 tmp = tmp + ((String )bcc.next()) + ","; 122 } 123 argString = argString + "bcc='" + tmp + "',"; 124 } 125 126 if(subject != null) 127 argString = argString + "subject=" + parseSubject(URLUTF8Encoder.encode(subject)) + ","; 128 if(body != null) 129 argString = argString + "body=<body>" + parseBody(URLUTF8Encoder.encode(body)) + "</body>,"; 130 131 if(attach != null) { 132 tmp = ""; 133 while (attach.hasNext()) { 134 tmp = tmp + "file://" + (String )attach.next() + ","; 135 } 136 argString = argString + "attachment='" + tmp + "'"; 137 } 138 139 return argString; 140 } 141 142 147 private String parseSubject(String inString) { 148 String tmp = inString; 149 150 tmp = tmp.replaceAll("%0a", "%20"); 152 153 return tmp; 154 } 155 156 161 private String parseBody(String inString) { 162 String tmp = inString; 163 164 tmp = tmp.replaceAll("%3c", "<"); 166 tmp = tmp.replaceAll("%3e", ">"); 167 168 tmp = tmp.replaceAll("%0a", "<br>"); 170 171 return tmp; 172 } 173 } 174 175 | Popular Tags |