I made a scriptrunner mail handler to create issues when sent to mail. My client requested to replace the * in desciption to "¤" character so before setting the description of the issue I just used String x=MailUtils.getBody(message).replace('*', '¤') and passed x in issueobject.setDescription(x). Now the stars are getting replaced with ¤ but the line breaks are not preserved . How to get the line breaks and replace the character at the same time.
Thanks in advance.
Hi @tapraj
Where exactly do you want the line breakers?
Could you share a dummy message where you want to modify the asterisk to the ¤ symbol?
Thank you and Kind regards,
Ram
Hi Ram,
Thank You for responding. The issue got resolved.
one of the two resolved the issue I am not sure which one exactly though.
1. I was previously using Outlook Web to send the mails to the mail handler
switching to Outlook Desktop application resolved the problem
2. I was using replaceAll(regex,string) to convert * to ¤ symbol
Switched to replace('*','¤ ')
Expected:
**********************************
*SYSTEMFEHLER-000022: BATCH-MODUL*
**********************************
...ZEITSTEMPEL:...... 19102020211141
...INT.OPERATION:.... U103-DATEI-NACH-DS
F050 Fehler in Datei: S00524019390110004447070059247
*****************************************
*****ENDE.DES.SYSTEMFEHLERPROTOKOLLS*****
*****************************************
Generated:
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ¤SYSTEMFEHLER-000011: BATCH-MODUL¤ ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ...ZEITSTEMPEL:...... 19042021094915 ...MODULHOSTNAME:.... S1617066 ZEILE-5:.. ..........................................................F7AG Das ausgewählte Freigabeobjekt kann nicht mehr bearbeitet werden. ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ¤¤¤¤¤ENDE.DES.SYSTEMFEHLERPROTOKOLLS¤¤¤¤¤ ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
was generating the description like this :
Regards,
Tejasvini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @tapraj,
I have tested out the dummy mail with this code below, and it seems to be working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.exception.CreateException
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.mail.MailUtils
import javax.mail.Message
import javax.mail.internet.InternetAddress
final targetProjectKey = "SAM"
final defaultReporterName = "admin"
final defaultIssueType = "Story"
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor) as MessageUserProcessor
def userManager = ComponentAccessor.userManager
def projectManager = ComponentAccessor.projectManager
def issueFactory = ComponentAccessor.issueFactory
def subject = message.subject as String
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
return
}
def project = projectManager.getProjectObjByKey(targetProjectKey)
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 messageBody = MailUtils.getBody(message).replace("*","¤")
def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(messageBody)
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 {
(messageHandlerContext as MessageHandlerContext).createIssue(user, issueObject)
} catch (CreateException e) {
log.error "Error creating issue: ", e
}
In my sample code, I am using:-
def messageBody = MailUtils.getBody(message).replace("*","¤")
and it seems to be working.
Below is the output it produced:-
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.