Skip to content

Commit

Permalink
adding fault tolerance for when there aren't any matches
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Jun 8, 2010
1 parent 21f85fb commit 3b1590e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bodyparts.gemspec
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = %q{bodyparts}
s.version = "0.1.0"
s.version = "0.1.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Max Ogden"]
Expand Down
14 changes: 8 additions & 6 deletions lib/bodyparts.rb
Expand Up @@ -27,11 +27,13 @@ def self.find_reply_in(email)
body = email.body.raw_source
end

matches = []
rules.each {|rule| matches << body.match(rule[:reply_delimiter])}
matches.compact!
match = matches.sort_by {|m| m.begin(0)}.first
new_message = body[0, match.begin(0)]
{:new_message => new_message.strip, :rest_of_thread => body[match.begin(0)..-1].strip}
matches = rules.map {|rule| body.match(rule[:reply_delimiter])}.compact!
unless matches.empty?
match = matches.sort_by {|m| m.begin(0)}.first
new_message = body[0, match.begin(0)]
{:new_message => new_message.strip, :rest_of_thread => body[match.begin(0)..-1].strip}
else
body
end
end
end

0 comments on commit 3b1590e

Please sign in to comment.