Logger.debug(this, "RETR: after:" +i);
boolean removeEmail = false;
Recipient r = new Recipient();
while (((s = in.readLine()) != null) && (!(s.equals(".")))) {
//t += s + "\n";
//get error message
if (s.startsWith("<<< ")) {
errorMessage = s.substring(4).trim();
}
//get recipient id
if (s.startsWith("X-RecipientId:")) {
java.util.StringTokenizer st = new java.util.StringTokenizer(s, ": ");
st.nextToken();
Logger.debug(this, "Found a X-Recipient ID=" + s);
try {
r = (Recipient) InodeFactory.getInode(st.nextToken(), Recipient.class);
} catch (Exception e) {
Logger.debug(this, "Recipient=" + r.getInode() + ", not found might be that the campaign was deleted.");
}
removeEmail = true;
Logger.debug(this, "Found recipient=" + r.getInode());
}
}
//if we have a recipient
if (InodeUtils.isSet(r.getInode())) {
r.setLastResult(500);
if(errorMessage == null){
r.setLastMessage("Email Bounced");
}
else {
r.setLastMessage(errorMessage);
}
HibernateUtil.saveOrUpdate(r);
Logger.debug(this, "Saved recipient with 500 last result" + r.getEmail());
User user = APILocator.getUserAPI().loadByUserByEmail(r.getEmail(), APILocator.getUserAPI().getSystemUser(), false);
UserProxy sub = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user,APILocator.getUserAPI().getSystemUser(), false);
Logger.debug(this, "Subscriber =" + sub.getInode());
if(InodeUtils.isSet(sub.getInode())){
Logger.debug(this, "errorMessage: " +errorMessage);
if(errorMessage == null){
sub.setLastMessage("Email Bounced");
}
else{
sub.setLastMessage(errorMessage.replaceAll("<","<").replaceAll(">", ">"));
}
sub.setLastResult(500);
HibernateUtil.saveOrUpdate(sub);
Campaign c = (Campaign) InodeFactory.getParentOfClass(r, Campaign.class);
if(c != null && InodeUtils.isSet(c.getInode())) {
MailingList ml = (MailingList) InodeFactory.getChildOfClass(c,MailingList.class);
if(ml != null && InodeUtils.isSet(ml.getInode()))
MailingListFactory.markAsBounceFromMailingList(ml, sub);
}
}
Logger.info(this, "Found a bounce for recipient: " + r.getInode());
}
if(removeEmail) {
Logger.debug(this, "Before deleting message");
send(out, "DELE " + i);