com.jalios.jcms.mail
Class MailManager

java.lang.Object
  extended by com.jalios.jcms.mail.MailManager

public class MailManager
extends Object

Provides convenient methods to manage DBMailMessage stored in DataBase and on HardDrive

Version:
$Revision: 69521 $
Author:
Jean-Philippe Encausse

Field Summary
static String REVISION
           
static String SEND_WITH_SITE_EMAIL
          Name of both JCMS property and context map attribute defining a MailMessage behavior.
 
Method Summary
static String addAuthKeyToImagesSrc(String content, Member mbr)
          When the site is private, add an authentication key to all src='...' URL in order for the mailer to access them without any authentication.
static String buildContentFromJsp(String jspPath, Member loggedMember, String language, HashMap<Object,Object> requestAttributeMap, HashMap<Object,Object> sessionAttributeMap)
          Builds a mail content from a given jsp
 MailMessage createDBMailMessage(javax.mail.Message msg, MailAccount account)
          Build a DBMessage from a Message and save in into the DB
 MailMessage getDBMailMessage(javax.mail.Message msg)
          Returns the DBMailMessage for the given Message
 MailMessage getDBMailMessage(String msgid)
          Returns the DBMailMessage for the given Message Id
 int getDBMailMessageCount()
          Returns the count of DBMailMessage
 int getDBMailMessageCount(String account)
          Returns the count of DBMailMessage for given account
 Collection<? extends MailMessage> getDBMailMessageReplies(String msgid)
          Returns the DBMailMessage for the given Message Id
 Set<Object> getDBMailMessageSet(String[] ids)
          Returns a Collection of MailMessage or Message-ID (if not found)
 Collection<? extends MailMessage> getDBMailMessageThread(String thread)
           
static Set<javax.mail.internet.InternetAddress> getIAFromMemberSet(Set<Member> mbrSet)
          Returns a Set of InternetAddress build from a Set of Members
static String getIncomingAddress(String localpart, Member mbr, String label)
          Returns JCMS incoming email for the given Member
static MailManager getInstance()
           
static TreeSet<String> getInvalidEmailSet(Set<String> mailSet, Set<Member> mbrSet)
          Retrieve all INVALID email from the specified mail and member Set.
static String getLocalPartSuffixAuthKey(Member mbr)
          Returns a localpart sufix authkey for given members
 MailFetcher getMailFetcher()
          Returns the MailFetcher
 String getMessageIdQuietly(javax.mail.Message msg)
          Convenient method that delegate to MailFetcher method
static void improveMailMessageConformity(MailMessage msg, HashMap<String,Object> ctxt)
          Improve the specified MailMessage conformity with mail sending best practices (if enabled).
 void init()
           
