OKMMail

Basics

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

Example of mailId:

  • Using UUID -> "c52f9ea0-0d6c-45da-bae4-d72b66f42da3";
  • Using path -> "/okm:root/2937b81d-0b10-4dd0-a426-9acbd80be1c9-some subject"

About the parameter named "dstId", the value of this parameter can be some valid folder UUID or path node.

Example of dstId:

  • Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
  • Using path -> "/okm:root/folder2"

About the parameter named "fldId",  the value of this parameter can be some valid folder UUID or path node.

Example of fldId:

  • Using UUID -> "c52f9ea0-0d6c-45da-bae4-d72b66f42da3";
  • Using path -> "/okm:root/test"

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".

On special cases you might be "promoted as Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

create

Description:

MethodReturn valuesDescription

create(String token, Mail 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:

  • 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 ).

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.

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

Description:

MethodReturn valuesDescription

getProperties(String token, String mailId)

Mail

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

Description:

MethodReturn valuesDescription

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

purge

Description:

MethodReturn valuesDescription

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.

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.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

Description:

MethodReturn valuesDescription

rename(String token, String mailId, String newName)

Mail

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

move

Description:

MethodReturn valuesDescription

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

copy

Description:

MethodReturn valuesDescription

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.

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

See "extendedCopy" method for this feature.

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

Description:

MethodReturn valuesDescription

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.

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

Additional extended attributes parameters:

  • 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 the wiki parameter is true the original values of the wiki will be copied.

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

Description:

MethodReturn valuesDescription

getChilds(String token, String fldId)

List<Mail>

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

The parameter mailId can be a folder node.

This method is deprecated in favour of getChildren method. We encourage do not using it, because on nearly future will be removed.

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

Description:

MethodReturn valuesDescription

getChildren(String token, String fldId)

List<Mail>

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

Description:

MethodReturn valuesDescription

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

Description:

MethodReturn valuesDescription

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

Description:

MethodReturn valuesDescription

importEml(String path, InputStream is)

Mail

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

Description:

MethodReturn valuesDescription

importMsg(String path, InputStream is)

Mail

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