try { sTrace = com.knowgate.debug.StackTraceUtil.getStackTrace(sqle);
DebugFile.writeln(sTrace);
} catch (Exception ignore) {}
try { if (null!=oStmt) oStmt.close(); oStmt=null; } catch (Exception ignore) {}
try { if (null!=oConn) oConn.rollback(); } catch (Exception ignore) {}
throw new MessagingException(DB.k_mime_msgs + " " + sqle.getMessage(), sqle);
}
if ((iOpenMode&MODE_BLOB)!=0) {
// Deallocate byte array containing message body for freeing memory as soon as possible
try { byOutStrm.close(); } catch (IOException ignore) {}
byOutStrm = null;
}
// *************************************************************************
// Now that we have saved the main message reference proceed to store
// its parts into k_mime_parts
try {
Object oContent = oMsg.getContent();
if (oContent instanceof MimeMultipart) {
try {
saveMimeParts(oMsg, sMsgCharSeq, sBoundary, sGuMimeMsg, sMessageID, dPgMessage.intValue(), 0);
} catch (MessagingException msge) {
// Close Mbox file rollback and re-throw
try { oConn.rollback(); } catch (Exception ignore) {}
throw new MessagingException(msge.getMessage(), msge.getNextException());
}
} // fi (MimeMultipart)
} catch (Exception xcpt) {
try { oConn.rollback(); } catch (Exception ignore) {}
throw new MessagingException("MimeMessage.getContent() " + xcpt.getMessage(), xcpt);
}
// *************************************************************************
// Store message recipients at k_inet_addrs
try {
if (oConn.getDataBaseProduct()==JDCConnection.DBMS_MYSQL)
sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",CONVERT('****************************USER' USING utf8),"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
else
sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",'****************************USER',"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
} catch (SQLException sqle) {
if (DebugFile.trace) DebugFile.writeln("SQLException " + sqle.getMessage());
sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",'****************************USER',"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
}
if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
PreparedStatement oAddr = null;
try {
oAddr = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet oRSet;
InternetAddress oInetAdr;
String sTxEmail, sGuCompany, sGuContact, sTxName, sTxSurname1, sTxSurname2, sTxPersonal;
// Get From address and keep them into pFrom properties
if (oFrom!=null) {
oAddr.setString(1, oFrom.getAddress());
oAddr.setString(2, sGuWorkArea);
oAddr.setString(3, oFrom.getAddress());
oAddr.setString(4, oFrom.getAddress());
oAddr.setString(5, oFrom.getAddress());
oAddr.setString(6, sGuWorkArea);
oRSet = oAddr.executeQuery();
if (oRSet.next()) {
sGuContact = oRSet.getString(1);
if (oRSet.wasNull()) sGuContact = "null";
sGuCompany = oRSet.getString(2);
if (oRSet.wasNull()) sGuCompany = "null";
if (sGuCompany.equals("****************************USER")) {
sTxName = oRSet.getString(3);
if (oRSet.wasNull()) sTxName = "";
sTxSurname1 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname1 = "";
sTxSurname2 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname2 = "";
sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
}
else
sTxPersonal = "null";
if (DebugFile.trace) DebugFile.writeln("from "+sGuContact+","+sGuCompany+","+sTxPersonal);
pFrom.put(oFrom.getAddress(), sGuContact+","+sGuCompany+","+sTxPersonal);
}
else
pFrom.put(oFrom.getAddress(), "null,null,null");
oRSet.close();
} // fi (oFrom)
if (DebugFile.trace) DebugFile.writeln("from count = " + pFrom.size());
// Get TO address and keep them into pTo properties
if (oTo!=null) {
for (int t=0; t<oTo.length; t++) {
oInetAdr = (InternetAddress) oTo[t];
sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);
oAddr.setString(1, sTxEmail);
oAddr.setString(2, sGuWorkArea);
oAddr.setString(3, sTxEmail);
oAddr.setString(4, sTxEmail);
oAddr.setString(5, sTxEmail);
oAddr.setString(6, sGuWorkArea);
oRSet = oAddr.executeQuery();
if (oRSet.next()) {
sGuContact = oRSet.getString(1);
if (oRSet.wasNull()) sGuContact = "null";
sGuCompany = oRSet.getString(2);
if (oRSet.wasNull()) sGuCompany = "null";
if (sGuCompany.equals("****************************USER")) {
sTxName = oRSet.getString(3);
if (oRSet.wasNull()) sTxName = "";
sTxSurname1 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname1 = "";
sTxSurname2 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname2 = "";
sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
}
else
sTxPersonal = "null";
pTo.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
} // fi (oRSet.next())
else
pTo.put(sTxEmail, "null,null,null");
oRSet.close();
} // next (t)
} // fi (oTo)
if (DebugFile.trace) DebugFile.writeln("to count = " + pTo.size());
// Get CC address and keep them into pTo properties
if (oCC!=null) {
for (int c=0; c<oCC.length; c++) {
oInetAdr = (InternetAddress) oCC[c];
sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);
oAddr.setString(1, sTxEmail);
oAddr.setString(2, sGuWorkArea);
oAddr.setString(3, sTxEmail);
oAddr.setString(4, sTxEmail);
oAddr.setString(5, sTxEmail);
oAddr.setString(6, sGuWorkArea);
oRSet = oAddr.executeQuery();
if (oRSet.next()) {
sGuContact = oRSet.getString(1);
if (oRSet.wasNull()) sGuContact = "null";
sGuCompany = oRSet.getString(2);
if (oRSet.wasNull()) sGuCompany = "null";
if (sGuCompany.equals("****************************USER")) {
sTxName = oRSet.getString(3);
if (oRSet.wasNull()) sTxName = "";
sTxSurname1 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname1 = "";
sTxSurname2 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname2 = "";
sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
}
else
sTxPersonal = "null";
pCC.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
} // fi (oRSet.next())
else
pCC.put(sTxEmail, "null,null,null");
oRSet.close();
} // next (c)
} // fi (oCC)
if (DebugFile.trace) DebugFile.writeln("cc count = " + pCC.size());
// Get BCC address and keep them into pTo properties
if (oBCC!=null) {
for (int b=0; b<oBCC.length; b++) {
oInetAdr = (InternetAddress) oBCC[b];
sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);
oAddr.setString(1, sTxEmail);
oAddr.setString(2, sGuWorkArea);
oAddr.setString(3, sTxEmail);
oAddr.setString(4, sTxEmail);
oAddr.setString(5, sTxEmail);
oAddr.setString(6, sGuWorkArea);
oRSet = oAddr.executeQuery();
if (oRSet.next()) {
sGuContact = oRSet.getString(1);
if (oRSet.wasNull()) sGuContact = "null";
sGuCompany = oRSet.getString(2);
if (oRSet.wasNull()) sGuCompany = "null";
if (sGuCompany.equals("****************************USER")) {
sTxName = oRSet.getString(3);
if (oRSet.wasNull()) sTxName = "";
sTxSurname1 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname1 = "";
sTxSurname2 = oRSet.getString(4);
if (oRSet.wasNull()) sTxSurname2 = "";
sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
}
else
sTxPersonal = "null";
pBCC.put(sTxEmail, sGuContact+","+sGuCompany);
} // fi (oRSet.next())
else
pBCC.put(sTxEmail, "null,null,null");
oRSet.close();
} // next (b)
} // fi (oCBB)
if (DebugFile.trace) DebugFile.writeln("bcc count = " + pBCC.size());
oAddr.close();
sSQL = "INSERT INTO " + DB.k_inet_addrs + " (gu_mimemsg,id_message,pg_message,tx_email,tp_recipient,gu_user,gu_contact,gu_company,tx_personal) VALUES ('"+sGuMimeMsg+"',?,"+String.valueOf(dPgMessage.intValue())+",?,?,?,?,?,?)";
if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
oStmt = oConn.prepareStatement(sSQL);
java.util.Enumeration oMailEnum;
String[] aRecipient;
if (!pFrom.isEmpty()) {
oMailEnum = pFrom.keys();
while (oMailEnum.hasMoreElements()) {
oStmt.setString(1, sMessageID);
sTxEmail = (String) oMailEnum.nextElement();
if (DebugFile.trace) DebugFile.writeln("processing mail address "+sTxEmail);
aRecipient = Gadgets.split(pFrom.getProperty(sTxEmail),',');
oStmt.setString(2, sTxEmail);
oStmt.setString(3, "from");
if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
oStmt.setNull(4, Types.CHAR);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else if (aRecipient[1].equals("****************************USER")) {
oStmt.setString(4, aRecipient[0]);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else {
oStmt.setNull(4, Types.CHAR);
oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
}
if (aRecipient[2].equals("null"))
oStmt.setNull(7, Types.VARCHAR);
else
oStmt.setString(7, aRecipient[2]);
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");
oStmt.executeUpdate();
} // wend
} // fi (from)
if (!pTo.isEmpty()) {
oMailEnum = pTo.keys();
while (oMailEnum.hasMoreElements()) {
oStmt.setString(1, sMessageID);
sTxEmail = (String) oMailEnum.nextElement();
aRecipient = Gadgets.split(pTo.getProperty(sTxEmail),',');
oStmt.setString(2, sTxEmail);
oStmt.setString(3, "to");
if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
oStmt.setNull(4, Types.CHAR);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else if (aRecipient[1].equals("****************************USER")) {
oStmt.setString(4, aRecipient[0]);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else {
oStmt.setNull(4, Types.CHAR);
oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
}
if (aRecipient[2].equals("null"))
oStmt.setNull(7, Types.VARCHAR);
else
oStmt.setString(7, aRecipient[2]);
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");
oStmt.executeUpdate();
} // wend
} // fi (to)
if (!pCC.isEmpty()) {
oMailEnum = pCC.keys();
while (oMailEnum.hasMoreElements()) {
oStmt.setString(1, sMessageID);
sTxEmail = (String) oMailEnum.nextElement();
aRecipient = Gadgets.split(pCC.getProperty(sTxEmail),',');
oStmt.setString(2, sTxEmail);
oStmt.setString(3, "cc");
if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
oStmt.setNull(4, Types.CHAR);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else if (aRecipient[1].equals("****************************USER")) {
oStmt.setString(4, aRecipient[0]);
oStmt.setString(5, null);
oStmt.setString(6, null);
}
else {
oStmt.setString(4, null);
oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
}
if (aRecipient[2].equals("null"))
oStmt.setNull(7, Types.VARCHAR);
else
oStmt.setString(7, aRecipient[2]);
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");
oStmt.executeUpdate();
} // wend
} // fi (cc)
if (!pBCC.isEmpty()) {
oMailEnum = pBCC.keys();
while (oMailEnum.hasMoreElements()) {
oStmt.setString(1, sMessageID);
sTxEmail = (String) oMailEnum.nextElement();
aRecipient = Gadgets.split(pBCC.getProperty(sTxEmail),',');
oStmt.setString(2, sTxEmail);
oStmt.setString(3, "bcc");
if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
oStmt.setNull(4, Types.CHAR);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else if (aRecipient[1].equals("****************************USER")) {
oStmt.setString(4, aRecipient[0]);
oStmt.setNull(5, Types.CHAR);
oStmt.setNull(6, Types.CHAR);
}
else {
oStmt.setNull(4, Types.CHAR);
oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
}
if (aRecipient[2].equals("null"))
oStmt.setNull(7, Types.VARCHAR);
else
oStmt.setString(7, aRecipient[2]);
oStmt.executeUpdate();
} // wend
} // fi (bcc)
oStmt.close();
oStmt=null;
oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iSize)+" WHERE "+DB.gu_category+"=?");
oStmt.setString(1, getCategory().getString(DB.gu_category));
oStmt.executeUpdate();
oStmt.close();
oStmt=null;
} catch (SQLException sqle) {
try { if (null!=oStmt) oStmt.close(); oStmt=null; } catch (Exception ignore) {}
try { if (null!=oAddr) oAddr.close(); oAddr=null; } catch (Exception ignore) {}
if (DebugFile.trace) DebugFile.decIdent();
throw new MessagingException(sqle.getMessage(), sqle);
}
if (DebugFile.trace) {
DebugFile.decIdent();
DebugFile.writeln("End DBFolder.indexMessage()");
}