OKMMail
Basics
Section titled “Basics”On almost methods you’ll see parameter named “mailId”. The value of this parameter can be some valid mail UUID or path.
About the parameter named “dstId”, the value of this parameter can be some valid folder UUID or path node.
About the parameter named “fldId”, the value of this parameter can be some valid folder UUID or path node.
Also on all methods you’ll see parameter named “token”. When accessing application across SOAP the login process returns a token, what is used to identify the user on all the exposed methods. From default application execution context you must use “null” value what indicates to the application must use the “user session”.
Methods
Section titled “Methods”create
Section titled “create”Description:
| Method | Return values | Description |
|---|---|---|
| create(String token, Mail mail) | Creates a new mail and returns as a result an object Mail. |
- The variable path into the parameter mail, must be initializated. It indicates the folder path into OpenKM.
- Other mandatory variables:
Example:
package com.openkm;
import java.util.Arrays;import java.util.Calendar;
import org.owasp.encoder.Encode;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { Mail mail = new Mail();
// Mail path = msgId + escaped(subject) String msgId = "2937b81d-0b10-4dd0-a426-9acbd80be1c9"; String subject = "some subject"; String mailPath = "/okm:root/"+ msgId + "-" + escape(subject); mail.setPath(mailPath);
// Other format for mail "some name <no_reply@openkm.com>" mail.setFrom("<no_reply@openkm.com>"); mail.setTo((String[])Arrays.asList("anonymous@gmail.com").toArray());
// You should set real dates mail.setSentDate(Calendar.getInstance()); mail.setReceivedDate(Calendar.getInstance()); mail.setContent("some content"); mail.setMimeType(Mail.MIME_TEXT); mail.setSubject(subject);
// Get only as an approximation of real size for these sample mail.setSize(mail.toString().getBytes("UTF-8").length); OKMMail.getInstance().create(null, mail); } catch (Exception e) { e.printStackTrace(); } }
private static String escape(String name) { String ret = cleanup(name);
// Fix XSS issues ret = Encode.forHtml(ret);
return ret; }
private static String cleanup(String name) { String ret = name.replace("/", ""); ret = ret.replace("*", ""); ret = ret.replaceAll("\\s+", " ").trim(); return ret; }}getProperties
Section titled “getProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getProperties(String token, String mailId) | Returns the mail properties. |
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { Mail mail = OKMMail.getInstance().getProperties(null, "064ff51a-b815-4f48-a096-b4946876784f"); System.out.println(mail); } catch (Exception e) { e.printStackTrace(); } }}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(String token, String mailId) | void | Delete a mail. |
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { OKMMail.getInstance().delete(null, "064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| purge(String token, String mailId) | void | The mail is definitely removed from the repository. |
- Usually you will purge mails into /okm:trash/userId - the personal trash user locations - but it is possible to directly purge any mail from the whole repository.
Example:
package com.openkm;
import com.openkm.api.OKMMail;
public class Test { public static void main(String[] args) { try { OKMMail.getInstance().purge(null, "064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } }}rename
Section titled “rename”Description:
| Method | Return values | Description |
|---|---|---|
| rename(String token, String mailId, String newName) | Rename a mail. |
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { OKMMail.getInstance().rename(null, "064ff51a-b815-4f48-a096-b4946876784f", "newname"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| move(String token, String mailId, String dstId) | void | Moves mail into some folder. |
- The values of the dstId parameter should be a folder UUID or path.
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { OKMMail.getInstance().move(null, "064ff51a-b815-4f48-a096-b4946876784f", "/okm:root/move/destination"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String mailId, String dstId) | void | Copies a mail into a folder. |
- The values of the dstId parameter should be a folder UUID or path.
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { OKMMail.getInstance().copy(null, "064ff51a-b815-4f48-a096-b4946876784f", "/okm:root/move/destination"); } catch (Exception e) { e.printStackTrace(); } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String token, String mailId, String dstId, ExtendedAttributes extAttr) | void | Copies a mail with the associated data into some folder. |
- The values of the dstId parameter should be a folder UUID or path.
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.ExtendedAttributes;
public class Test { public static void main(String[] args) { try { ExtendedAttributes extAttr = new ExtendedAttributes(); extAttr.setKeywords(true); OKMMail.getInstance().extendedCopy(null, "064ff51a-b815-4f48-a096-b4946876784f","/okm:root/test", extAttr);
} catch (Exception e) { e.printStackTrace(); } }}getChilds
Section titled “getChilds”Description:
| Method | Return values | Description |
|---|---|---|
| getChilds(String token, String fldId) | List |
Returns a list of all mails which their parent is mailId. |
- The parameter mailId can be a folder node.
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { for (Mail mail : OKMMail.getInstance().getChilds(null, "/okm:root/test")) { System.out.println(mail); } } catch (Exception e) { e.printStackTrace(); } }}getChildren
Section titled “getChildren”Description:
| Method | Return values | Description |
|---|---|---|
| getChildren(String token, String fldId) | List |
Returns a list of all mails which their parent is mailId. |
- The parameter mailId can be a folder node.
Example:
package com.openkm;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { for (Mail mail : OKMMail.getInstance().getChildren(null, "/okm:root/test")) { System.out.println(mail); } } catch (Exception e) { e.printStackTrace(); } }}isValid
Section titled “isValid”Description:
| Method | Return values | Description |
|---|---|---|
| isValid(String token, String mailId) | boolean | Returns a boolean that indicates if the node is a mail or not. |
Example:
package com.openkm;
import com.openkm.api.OKMMail;
public class Test { public static void main(String[] args) { try { boolean valid = OKMMail.getInstance().isValid(null, "064ff51a-b815-4f48-a096-b4946876784f"); System.out.println(valid); } catch (Exception e) { e.printStackTrace(); } }}getPath
Section titled “getPath”Description:
| Method | Return values | Description |
|---|---|---|
| getPath(String token, String uuid) | String | Convert folder UUID to mail path. |
Example:
package com.openkm;
import com.openkm.api.OKMMail;
public class Test { public static void main(String[] args) { try { String path = OKMMail.getInstance().getPath(null, "064ff51a-b815-4f48-a096-b4946876784f"); System.out.println(path); } catch (Exception e) { e.printStackTrace(); } }}importEml
Section titled “importEml”Description:
| Method | Return values | Description |
|---|---|---|
| importEml(String path, InputStream is) | Import a mail in EML format. |
- The values of the path parameter should be a folder path. The path parameter indicate where the mail will be stored in the repository after is imported.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/files/test.eml"); Mail mail = OKMMail.getInstance().importEml("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", is); System.out.println(mail); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}importMsg
Section titled “importMsg”Description:
| Method | Return values | Description |
|---|---|---|
| importMsg(String path, InputStream is) | Import a mail in MSG format. |
- The values of the path parameter should be a folder path. The path parameter indicate where the mail will be stored in the repository after is imported.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMMail;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/files/test.msg"); Mail mail = OKMMail.getInstance().importMsg("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", is); System.out.println(mail); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}