1 package com.knowgate.hipergate; 2 3 import java.io.FileNotFoundException ; 4 import java.io.IOException ; 5 import java.io.File ; 6 import java.io.FileOutputStream ; 7 import java.sql.Connection ; 8 import java.sql.SQLException ; 9 10 import java.util.Properties ; 11 12 import javax.mail.*; 13 import javax.mail.internet.*; 14 15 import bsh.Interpreter; 16 import bsh.TargetError; 17 import bsh.EvalError; 18 19 import com.knowgate.debug.DebugFile; 20 import com.knowgate.jdc.JDCConnection; 21 import com.knowgate.dataobjs.DB; 22 import com.knowgate.dataobjs.DBBind; 23 import com.knowgate.misc.Environment; 24 import com.knowgate.misc.Gadgets; 25 26 30 31 public class InetMailAgent { 32 33 private static DBBind oDBB = null; 34 35 public InetMailAgent() { 36 } 37 38 40 public static void ForumsProcessor(Connection oConn, MimeMessage oMail, Properties oProps) { 41 42 } 43 44 46 public static void BugsProcessor(Connection oConn, MimeMessage oMail, Properties oProps) { 47 48 } 49 50 52 public static void VDiskProcessor(JDCConnection oConn, MimeMessage oMail, Properties oProps) 53 throws FileNotFoundException , IOException , SQLException , MessagingException { 54 55 final String sSep = System.getProperty("file.separator"); 56 57 Category oCatg = new Category(oConn, oProps.getProperty("category")); 58 String sPath = oCatg.getPath(oConn); 59 String sEML = Gadgets.chomp(sPath, sSep) + oMail.getMessageID(); 60 String sSubject = oMail.getSubject(); 61 62 if (null==sSubject) 63 sSubject = "no subject"; 64 else if (sSubject.length()>128) 65 sSubject = sSubject.substring(0, 127); 66 67 FileOutputStream oOut = new FileOutputStream (sEML); 68 69 oMail.writeTo(oOut); 70 71 oOut.close(); 72 73 Product oProd = new Product(); 74 oProd.put(DB.gu_owner, oCatg.getString(DB.gu_owner)); 75 oProd.put(DB.nm_product, sSubject); 76 oProd.store(oConn); 77 78 ProductLocation oLoca = new ProductLocation(); 79 80 oLoca.put(DB.gu_product, oProd.getString(DB.gu_product)); 81 82 oLoca.put(DB.gu_owner, oCatg.getString(DB.gu_owner)); 83 84 oLoca.put(DB.len_file, oMail.getSize()); 85 86 javax.mail.Address [] oFrom = oMail.getFrom(); 87 88 oLoca.put(DB.tx_email, oFrom[0].toString()); 89 90 oLoca.setPath("localhost", "file://" + sEML); 91 92 oLoca.store(oConn); 93 } 94 95 98 public static void main(String [] argv) 99 throws ClassNotFoundException , SQLException , MessagingException, 100 EvalError, FileNotFoundException , IOException { 101 102 final String sSep = System.getProperty("file.separator"); 103 104 String sFile = argv[0]; 105 String sBody, sTo, sFrom, sType; 106 File oFile; 107 108 Environment.loadProfile(sFile, sFile); 109 110 if (null==oDBB) oDBB = new DBBind(sFile); 111 112 String sDir = Environment.getProfilePath(sFile, "storage"); 113 114 sDir += "mailagent" + sSep; 115 116 JDCConnection oCon = oDBB.getConnection("inetmailagent"); 117 118 Session oSession = Session.getDefaultInstance(Environment.getProfile(sFile), null); 119 120 MimeMessage oMail = new MimeMessage(oSession,System.in); 121 122 javax.mail.Address [] oAddrs = oMail.getAllRecipients(); 123 124 for (int f=0; f<oAddrs.length; f++) { 125 oFile = new File (sDir + oAddrs[f].toString() + ".cnf"); 126 127 if (oFile.exists()) { 128 sTo = oAddrs[f].toString(); 129 Environment.loadProfile("to", sDir + sTo + ".cnf"); 130 131 Interpreter oInterpreter = new Interpreter(); 132 133 oInterpreter.set ("DefaultConnection", oCon); 134 oInterpreter.set ("MessageMail", oMail); 135 oInterpreter.set ("ToProperties", Environment.getProfile("to")); 136 137 oInterpreter.eval(sDir + "scripts" + sSep + Environment.getProfileVar("to", "script")); 138 139 Object obj = oInterpreter.get("ErrorCode"); 140 } 141 } 143 oCon.close("inetmailagent"); 144 } 145 } | Popular Tags |