static String replaceRelativeUrlsWithAbsoluteUrls(String contentHtml)
          Convert all relative URLs inside the specified HTML content into absolute URL.
 void saveDBMailMessage(MailMessage mail, Map<String,Object> context)
          Build a DBMessage from a Message and save in into the DB
 File writeEml(javax.mail.Message msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

SEND_WITH_SITE_EMAIL

public static final String SEND_WITH_SITE_EMAIL
Name of both JCMS property and context map attribute defining a MailMessage behavior.

The value is a boolean which defines if MailMessage should be sent using the Member name and e-mail, or using the user name but with the site e-mail address.
If set to true, mail are sent using the site default email address, and the original Member is used in the ReplyTo header.
If set to false, mail are sent using original member email address.

Value can be specified :

Default JCMS behavior (following fix JCMS-3740) is to send mail using the site email address.

Since:
JCMS-3740
See Also:
Constant Field Values
Method Detail

getInstance

public static MailManager getInstance()

init

public void init()

improveMailMessageConformity

public static void improveMailMessageConformity(MailMessage msg,
                                                HashMap<String,Object> ctxt)
Improve the specified MailMessage conformity with mail sending best practices (if enabled).

Implementation details

If following criterias are met :

The MailMessage is rewriten to use the site e-mail address in the From header :

Parameters:
msg - the MailMessage to modify if criterias are met
ctxt - the context map attribute of MailMessage.send(HashMap), MUST NOT be null
Since:
JCMS-3740

addAuthKeyToImagesSrc

public static String addAuthKeyToImagesSrc(String content,
                                           Member mbr)
When the site is private, add an authentication key to all src='...' URL in order for the mailer to access them without any authentication.

Parameters:
content - html content to update
mbr - the recipient member
Returns:
String the modified content

replaceRelativeUrlsWithAbsoluteUrls

public static String replaceRelativeUrlsWithAbsoluteUrls(String contentHtml)
Convert all relative URLs inside the specified HTML content into absolute URL.

Uses the current channel URL as prefix of relative URL.

Parameters:
contentHtml - the HTML content in which to look for relative URL (in src and href attributes)
Returns:
the modified content

getDBMailMessageSet

public Set<Object> getDBMailMessageSet(String[] ids)
Returns a Collection of MailMessage or Message-ID (if not found)

Parameters:
ids - a list of Message-ID
Returns:
Collection of MailMessage or Message-ID

getDBMailMessageCount

public int getDBMailMessageCount()
Returns the count of DBMailMessage

Returns:
int the DBMailMessageCount

getDBMailMessageCount

public int getDBMailMessageCount(String account)
Returns the count of DBMailMessage for given account

Parameters:
account - the account name
Returns:
int the DBMailMessageCount

getDBMailMessage

public MailMessage getDBMailMessage(javax.mail.Message msg)
Returns the DBMailMessage for the given Message

Parameters:
msg - a javax.mail.Message
Returns:
a DBMailMessage stored in db

getDBMailMessage

public MailMessage getDBMailMessage(String msgid)
Returns the DBMailMessage for the given Message Id

Parameters:
msgid - the message id
Returns:
a DBMailMessage stored in db

getDBMailMessageReplies

public Collection<? extends MailMessage> getDBMailMessageReplies(String msgid)
Returns the DBMailMessage for the given Message Id

Parameters:
msgid - the message id
Returns:
a DBMailMessage stored in db

getDBMailMessageThread

public Collection<? extends MailMessage> getDBMailMessageThread(String thread)

createDBMailMessage

public MailMessage createDBMailMessage(javax.mail.Message msg,
                                       MailAccount account)
Build a DBMessage from a Message and save in into the DB

Parameters:
msg - a javax.mail.Message
account - the mailAccount
Returns:
MailMessage instanciate or null if exception appends

saveDBMailMessage

public void saveDBMailMessage(MailMessage mail,
                              Map<String,Object> context)
Build a DBMessage from a Message and save in into the DB

Parameters:
mail - the MailMessage
context - the contextual map

writeEml

public File writeEml(javax.mail.Message msg)

getMailFetcher

public MailFetcher getMailFetcher()
Returns the MailFetcher

Returns:
MailFetcher

getMessageIdQuietly

public String getMessageIdQuietly(javax.mail.Message msg)
Convenient method that delegate to MailFetcher method

Parameters:
msg - the javax.mail.Message
Returns:
String the message Id or null
See Also:
MailFetcher.getMessageIdQuietly(Message)

getIncomingAddress

public static String getIncomingAddress(String localpart,
                                        Member mbr,
                                        String label)
Returns JCMS incoming email for the given Member

Parameters:
localpart - the mail prefix
mbr - Member author of the mail
label - the email label
Returns:
String valid incoming email

getLocalPartSuffixAuthKey

public static String getLocalPartSuffixAuthKey(Member mbr)
Returns a localpart sufix authkey for given members

Parameters:
mbr - the member
Returns:
String localpart sufix authkey (starting with +)

getIAFromMemberSet

public static Set<javax.mail.internet.InternetAddress> getIAFromMemberSet(Set<Member> mbrSet)
                                                                   throws javax.mail.MessagingException
Returns a Set of InternetAddress build from a Set of Members

Parameters:
mbrSet - a Set of Members
Returns:
Set of InternetAddress
Throws:
javax.mail.MessagingException

getInvalidEmailSet

public static TreeSet<String> getInvalidEmailSet(Set<String> mailSet,
                                                 Set<Member> mbrSet)
Retrieve all INVALID email from the specified mail and member Set.

Parameters:
mailSet - a set of email addresses
mbrSet - a set of Member
Returns:
a set of invalid email
Since:
jcms-6.1

buildContentFromJsp

public static String buildContentFromJsp(String jspPath,
                                         Member loggedMember,
                                         String language,
                                         HashMap<Object,Object> requestAttributeMap,
                                         HashMap<Object,Object> sessionAttributeMap)
Builds a mail content from a given jsp

Parameters:
jspPath - the jsp to process
loggedMember - the loggedMember
language - the user language
requestAttributeMap - Map of request attributes
sessionAttributeMap - Map of session attributes
Returns:
String builded content


Copyright © 2001-2010 Jalios SA. All Rights Reserved.