The next script should help in detecting problematic emails:
Code: Select allimport com.openkm.core.DatabaseException;
import com.openkm.dao.bean.NodeMail;
import com.openkm.dao.HibernateUtil;
import javax.mail.internet.*;
import org.hibernate.*;
import java.util.*;
String qs = "from NodeMail nm";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Query q = session.createQuery(qs);
for (NodeMail nm : q.list()) {
try {
new InternetAddress(nm.getFrom());
for (String address : nm.getTo()) {
new InternetAddress(address);
}
for (String address : nm.getReply()) {
new InternetAddress(address);
}
for (String address : nm.getCc()) {
new InternetAddress(address);
}
for (String address : nm.getBcc()) {
new InternetAddress(address);
}
} catch (AddressException e) {
print("Error con : " + nm.getUuid() + "<br>");
}
}
HibernateUtil.commit(session.getTransaction());
} catch (HibernateException e) {
HibernateUtil.rollback(session.getTransaction());
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
you can try to solve with this script ( what removes a comma beween the name and the email "Name, <email>" , this is the most common issue, if not should investigate in deep a single email data to indentify the problema and then build a script to apply the correction )
Code: Select allimport com.openkm.core.DatabaseException;
import com.openkm.dao.bean.NodeMail;
import com.openkm.dao.HibernateUtil;
import javax.mail.internet.*;
import org.hibernate.*;
import java.util.*;
String qs = "from NodeMail nm";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Query q = session.createQuery(qs);
for (NodeMail nm : q.list()) {
try {
new InternetAddress(nm.getFrom());
for (String address : nm.getTo()) {
new InternetAddress(address);
}
for (String address : nm.getReply()) {
new InternetAddress(address);
}
for (String address : nm.getCc()) {
new InternetAddress(address);
}
for (String address : nm.getBcc()) {
new InternetAddress(address);
}
} catch (AddressException e) {
print("Error con : " + nm.getUuid() + "<br>");
nm.from = nm.from.replaceAll(",", "").trim();
// to
Set to = new HashSet();
for (String address : nm.getTo()) {
to.add(address.replaceAll(",", "").trim());
}
nm.to = to;
// reply
Set reply = new HashSet();
for (String address : nm.getReply()) {
reply.add(address.replaceAll(",", "").trim());
}
nm.reply = reply;
// Cc
Set cc = new HashSet();
for (String address : nm.getCc()) {
cc.add(address.replaceAll(",", "").trim());
}
nm.cc = cc;
// Bcc
Set bcc = new HashSet();
for (String address : nm.getBcc()) {
bcc.add(address.replaceAll(",", "").trim());
}
nm.bcc = bcc;
session.update(nm);
}
}
HibernateUtil.commit(session.getTransaction());
} catch (HibernateException e) {
HibernateUtil.rollback(session.getTransaction());
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}