From e22296cd08df872e89a94c9ac5ef688f4d9de46d Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Fri, 11 Oct 2024 21:27:35 -0700 Subject: [PATCH] Workaround ruby-list:2840 Fixes #17. --- app/models/message.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/message.rb b/app/models/message.rb index 965160e..6886765 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,6 +1,8 @@ BLADE_BUCKET_REGION = 'ap-northeast-1' BLADE_BUCKET_NAME = 'blade.ruby-lang.org' +require 'kconv' + class Message < ApplicationRecord # Not really sure we will utlize this configuration, # but I don't want to make this column. @@ -19,8 +21,14 @@ def self.from_s3(list_name, list_seq) end def self.from_string(str) - hs, body = str.encode('utf-8', invalid: :replace).split(/\n\n/, 2) - headers = hs.split(/\n/).map { |line| + headers_str, body = str.split(/\n\n/, 2) + + # Not really sure this is from the original email, or while making + # blade.ruby-lang.org's S3 archive, but there are emails without + # a proper Form header, such as ruby-list:2840. + headers_str = Kconv.toutf8(headers_str).gsub(/\r\n/, '') + + headers = headers_str.split(/\n/).map { |line| line.split(/:\s+/, 2) }.to_h