• Copying email attachments to taxonomy

  • 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.
 #41740  by mataratones
 
Thanks for this great product, now that preview is working smoothly (6.3.1) I really enjoy it.

I can get my emails into OpenKM, what I would like to know is if there is a way to copy just an attachment -- not the email itself -- into another folder (in the taxonomy, in particular). I found some advice about how to automate the moving of attachments, which would be even better, but I don't have time to figure out the code right now; I just want to know how to do it manually. The wiki (http://wiki.openkm.com/index.php/E-mail) implies that it is possible by right-clicking, but I am unable to get a menu when right-clicking on an attachment.
 #41750  by jllort
 
This feature is not implemented. You are talking about when a mail is created, extract documents into and remove the mail. It can be done, but you should create an Automation action for it. If you want I can guide for it.
 #41757  by mataratones
 
I mean like a filter. When an email is imported/downloaded via IMAP, copy the attachment to another OpenKM folder.

It would be great if you could guide me through it.
 #41769  by jllort
 
From account configuration you can specify the mail location ( body + attachments ), but you can not disaggregate from that view. You should create automation event based on mail creation and then, copy attachments to parent and finally remove the mail.

I suggest download our OpenKM portable environment where you can see some automation sample https://sourceforge.net/projects/openkmportabledev/

About API you should consider take a look at OKMMail and OKMDocument ( https://docs.openkm.com/apidoc/com/okm/6.3.1/ ).
At OKMDocument the methods getChilds(String token, String fldId), where fldId is the mail UUID and move(String token, String docPath, String destPath)
At OKMMail the method purge(null, mailPath);

Take your time, step by step to success on it. The logic should be:
- Automation event call your action
- With mail uuid ( which comes into the event ) you list all documents into
- Move each document to new location ( you must get the parent of the mail or another location, if you need help on it tell to us ).
- Finally purge the mail.
 #45432  by ToCa13579
 
I know this thread is from 2016, but I am new to OpenKM and scripting.

I am trying to accomplish the same task here as the previous poster. I tried downloading the development package and extracting it on Windows and it keeps giving me an error that a path is to long and will not extract correctly.

Am I doing something wrong? Any help would be greatly appreciated.
 #45450  by jllort
 
Try downloading our new development environment https://s3-eu-west-1.amazonaws.com/open ... PorDev.ova ( it's a complete VM what comes with everything you need ). In few days we will officially publish on the website by now has only announced from our newsletter. We will share a video showing the process.
 #47052  by sku
 
Hi everybody,

I'm using openkm since ver. 5.1 . I think it's a great tool .
I migrated to v. 6.3.3 and I need to extract attachement from email and put them in a specific folder.
I tried to use script advertised on forum however, it doesn't work .
I receive this error : "bsh.ParseException: Parse error at line 29, column 1. Encountered: Node" .
I tried several things, including downloading dev. environement, however seems nothing will solve my problem .
Can somebody help ? I post also the code here :
Code: Select all
import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.module.jcr.stuff.JcrSessionManager;
import javax.jcr.*;
import javax.jcr.Node;
import java.lang.String;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.*;
import com.openkm.module.direct.*;
import com.openkm.api.*;
import java.io.*;
import com.openkm.api.OKMDocument;
import com.openkm.api.OKMRepository;
import com.openkm.dao.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;
import com.openkm.dao.bean.NodeDocumentVersion;
import javax.jcr.Node;
import javax.jcr.NodeIterator;

String token = DbSessionManager.getInstance().getSystemToken();
DbSessionManager session = new DbSessionManager()
//Session session = HibernateUtil.getSessionFactory().openSession();
 
Node okmmail = session.getRootNode().getNode(Repository.MAIL);
Node okmroot = session.getRootNode().getNode(Repository.ROOT);

String DirectoryPath;
String DocumentName;
String DocumentDate;
Boolean DateOk;
DateFormat dateFormat;
Date date;
Boolean done = false;

for (NodeIterator it = okmmail.getNodes(); it.hasNext(); ) {
    Node userMailFolder = it.nextNode();
	
	if(userMailFolder.getPath().equals("/okm:mail/fmdg") ) {
		
		//Check the mails in the doc Folder
		for (NodeIterator itut = userMailFolder.getNodes(); itut.hasNext(); ) {
		//aktuelles Mail aufbereiten
        	Node mail = itut.nextNode();
		Mail actMail = OKMMail.getInstance().getProperties(null, mail.getPath());
		List attach = actMail.getAttachments();
		
		//get the subject from the mail
		String mailSubject = actMail.getSubject();

		//get the keyword from the subject
		String Keyword = mailSubject.replaceAll(" ", "");
		Keyword = Keyword.replaceAll("[0-9-,.]", ""); 
		Keyword = Keyword.toLowerCase();

		DirectoryPath = "/MAIL/MAIL-ATTACHEMETS/";
		DocumentName = "EMAIL";		
		//check if date is typed in. Else date is today
		if(mailSubject.matches(".*[0-9-].*")){
			DateOk = true;	
			//create string just with the date
			DocumentDate = mailSubject.replaceAll(" ", "");
			DocumentDate = DocumentDate.replaceAll("[aA-zZ,+-]", "");
			DocumentName = DocumentName + " " + DocumentDate;
		}else{
			DateOk = false;
			//get ready for date today
			dateFormat = new SimpleDateFormat("yyyyMMdd");
			date = new Date();
		}	
			//Move the attachments to the right TaxDirectory and rename it
			for(Document:attach){
					new DirectDocumentModule().copy(token, Document.getPath(), okmroot.getPath() + DirectoryPath);
					if(DateOk == true){
						new DirectDocumentModule().rename(token, okmroot.getPath() + DirectoryPath + "Untitled .pdf", DocumentName);
						done = true;
					}else{
						new DirectDocumentModule().rename(token, okmroot.getPath() + DirectoryPath + "Untitled .pdf", DocumentName +" "+ dateFormat.format(date));
						done = true;
					}
				}
			//Delete mail, if attachment movement is successful.
			if(done == true){
				new DirectDocumentModule().delete(token, actMail.getPath());
				print("Verschieben nach " + DirectoryPath +" erfolgreich. Mail wurde gelöscht");
			}
			session.save();
		}		
	userMailFolder.save();
	}
}
 #47055  by jllort
 
From version 6.x we are not using JCR than mean everything in your code what makes reference to JCR is wrong.

I suggest:
1- Create a class into development environment to check compilation
2- If you are using into Automation I suggest create a plugin -> https://docs.openkm.com/kcenter/view/ok ... ction.html ( the plugin architecture works with the latest community version, I suggest upgrade until the last version ). An advantage of using java class in Automation is that you will be able to debug the process in your development environment.
 #47735  by greg.waw
 
I am using community version 6.3.7
I tried to follow instructions above and I can't get attachments from mail in automation triggered by Mail creation.
I wrote my own Action and I used it in Automation which is triggered by mail creation event. I am able to get all mail attributes but when I try to call getChildren I always get empty list. When second automation was defined with trigger of "Document create" event I noticed that this automation is called for attached document later than the first one for Mail creation. So I suspect that when "Mail creation" event is triggered there is no children (attachments) in repository yet.

I also tried to list all mails in parent directory and later lists of their attachments (children of mail nodes) and all old mails had attachments but new mail was empty.

I can conclude that it is not possible to copy/move attachments in Automation triggered by Mail creation event. Am I right?
 #47747  by jllort
 
Mail is not created in a single step, first is created the Mail object and later the documents into. When you watch the Mail creation still documents are not into. You should watch for document creation either email creation and then check if the parent of the document is an Email, that should be the right way to intercept attachments creation.

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.