• 6.3.0: Mail export fails whith "illegal address" error

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #43565  by MKochS
 
Mail export fails as soon as the export process hits a mail with unexpected characters in the address line. I have the following in catalina.log:
Code: Select all
2017-04-05 11:50:36,064 [http-bio-127.0.0.1-8080-exec-85] ERROR com.openkm.util.impexp.RepositoryExporter- Illegal address
javax.mail.internet.AddressException: Illegal address in string ``Doe, John <john.doe@invalid>''
As a result, the whole export process stops and nothing is exported at all.

I'm getting this several times. What all mails in question seem to have in common is the comma between last and first name. Is there a workaround?

TIA
Mattias
 #50568  by yiannis22
 
I have the same problem now.
I'd like to move the system to a new machine and within this step changing from HSQLDB to MySQL.
On the old machine I did all the migrations till version 6.3.6
If I do the repository export now, I am getting lots of "illegal address" errors.
Is there any way to correct them automatically ?
Or..in case...how do I correct them manually in the old system ?

rgds

Thomas
 #50585  by jllort
 
The next script should help in detecting problematic emails:
Code: Select all
import 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() + "&lt;br&gt;");
        }
    }
 
    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 all
import 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() + "&lt;br&gt;");
            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);
}

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.