|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.jira.service.util.handler.AbstractMessageHandler
@PublicSpi public abstract class AbstractMessageHandler
An AbstractMessageHandler that stores the parameter map.
TODO Insert summary about other responsibilities/ features of this class.saveAttachmentIfNecessary(javax.mail.Part, javax.mail.Message, User,
org.ofbiz.core.entity.GenericValue)
method.
This method eventually calls others which attempt to locate all parts that are possible candidates and should be kept
after it is categorised a part as a particular type. These types are attachAttachmentsParts(javax.mail.Part)
attachHtmlParts(javax.mail.Part)
attachInlineParts(javax.mail.Part)
is abstractattachMessagePart(javax.mail.Part, javax.mail.Message)
attachPlainTextParts(javax.mail.Part)
is
abstractMailUtils
class to assist with
simple tests.
Field Summary | |
---|---|
protected ApplicationProperties |
applicationProperties
|
String |
bulk
How to handle emails with header: "Precedence: bulk" |
String |
catchEmail
New issues without this recipient are ignored. |
protected CommentManager |
commentManager
|
protected static String |
CONTENT_TYPE_TEXT
|
boolean |
createUsers
Whether to create users if they do not exist |
protected boolean |
deleteEmail
This is a silly protected field that indicates whether the email should be deleted BUT only after the canHandleMessage() method is called. |
protected EntityCreationHandler |
entityCreationHandler
|
protected static String |
HEADER_IN_REPLY_TO
|
protected static String |
HEADER_MESSAGE_ID
|
protected IssueFactory |
issueFactory
|
static String |
KEY_BULK
|
static String |
KEY_CATCHEMAIL
|
static String |
KEY_CREATEUSERS
|
static String |
KEY_FINGER_PRINT
|
static String |
KEY_NOTIFYUSERS
|
static String |
KEY_REPORTER
|
protected org.apache.log4j.Logger |
log
|
protected MailHandlerExecutionMonitor |
mailHandlerExecutionMonitor
|
boolean |
notifyUsers
|
protected Map<String,String> |
params
|
String |
reporteruserName
Username of default reporter, if sender not recognized. |
protected UserManager |
userManager
|
static String |
VALUE_BULK_DELETE
|
static String |
VALUE_BULK_FORWARD
|
static String |
VALUE_BULK_IGNORE
|
static String |
VALUE_FINGER_PRINT_ACCEPT
Value for parameter KEY_FINGER_PRINT which matches legacy behaviour, accepting emails even if this JIRA
sent them. |
static String |
VALUE_FINGER_PRINT_FORWARD
Default value for parameter KEY_FINGER_PRINT which matches forwards emails if this JIRA sent them,
falling back to VALUE_FINGER_PRINT_IGNORE if the forward email address is missing. |
static String |
VALUE_FINGER_PRINT_IGNORE
Value for parameter KEY_FINGER_PRINT which makes this handler ignore emails detected to have been sent
by this instance of JIRA. |
Constructor Summary | |
---|---|
protected |
AbstractMessageHandler()
|
protected |
AbstractMessageHandler(CommentManager commentManager,
IssueFactory issueFactory,
ApplicationProperties applicationProperties,
JiraApplicationContext jiraApplicationContext)
Deprecated. Use AbstractMessageHandler(CommentManager, IssueFactory, UserManager, ApplicationProperties, JiraApplicationContext, MailLoggingManager) instead. Since v5.0. |
protected |
AbstractMessageHandler(CommentManager commentManager,
IssueFactory issueFactory,
UserManager userManager,
ApplicationProperties applicationProperties,
JiraApplicationContext jiraApplicationContext,
MailLoggingManager mailLoggingManager)
|
Method Summary | |
---|---|
void |
addError(String error)
|
void |
addError(String error,
Exception e)
|
void |
addInfo(String info)
|
protected boolean |
attachAttachmentsParts(javax.mail.Part part)
Only attach an attachment part if it's content is not empty and if it is not a signature part. |
protected abstract boolean |
attachHtmlParts(javax.mail.Part part)
This method determines whether or not HTML parts should be attached. |
protected boolean |
attachInlineParts(javax.mail.Part part)
Only attach an inline part if it's content is not empty and if it is not a signature part. |
protected boolean |
attachMessagePart(javax.mail.Part messagePart,
javax.mail.Message containingMessage)
JRA-15133: if this part is an attached message, skip it if: the option to ignore attached messages is set to true, OR this message is in reply to the attached one (redundant info), OR if the message is not in reply to the attached one, skip if the content is empty This is required to handle the behaviour of some mail clients (e.g. |
protected abstract boolean |
attachPlainTextParts(javax.mail.Part part)
This method determines whether or not plain text parts should be attached. |
protected boolean |
attachRelatedPart(javax.mail.Part part)
JRA-15670: if this part is contained within a multipart/related message, keep it, as it may be a legitimate attachment, but without the content disposition set to a sensible value (e.g. |
protected boolean |
canHandleMessage(javax.mail.Message message)
Validation call to be made at the start of handleMessage(). It sets a global boolean deleteEmail, whether the email should be deleted if it cannot be handled. |
protected Collection<ChangeItemBean> |
createAttachmentsForMessage(javax.mail.Message message,
org.ofbiz.core.entity.GenericValue issue)
Loops through all the Part s, and for each one of type Part.ATTACHMENT , call createAttachmentWithPart(Part,User,GenericValue) . |
protected ChangeItemBean |
createAttachmentWithPart(javax.mail.Part part,
com.atlassian.crowd.embedded.api.User reporter,
org.ofbiz.core.entity.GenericValue issue)
Create an attachment for a particular mime-part. |
protected com.atlassian.crowd.embedded.api.User |
createUserForReporter(javax.mail.Message message)
Tries to create a user using the details provided by the reporter. |
protected com.atlassian.crowd.embedded.api.User |
findUserByEmail(String emailAddress)
Returns the first User found with an email address that equals the given emailAddress case insensitively. |
protected com.atlassian.crowd.embedded.api.User |
findUserByUsername(String username)
Finds the user with the given username or returns null if there is no such User. |
protected org.ofbiz.core.entity.GenericValue |
getAssociatedIssue(javax.mail.Message message)
|
protected File |
getFileFromPart(javax.mail.Part part,
String issueKey)
|
protected String |
getFilenameForAttachment(javax.mail.Part part)
Handy method which takes a number of strategies when attempting to give a filename for a particular part. |
protected I18nHelper |
getI18nBean()
|
protected MailHandlerExecutionMonitor |
getMailHandlerExecutionMonitor()
|
protected String |
getPrecedenceHeader(javax.mail.Message message)
Extract the 'Precedence' header value from the message |
protected com.atlassian.crowd.embedded.api.User |
getReporter(javax.mail.Message message)
Get the reporter from the email address who sent the message, or else create a new user if creating users is set to true, or use the default reporter if one is specified. |
abstract boolean |
handleMessage(javax.mail.Message message)
Perform the specific work of this handler for the given message. |
void |
init(Map<String,String> params,
EntityCreationHandler entityCreationHandler)
Will be called before any messages are to be handled. |
protected boolean |
isAutoSubmitted(javax.mail.Message message)
|
protected boolean |
isDeliveryStatus(javax.mail.Message message)
|
protected boolean |
isDryRunMode()
|
protected void |
recordMessageId(String type,
javax.mail.Message message,
Long issueId)
|
protected String |
renameFileIfInvalid(String filename,
org.ofbiz.core.entity.GenericValue issue,
com.atlassian.crowd.embedded.api.User reporter)
Replaces all invalid characters in the filename using FileNameCharacterCheckerUtil.replaceInvalidChars(String,
char) with INVALID_CHAR_REPLACEMENT as the replacement character. |
void |
setMailHandlerExecutionMonitor(MailHandlerExecutionMonitor mailHandlerExecutionMonitor)
|
protected boolean |
shouldAttach(javax.mail.Part part,
javax.mail.Message containingMessage)
This method determines if a particular part should be included added as an attachment to an issue. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.apache.log4j.Logger log
public static final String KEY_REPORTER
public static final String KEY_CATCHEMAIL
public static final String KEY_CREATEUSERS
public static final String KEY_NOTIFYUSERS
public static final String KEY_FINGER_PRINT
public static final String VALUE_FINGER_PRINT_ACCEPT
KEY_FINGER_PRINT
which matches legacy behaviour, accepting emails even if this JIRA
sent them.
public static final String VALUE_FINGER_PRINT_FORWARD
KEY_FINGER_PRINT
which matches forwards emails if this JIRA sent them,
falling back to VALUE_FINGER_PRINT_IGNORE
if the forward email address is missing.
public static final String VALUE_FINGER_PRINT_IGNORE
KEY_FINGER_PRINT
which makes this handler ignore emails detected to have been sent
by this instance of JIRA.
public static final String KEY_BULK
public static final String VALUE_BULK_IGNORE
public static final String VALUE_BULK_FORWARD
public static final String VALUE_BULK_DELETE
protected static final String CONTENT_TYPE_TEXT
protected static final String HEADER_MESSAGE_ID
protected static final String HEADER_IN_REPLY_TO
protected boolean deleteEmail
protected MailHandlerExecutionMonitor mailHandlerExecutionMonitor
protected Map<String,String> params
public String reporteruserName
public String catchEmail
public String bulk
public boolean createUsers
public boolean notifyUsers
protected EntityCreationHandler entityCreationHandler
protected final CommentManager commentManager
protected final IssueFactory issueFactory
protected final UserManager userManager
protected final ApplicationProperties applicationProperties
Constructor Detail |
---|
protected AbstractMessageHandler()
protected AbstractMessageHandler(CommentManager commentManager, IssueFactory issueFactory, ApplicationProperties applicationProperties, JiraApplicationContext jiraApplicationContext)
AbstractMessageHandler(CommentManager, IssueFactory, UserManager, ApplicationProperties, JiraApplicationContext, MailLoggingManager)
instead. Since v5.0.
commentManager
- issueFactory
- applicationProperties
- jiraApplicationContext
- protected AbstractMessageHandler(CommentManager commentManager, IssueFactory issueFactory, UserManager userManager, ApplicationProperties applicationProperties, JiraApplicationContext jiraApplicationContext, MailLoggingManager mailLoggingManager)
Method Detail |
---|
public void init(Map<String,String> params, EntityCreationHandler entityCreationHandler)
MessageHandler
init
in interface MessageHandler
params
- configuration.public abstract boolean handleMessage(javax.mail.Message message) throws javax.mail.MessagingException
handleMessage
in interface MessageHandler
message
- the message to check for handling.
javax.mail.MessagingException
- if anything went wrong.protected boolean canHandleMessage(javax.mail.Message message)
message
- message to check if it can be handled
protected Collection<ChangeItemBean> createAttachmentsForMessage(javax.mail.Message message, org.ofbiz.core.entity.GenericValue issue) throws IOException, javax.mail.MessagingException
Part
s, and for each one of type Part.ATTACHMENT
, call createAttachmentWithPart(Part,User,GenericValue)
.
message
- The multipart message to search for attachments inissue
- The issue to create attachments in
IOException
- If there is a problem creating the attachment
javax.mail.MessagingException
- If there is a problem reading the messageprotected final boolean shouldAttach(javax.mail.Part part, javax.mail.Message containingMessage) throws javax.mail.MessagingException, IOException
part
- the part to potentially attachcontainingMessage
- the message which contained the part - may be null
IOException
- if javamail complains
javax.mail.MessagingException
- if javamail complainsprotected abstract boolean attachPlainTextParts(javax.mail.Part part) throws javax.mail.MessagingException, IOException
part
- the part to be attached - already determined to be type text/plain.
IOException
- if javamail complains
javax.mail.MessagingException
- if javamail complainsprotected abstract boolean attachHtmlParts(javax.mail.Part part) throws javax.mail.MessagingException, IOException
part
- the part to be attached - already determined to be type text/html.
IOException
- if javamail complains
javax.mail.MessagingException
- if javamail complainsprotected boolean attachInlineParts(javax.mail.Part part) throws javax.mail.MessagingException, IOException
part
- a mail part - assumed to have inline disposition
javax.mail.MessagingException
- if Content-Type checks fail
IOException
- if content checks failprotected boolean attachAttachmentsParts(javax.mail.Part part) throws javax.mail.MessagingException, IOException
part
- a mail part - assumed to have attachment disposition
javax.mail.MessagingException
- if Content-Type checks fail
IOException
- if content checks failprotected boolean attachMessagePart(javax.mail.Part messagePart, javax.mail.Message containingMessage) throws IOException, javax.mail.MessagingException
messagePart
- the Message part (already known to be of message content type)containingMessage
- the original message which contains messagePart
IOException
- if javamail complains
javax.mail.MessagingException
- if javamail complainsprotected boolean attachRelatedPart(javax.mail.Part part) throws IOException, javax.mail.MessagingException
part
- the part contained within the related message
IOException
- if javamail complains
javax.mail.MessagingException
- if javamail complainsprotected ChangeItemBean createAttachmentWithPart(javax.mail.Part part, com.atlassian.crowd.embedded.api.User reporter, org.ofbiz.core.entity.GenericValue issue) throws IOException
Part.ATTACHMENT
.
part
- part of disposition Part.ATTACHMENT
to create the attachment fromreporter
- issue reporterissue
- issue to create attachments in
ChangeItemBean
representing the added attachment, or null if no attachment was created
IOException
- If there is a problem creating the attachment in the filesystemprotected String getFilenameForAttachment(javax.mail.Part part) throws javax.mail.MessagingException, IOException
part
- The part being tested.
javax.mail.MessagingException
- relays any MessagingException thrown by a lower layer such as java mail
IOException
- relays any IOExceptionsprotected String renameFileIfInvalid(String filename, org.ofbiz.core.entity.GenericValue issue, com.atlassian.crowd.embedded.api.User reporter)
FileNameCharacterCheckerUtil.replaceInvalidChars(String,
char)
with INVALID_CHAR_REPLACEMENT
as the replacement character.
filename
- filename to check if its validissue
- issue the file is to be attachedreporter
- the author of the comment to add to the issue if the filename is invalid
INVALID_CHAR_REPLACEMENT
protected File getFileFromPart(javax.mail.Part part, String issueKey) throws IOException, javax.mail.MessagingException, org.ofbiz.core.entity.GenericEntityException
IOException
javax.mail.MessagingException
org.ofbiz.core.entity.GenericEntityException
protected com.atlassian.crowd.embedded.api.User getReporter(javax.mail.Message message) throws javax.mail.MessagingException
message
- The email message to search through.
javax.mail.MessagingException
- If there is a problem getting the user who created the message.protected com.atlassian.crowd.embedded.api.User findUserByUsername(String username)
username
- the username.
protected com.atlassian.crowd.embedded.api.User findUserByEmail(String emailAddress)
emailAddress
- the email address to match.
protected com.atlassian.crowd.embedded.api.User createUserForReporter(javax.mail.Message message)
message
- The original e-mail message.
protected String getPrecedenceHeader(javax.mail.Message message) throws javax.mail.MessagingException
message
- message
javax.mail.MessagingException
- in case of extraction of the header failsprotected boolean isDeliveryStatus(javax.mail.Message message) throws javax.mail.MessagingException
javax.mail.MessagingException
protected boolean isAutoSubmitted(javax.mail.Message message) throws javax.mail.MessagingException
javax.mail.MessagingException
protected void recordMessageId(String type, javax.mail.Message message, Long issueId) throws javax.mail.MessagingException
javax.mail.MessagingException
protected org.ofbiz.core.entity.GenericValue getAssociatedIssue(javax.mail.Message message)
public void setMailHandlerExecutionMonitor(MailHandlerExecutionMonitor mailHandlerExecutionMonitor)
setMailHandlerExecutionMonitor
in interface MessageHandler
public void addInfo(String info)
public void addError(String error)
public void addError(String error, Exception e)
protected MailHandlerExecutionMonitor getMailHandlerExecutionMonitor()
protected I18nHelper getI18nBean()
protected boolean isDryRunMode()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |