Skip to content

Commit

Permalink
Merge pull request #222 from sisimai/make-vacation-optional
Browse files Browse the repository at this point in the history
Beginning v5.0.0, sisimai does not return the result which reason is …
  • Loading branch information
azumakuniyuki authored May 4, 2021
2 parents eec6bb4 + 3543e81 commit 9704cb5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README-JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ v = Sisimai.rise(f.read)
# method like the following:
v = Sisimai.rise('/path/to/mbox', delivered: true)

# Beginning with v5.0.0, sisimai does not return the reulst which "reason" is "vaction" by default.
# If you want to get bounce records which reason is "vacation", set "vacation" option to rise()
# method like the following:
v = Sisimai.rise('/path/to/mbox', vacation: true);

if v.is_a? Array
v.each do |e|
puts e.class # Sisimai::Data
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ v = Sisimai.rise(f.read)
# method like the following:
v = Sisimai.rise('/path/to/mbox', delivered: true)

# Beginning with v5.0.0, sisimai does not return the reulst which "reason" is "vaction" by default.
# If you want to get bounce records which reason is "vacation", set "vacation" option to rise()
# method like the following:
v = Sisimai.rise('/path/to/mbox', vacation: true );

if v.is_a? Array
v.each do |e|
puts e.class # Sisimai::Data
Expand Down
4 changes: 3 additions & 1 deletion lib/sisimai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def make(argv0, **argv1)
# @param [IO] argv0 or STDIN object
# @param [Hash] argv1 Parser options(delivered=false)
# @options argv1 [Boolean] delivered true: Include "delivered" reason
# @options argv1 [Boolean] vacation true: Include "vacation" reason
# @options argv1 [Array] c___ Proc object to a callback method for the message and each file
# @return [Array] Parsed objects
# @return [nil] nil if the argument was wrong or an empty array
Expand All @@ -34,7 +35,7 @@ def rise(argv0, **argv1)
while r = mail.data.read do
# Read and parse each email file
path = mail.data.path
args = { data: r, hook: c___[0], origin: path, delivered: argv1[:delivered] }
args = { data: r, hook: c___[0], origin: path, delivered: argv1[:delivered], vacation: argv1[:vacation] }
fact = Sisimai::Fact.rise(**args) || []

if c___[1]
Expand All @@ -61,6 +62,7 @@ def rise(argv0, **argv1)
# @param [IO] argv0 or STDIN object
# @param [Hash] argv1 Parser options
# @options argv1 [Integer] delivered true: Include "delivered" reason
# @options argv1 [Integer] vacation true: Include "vacation" reason
# @options argv1 [Lambda] hook Lambda object to be called back
# @return [String] Parsed data as JSON text
def dump(argv0, **argv1)
Expand Down
6 changes: 6 additions & 0 deletions lib/sisimai/fact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def initialize(argvs)
# @param [Hash] argvs
# @options argvs [String] data Entire email message
# @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
Expand Down Expand Up @@ -130,6 +131,11 @@ def self.rise(**argvs)
next if p['deliverystatus'].start_with?('2.')
end

unless argvs[:vacation]
# Skip if the value of "reason" is "vacation"
next if p['reason'] == 'vacation'
end

# EMAILADDRESS: Detect email address from message/rfc822 part
RFC822Head[:addresser].each do |f|
# Check each header in message/rfc822 part
Expand Down
2 changes: 1 addition & 1 deletion test/public/lhost-code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def enginetest(enginename = nil, isexpected = {}, privateset = false, onlydebugs

while r = mailobject.data.read do
# Read messages in each email
listoffact = Sisimai::Fact.rise(data: r, delivered: true, origin: cf)
listoffact = Sisimai::Fact.rise(data: r, delivered: true, vacation: true, origin: cf)

unless listoffact
if privateset
Expand Down

0 comments on commit 9704cb5

Please sign in to comment.