whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Ensure all message has expected CRLF terminators
Date Mon, 11 Feb 2019 21:32:18 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 284f0ae  Ensure all message has expected CRLF terminators
284f0ae is described below

commit 284f0ae81f88787e0e6523ad4a47199d064d6987
Author: Sebb <sebb@apache.org>
AuthorDate: Mon Feb 11 21:32:08 2019 +0000

    Ensure all message has expected CRLF terminators
---
 www/secretary/workbench/models/message.rb | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/www/secretary/workbench/models/message.rb b/www/secretary/workbench/models/message.rb
index b94b2ed..fb19bbb 100644
--- a/www/secretary/workbench/models/message.rb
+++ b/www/secretary/workbench/models/message.rb
@@ -327,22 +327,17 @@ class Message
     Digest::SHA1.hexdigest(getmid(message) || message)[0..9]
   end
 
+  # Matches LF, but not CRLF
+  LF_ONLY = Regexp.new("(?<!\r)\n")
+  CRLF = "\r\n"
+
   #
   # parse a message, returning headers
   #
   def self.parse(message)
-    # cleanup broken header separators.  Avoid copying the possibly large body
-    # unless a fixup is needed.
-    message.sub! /\AFrom .*\r?\n/i, '' if message =~ /^\AFrom /i
-    headers = message[/(.*?)\r?\n\r?\n/m, 1]
-    if headers.include? "\n" and not headers.include? "\r\n"
-      headers, body = message.split(/\r?\n\r?\n/, 2)
-      headers.gsub!("\n", "\r\n")
-      message = "#{headers}\r\n\r\n#{body}"
-    end
 
-    # parse cleaned up message
-    mail = Mail.read_from_string(message)
+    # parse cleaned up message (need to fix every line, not just headers)
+    mail = Mail.read_from_string(message.gsub(LF_ONLY, CRLF))
 
     # parse from address (if it exists)
     from_value = mail[:from].value rescue ''


Mime
View raw message