Hi!
I've finished the Beanshell script (some time ago) - but have one question left.
First, here is the script:
Code: Select allimport javax.jcr.*;
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.*;
String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
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/Docs") ) {
//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();
//Path to the right TaxDirectory and Document name
if(Keyword.equals("pro")){
DirectoryPath = "/Calculations/";
DocumentName = "Prodega";
}
else if(Keyword.equals("oth")){
DirectoryPath = "/Others/";
DocumentName = "Prodega";
}
//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();
}
}
How does it works?
Here is an example...
Let's say you have following environment:
Taxonomy:
- Manuals
- Calculations
- Others
Mail:
- Docs (Which checks the given mail-inbox every 5 minutes an import the mails).
Now, the script automatically checks the subject of the mails for keywords, move the attachments in the right taxonomy-folder and rename it (with date if necessary).
The Keywords are set in the script.
All you need to do is scan in the document with the right keyword. After, it will be imported to the Docs-mailfolder. Then, the script checks the subject with the keyword and move the attachment in the right folder incl. renaming the file.
Input - without date:
(Mail with .pdf-attachment)
<to>
openkm@domain.ch</to>
<subject>pro</subject>
Result:
PDF Document in Calculations --> Prodega 20120319 (Date today).
Input - with date:
(Mail with .pdf-attachment)
<to>
openkm@domain.ch</to>
<subject>pro 20120101</subject>
Result:
PDF Document in Calculations --> Prodega 20120101.
I hope my explanation is clearly. Else, feel free to ask
My problem is the cronjob.
When I start the script manually (with the execute-button), everything works fine.
But when the script starts from the cronjob, there is a error-message:
Sourced file: inline evaluation of: ``import javax.jcr.*; import java.lang.String; import java.text.DateFormat; import . . . '' : Typed variable declaration : target exception : at Line: 34 : in file: inline evaluation of: ``import javax.jcr.*; import java.lang.String; import java.text.DateFormat; import . . . '' : .getProperties ( null , mail .getPath ( ) ) Target exception: com.openkm.core.RepositoryException: CallbackHandler does not support: javax.security.auth.callback.NameCallback@1e311e31: CallbackHandler does not support: javax.security.auth.callback.NameCallback@1e311e31
Can anyone give me a hint how to handle this problem? Is there a problem with the security?
Thank for the support!
Kind regards!