FEATURE: convert plain text emails to markdown

This commit is contained in:
Gerhard Schlager
2017-12-06 01:47:31 +01:00
parent 75463e5a91
commit 16738cfb1b
7 changed files with 419 additions and 24 deletions

View File

@ -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

View File

@ -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)