summaryrefslogtreecommitdiff
path: root/lib/gitlab/email
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/email')
-rw-r--r--lib/gitlab/email/common.rb4
-rw-r--r--lib/gitlab/email/handler/create_issue_handler.rb2
-rw-r--r--lib/gitlab/email/handler/service_desk_handler.rb2
-rw-r--r--lib/gitlab/email/html_parser.rb9
-rw-r--r--lib/gitlab/email/html_to_markdown_parser.rb29
-rw-r--r--lib/gitlab/email/message/in_product_marketing/create.rb8
6 files changed, 44 insertions, 10 deletions
diff --git a/lib/gitlab/email/common.rb b/lib/gitlab/email/common.rb
index afee8d9cd3d..01316995c4d 100644
--- a/lib/gitlab/email/common.rb
+++ b/lib/gitlab/email/common.rb
@@ -54,6 +54,10 @@ module Gitlab
# It's looking for each <...>
references.scan(/(?!<)[^<>]+(?=>)/)
end
+
+ def encrypted_secrets
+ Settings.encrypted(config.encrypted_secret_file)
+ end
end
end
end
diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb
index e21a88c4e0d..c325112b673 100644
--- a/lib/gitlab/email/handler/create_issue_handler.rb
+++ b/lib/gitlab/email/handler/create_issue_handler.rb
@@ -62,7 +62,7 @@ module Gitlab
def create_issue
::Issues::CreateService.new(
- project: project,
+ container: project,
current_user: author,
params: {
title: mail.subject,
diff --git a/lib/gitlab/email/handler/service_desk_handler.rb b/lib/gitlab/email/handler/service_desk_handler.rb
index 06365296a76..076ba42daac 100644
--- a/lib/gitlab/email/handler/service_desk_handler.rb
+++ b/lib/gitlab/email/handler/service_desk_handler.rb
@@ -92,7 +92,7 @@ module Gitlab
def create_issue!
result = ::Issues::CreateService.new(
- project: project,
+ container: project,
current_user: User.support_bot,
params: {
title: mail.subject,
diff --git a/lib/gitlab/email/html_parser.rb b/lib/gitlab/email/html_parser.rb
index 27ba5d2a314..10dbedbb464 100644
--- a/lib/gitlab/email/html_parser.rb
+++ b/lib/gitlab/email/html_parser.rb
@@ -18,9 +18,6 @@ module Gitlab
end
def filter_replies!
- document.xpath('//blockquote').each(&:remove)
- document.xpath('//table').each(&:remove)
-
# bogus links with no href are sometimes added by outlook,
# and can result in Html2Text adding extra square brackets
# to the text, so we unwrap them here.
@@ -37,7 +34,11 @@ module Gitlab
end
def filtered_text
- @filtered_text ||= Html2Text.convert(filtered_html)
+ @filtered_text ||= if Feature.enabled?(:service_desk_html_to_text_email_handler)
+ ::Gitlab::Email::HtmlToMarkdownParser.convert(filtered_html)
+ else
+ Html2Text.convert(filtered_html)
+ end
end
end
end
diff --git a/lib/gitlab/email/html_to_markdown_parser.rb b/lib/gitlab/email/html_to_markdown_parser.rb
new file mode 100644
index 00000000000..42dd012308b
--- /dev/null
+++ b/lib/gitlab/email/html_to_markdown_parser.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'nokogiri'
+
+module Gitlab
+ module Email
+ class HtmlToMarkdownParser < Html2Text
+ ADDITIONAL_TAGS = %w[em strong img details].freeze
+ IMG_ATTRS = %w[alt src].freeze
+
+ def self.convert(html)
+ html = fix_newlines(replace_entities(html))
+ doc = Nokogiri::HTML(html)
+
+ HtmlToMarkdownParser.new(doc).convert
+ end
+
+ def iterate_over(node)
+ return super unless ADDITIONAL_TAGS.include?(node.name)
+
+ if node.name == 'img'
+ node.keys.each { |key| node.remove_attribute(key) unless IMG_ATTRS.include?(key) } # rubocop:disable Style/HashEachMethods
+ end
+
+ Kramdown::Document.new(node.to_html, input: 'html').to_commonmark
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/email/message/in_product_marketing/create.rb b/lib/gitlab/email/message/in_product_marketing/create.rb
index 6b01c83b8e7..68f9a9a21c9 100644
--- a/lib/gitlab/email/message/in_product_marketing/create.rb
+++ b/lib/gitlab/email/message/in_product_marketing/create.rb
@@ -68,7 +68,7 @@ module Gitlab
private
def project_link
- link(s_('InProductMarketing|create a project'), help_page_url('gitlab-basics/create-project'))
+ link(s_('InProductMarketing|create a project'), help_page_url('user/project/index'))
end
def repo_link
@@ -76,7 +76,7 @@ module Gitlab
end
def github_link
- link(s_('InProductMarketing|GitHub Enterprise projects to GitLab'), help_page_url('integration/github'))
+ link(s_('InProductMarketing|GitHub Enterprise projects to GitLab'), help_page_url('user/project/import/github'))
end
def bitbucket_link
@@ -84,11 +84,11 @@ module Gitlab
end
def mirroring_link
- link(s_('InProductMarketing|repository mirroring'), help_page_url('user/project/repository/repository_mirroring'))
+ link(s_('InProductMarketing|repository mirroring'), help_page_url('user/project/repository/mirror/index'))
end
def basics_link
- link(s_('InProductMarketing|Git basics'), help_page_url('gitlab-basics/index'))
+ link(s_('InProductMarketing|Git basics'), help_page_url('topics/git/index'))
end
def import_link