Advertisement
Guest User

Untitled

a guest
Aug 28th, 2018
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. import com.atlassian.jira.component.ComponentAccessor
  2. import com.atlassian.jira.event.type.EventDispatchOption
  3. import com.atlassian.jira.issue.MutableIssue
  4. import com.atlassian.jira.user.ApplicationUser
  5.  
  6. String issueDescription = event.issue.description
  7. ApplicationUser actor = ComponentAccessor.userManager.getUserByName("automation-agent")
  8.  
  9. if (issueDescription ==~ /(?siu).*(?:\{color:[#a-z0-9]+}|\{color}).*/) {
  10. def regexEmptySpaces = /(?siu)(?:\{color:[#a-z0-9]+}|\{color}|[ \p{Zs}]+)*/
  11. def regexEmptyLines = /(?siu)(?:\{color:[#a-z0-9]+}|\{color}|[\s\p{Z}]+)+/
  12. def regexEmailSignatureLogo = /(?<=[\r\n])/ + regexEmptySpaces + /!(?:/ +
  13. /image[0-9]+\.[a-z]+(?:\|thumbnail)?/ +
  14. /|https?:\/\/mail\.stoloto\.ru\/res\/StolotoCJSC\.png/ +
  15. /)!/ + regexEmptySpaces + /(?:[\r\n]{1,2}|\p{Z}|$)/
  16.  
  17.  
  18. def regexEmailSignatures = [
  19. stoloto: (/(?siu)(?<=[\r\n])/ + regexEmptyLines +
  20. /(?:\[\{color:[#a-z0-9]+\})?(?:–{3,}|-{3,}|_{3,}|\>{2,})[\s\p{Z}]*С уважением/ +
  21. /.*?\[/ + regexEmptySpaces + /www\.stoloto\.ru/ + regexEmptySpaces +
  22. /\|https?:\/\/www\.stoloto\.ru\/?\]/ + regexEmptyLines +
  23. /(?:/ + regexEmailSignatureLogo + /)?(?=[\r\n])/),
  24. ]
  25. for (regexp in regexEmailSignatures) {
  26. issueDescription = issueDescription.replaceAll(regexp.value, "")
  27. }
  28.  
  29. def regexMessageHistoryQuote = /(?siu)(?:/ +
  30. /\{quote}.*\{quote}/ +
  31. /|[\r\n]+\|\{color:[#a-z0-9]+}.*jira-generated-image-avatar.*Atlassian logo\{color:[#a-z0-9]+}.*\{color}\|/ + regexEmptyLines +
  32. /|\{color:[#a-z0-9]+}—-—-—-—\{color}.*\|https:\/\/jira\.stoloto\.ru\/servicedesk\/customer\/portals]/ + regexEmptyLines +
  33. /|\{color:[#a-z0-9]+}—-—-—-—\{color}.*(?:jira-generated-image-static-information-|jira-generated-image-avatar-).*/ +
  34. /)/
  35.  
  36. issueDescription = issueDescription.replaceAll(regexMessageHistoryQuote, '')
  37.  
  38. def regexEmailHeader = /(?siu)(?<=[\r\n])/ + regexEmptyLines +
  39. /[\s*]+?(?:from|от|отправитель)(?:\([a-zа-я]\))?:\*?([^\r\n]*)[\r\n]+/ +
  40. /(?:[\s*]+?(?:sent|отправлено|to|кому|получатель|cc|копия|bcc|скрытая(?: копия)?)(?:\([a-zа-я]\))?:\*?[^\r\n]*[\r\n]+)+/ +
  41. /[\s*]+?(?:subject|тема)(?:\([a-zа-я]\))?:\*?[^\r\n]*/ +
  42. regexEmptyLines + /(?=[\r\n]|$)/
  43.  
  44. issueDescription = issueDescription.replaceAll(regexEmailHeader + /(?=$)/, "")
  45. issueDescription = issueDescription.replaceAll(
  46. regexEmailHeader + /(?:/ + regexEmptyLines + /|/ + regexEmailSignatureLogo + /)+(?=[\r\n]{1,2}|$)/, ""
  47. )
  48. issueDescription = issueDescription.replaceAll(regexEmailHeader, "<hr />{color:skyblue}\$1{color}\n")
  49. issueDescription = issueDescription.replaceAll(/^/ + regexEmptyLines, '')
  50. issueDescription = issueDescription.replaceAll(/(?siu)(?:\{color:[#a-z0-9]+}|\{color}|----|[\s\p{Z}]+)+$/, '')
  51. } else if (issueDescription ==~ /(?siu).*(?:<p><font color="[#a-z0-9]+">.*?<\/font><\/p>).*/) {
  52. def regexEmptySpaces = /(?siu)(?:/ +
  53. /<p><font color="[#a-z0-9]+"><\/font><\/p>/ +
  54. /|<p><font color="[#a-z0-9]+">&nbsp;<\/font><\/p>/ +
  55. /|<p><\/p>/ +
  56. /|<p>&nbsp;<\/p>/ +
  57. /)*/
  58.  
  59. def regexEmptyLines = /(?siu)(?:/ +
  60. /<p><font color="[#a-z0-9]+"><\/font><\/p>/ +
  61. /|<p><font color="[#a-z0-9]+">&nbsp;<\/font><\/p>/ +
  62. /|<p><\/p>/ +
  63. /|<p>&nbsp;<\/p>/ +
  64. /|(?<=[\r\n])(?:/ + regexEmptySpaces + /|[ \p{Zs}])*<br(?: \/)?>(?:/ + regexEmptySpaces + /|[ \p{Zs}])*(?=[\r\n])/ +
  65. /)*/
  66.  
  67.  
  68. def regexEmailSignatures = [
  69. stoloto: (/(?siu)\<p\>\<font\ color\=\"[#a-z0-9]+\"\>(?:–{3,}|-{3,}|_{3,}|\>{2,})\<br(?:\ \/)?\>/ +
  70. /[\ \r\n]*С уважением,\<br(?:\ \/)?\>/ +
  71. /.*?\<\/p\>/),
  72. ]
  73. for (regexp in regexEmailSignatures) {
  74. issueDescription = issueDescription.replaceAll(regexp.value, "")
  75. }
  76.  
  77. def regexEmailHeader = /(?siu)<p>(?:<br(?: \/)?>)?/ +
  78. /[ \r\n]*(?:<b>)?(?:from|от|отправитель)(?:\([a-zа-я]\))?:(?:<b>)?([^\r\n]*?)<br(?: \/)?>/ +
  79. /(?:[ \r\n]*(?:<b>)?(?:sent|отправлено|to|кому|получатель|cc|копия|bcc|скрытая(?: копия)?)(?:\([a-zа-я]\))?:(?:<b>)?[^\r\n]*?<br(?: \/)?>)+/ +
  80. /[ \r\n]*(?:<b>)?(?:subject|тема)(?:\([a-zа-я]\))?:(?:<b>)?[^\r\n]*?/ +
  81. /<\/p>/
  82.  
  83. issueDescription = issueDescription.replaceAll(regexEmptyLines, "")
  84. issueDescription = issueDescription.replaceAll(regexEmailHeader + /(?=$)/, "")
  85. issueDescription = issueDescription.replaceAll(regexEmailHeader, "<br><hr /><p style=\"color: skyBlue;\">\$1</p>")
  86. } else {
  87. log.warn('@TODO: Simple Text - develop handler')
  88. }
  89. MutableIssue mutableIssue = event.issue as MutableIssue
  90. mutableIssue.description = issueDescription
  91.  
  92. ComponentAccessor.issueManager.updateIssue(actor, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement