Class OutgoingEmail
- java.lang.Object
-
- com.google.gerrit.server.mail.send.OutgoingEmail
-
- Direct Known Subclasses:
AddKeySender
,ChangeEmail
,DeleteKeySender
,HttpPasswordUpdateSender
,InboundEmailRejectionSender
,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 NotifyResolver.Result
notify
protected Map<String,Object>
soyContext
protected Map<String,Object>
soyContextEmailData
-
Constructor Summary
Constructors Modifier Constructor Description protected
OutgoingEmail(EmailArguments args, String messageClass)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addByAccountId(RecipientType rt, Account.Id to)
Adds a recipient that the email will be sent to.protected void
addByAccountId(RecipientType rt, Account.Id to, boolean override)
Adds a recipient that the email will be sent to.void
addByEmail(RecipientType rt, Address addr)
Adds a recipient that the email will be sent to.void
addByEmail(RecipientType rt, Address addr, boolean override)
Adds a recipient that the email will be sent to.void
addFooter(String footer)
Add a line to email footer with additional information.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()
protected String
getNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account; if neither are available, returns the Anonymous Coward name.protected String
getNameFor(Account.Id accountId)
Lookup a human readable name for an account, usually the "full name".String
getSettingsUrl()
Map<String,Object>
getSoyContext()
Mutable map of parameters passed into email templates when rendering.Map<String,Object>
getSoyContextEmailData()
Mutable content of `email` parameter in the templates.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
isRecipientAllowed(Account.Id to)
Returns whether this email is allowed to be sent to the given accountprotected boolean
isRecipientAllowed(Address addr)
Returns whether this email is allowed to be sent to the given addressprotected 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
setFrom(Account.Id id)
protected void
setHeader(String name, String value)
Set a header in the outgoing message.protected void
setHeader(String name, Instant date)
void
setMessageId(MessageIdGenerator.MessageId messageId)
void
setNotify(NotifyResolver.Result notify)
protected void
setupSoyContext()
protected boolean
shouldSendMessage()
protected String
soyHtmlTemplate(String name)
Renders a soy template of kind="html".protected String
textTemplate(String name)
Renders a soy template of kind="text".protected boolean
useHtml()
-
-
-
Field Detail
-
messageClass
protected String messageClass
-
args
protected final EmailArguments args
-
fromId
protected Account.Id fromId
-
notify
protected NotifyResolver.Result notify
-
-
Constructor Detail
-
OutgoingEmail
protected OutgoingEmail(EmailArguments args, String messageClass)
-
-
Method Detail
-
setFrom
public void setFrom(Account.Id id)
-
setNotify
public void setNotify(NotifyResolver.Result notify)
-
setMessageId
public void setMessageId(MessageIdGenerator.MessageId messageId)
-
send
public void send() throws com.google.gerrit.exceptions.EmailException
Format and enqueue the message for delivery.- Throws:
com.google.gerrit.exceptions.EmailException
-
format
protected abstract void format() throws com.google.gerrit.exceptions.EmailException
Format the message body by callingappendText(String)
.- Throws:
com.google.gerrit.exceptions.EmailException
-
init
protected void init() throws com.google.gerrit.exceptions.EmailException
Setup the message headers and envelope (TO, CC, BCC).- Throws:
com.google.gerrit.exceptions.EmailException
- if an error occurred.
-
getFromLine
protected String getFromLine()
-
getGerritHost
public String getGerritHost()
-
getSettingsUrl
public String getSettingsUrl()
-
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)
Lookup a human readable name for an account, usually the "full name".
-
getNameEmailFor
protected String getNameEmailFor(Account.Id accountId)
Gets the human readable name and email for an account; if neither are available, returns the Anonymous Coward name.- Parameters:
accountId
- user to fetch.- Returns:
- name/email of account, or Anonymous Coward if unset.
-
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 or the accountId is null.
-
shouldSendMessage
protected boolean shouldSendMessage()
-
addByEmail
public final void addByEmail(RecipientType rt, Address addr)
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)addr
- Name and email of the recipient.
-
addByEmail
public final void addByEmail(RecipientType rt, Address addr, boolean override)
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC).addr
- Name and email of the recipient.override
- if the recipient was added previously and override is false no change is made regardless ofrt
.
-
isRecipientAllowed
protected boolean isRecipientAllowed(Address addr) throws PermissionBackendException
Returns whether this email is allowed to be sent to the given address- Parameters:
addr
- email address of recipient.- Throws:
PermissionBackendException
- thrown if checking a permission fails due to an error in the permission backend
-
addByAccountId
protected void addByAccountId(RecipientType rt, Account.Id to)
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)to
- Gerrit Account of the recipient.
-
addByAccountId
protected void addByAccountId(RecipientType rt, Account.Id to, boolean override)
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)to
- Gerrit Account of the recipient.override
- if the recipient was added previously and override is false no change is made regardless ofrt
.
-
isRecipientAllowed
protected boolean isRecipientAllowed(Account.Id to) throws PermissionBackendException
Returns whether this email is allowed to be sent to the given account- Parameters:
to
- account.- Throws:
PermissionBackendException
- thrown if checking a permission fails due to an error in the permission backend
-
setupSoyContext
protected void setupSoyContext()
-
getSoyContext
public Map<String,Object> getSoyContext()
Mutable map of parameters passed into email templates when rendering.
-
getSoyContextEmailData
public Map<String,Object> getSoyContextEmailData()
Mutable content of `email` parameter in the templates.
-
addFooter
public void addFooter(String footer)
Add a line to email footer with additional information. Typically, in the form of <key>: <value>.
-
soyHtmlTemplate
protected String soyHtmlTemplate(String name)
Renders a soy template of kind="html".
-
removeUser
protected void removeUser(Account user)
-
useHtml
protected final boolean useHtml()
-
-