Skip to content

Commit

Permalink
Merge pull request #303 from sisimai/warn-when-call-sisimai-message-load
Browse files Browse the repository at this point in the history
Remove Sisimai::Message.load method and related codes
  • Loading branch information
azumakuniyuki authored Jul 19, 2024
2 parents d3e1101 + 70bcd1c commit 9df9147
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 93 deletions.
6 changes: 1 addition & 5 deletions lib/sisimai/fact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,14 @@ 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)
return nil unless 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
Expand Down
75 changes: 6 additions & 69 deletions lib/sisimai/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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
# 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

# 1. MTA Module Candidates to be tried on first
# 2. Sisimai::Lhost::*
# 3. Sisimai::RFC3464
# 4. Sisimai::ARF
# 5. Sisimai::RFC3834
[argvs['tryonfirst'], DefaultSet].flatten.each do |r|
# Try MTA module candidates
next if haveloaded[r]
Expand Down
21 changes: 2 additions & 19 deletions test/public/message-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9df9147

Please sign in to comment.