Class MailFunctions

java.lang.Object
com.groiss.mail.MailFunctions

public class MailFunctions extends Object
Utility class containing methods which are helpful for using the mail functionality in @enterprise.
  • Constructor Details

    • MailFunctions

      public MailFunctions()
  • Method Details

    • isDefaultMailAction

      public static boolean isDefaultMailAction(String actionId)
      Checks, if given actionId in String format is a default action (see MailFunctions.DefaultMailFunction).
      Parameters:
      actionId - the id of the mail function that is executed in following format:
      <xml-id>.<node-id> (e.g. in case of default action "compose" the id is "admin.composeSC"))
      Returns:
      true, if action is a default action, otherwise false
    • getEmailsFolder

      public static DMSFolder getEmailsFolder(ProcessInstance pi, boolean createFolder)
      returns the folder "Emails" of given process instance
      Parameters:
      pi - the process instance which should contain folder "Emails"
      createFolder - if true, email folder is created automatically
      Returns:
      the folder, or null, if no folder could be found (or created)
    • getEmailsFolder

      public static DMSFolder getEmailsFolder(DMSFolder folder, boolean createFolder)
      returns the folder "Emails" of given DMSFolder
      Parameters:
      folder - the DMS folder which should contain folder "Emails"
      createFolder - if true, email folder is created automatically
      Returns:
      the folder, or null, if no folder could be found (or created)
    • outgoingMailSubject

      public static String outgoingMailSubject(ProcessInstance pi, String subject)
      Returns the subject of given process instance as defined with configuration parameter "ep.mail.subjpattern".
      Parameters:
      pi - the process instance for getting pid
      subject - the mail subject
      Returns:
      the subject in format <subject> (<ep.mail.subjpattern> + <pid>) or if "ep.mail.subjpattern" is not defined, the given <subject>. In no <subject> is given, the toString of pi.
    • getSubject

      public static String getSubject(String actionId, ProcessInstance pi, Message msg) throws Exception
      Get the subject depending on the given default action and message.
      Parameters:
      actionId - the id of the mail function that is executed which must be a MailFunctions.DefaultMailFunction in following format:
      <xml-id>.<node-id> (e.g. in case of default action "compose" the id is "admin.composeSC"))
      pi - the ProcessInstance for determining the subject; can be null
      msg - the referenced Message object; can be null
      Returns:
      the subject depending on the given action or null, if no subject could be determined. Returned subject depending on action:
      • compose: Text returned by outgoingMailSubject(ProcessInstance, String)
      • reply and replyall: Text "Re: <subj_of_msg_and_mail_subject_pattern>"
      • forward: Text "Fwd: <subj_of_msg_and_mail_subject_pattern>"
      • editdraft: Text "<subj_of_msg>"
      Throws:
      Exception
    • getRecipients

      public static Map<Message.RecipientType,String> getRecipients(String actionId, DMSDocForm email, Message msg) throws Exception
      Get the recipients depending on the given default actions.
      Parameters:
      actionId - the id of the mail function that is executed which must be a MailFunctions.DefaultMailFunction in following format:
      <xml-id>.<node-id> (e.g. in case of default action "compose" the id is "admin.composeSC"))
      email - the email object stored in @enterprise as DMSDocForm
      msg - the referenced Message object
      Returns:
      a HashMap containing the Message.RecipientType as key and the appropriate recipient email addresses as string value. Returned recipients depending on action:
      Throws:
      Exception
    • getMailText

      public static Pair<String,String> getMailText(String actionId, Message msg) throws Exception
      Returns the default mail text of given message in text/plain and text/html format
      Parameters:
      actionId - the id of the mail function that is executed which must be a MailFunctions.DefaultMailFunction in following format:
      <xml-id>.<node-id> (e.g. in case of default action "compose" the id is "admin.composeSC"))
      msg - the Message object that is used for extraction of mail text (body)
      Returns:
      a Pair containing the mail text as text/plain (key) and text/html (value)
      Throws:
      Exception
    • getReplyRecipient

      public static String getReplyRecipient(DMSDocForm email)
      Returns the appropriate recipient. If a reply should be performed on a mail which has been written by myself (new sender = old sender) the recipient of reply mail is taken as recipient.
      Parameters:
      email - the mail object where reply should be performed
      Returns:
      the appropriate recipient
    • getAttachmentParts

      public static List<Part> getAttachmentParts(List<DMSObject> dmsAttachments, List<Pair<String,File>> files) throws Exception

      Returns an ArrayList of Part objects. These objects represent the attachments (DMS and File attachments that are passed as parameters.

      Note that DMS attachments which are not of type DocForm are omitted.

      Parameters:
      dmsAttachments - a list of DMSObject instances.
      files - a list of Pair objects (first is the filename (java.lang.String), second is the file itself (java.io.File)).
      Returns:
      list of Part objects, that represent the attachments.
      Throws:
      Exception
    • hasMails

      public static boolean hasMails(ProcessInstance pi)
      Method to check, if mails exist in "Emails" folder of the process instance.
      Parameters:
      pi - the ProcessInstance to check, if "Emails" folder contains mails
      Returns:
      true, if mails are available and the current user has the permissions to see them; otherwise false
    • hasMails

      public static boolean hasMails(DMSFolder emailFldr)
      Method to check, if mails exist in the given folder.
      Parameters:
      emailFldr - the DMSFolder where mails are stored
      Returns:
      true, if mails are available and the current user has the permissions to see them (Right.VIEW); otherwise false
    • hasMailQueueEntry

      public static boolean hasMailQueueEntry(Persistent refObj)
      Checks, if a mailqueue item exists for the referenced object
      Parameters:
      refObj - the referenced object
      Returns:
      true, if mailqueue item could be found; otherwise false
    • toJSON

      public static JSONObject toJSON(DMSDocForm emailObj) throws Exception
      Returns the following JSON structure of given email object:
                       {"_toString":"<the_toString_of_emailObj>",
                         "objectId":"<classname_of_emailObj>:<oid>",
                         "mailstatus":"mailqueued|draftmail|mailrec|mailsent",
                         "subj":"<the_subj_of_emailObj>", ====> only, if field 'subj' in emailObj is given; otherwise the text '<No subject>'
                         "sender":"<the_sender_emailAddr_of_emailObj>", ====> only, if field 'sender' in emailObj is given
                         "recipient":"<the_recipient_emailAddr_of_emailObj>", ====> only, if field 'recipient' in emailObj is given
                         "maildate":<sent_date_of_msg_in_ms>,
                         "avwcreatedat":<creation_date_of_emailObj_in_ms>,
                         "replytoid":"<reply_to_oid_of_msg>",
                         "hasAttachments":true|false
                        }
       
      Parameters:
      emailObj - the email object for that a JSON representation is needed
      Returns:
      the JSONObject
      Throws:
      Exception
    • hasRightForMailList

      public static boolean hasRightForMailList(List<DMSObject> mails)
      Method to check, if the current user has the Right.VIEW for given mail list.
      Parameters:
      mails - a list of mails represented as DMSObject
      Returns:
      true if the current user has the permissions to see them; otherwise false
    • showMailPane

      public Page showMailPane(HttpServletRequest req)
      Returns a page holding the mail pane of the passed object. In case of a DMSFolder the subfolder with name "Emails" is used in MailPane as context object. In case of a ProcessInstance the process instance itself is used in MailPane as context object.
      Parameters:
      req - the request which must contain following elements:
      • object: Either a DMSFolder or a ProcessInstance in following format: <classname>:<oid>
      • mailpane: An own defined MailPane widget. If this parameter is empty, the default "ep/widget/smartclient/wl/MailPane" is used
      • mailhandler: An own defined com.groiss.smartclient.mail.MailActionsHandler class. If this parameter is empty, no mail handler is used
      Returns:
      a Page containing the MailPane
    • showMailPane

      public static Page showMailPane(Persistent object, String mailPane, String mailHandlerClass)
      Returns a page holding the mail pane of the passed object. In case of a DMSFolder a new created sub-folder with name "Emails" is used in MailPane as context object. In case of a ProcessInstance the process instance itself is used in MailPane as context object.
      Parameters:
      object - a DMSFolder or ProcessInstance
      mailPane - an own defined MailPane widget; if this parameter is empty, the default "ep/widget/smartclient/wl/MailPane" is used
      mailHandlerClass - an own defined com.groiss.smartclient.mail.MailActionsHandler class; if this parameter is empty, no mail handler is used
      Returns:
      a Page containing the MailPane