if (DebugFile.trace) {
DebugFile.writeln("Begin DraftsHelper.draftMessage("+sMailHost+","+sGuWorkArea+","+sUserId+","+sContentType+")");
DebugFile.incIdent();
}
JDCConnection oConn = oDraftsFldr.getConnection();
java.sql.PreparedStatement oStmt;
java.sql.ResultSet oRSet;
com.knowgate.acl.ACLUser oUsr = new com.knowgate.acl.ACLUser();
if (!oUsr.load(oConn, new Object[]{sUserId})) {
if (DebugFile.trace) {
DebugFile.writeln("ERROR: User "+sUserId+" not found");
DebugFile.decIdent();
}
throw new SQLException("DraftsHelper.draftMessage() User "+sUserId+" not found");
} // fi
String sGuMsg = Gadgets.generateUUID();
String sGuFldr= oDraftsFldr.getCategoryGuid();
String sFrom = oUsr.getStringNull(DB.nm_user,"")+" "+oUsr.getStringNull(DB.tx_surname1,"")+" "+oUsr.getStringNull(DB.tx_surname2,"");
String sIdMsg = "<"+sGuMsg+"."+oUsr.getStringNull(DB.tx_nickname,"")+"@"+sMailHost+">";
oConn.setAutoCommit(false);
if (DebugFile.trace) {
DebugFile.writeln("Creating message "+sGuMsg+" "+sIdMsg+" at folder "+oDraftsFldr.getName()+" "+sGuFldr);
DebugFile.writeln("JDCConnection.prepareStatement(SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"='"+sGuFldr+"')");
}
oStmt = oConn.prepareStatement("SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"=?");
oStmt.setString (1,sGuFldr);
oRSet = oStmt.executeQuery();
oRSet.next();
java.math.BigDecimal oMax = oRSet.getBigDecimal(1);
if (oRSet.wasNull()) oMax = new java.math.BigDecimal(0);
oRSet.close();
oStmt.close();
if (DebugFile.trace) {
DebugFile.writeln("JDCConnection.prepareStatement(INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES('"+sGuMsg+"',"+oMax.add(new java.math.BigDecimal(1)).toString()+",'"+sGuWorkArea+"','"+sGuFldr+"','text/"+sContentType+"; charset=utf-8','"+sIdMsg+"','','"+oUsr.getString(DB.tx_main_email)+"','"+oUsr.getString(DB.tx_main_email)+"','"+sFrom.trim()+"',0,1,0))");
}
oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES(?,?,?,?,?,?,?,?,?,?,0,1,0)");
oStmt.setString (1,sGuMsg);
oStmt.setBigDecimal (2,oMax.add(new java.math.BigDecimal(1)));
oStmt.setString (3,sGuWorkArea);
oStmt.setString (4,sGuFldr);
oStmt.setString (5,"text/"+sContentType+"; charset=utf-8");
oStmt.setString (6,sIdMsg);
oStmt.setString (7,"");
oStmt.setString (8,oUsr.getString(DB.tx_main_email));
oStmt.setString (9,oUsr.getString(DB.tx_main_email));
oStmt.setString (10,sFrom.trim());
if (DebugFile.trace) {
DebugFile.writeln("JDCConnection.executeUpdate(INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES('"+sGuMsg+"',?,'"+sGuWorkArea+"','"+sGuFldr+"','text/"+sContentType+"; charset=utf-8','"+sIdMsg+"','','"+oUsr.getString(DB.tx_main_email)+"','"+oUsr.getString(DB.tx_main_email)+"','"+sFrom.trim()+"',0,1,0))");
}
nAffected = oStmt.executeUpdate();
oStmt.close();
if (DebugFile.trace) {
DebugFile.writeln(String.valueOf(nAffected)+" affected rows");
}
oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+") VALUES (?,?,?,?,?,?)");
oStmt.setString (1,sGuMsg);
oStmt.setString (2,sIdMsg);
oStmt.setString (3,oUsr.getString(DB.tx_main_email));
oStmt.setString (4,"from");
oStmt.setString (5,sFrom.trim());
oStmt.setString (6,sUserId);
if (DebugFile.trace) {
DebugFile.writeln("JDCConnection.executeUpdate(INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+") VALUES ('"+sGuMsg+"','"+sIdMsg+"','"+oUsr.getString(DB.tx_main_email)+"','from','"+sFrom.trim()+"','"+sUserId+"'))");
}
nAffected = oStmt.executeUpdate();
oStmt.close();
if (DebugFile.trace) {
DebugFile.writeln(String.valueOf(nAffected)+" affected rows");
}
if (!oConn.getAutoCommit()) {
if (DebugFile.trace)
DebugFile.writeln("Connection.commit()");
oConn.commit();
}
DBMimeMessage oRetVal = oDraftsFldr.getMessageByGuid(sGuMsg);
if (DebugFile.trace) {