Hey!
I use the ScriptRunner Mail Handler to create new issue from incoming emails:


The script looks like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.exception.CreateException
import com.atlassian.jira.config.util.JiraHome
import com.atlassian.jira.service.services.file.FileService
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageHandlerContext
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.mail.MailUtils
import javax.mail.Message
import javax.mail.internet.InternetAddress
import org.apache.commons.io.FileUtils
final defaultIssueType = 'Task'
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor) as MessageUserProcessor
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.projectManager
def issueFactory = ComponentAccessor.issueFactory
JiraHome jiraHome = ComponentAccessor.getComponent(JiraHome)
def subject = message.subject as String
def getProject = subject.split(' ')[0]
log.warn("Проект пойманный в обработчике - ${getProject}")
def getBody = MailUtils.getBody(message).split("С уважением")
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
log.warn("Данная задача уже имеется, ничего не делаем!")
return
}
def project = projectManager.getProjectObjByKey(getProject)
//def user = userManager.getUserByName(defaultReporterName)
def reporterUser = messageUserProcessor.getAuthorFromSender(message) //?: user
def allCcRecipients = message.getRecipients(Message.RecipientType.CC) as List<InternetAddress>
def firstValidUser = allCcRecipients.findResult {
messageUserProcessor.findUserByEmail(it.address)
}
def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject.split("${getProject}")[1].trim())
issueObject.setDescription(getBody[0].trim())
issueObject.setIssueTypeId(project.issueTypes.find {it.name == defaultIssueType}.id)
issueObject.setReporter(reporterUser)
firstValidUser ?
issueObject.setAssignee(firstValidUser as ApplicationUser) :
log.error('Unable to retrieve valid user from message CC list, issue will be created without assignee')
try {
issue = messageHandlerContext.createIssue(reporterUser, issueObject)
def attachments = MailUtils.getAttachments(message)
def attachmentFileName = ""
attachments.each { MailUtils.Attachment attachment ->
if (attachment.filename.contains("utf_8")) {
attachmentFileName = "MsgAttachment.eml"
} else {
attachmentFileName = attachment.filename
}
def destination = new File(jiraHome.home, FileService.MAIL_DIR).getCanonicalFile()
def file = FileUtils.getFile(destination, attachmentFileName) as File
FileUtils.writeByteArrayToFile(file, attachment.contents)
messageHandlerContext.createAttachment(file, attachment.filename, attachment.contentType, reporterUser, issue)
}
log.warn("Задача ${issue} была успешно создана из обработчика jiratask@ntsmail.ru")
} catch (CreateException e) {
log.error('Error creating issue: ', e)
} catch (NullPointerException npe) {
log.error('Error adding attachments issue: ', npe)
} catch (FileNotFoundException fnfe) {
log.error('The filename, directory name, or volume label syntax is incorrect: ', fnfe)
}
And when creating new issue from emails, I would like to display the attached screenshots in the issue description, since this is displayed in the body of the email.
And it turns out that screenshots are added only to the attachments of the issue, and they disappear from the description itself, which has a bad effect on the context of the issue. Please tell me if there is any way to display screenshots in the task description?
Here is an example of an email being sent:

And here's what the issue looks like:
