Class OutgoingEmail
- java.lang.Object
-
- com.google.gerrit.server.mail.send.OutgoingEmail
-
- Direct Known Subclasses:
AddKeySender
,DeleteKeySender
,HttpPasswordUpdateSender
,NotificationEmail
,RegisterNewEmailSender
public abstract class OutgoingEmail extends Object
Sends an email to one or more interested parties.
-
-
Field Summary
Fields Modifier and Type Field Description protected EmailArguments
args
protected List<String>
footers
protected Account.Id
fromId
protected String
messageClass
protected NotifyHandling
notify
protected Map<String,Object>
soyContext
protected Map<String,Object>
soyContextEmailData
protected org.apache.velocity.VelocityContext
velocityContext
-
Constructor Summary
Constructors Modifier Constructor Description protected
OutgoingEmail(EmailArguments ea, String mc)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
add(RecipientType rt, Account.Id to)
Schedule delivery of this message to the given account.protected void
add(RecipientType rt, Account.Id to, boolean override)
protected void
add(RecipientType rt, UserIdentity who)
protected void
add(RecipientType rt, UserIdentity who, boolean override)
protected void
add(RecipientType rt, Address addr)
Schedule delivery of this message to the given account.protected void
add(RecipientType rt, Address addr, boolean override)
protected void
add(RecipientType rt, Collection<Account.Id> list)
Schedule this message for delivery to the listed accounts.protected void
add(RecipientType rt, Collection<Account.Id> list, boolean override)
Schedule this message for delivery to the listed accounts.protected void
addByEmail(RecipientType rt, Collection<Address> list)
Schedule this message for delivery to the listed address.protected void
addByEmail(RecipientType rt, Collection<Address> list, boolean override)
Schedule this message for delivery to the listed address.protected void
appendHtml(String html)
Append html to the outgoing email body.protected void
appendText(String text)
Append text to the outgoing email body.protected abstract void
format()
Format the message body by callingappendText(String)
.protected String
getFromLine()
String
getGerritHost()
String
getGerritUrl()
protected String
getNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account.protected String
getNameFor(Account.Id accountId)
Gets the human readable name for an account, usually the "full name".String
getSettingsUrl()
protected String
getUserNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account; if both are unavailable, returns the username.protected void
init()
Setup the message headers and envelope (TO, CC, BCC).protected boolean
isVisibleTo(Account.Id to)
protected void
removeHeader(String name)
Remove a header from the outgoing message.protected void
removeUser(Account user)
void
send()
Format and enqueue the message for delivery.void
setAccountsToNotify(com.google.common.collect.ListMultimap<RecipientType,Account.Id> accountsToNotify)
void
setFrom(Account.Id id)
protected void
setHeader(String name, String value)
Set a header in the outgoing message.protected void
setHeader(String name, Date date)
void
setNotify(NotifyHandling notify)
protected void
setupSoyContext()
protected void
setupVelocityContext()
protected void
setVHeader(String name, String value)
Set a header in the outgoing message using a template.protected boolean
shouldSendMessage()
protected String
soyHtmlTemplate(String name)
protected String
soyTextTemplate(String name)
protected boolean
supportsHtml()
Override this method to enable HTML in a subclass.protected String
textTemplate(String name)
Evaluate the named template according to the following priority: 1) Velocity file override, OR...protected boolean
useHtml()
protected String
velocify(String template)
protected String
velocifyFile(String name)
-
-
-
Field Detail
-
messageClass
protected String messageClass
-
velocityContext
protected org.apache.velocity.VelocityContext velocityContext
-
args
protected final EmailArguments args
-
fromId
protected Account.Id fromId
-
notify
protected NotifyHandling notify
-
-
Constructor Detail
-
OutgoingEmail
protected OutgoingEmail(EmailArguments ea, String mc)
-
-
Method Detail
-
setFrom
public void setFrom(Account.Id id)
-
setNotify
public void setNotify(NotifyHandling notify)
-
setAccountsToNotify
public void setAccountsToNotify(com.google.common.collect.ListMultimap<RecipientType,Account.Id> accountsToNotify)
-
send
public void send() throws EmailException
Format and enqueue the message for delivery.- Throws:
EmailException
-
format
protected abstract void format() throws EmailException
Format the message body by callingappendText(String)
.- Throws:
EmailException
-
init
protected void init() throws EmailException
Setup the message headers and envelope (TO, CC, BCC).- Throws:
EmailException
- if an error occurred.
-
getFromLine
protected String getFromLine()
-
getGerritHost
public String getGerritHost()
-
getSettingsUrl
public String getSettingsUrl()
-
getGerritUrl
public String getGerritUrl()
-
setVHeader
protected void setVHeader(String name, String value) throws EmailException
Set a header in the outgoing message using a template.- Throws:
EmailException
-
setHeader
protected void setHeader(String name, String value)
Set a header in the outgoing message.
-
removeHeader
protected void removeHeader(String name)
Remove a header from the outgoing message.
-
appendText
protected void appendText(String text)
Append text to the outgoing email body.
-
appendHtml
protected void appendHtml(String html)
Append html to the outgoing email body.
-
getNameFor
protected String getNameFor(Account.Id accountId)
Gets the human readable name for an account, usually the "full name".- Parameters:
accountId
- user to fetch.- Returns:
- name of the account, or the server identity name if null.
-
getNameEmailFor
protected String getNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account.- Parameters:
accountId
- user to fetch.- Returns:
- name/email of account; Anonymous Coward if unset or the server identity if null.
-
getUserNameEmailFor
protected String getUserNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account; if both are unavailable, returns the username. If no username is set, this function returns null.- Parameters:
accountId
- user to fetch.- Returns:
- name/email of account, username, or null if unset.
-
shouldSendMessage
protected boolean shouldSendMessage()
-
add
protected void add(RecipientType rt, Collection<Account.Id> list)
Schedule this message for delivery to the listed accounts.
-
add
protected void add(RecipientType rt, Collection<Account.Id> list, boolean override)
Schedule this message for delivery to the listed accounts.
-
addByEmail
protected void addByEmail(RecipientType rt, Collection<Address> list)
Schedule this message for delivery to the listed address.
-
addByEmail
protected void addByEmail(RecipientType rt, Collection<Address> list, boolean override)
Schedule this message for delivery to the listed address.
-
add
protected void add(RecipientType rt, UserIdentity who)
-
add
protected void add(RecipientType rt, UserIdentity who, boolean override)
-
add
protected void add(RecipientType rt, Account.Id to)
Schedule delivery of this message to the given account.
-
add
protected void add(RecipientType rt, Account.Id to, boolean override)
-
isVisibleTo
protected boolean isVisibleTo(Account.Id to) throws com.google.gwtorm.server.OrmException, PermissionBackendException
- Parameters:
to
- account.- Returns:
- whether this email is visible to the given account.
- Throws:
com.google.gwtorm.server.OrmException
PermissionBackendException
-
add
protected void add(RecipientType rt, Address addr)
Schedule delivery of this message to the given account.
-
add
protected void add(RecipientType rt, Address addr, boolean override)
-
setupVelocityContext
protected void setupVelocityContext()
-
setupSoyContext
protected void setupSoyContext()
-
velocify
protected String velocify(String template) throws EmailException
- Throws:
EmailException
-
velocifyFile
protected String velocifyFile(String name) throws EmailException
- Throws:
EmailException
-
textTemplate
protected String textTemplate(String name) throws EmailException
Evaluate the named template according to the following priority: 1) Velocity file override, OR... 2) Soy file override, OR... 3) Soy resource.- Throws:
EmailException
-
removeUser
protected void removeUser(Account user)
-
useHtml
protected final boolean useHtml()
-
supportsHtml
protected boolean supportsHtml()
Override this method to enable HTML in a subclass.
-
-