email= ((InternetAddress)messages[i].getFrom()[0]).getAddress();
name= ((InternetAddress)messages[i].getFrom()[0]).getPersonal();
subject= messages[i].getSubject();
content= messages[i].getContent().toString();
DinboxEvent entry = new DinboxEvent();
Criteria criteria = new Criteria();
criteria.add(DistributorPeer.EMAIL, (Object)email, Criteria.EQUAL);
if (DistributorPeer.doSelect(criteria).size()>0){
Distributor myDistrib = (Distributor) DistributorPeer.doSelect(criteria).get(0);
entry.setDistributorId(myDistrib.getDistributorId());
}else{
if (name!=null){
entry.setBody("From: " + name + " " + email + "\n\n" + content);
}else{
entry.setBody("From: " + email + "\n\n" + content);
}
}
entry.setDinboxEventCode(getTempCode());
entry.setEventType(10);
entry.setEventChannel(10);
entry.setSubject(subject);
entry.setIssuedDate(new Date());
entry.setCreatedBy("scheduler");
entry.setCreated(new Date());
entry.setModifiedBy("scheduler");
entry.setModified(new Date());
Connection conn = Transaction.begin(DinboxEventPeer.DATABASE_NAME);
boolean success = false;
try {
entry.save(conn);
entry.setDinboxEventCode(getRowCode("IE", entry.getDinboxEventId()));
entry.save(conn);
Transaction.commit(conn);
success = true;
} finally {
if (!success) Transaction.safeRollback(conn);