Job oSnd;
DBPersist oJob = new DBPersist(DB.k_jobs,"Job");
oCon = oDbb.getConnection("SendMail",false);
oCon.setAutoCommit(false);
ACLUser oUsr = new ACLUser(oCon, oMacc.getString(DB.gu_user));
String sJobId = Job.getIdFromTitle(oCon, sJobTl, oUsr.getString(DB.gu_workarea));
if (null==sJobId) {
if (DebugFile.trace) DebugFile.writeln("Job "+sJobTl+" not found, creating a new one...");
if (oMacc.isNull(DB.gu_account)) {
if (DebugFile.trace) DebugFile.decIdent();
throw new SQLException("No MailAccount found for user "+oUsr.getString(DB.gu_user),"01S06");
}
String sMBoxDir = DBStore.MBoxDirectory(oDbb.getProfileName(),oUsr.getInt(DB.id_domain),oUsr.getString(DB.gu_workarea));
if (DebugFile.trace) DebugFile.writeln("mbox directory is "+sMBoxDir);
SessionHandler oHndl = new SessionHandler(oMacc,sMBoxDir);
DBStore oRDBMS = DBStore.open(oHndl.getSession(), oDbb.getProfileName(), sMBoxDir, oUsr.getString(DB.gu_user), oUsr.getString(DB.tx_pwd));
DBFolder oOutbox = oRDBMS.openDBFolder("outbox",DBFolder.READ_WRITE);
DBMimeMessage oMsg = DraftsHelper.draftMessage(oOutbox, oMacc.getString(DB.outgoing_server),
oUsr.getString(DB.gu_workarea),
oUsr.getString(DB.gu_user),
sTextHtml==null ? "plain" : "html");
String sMsgId = oMsg.getContentID();
if (null==sMsgId) throw new NullPointerException("MIME message identifier could not be set for message with GUID "+oMsg.getMessageGuid());
DraftsHelper.draftUpdate(oCon, oUsr.getInt(DB.id_domain),
oUsr.getString(DB.gu_workarea),
oMsg.getMessageGuid(), sMsgId,
sFromAddr,sReplyAddr,sFromPersonal,
sSubject, "text/"+(sTextHtml==null ? "plain" : "html")+";charset="+sEncoding,
(sTextHtml==null ? sTextPlain : sTextHtml), null, null, null);
if (aAttachments!=null) {
Integer oPart = DBCommand.queryMaxInt(oCon, DB.id_part, DB.k_mime_parts, DB.gu_mimemsg+"='"+oMsg.getMessageGuid()+"'");
if (oPart==null) oPart = new Integer(1);
PreparedStatement oStm = oCon.prepareStatement("INSERT INTO " + DB.k_mime_parts + "("+DB.gu_mimemsg+","+DB.id_message+","+DB.id_part+","+DB.id_disposition+","+DB.id_content+","+DB.id_type+","+DB.len_part+","+DB.de_part+","+DB.file_name+") VALUES ('"+oMsg.getMessageGuid()+"',?,?,'reference',?,?,?,?,?)");
for (int p=0; p<aAttachments.length; p++) {
String sFilePath = Gadgets.chomp(sUserDir,File.separator)+aAttachments[p];
File oAttach = new File(sFilePath);
if (oAttach.exists()) {
oStm.setString(1, sMsgId);
oStm.setInt(2, oPart.intValue()+p);
oStm.setString(3, DBMimePart.getMimeType(oCon,aAttachments[p]));
oStm.setString(4, DBMimePart.getMimeType(oCon,aAttachments[p]));
oStm.setInt(5, (int) oAttach.length());
oStm.setString(6, aAttachments[p]);
oStm.setString(7, sFilePath);
oStm.executeUpdate();
} // fi
} // next
oStm.close();
} // fi
sJobId = (sId.length()==32 ? sId : Gadgets.generateUUID());
oJob.put(DB.gu_job, sJobId);
oJob.put(DB.gu_workarea, oUsr.getString(DB.gu_workarea));
oJob.put(DB.gu_writer, oUsr.getString(DB.gu_user));
oJob.put(DB.id_command, Job.COMMAND_SEND);
oJob.put(DB.id_status, bAutoRunJob ? Job.STATUS_SUSPENDED : Job.STATUS_PENDING);
oJob.put(DB.tl_job, sJobTl);
oJob.put(DB.tx_parameters, (bTestMode ? "testmode:true," : "")+
"message:"+oMsg.getMessageGuid()+","+