Package com.groiss.mail
Class MailFunctions
java.lang.Object
com.groiss.mail.MailFunctions
Utility class containing methods which are helpful for using
the mail functionality in @enterprise.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
DefaultMailFunctions defines the default actions of the mail client as entered inadmin.xml
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns anArrayList
ofPart
objects.static DMSFolder
getEmailsFolder
(DMSFolder folder, boolean createFolder) returns the folder "Emails" of given DMSFolderstatic DMSFolder
getEmailsFolder
(ProcessInstance pi, boolean createFolder) returns the folder "Emails" of given process instancegetMailText
(String actionId, Message msg) Returns the default mail text of given message in text/plain and text/html formatstatic Map<Message.RecipientType,
String> getRecipients
(String actionId, DMSDocForm email, Message msg) Get the recipients depending on the given default actions.static String
getReplyRecipient
(DMSDocForm email) Returns the appropriate recipient.static String
getSubject
(String actionId, ProcessInstance pi, Message msg) Get the subject depending on the given default action and message.static boolean
hasMailQueueEntry
(Persistent refObj) Checks, if a mailqueue item exists for the referenced objectstatic boolean
Method to check, if mails exist in the given folder.static boolean
Method to check, if mails exist in "Emails" folder of the process instance.static boolean
hasRightForMailList
(List<DMSObject> mails) Method to check, if the current user has theRight.VIEW
for given mail list.static boolean
isDefaultMailAction
(String actionId) Checks, if given actionId in String format is a default action (seeMailFunctions.DefaultMailFunction
).static String
outgoingMailSubject
(ProcessInstance pi, String subject) Returns the subject of given process instance as defined with configuration parameter "ep.mail.subjpattern".static Page
showMailPane
(Persistent object, String mailPane, String mailHandlerClass) Returns a page holding the mail pane of the passed object.Returns a page holding the mail pane of the passed object.static JSONObject
toJSON
(DMSDocForm emailObj) Returns the following JSON structure of given email object:
-
Constructor Details
-
MailFunctions
public MailFunctions()
-
-
Method Details
-
isDefaultMailAction
Checks, if given actionId in String format is a default action (seeMailFunctions.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, otherwisefalse
-
getEmailsFolder
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
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
Returns the subject of given process instance as defined with configuration parameter "ep.mail.subjpattern".- Parameters:
pi
- the process instance for getting pidsubject
- 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
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 aMailFunctions.DefaultMailFunction
in following format:
<xml-id>.<node-id>
(e.g. in case of default action "compose" the id is "admin.composeSC"))pi
- theProcessInstance
for determining the subject; can benull
msg
- the referencedMessage
object; can benull
- 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>"
- compose: Text returned by
- 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 aMailFunctions.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 asDMSDocForm
msg
- the referencedMessage
object- Returns:
- a
HashMap
containing theMessage.RecipientType
as key and the appropriate recipient email addresses as string value. Returned recipients depending on action:- reply: The
Message.RecipientType.TO
only where value is determined bygetReplyRecipient(DMSDocForm)
- replyall: The
Message.RecipientType.TO
andMessage.RecipientType.CC
of givenMessage
- editdraft: The
Message.RecipientType.TO
,Message.RecipientType.CC
andMessage.RecipientType.BCC
of givenMessage
- reply: The
- Throws:
Exception
-
getMailText
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 aMailFunctions.DefaultMailFunction
in following format:
<xml-id>.<node-id>
(e.g. in case of default action "compose" the id is "admin.composeSC"))msg
- theMessage
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
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 ExceptionReturns an
ArrayList
ofPart
objects. These objects represent the attachments (DMS andFile
attachments that are passed as parameters.Note that DMS attachments which are not of type
DocForm
are omitted. -
hasMails
Method to check, if mails exist in "Emails" folder of the process instance.- Parameters:
pi
- theProcessInstance
to check, if "Emails" folder contains mails- Returns:
true
, if mails are available and the current user has the permissions to see them; otherwisefalse
-
hasMails
Method to check, if mails exist in the given folder.- Parameters:
emailFldr
- theDMSFolder
where mails are stored- Returns:
true
, if mails are available and the current user has the permissions to see them (Right.VIEW
); otherwisefalse
-
hasMailQueueEntry
Checks, if a mailqueue item exists for the referenced object- Parameters:
refObj
- the referenced object- Returns:
true
, if mailqueue item could be found; otherwisefalse
-
toJSON
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
Method to check, if the current user has theRight.VIEW
for given mail list.- Parameters:
mails
- a list of mails represented asDMSObject
- Returns:
true
if the current user has the permissions to see them; otherwisefalse
-
showMailPane
Returns a page holding the mail pane of the passed object. In case of aDMSFolder
the subfolder with name "Emails" is used in MailPane as context object. In case of aProcessInstance
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 aProcessInstance
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
- object: Either a
- Returns:
- a Page containing the MailPane
-
showMailPane
Returns a page holding the mail pane of the passed object. In case of aDMSFolder
a new created sub-folder with name "Emails" is used in MailPane as context object. In case of aProcessInstance
the process instance itself is used in MailPane as context object.- Parameters:
object
- aDMSFolder
orProcessInstance
mailPane
- an own defined MailPane widget; if this parameter is empty, the default "ep/widget/smartclient/wl/MailPane" is usedmailHandlerClass
- an own definedcom.groiss.smartclient.mail.MailActionsHandler
class; if this parameter is empty, no mail handler is used- Returns:
- a Page containing the MailPane
-