Copying email attachments to taxonomy

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.
Post Reply
mataratones
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Thu May 05, 2016 2:06 am

Copying email attachments to taxonomy

Post by mataratones » Thu May 05, 2016 2:13 am

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.

jllort
Moderator
Moderator
Posts: 10451
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Copying email attachments to taxonomy

Post by jllort » Sat May 07, 2016 6:47 am

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.

mataratones
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Thu May 05, 2016 2:06 am

Re: Copying email attachments to taxonomy

Post by mataratones » Sun May 08, 2016 1:47 am

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.

jllort
Moderator
Moderator
Posts: 10451
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Copying email attachments to taxonomy

Post by jllort » Wed May 11, 2016 6:02 pm

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.

ToCa13579
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Sun Mar 11, 2018 8:42 pm

Re: Copying email attachments to taxonomy

Post by ToCa13579 » Sun Mar 11, 2018 10:03 pm

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.

jllort
Moderator
Moderator
Posts: 10451
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Copying email attachments to taxonomy

Post by jllort » Thu Mar 15, 2018 7:44 pm

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.

ToCa13579
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Sun Mar 11, 2018 8:42 pm

Re: Copying email attachments to taxonomy

Post by ToCa13579 » Sun Mar 18, 2018 12:23 pm

Thank you!

I will try this as soon as possible!

sku
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: Sat Nov 17, 2018 6:25 pm

Re: Copying email attachments to taxonomy

Post by sku » Sat Nov 17, 2018 6:30 pm

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();
	}
}

jllort
Moderator
Moderator
Posts: 10451
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Copying email attachments to taxonomy

Post by jllort » Sun Nov 18, 2018 5:40 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests