mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: convert plain text emails to markdown
This commit is contained in:
@ -104,30 +104,19 @@ module ImportScripts::Mbox
|
||||
id: row['msg_id'],
|
||||
user_id: user_id,
|
||||
created_at: to_time(row['email_date']),
|
||||
raw: format_raw(row['body'], attachment_html, row['elided'], row['format']),
|
||||
raw: format_raw(row['body'], attachment_html, row['elided']),
|
||||
raw_email: row['raw_message'],
|
||||
via_email: true,
|
||||
cook_method: Post.cook_methods[:email],
|
||||
post_create_action: proc do |post|
|
||||
create_incoming_email(post, row)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def format_raw(email_body, attachment_html, elided, format)
|
||||
email_body ||= ''
|
||||
|
||||
case format
|
||||
when Email::Receiver::formats[:markdown]
|
||||
body = email_body
|
||||
body << attachment_html if attachment_html.present?
|
||||
body << Email::Receiver.elided_html(elided) if elided.present?
|
||||
when Email::Receiver::formats[:plaintext]
|
||||
body = %|[plaintext]\n#{escape_tags(email_body)}\n[/plaintext]|
|
||||
body << %|\n[attachments]\n#{escape_tags(attachment_html)}\n[/attachments]| if attachment_html.present?
|
||||
body << %|\n[elided]\n#{escape_tags(elided)}\n[/elided]| if elided.present?
|
||||
end
|
||||
|
||||
def format_raw(email_body, attachment_html, elided)
|
||||
body = email_body || ''
|
||||
body << attachment_html if attachment_html.present?
|
||||
body << Email::Receiver.elided_html(elided) if elided.present?
|
||||
body
|
||||
end
|
||||
|
||||
|
@ -163,7 +163,7 @@ module ImportScripts::Mbox
|
||||
end
|
||||
|
||||
def read_mail_from_string(raw_message)
|
||||
Email::Receiver.new(raw_message) unless raw_message.blank?
|
||||
Email::Receiver.new(raw_message, convert_plaintext: true) unless raw_message.blank?
|
||||
end
|
||||
|
||||
def extract_reply_message_ids(mail)
|
||||
|
Reference in New Issue
Block a user