From 68cde90954765be0471c71dfb8bda5fbf1e0a36e Mon Sep 17 00:00:00 2001 From: Dominik Menke Date: Tue, 6 Feb 2024 17:24:50 +0100 Subject: [PATCH] update to Sisimai 5.0.0 --- Gemfile | 2 +- Gemfile.lock | 28 ++++++++++++++-------------- app.rb | 2 ++ lib/classifier.rb | 19 +++++++++++++------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 1c35f09..e07e3bd 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" git_source(:github) { |name| "https://github.com/#{name}.git" } gem "sinatra" -gem "sisimai", github: "sisimai/rb-sisimai", ref: "v4.25.16p1" +gem "sisimai", github: "sisimai/rb-sisimai", ref: "v5.0.0" gem "webrick" group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 34533aa..83d559b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: https://github.com/sisimai/rb-sisimai.git - revision: 7d972e18862ab2c07a181e2839b4e78505d9d2c8 - ref: v4.25.16p1 + revision: cd166bcb59b5929fa75d33df22fd0896f33e3eb2 + ref: v5.0.0 specs: - sisimai (4.25.16p1) + sisimai (5.0.0) oj (>= 3.0.0) GEM @@ -33,19 +33,19 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.1) + rspec-support (~> 3.13.0) + rspec-support (3.13.0) ruby2_keywords (0.0.5) sinatra (4.0.0) mustermann (~> 3.0) diff --git a/app.rb b/app.rb index ad3e622..9b40be2 100644 --- a/app.rb +++ b/app.rb @@ -1,4 +1,6 @@ require "sinatra" +require "sisimai" +require "sisimai/fact" require "oj" require_relative "lib/classifier" diff --git a/lib/classifier.rb b/lib/classifier.rb index d1b62dd..2a88fe2 100644 --- a/lib/classifier.rb +++ b/lib/classifier.rb @@ -1,11 +1,18 @@ require "sisimai" -require "sisimai/data" -require "sisimai/message" +require "sisimai/fact" def classify(message) - msg = Sisimai::Message.new(data: message) - return if msg.void + fact = Sisimai::Fact.rise(data: message, vacation: true, delivered: true)&.first + return unless fact - result = Sisimai::Data.make(data: msg, origin: "") - return result[0] + fact.damn.merge("softbounce" => to_softbounce(fact)) +end + +# Sisimai::Fact has deprecated and will remove #softbounce in v5.1.0. +# For backward compatibility we'll keep it though. +def to_softbounce(fact) + return 0 if fact.hardbounce + return -1 if %w[delivered feedback vacation].include?(fact.reason) + + 1 end