1 26 package org.snipsnap.net.admin; 27 28 import org.snipsnap.config.Configuration; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 import java.util.Map ; 33 import java.net.InetAddress ; 34 import java.net.Socket ; 35 import java.net.InetSocketAddress ; 36 import java.net.UnknownHostException ; 37 import java.io.IOException ; 38 39 public class SetupMail implements SetupHandler { 40 public String getName() { 41 return "mail"; 42 } 43 44 public Map setup(HttpServletRequest request, HttpServletResponse response, Configuration config, Map errors) { 45 String mailHost = request.getParameter(Configuration.APP_MAIL_HOST); 46 config.setMailHost(mailHost); 47 if (null != mailHost && !"".equals(mailHost)) { 48 try { 49 final InetAddress address = InetAddress.getByName(mailHost); 51 Socket socket = new Socket (); 52 try { 53 socket.connect(new InetSocketAddress (address, 25), 5 * 1000); 54 socket.close(); 55 } catch (IOException e) { 56 errors.put(Configuration.APP_MAIL_HOST, Configuration.APP_MAIL_HOST + ".connect"); 57 } 58 } catch (UnknownHostException e) { 59 errors.put(Configuration.APP_MAIL_HOST, Configuration.APP_MAIL_HOST + ".unknown"); 60 } 61 } 62 63 String mailDomain = request.getParameter(Configuration.APP_MAIL_DOMAIN); 64 config.setMailDomain(mailDomain); 65 if (config.getMailHost() != null && !"".equals(config.getMailHost())) { 66 if (mailDomain == null || "".equals(mailDomain) || mailDomain.indexOf('@') != -1) { 67 errors.put(Configuration.APP_MAIL_DOMAIN, Configuration.APP_MAIL_DOMAIN); 68 } 69 } 70 71 return errors; 72 } 73 } 74 | Popular Tags |