Package com.atlassian.jira.mail.util
Class MailAttachmentsManagerImpl
java.lang.Object
com.atlassian.jira.mail.util.MailAttachmentsManagerImpl
- All Implemented Interfaces:
MailAttachmentsManager
Stateful, created per single email sent to recipient
-
Field Summary
Fields inherited from interface com.atlassian.jira.mail.util.MailAttachmentsManager
CID_PREFIX -
Method Summary
Modifier and TypeMethodDescriptionaddAttachmentAndReturnCid(MailAttachment mailAttachment) Adds an attachment to the mail attachments manager's collection of attachments.Iterable<jakarta.mail.BodyPart> Builds bodyPart for each image (including avatars) added to this managerstatic LongextractAttachmentId(String path) protected StringgetAbsoluteUrl(String path) intReturns the number of attachments added to this managergetAvatarUrl(Avatar avatar, Avatar.Size size, String avatarOwnerDescription) Returns a link to accessAvatar(icon for project or some other entity in Jira) in email message.getAvatarUrl(TemplateUser templateUser) Returns a link to access user avatar in email message.getAvatarUrl(ApplicationUser user) Returns a link to access user avatar in email message.getAvatarUrl(String username) Returns a link to access user avatar in email message.getExternalImageUrl(String path) If the path is a relative url tries to add the image specified as an attachment.getImageUrl(String path) Tries to inline image specified by path and add it to email attachments or add JWT tokengetIssueTypeIconUrl(IssueType issueType) booleanNeeded to attach/or not Use only afterMailAttachmentsManager.inlineImages(String)as it will count found images in rendered html.inlineImages(String html) processImages(String html) - Looks fortags and tries to inline image if it's an internal resource.
removeBaseUrl(String url) Tries to remove the baseUrl (eg: http://example.com/jira) or the basePath (/jira) from an URL, and return the result.static MailAttachmentsManagerImplwithJwtTokens(AvatarService avatarService, AvatarTranscoder avatarTranscoder, UserManager userManager, AvatarManager avatarManager, ApplicationProperties applicationProperties, ImageAttachmentJwtTokenService imageAttachmentJwtTokenService, ImageAttachmentAltAttributeService imageAttachmentAltAttributeService, String recipientUserName, AttachmentManager attachmentManager, ThumbnailManager thumbnailManager) Created this way it will try to add JWT tokens to secured image paths.static MailAttachmentsManagerImplwithoutJwtTokens(AvatarService avatarService, AvatarTranscoder avatarTranscoder, UserManager userManager, AvatarManager avatarManager, ApplicationProperties applicationProperties, ImageAttachmentJwtTokenService imageAttachmentJwtTokenService, ImageAttachmentAltAttributeService imageAttachmentAltAttributeService, AttachmentManager attachmentManager, ThumbnailManager thumbnailManager) Created this way it won't try to add JWT tokens to secured image paths.
-
Method Details
-
withoutJwtTokens
public static MailAttachmentsManagerImpl withoutJwtTokens(AvatarService avatarService, AvatarTranscoder avatarTranscoder, UserManager userManager, AvatarManager avatarManager, ApplicationProperties applicationProperties, ImageAttachmentJwtTokenService imageAttachmentJwtTokenService, ImageAttachmentAltAttributeService imageAttachmentAltAttributeService, AttachmentManager attachmentManager, ThumbnailManager thumbnailManager) Created this way it won't try to add JWT tokens to secured image paths. Only internal resources will be inlined with src='cid:...' and displayed in emails. -
withJwtTokens
public static MailAttachmentsManagerImpl withJwtTokens(AvatarService avatarService, AvatarTranscoder avatarTranscoder, UserManager userManager, AvatarManager avatarManager, ApplicationProperties applicationProperties, ImageAttachmentJwtTokenService imageAttachmentJwtTokenService, ImageAttachmentAltAttributeService imageAttachmentAltAttributeService, String recipientUserName, AttachmentManager attachmentManager, ThumbnailManager thumbnailManager) Created this way it will try to add JWT tokens to secured image paths. Internal resources will be inlined with scr='cid:...' and displayed in emails. Image attachments starting with /secured/ will have JWT token parameter added to the -
getAvatarUrl
Description copied from interface:MailAttachmentsManagerReturns a link to access user avatar in email message. If avatar can be attached to email, the cid link is returned, otherwise avatar URL is returned and no image is attached. (E.g. If Gravatar is enabled)- Specified by:
getAvatarUrlin interfaceMailAttachmentsManager- Parameters:
username-- Returns:
- cid link or Avatar URL
-
getAvatarUrl
Description copied from interface:MailAttachmentsManagerReturns a link to access user avatar in email message. If avatar can be attached to email, the cid link is returned, otherwise avatar URL is returned and no image is attached. (E.g. If Gravatar is enabled)- Specified by:
getAvatarUrlin interfaceMailAttachmentsManager- Parameters:
templateUser-- Returns:
- cid link or Avatar URL
-
getAvatarUrl
Description copied from interface:MailAttachmentsManagerReturns a link to access user avatar in email message. If avatar can be attached to email, the cid link is returned, otherwise avatar URL is returned and no image is attached. (E.g. If Gravatar is enabled)- Specified by:
getAvatarUrlin interfaceMailAttachmentsManager- Parameters:
user-- Returns:
- cid link or Avatar URL
-
getAvatarUrl
public String getAvatarUrl(@Nonnull Avatar avatar, @Nonnull Avatar.Size size, String avatarOwnerDescription) Description copied from interface:MailAttachmentsManagerReturns a link to accessAvatar(icon for project or some other entity in Jira) in email message.- Specified by:
getAvatarUrlin interfaceMailAttachmentsManager- Parameters:
avatar-Avatarto display in emailsize- avatar sizeavatarOwnerDescription- Description of avatar- Returns:
- cid link
-
getIssueTypeIconUrl
-
addAttachmentAndReturnCid
Description copied from interface:MailAttachmentsManagerAdds an attachment to the mail attachments manager's collection of attachments. This collection will eventually be attached to the email. This method will return a CID that can be used to reference the attachment in the body of an email. Given the same mail attachment multiple times, this method will return the same CID.- Specified by:
addAttachmentAndReturnCidin interfaceMailAttachmentsManager- Parameters:
mailAttachment-- Returns:
- The CID for an attachment
-
extractAttachmentId
-
getImageUrl
Description copied from interface:MailAttachmentsManagerTries to inline image specified by path and add it to email attachments or add JWT token- Specified by:
getImageUrlin interfaceMailAttachmentsManager- Parameters:
path-- Returns:
- image cid link if it's an internal resource
- image link appended with JWT token if it's /secure/thumbnail/* or /secure/attachment/*
- unchanged otherwise
-
processImages
Description copied from interface:MailAttachmentsManager- Looks for
tags and tries to inline image if it's an internal resource. Otherwise adds JWT token for every /secure/* image or leaves unchanged for other paths.
- Counts how many images there are that start with /secure/* so
MailAttachmentsManager.hasSecuredImage()can calculate the result needed to construct email footer- Adds default 'alt' attribute which is an attachment file name in case img has none
- Specified by:
processImagesin interfaceMailAttachmentsManager- Parameters:
html- HTML to change.- Returns:
- The same HTML with the images inlined or JWT tokens parameter added to images' src attribute.
-
inlineImages
- Specified by:
inlineImagesin interfaceMailAttachmentsManager
-
hasSecuredImage
public boolean hasSecuredImage()Description copied from interface:MailAttachmentsManagerNeeded to attach/or not Use only afterMailAttachmentsManager.inlineImages(String)as it will count found images in rendered html.- Specified by:
hasSecuredImagein interfaceMailAttachmentsManager- Returns:
- true when there is at least one image with contains /secure/* as src found in html
-
removeBaseUrl
Description copied from interface:MailAttachmentsManagerTries to remove the baseUrl (eg: http://example.com/jira) or the basePath (/jira) from an URL, and return the result. Some quick examples (let's assume baseUrl = http://example.com/jira)- http://example.com/jira/images/icon.png --> /images/icon.png
- /jira/images/icon.png --> /images/icon.png
- /images/icon.png --> /images/icon.png
- http://example.com/test/images/icon.png --> http://example.com/test/images/icon.png
- http://google.com/jira/images/icon.png --> http://google.com/jira/images/icon.png
- Specified by:
removeBaseUrlin interfaceMailAttachmentsManager- Parameters:
url- the url to remove the baseUrl from- Returns:
- the url without the baseUrl nor the basePath
-
getExternalImageUrl
Description copied from interface:MailAttachmentsManagerIf the path is a relative url tries to add the image specified as an attachment. Returns a cid link if successful, or unchanged path if not- Specified by:
getExternalImageUrlin interfaceMailAttachmentsManager
-
getAbsoluteUrl
-
getAttachmentsCount
public int getAttachmentsCount()Description copied from interface:MailAttachmentsManagerReturns the number of attachments added to this manager- Specified by:
getAttachmentsCountin interfaceMailAttachmentsManager- Returns:
- number of attachments
-
buildAttachmentsBodyParts
Description copied from interface:MailAttachmentsManagerBuilds bodyPart for each image (including avatars) added to this manager- Specified by:
buildAttachmentsBodyPartsin interfaceMailAttachmentsManager- Returns:
- Added attachments as list of BodyParts
-