* [sup-devel] Message parsing fixes
@ 2011-02-17 14:44 Gaudenz Steinlin
0 siblings, 0 replies; only message in thread
From: Gaudenz Steinlin @ 2011-02-17 14:44 UTC (permalink / raw)
To: sup-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 268 bytes --]
Hi
While reimporting all my messages to recreate the index I fixed a few
message parsing issues. Please consider the attached patches against
master.
Gaudenz
--
Ever tried. Ever failed. No matter.
Try again. Fail again. Fail better.
~ Samuel Beckett ~
[-- Attachment #1.1.2: 0001-Don-t-normalize_whitespace-message-rfc822-parts.patch --]
[-- Type: application/octet-stream, Size: 1132 bytes --]
From e802cdf5c960bbffb1ba2ae0f70a21f364657c5d Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:33:11 +0100
Subject: [PATCH 1/2] Don't normalize_whitespace message/rfc822 parts
Currently whitespace normalization is done on the whole message
including headers and before setting the correct encoding. This causes
exceptions on ruby 1.9 for non ASCII messages.
These part's are recursively parsed as normal messages later on.
Whitespace normalization is then done on the body. This should be
enough.
---
lib/sup/message.rb | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 66745ca..a6216b5 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -443,7 +443,6 @@ private
else
raise RMail::EncodingUnsupportedError, encoding.inspect
end
- body = body.normalize_whitespace
payload = RMail::Parser.read(body)
from = payload.header.from.first ? payload.header.from.first.format : ""
to = payload.header.to.map { |p| p.format }.join(", ")
--
1.7.2.3
[-- Attachment #1.1.3: 0002-Be-more-cautious-about-invalid-content-type-headers.patch --]
[-- Type: application/octet-stream, Size: 1526 bytes --]
From 6af787dd9cbac810d20e9fb66277749da927e915 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:36:27 +0100
Subject: [PATCH 2/2] Be more cautious about invalid content-type headers
The original RMail code calls value.strip.split(/\s*;\s*/)[0].downcase
without checking if split returned an element. This monkey patches the
relevant function for sup to catch this error.
---
lib/sup/util.rb | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 45dec3b..1444100 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -111,6 +111,31 @@ module RMail
# end
end
end
+
+ class Header
+ ## Be more cautious about invalid content-type headers
+ ## the original RMail code calls
+ ## value.strip.split(/\s*;\s*/)[0].downcase
+ ## without checking if split returned an element
+
+ # This returns the full content type of this message converted to
+ # lower case.
+ #
+ # If there is no content type header, returns the passed block is
+ # executed and its return value is returned. If no block is passed,
+ # the value of the +default+ argument is returned.
+ def content_type(default = nil)
+ if value = self['content-type'] and ct = value.strip.split(/\s*;\s*/)[0]
+ return ct.downcase
+ else
+ if block_given?
+ yield
+ else
+ default
+ end
+ end
+ end
+ end
end
class Range
--
1.7.2.3
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 482 bytes --]
[-- Attachment #2: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-02-17 14:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-17 14:44 [sup-devel] Message parsing fixes Gaudenz Steinlin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox