From 4b2e9ca9cc87f0d7b7b6a53385cd64e0b70d44a7 Mon Sep 17 00:00:00 2001 From: azumakuniyuki Date: Tue, 9 Jul 2024 22:10:41 +0900 Subject: [PATCH 1/2] Remove Sisimai::Message.load method and related codes #302 --- lib/sisimai/fact.rb | 6 +--- lib/sisimai/message.rb | 71 +++---------------------------------- test/public/message-test.rb | 21 ++--------- 3 files changed, 7 insertions(+), 91 deletions(-) diff --git a/lib/sisimai/fact.rb b/lib/sisimai/fact.rb index 3b72d4d3..1d806eeb 100644 --- a/lib/sisimai/fact.rb +++ b/lib/sisimai/fact.rb @@ -96,8 +96,6 @@ def initialize(argvs) # @options argvs [Boolean] delivered Include the result which has "delivered" reason # @options argvs [Boolean] vacation Include the result which has "vacation" reason # @options argvs [Proc] hook Proc object of callback method - # @options argvs [Array] load User defined MTA module list - # @options argvs [Array] order The order of MTA modules # @options argvs [String] origin Path to the original email file # @return [Array] Array of Sisimai::Fact objects def self.rise(**argvs) @@ -105,9 +103,7 @@ def self.rise(**argvs) return nil unless argvs.is_a? Hash email = argvs[:data]; return nil unless email - loads = argvs[:load] || nil - order = argvs[:order] || nil - args1 = { data: email, hook: argvs[:hook], load: loads, order: order } + args1 = { data: email, hook: argvs[:hook] } mesg1 = Sisimai::Message.rise(**args1) return nil unless mesg1 diff --git a/lib/sisimai/message.rb b/lib/sisimai/message.rb index c4a7d0f3..676e4cb1 100644 --- a/lib/sisimai/message.rb +++ b/lib/sisimai/message.rb @@ -26,8 +26,6 @@ class << self # Read an email message and convert to structured format # @param [Hash] argvs Module to be loaded # @options argvs [String] :data Entire email message - # @options argvs [Array] :load User defined MTA module list - # @options argvs [Array] :order The order of MTA modules # @options argvs [Code] :hook Reference to callback method # @return [Sisimai::Message] Structured email data or nil if each # value of the arguments are missing @@ -37,16 +35,6 @@ def rise(**argvs) thing = { 'from' => '','header' => {}, 'rfc822' => '', 'ds' => [], 'catch' => nil } param = {} - # 0. Load specified MTA modules - [:load, :order].each do |e| - # Order of MTA modules - next unless argvs[e] - next unless argvs[e].is_a? Array - next if argvs[e].empty? - param[e.to_s] = argvs[e] - end - tobeloaded = Sisimai::Message.load(param) - aftersplit = nil beforefact = nil parseagain = 0 @@ -81,7 +69,6 @@ def rise(**argvs) 'hook' => argvs[:hook] || nil, 'mail' => thing, 'body' => aftersplit[2], - 'tobeloaded' => tobeloaded, 'tryonfirst' => Sisimai::Order.make(thing['header']['subject']) } break if beforefact = Sisimai::Message.sift(param) @@ -106,46 +93,7 @@ def rise(**argvs) return thing end - # Load MTA modules which specified at 'order' and 'load' in the argument - # @param [Hash] argvs Module information to be loaded - # @options argvs [Array] load User defined MTA module list - # @options argvs [Array] order The order of MTA modules - # @return [Array] Module list - # @since v4.20.0 - def load(argvs) - modulelist = [] - tobeloaded = [] - - %w[load order].each do |e| - # The order of MTA modules specified by user - next unless argvs[e] - next unless argvs[e].is_a? Array - next if argvs[e].empty? - - modulelist += argvs['order'] if e == 'order' - next unless e == 'load' - - # Load user defined MTA module - argvs['load'].each do |v| - # Load user defined MTA module - begin - require v.to_s.gsub('::', '/').downcase - rescue LoadError - warn ' ***warning: Failed to load ' << v - next - end - tobeloaded << v - end - end - - while e = modulelist.shift do - # Append the custom order of MTA modules - next if tobeloaded.index(e) - tobeloaded << e - end - - return tobeloaded - end + def load(argvs); ' ***warning: Sisimai::Message->load will be removed at v5.1.1'; return []; end # Divide email data up headers and a body part. # @param [String] email Email data @@ -354,7 +302,6 @@ def tidy(argv0 = '') # @param options mail [Array] ds Delivery status list(decoded data) # @param options argvs [String] body Email message body # @param options argvs [Array] tryonfirst MTA module list to load on first - # @param options argvs [Array] tobeloaded User defined MTA module list # @return [Hash] Decoded and structured bounce mails def sift(argvs) return nil unless argvs['mail'] @@ -416,21 +363,11 @@ def sift(argvs) catch :DECODER do while true - # 1. User-Defined Module - # 2. MTA Module Candidates to be tried on first - # 3. Sisimai::Lhost::* - # 4. Sisimai::RFC3464 + # 1. MTA Module Candidates to be tried on first + # 2. Sisimai::Lhost::* + # 3. Sisimai::RFC3464 # 5. Sisimai::ARF # 6. Sisimai::RFC3834 - while r = argvs['tobeloaded'].shift do - # Call user defined MTA modules - next if haveloaded[r] - havesifted = Module.const_get(r).inquire(mailheader, bodystring) - haveloaded[r] = true - modulename = r - throw :DECODER if havesifted - end - [argvs['tryonfirst'], DefaultSet].flatten.each do |r| # Try MTA module candidates next if haveloaded[r] diff --git a/test/public/message-test.rb b/test/public/message-test.rb index 6ca1ed35..2037ce05 100644 --- a/test/public/message-test.rb +++ b/test/public/message-test.rb @@ -2,7 +2,7 @@ require 'sisimai/message' class MessageTest < Minitest::Test - Methods = { class: %w[rise load sift part tidy makemap] } + Methods = { class: %w[rise sift part tidy makemap] } Mailbox = './set-of-emails/mailbox/mbox-0' Fhandle = File.open(Mailbox, 'r') Mailtxt = Fhandle.read; Fhandle.close @@ -78,14 +78,7 @@ def test_rise assert_instance_of Hash, cv['rfc822'] assert_instance_of String, cv['from'] - ca = { - data: Mailtxt, - hook: Lambda1, - order:[ - 'Sisimai::Lhost::Sendmail', 'Sisimai::Lhost::Postfix', 'Sisimai::Lhost::qmail', - 'Sisimai::Lhost::Exchange2003', 'Sisimai::Lhost::Gmail', 'Sisimai::Lhost::Verizon', - ] - } + ca = { data: Mailtxt, hook: Lambda1 } cv = Sisimai::Message.rise(**ca) assert_instance_of Hash, cv assert_instance_of Array, cv['ds'] @@ -121,16 +114,6 @@ def test_rise end end - def test_load - assert_instance_of Array, Sisimai::Message.load('load' => ['Sisimai::Lhost::Postfix'], 'order' => ['Sisimai::Lhost::Postfix']) - assert_instance_of Array, Sisimai::Message.load('load' => {}, 'order' => []) - assert_instance_of Array, Sisimai::Message.load('load' => [], 'order' => {}) - ce = assert_raises ArgumentError do - Sisimai::Message.load() - Sisimai::Message.load(nil, nil) - end - end - def test_tidy cv = Sisimai::Message.tidy(RFC822B) assert_instance_of ::String, cv From 70bcd1cdcffd53ae0fac947f42126dd29ee82eba Mon Sep 17 00:00:00 2001 From: azumakuniyuki Date: Tue, 9 Jul 2024 22:27:44 +0900 Subject: [PATCH 2/2] Update the comment in sift method #302 --- lib/sisimai/message.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sisimai/message.rb b/lib/sisimai/message.rb index 676e4cb1..431f1ba9 100644 --- a/lib/sisimai/message.rb +++ b/lib/sisimai/message.rb @@ -366,8 +366,8 @@ def sift(argvs) # 1. MTA Module Candidates to be tried on first # 2. Sisimai::Lhost::* # 3. Sisimai::RFC3464 - # 5. Sisimai::ARF - # 6. Sisimai::RFC3834 + # 4. Sisimai::ARF + # 5. Sisimai::RFC3834 [argvs['tryonfirst'], DefaultSet].flatten.each do |r| # Try MTA module candidates next if haveloaded[r]