1 19 package org.lucane.applications.jmail; 20 21 import org.lucane.common.*; 22 import org.lucane.common.crypto.*; 23 import org.lucane.common.net.ObjectConnection; 24 import org.lucane.server.*; 25 import org.lucane.server.database.*; 26 27 import java.sql.*; 28 29 public class JMailService 30 extends Service 31 { 32 DatabaseAbstractionLayer layer = null; 33 34 public JMailService() 35 { 36 } 37 38 public void init(Server parent) 39 { 40 layer = parent.getDBLayer(); 41 } 42 43 public void install() 44 { 45 try { 46 String dbDescription = getDirectory() + "db-jmail.xml"; 47 layer.getTableCreator().createFromXml(dbDescription); 48 } catch (Exception e) { 49 Logging.getLogger().severe("Unable to install JMailService !"); 50 e.printStackTrace(); 51 } 52 } 53 54 public void process(ObjectConnection oc, Message message) 55 { 56 JMailAction jma = (JMailAction)message.getData(); 57 String user = message.getSender().getName(); 58 Account account; 59 60 try { 61 switch(jma.action) 62 { 63 case JMailAction.GET_ACCOUNT: 64 account = this.getAccount(user); 65 oc.write("OK"); 66 oc.write(account); 67 break; 68 } 69 } catch(Exception e) { 70 try { 71 oc.write("FAILED " + e); 72 } catch(Exception e2) {} 73 e.printStackTrace(); 74 } 75 } 76 77 78 private Account getAccount(String user) 79 throws Exception 80 { 81 Account a = null; 82 83 Connection connex = layer.getConnection(); 84 PreparedStatement select = connex.prepareStatement( 85 "SELECT * FROM JMailAccounts WHERE userName=?"); 86 select.setString(1, user); 87 88 ResultSet rs = select.executeQuery(); 89 90 91 if(rs.next()) 92 { 93 String address = rs.getString(2); 94 String type = rs.getString(3); 95 String inHost = rs.getString(4); 96 int inPort = rs.getInt(5); 97 String outHost = rs.getString(6); 98 int outPort = rs.getInt(7); 99 String login = rs.getString(8); 100 String password = rs.getString(9); 101 int refreshInterval = rs.getInt(10); 102 103 password = BlowFish.decipher(login, password); 104 a = new Account(address, type, inHost, inPort, outHost, outPort, login, password, refreshInterval); 105 } 106 107 rs.close(); 108 select.close(); 109 connex.close(); 110 111 return a; 112 } 113 } 114 | Popular Tags |