IDEMPIERE-1822 RequestEmailProcessor is not compatible with gmail / peer review and text - add some additional fixes for problems found on test

This commit is contained in:
Carlos Ruiz 2014-04-20 17:31:43 -05:00
parent e36156fb61
commit 9cf721e1ad
1 changed files with 18 additions and 11 deletions

View File

@ -38,10 +38,10 @@ import javax.mail.Multipart;
import javax.mail.Part; import javax.mail.Part;
import javax.mail.Session; import javax.mail.Session;
import javax.mail.Store; import javax.mail.Store;
import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MAttachment; import org.compiere.model.MAttachment;
import org.compiere.model.MColumn;
import org.compiere.model.MRequest; import org.compiere.model.MRequest;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
@ -311,6 +311,8 @@ public class RequestEMailProcessor extends SvrProcess
Message[] deleted = inbox.expunge(); Message[] deleted = inbox.expunge();
noRequest++; noRequest++;
} else {
noError++;
} }
} catch (Exception e) { } catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info("message " + hdrs[0] + " threw error"); if (log.isLoggable(Level.INFO)) log.info("message " + hdrs[0] + " threw error");
@ -371,20 +373,27 @@ public class RequestEMailProcessor extends SvrProcess
} }
// Message-ID as documentNo // Message-ID as documentNo
String[] hdrs = msg.getHeader("Message-ID"); String[] hdrs = msg.getHeader("Message-ID");
// set DocumentNo
int maxlen = MColumn.get(getCtx(), MRequest.Table_Name, MRequest.COLUMNNAME_DocumentNo).getFieldLength();
String documentNo = hdrs[0];
if (documentNo.startsWith("<") && documentNo.endsWith(">"))
documentNo = documentNo.substring(1, documentNo.length()-1);
if (documentNo.length() > maxlen)
documentNo = documentNo.substring(0,30);
// Review if the e-mail was already created, comparing Message-ID+From+body // Review if the e-mail was already created, comparing Message-ID+From+body
int retValuedup = 0; int retValuedup = 0;
String sqldup = "select r_request_id from r_request " String sqldup = "SELECT R_Request_ID FROM R_Request "
+ "where ad_client_id = ? " + "WHERE AD_Client_ID = ? "
+ "and documentno = ? " + "AND DocumentNo = ? "
+ "and startdate = ?"; + "AND StartDate = ?";
PreparedStatement pstmtdup = null; PreparedStatement pstmtdup = null;
ResultSet rsdup = null; ResultSet rsdup = null;
try try
{ {
pstmtdup = DB.prepareStatement (sqldup, null); pstmtdup = DB.prepareStatement (sqldup, null);
pstmtdup.setInt(1, getAD_Client_ID()); pstmtdup.setInt(1, getAD_Client_ID());
pstmtdup.setString(2, hdrs[0].substring(0,30)); pstmtdup.setString(2, documentNo);
pstmtdup.setTimestamp(3, new Timestamp(msg.getSentDate().getTime())); pstmtdup.setTimestamp(3, new Timestamp(msg.getSentDate().getTime()));
rsdup = pstmtdup.executeQuery (); rsdup = pstmtdup.executeQuery ();
if (rsdup.next ()) if (rsdup.next ())
@ -463,8 +472,7 @@ public class RequestEMailProcessor extends SvrProcess
msgreq = new StringBuilder("FROM: ") .append(from[0].toString()).append("\n").append(getMessage(msg)); msgreq = new StringBuilder("FROM: ") .append(from[0].toString()).append("\n").append(getMessage(msg));
req.setResult(msgreq.toString()); req.setResult(msgreq.toString());
// Message-ID as documentNo // Message-ID as documentNo
if (hdrs != null) req.setDocumentNo(documentNo);
req.setDocumentNo(hdrs[0].substring(0,30));
// Default request type for this process // Default request type for this process
if (R_RequestType_ID > 0) if (R_RequestType_ID > 0)
@ -555,9 +563,8 @@ public class RequestEMailProcessor extends SvrProcess
String disposition = part.getDisposition(); String disposition = part.getDisposition();
if ((disposition != null) && if ( disposition != null
((disposition.equals(Part.ATTACHMENT) || && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
(disposition.equals(Part.INLINE))))) {
MAttachment attach = req.createAttachment(); MAttachment attach = req.createAttachment();