Mail samples

Basics

On almost methods you'll see parameter named "mailId". The value of this parameter can be a valid mail UUID or path.

Example of fldId:

  • Using UUID -> "064ff51a-b815-4f48-a096-b4946876784f";
  • Using path -> "/okm:root/2937b81d-0b10-4dd0-a426-9acbd80be1c9-some subject"

Methods

createMail

Description:

MethodReturn valuesDescription

createMail(Mail mail)

Mail

Creates a new mail and returns as a result an object Mail.

The variable path into the parameter mail must be initialized. It indicates the folder path into OpenKM.

Other mandatory variables:

  • size ( mail size in bytes ).
  • from ( mail from account ).
  • reply, to, cc, bcc ( mail accounts are optional ).
  • sendDate ( date when mail was sent ).
  • receivedDate ( date when was received ).
  • subject ( mail subject ).
  • content ( the mail content ).
  • mimeType ( HTML or text mime type ).
  • headers ( the mail headers are optional).
  • raw ( the mail raw are optional).
  • origin ( msg, eml, api, pop3, imap origin )
  • title ( mail title )

Mai accounts allowed formats:

  • "\"John King\" <jking@mail.com>"
  • "<jking@mail.com>"

Mail path allowed is:

MSGID + "-" + sanitized(subject).

MIME types values:

  • Mail.MIME_TEXT for text mail format.
  • Mail.MIME_HTML for html mail format.

The other variables of Mail ( mail ) will not take any effect on mail creation.

Example:

package com.openkm;

import java.util.Arrays;
import java.util.Calendar;

import org.owasp.encoder.Encode;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         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); ws.createMail(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;     } }

getMailProperties

Description:

MethodReturn valuesDescription

getMailProperties(String mailId)

Mail

Returns the mail properties.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { System.out.println(ws.getMailProperties("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } } }

deleteMail

Description:

MethodReturn valuesDescription

deleteMail(String mailId)

void

Deletes a mail.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.deleteMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

purgeMail

Description:

MethodReturn valuesDescription

purgeMail(String mailId)

void

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.

When a mail is purged it will only be able to be restored from a previously repository backup. The purge action removes the mail definitely from the repository.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.purgeMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

renameMail

Description:

MethodReturn valuesDescription

renameMail(String mailId, String newName)

void

Rename a mail.

From OpenKM frontend UI the subject is used to show the mail name at file browser table. That means this change will take effect internally on mail path, but will not be appreciated from default UI.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.renameMail("064ff51a-b815-4f48-a096-b4946876784f","new name"); } catch (Exception e) { e.printStackTrace(); } } }

moveMail

Description:

MethodReturn valuesDescription

moveMail(String mailId, String dstId)

void

Move mail into a folder.

The values of the dstId parameter should be a folder UUID or path.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.moveMail("064ff51a-b815-4f48-a096-b4946876784f","/okm:root/tmp"); } catch (Exception e) { e.printStackTrace(); } } }

copyMail

Description:

MethodReturn valuesDescription

public void copyMail(String mailId, String dstId, String newName)

void

Copies mail into a folder.

The values of the dstId parameter should be a folder UUID or path.

When parameter newName value is null, mail will preserve the same name.

Only the security grants are copied to the destination, the metadata, keywords, etc. of the folder are not copied.

See "extendedMailCopy" method for this feature.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.copyMail("064ff51a-b815-4f48-a096-b4946876784f","/okm:root/temp","new_name"); } catch (Exception e) { e.printStackTrace(); } } }

extendedMailCopy

Description:

MethodReturn valuesDescription

extendedMailCopy(String mailId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki)

void

Copy mail width with associated data into a folder.

The values of the dstId parameter should be a folder UUID or path.

By default, only the binary data and the security grants, the metadata, keywords, etc. of the folder are not copied.

Additional:

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original values of the notes will be copied.
  • When wiki parameter is true the original values of the wiki will be copied.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.extendedMailCopy("064ff51a-b815-4f48-a096-b4946876784f", "/okm:root/tmp", true, true, true, true, true); } catch (Exception e) { e.printStackTrace(); } } }

getMailChildren

Description:

MethodReturn valuesDescription

 getMailChildren(String fldId)

List<Mail>

Returns a list of all mails which their parent is fldId.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username =  "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (Mail mail : ws.getMailChildren("/okm:root")) {                 System.out.println(mail);             } } catch (Exception e) { e.printStackTrace(); } } }

isValidMail

Description:

MethodReturn valuesDescription

isValidMail(String mailId)

Boolean

Returns a boolean that indicates if the node is a mail or not.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { // Return false ws.isValidMail("/okm:root/logo.png");
             // Return true ws.isValidMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

getMailPath

Description:

MethodReturn valuesDescription

getMailPath(String uuid)

String

Converts mail UUID to mail path.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { System.out.println(ws.getMailPath("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } } }

importEml

Description:

MethodReturn valuesDescription

importEml(String dstId, InputStream is)

Mail

Import a mail in EML format.

The values of the dstId parameter should be a folder or record UUID or path. The dstId parameter indicates where the mail will be stored in the repository after is imported.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.InputStream;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);

        try {
            InputStream is = new FileInputStream("/home/files/test.eml");
            Mail mail = ws.importEml("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

importMsg

Description:

MethodReturn valuesDescription

importMsg(String dstId, InputStream is)

Mail

Import a mail in MSG format.

The values of the dstId parameter should be a folder or record UUID or path. The dstId parameter indicate where the mail will be stored in the repository after is sent.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);

        try {
            InputStream is = new FileInputStream("/home/files/test.msg");
            Mail mail = ws.importMsg("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}