Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sisimai::Fact and Updates on Sisimai::Message #420

Merged
merged 93 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
c4d4e7d
Remove unused method Sisimai::Address->new
azumakuniyuki Nov 26, 2020
2ad74f4
Method name changed: make() => rise()
azumakuniyuki Nov 26, 2020
998fb1d
Tiny code updates
azumakuniyuki Nov 26, 2020
7d14b7d
Tiny code updates
azumakuniyuki Nov 26, 2020
01ad479
Tiny code updates
azumakuniyuki Nov 26, 2020
4c1529c
The method name of the constructor is "new()"
azumakuniyuki Nov 27, 2020
65de2d2
@aol ??: Remove "@" from all the hostname
azumakuniyuki Dec 1, 2020
c8e41ca
Remove angle brackets from an email address at new()
azumakuniyuki Dec 1, 2020
02c0e8f
Add code for detecting fields defined in RFC3464
azumakuniyuki Dec 1, 2020
0ad1cac
Check ":" in the end of the recipient address (do not capture)
azumakuniyuki Dec 1, 2020
5c15117
Tiny code improvement: variable name
azumakuniyuki Dec 1, 2020
954e486
Code improvement for setting the value of "lhost": do not set an emai…
azumakuniyuki Dec 1, 2020
e22c927
Code improvement for detecting SMTP reply code
azumakuniyuki Dec 1, 2020
091edf5
Call Sisimai::Address->s3s4 for a recipient address
azumakuniyuki Dec 1, 2020
4480f9e
Fix code for removing leading and trailing characters
azumakuniyuki Dec 2, 2020
2006c7e
Fix date string
azumakuniyuki Dec 2, 2020
2f1477a
Fix date string
azumakuniyuki Dec 2, 2020
da21fc0
Code improvement for converting a full month name, a full day of week…
azumakuniyuki Dec 2, 2020
f7b1316
Remove trailing "." character in an email address
azumakuniyuki Dec 2, 2020
9d13f0c
Code improvement for checking the day of month value (int)
azumakuniyuki Dec 2, 2020
7fe8e9c
Remove "." character at the end of the email address
azumakuniyuki Dec 2, 2020
a2d3b43
Sample email files renamed (rhost)
azumakuniyuki Dec 2, 2020
ef54aa9
Remove ";" from the end of an email address
azumakuniyuki Dec 4, 2020
aa3f878
Fix bug in the code to remove ";" character
azumakuniyuki Dec 4, 2020
5e09bbf
Rewrite all the test code for Sisimai::Lhost, Sisimai::Rhost, Sisimai…
azumakuniyuki Dec 7, 2020
f7cb231
Compare a D.S.N., a reason, a hardbounce, and a replycode with the pa…
azumakuniyuki Dec 7, 2020
9a77e90
Compare a D.S.N., a reason, a hardbounce, and a replycode with the pa…
azumakuniyuki Dec 7, 2020
1601b7d
Tiny code improvement: variable name changed
azumakuniyuki Dec 7, 2020
9af7525
Allow "deliverable" as a value of "Action:" field
azumakuniyuki Dec 7, 2020
606dcb9
Undef => undef in each method comment
azumakuniyuki Dec 7, 2020
84766d5
The value of "Action" is "delivered"
azumakuniyuki Dec 7, 2020
d2c9a46
Undef => undef in each method comment
azumakuniyuki Dec 7, 2020
c00b6cd
Undef => undef in each method comment
azumakuniyuki Dec 7, 2020
e0a7048
Sisimai::Data and Sisimai::Data::* have been renamed to Sisimai::Fact…
azumakuniyuki Dec 7, 2020
08484ee
Sisimai::Message no longer creates an object, returns a HASH
azumakuniyuki Dec 7, 2020
22bcd28
Sisimai::Data -> Sisimai::Fact on commit e0a70488, Updates for Sisima…
azumakuniyuki Dec 7, 2020
f02007b
Remove test code for Sisimai::Data e0a70488
azumakuniyuki Dec 7, 2020
e194960
Sisimai/Data => Sisimai/Fact e0a70488
azumakuniyuki Dec 7, 2020
237b37f
Update test code for commit e0a70488 (Sisimai::Fact) and commit 08484…
azumakuniyuki Dec 7, 2020
cde56c4
Change the order of variables
azumakuniyuki Dec 8, 2020
3cf64ec
is_emailaddress, is_mailerdaemon have been moved from RFC5322 to Address
azumakuniyuki Dec 8, 2020
071e3e7
Sisimai::Fact->softbounce displays warning
azumakuniyuki Dec 8, 2020
73e44cf
Keep Sisimai->make method for the backward compatible
azumakuniyuki Dec 8, 2020
37f18c0
First of all, Display the warning message
azumakuniyuki Dec 8, 2020
7dc1c44
Update comment for regular expressions of an email address
azumakuniyuki Dec 9, 2020
48326db
Fix code for detecting the value of "timestamp"
azumakuniyuki Dec 9, 2020
9d552cc
Tiny code improvement for detecting the value of "reason"
azumakuniyuki Dec 9, 2020
de13414
Fix a bug in code to check the value of reason for "hardbounce"
azumakuniyuki Dec 9, 2020
3cb98b3
Tiny code improvement in Sisimai::Fact->damn method
azumakuniyuki Dec 9, 2020
fada024
Tiny comment improvement
azumakuniyuki Dec 9, 2020
88a463d
Regular expression for values of "Action" field in the alphabetical o…
azumakuniyuki Dec 9, 2020
b7aab66
Comment improvement
azumakuniyuki Dec 9, 2020
8b57a4f
Comment improvement
azumakuniyuki Dec 9, 2020
e56a6b8
Comment improvement
azumakuniyuki Dec 9, 2020
88cc72c
Update test code for Sisimai class
azumakuniyuki Dec 10, 2020
a17aeca
Update test for Sisimai::Fact->catch
azumakuniyuki Dec 10, 2020
d7e5999
Remove some space characters
azumakuniyuki Dec 22, 2020
107e46e
Tiny test code improvement
azumakuniyuki Dec 22, 2020
8dc447b
Remove unused variable
azumakuniyuki Jan 14, 2021
2aedaeb
Use single or double quotations
azumakuniyuki Jan 14, 2021
d2def57
Use q|| instead of quotations
azumakuniyuki Jan 16, 2021
d08a266
Header field names are not written in a upper case
azumakuniyuki Jan 16, 2021
2670407
Remove duplicated test code for checking the return value of Sisimai:…
azumakuniyuki Jan 16, 2021
66e6352
Sisimai::Message no longer creates a object
azumakuniyuki Jan 17, 2021
38b079b
Tiny test code improvement
azumakuniyuki Jan 17, 2021
38479e2
Tiny test code improvement
azumakuniyuki Jan 18, 2021
a9092dc
Remove "softbounce", use "hardbounce" instead #420
azumakuniyuki Jan 18, 2021
862a3c8
Check the number of keys returned from Sisimai::Lhost.DELIVERYSTATUS …
azumakuniyuki Jan 18, 2021
bcd0e59
ErrorText has been moved to 200-reason.t
azumakuniyuki Jan 18, 2021
4585498
Variable name has been changed to $Samples
azumakuniyuki Jan 18, 2021
6736062
Test code improvement for Sisimai::Reason
azumakuniyuki Jan 18, 2021
3f8e1be
Pass the value returned from Sisimai::Fact->damn to each method of Si…
azumakuniyuki Jan 19, 2021
f1d2900
Test code improvement at lhost-code
azumakuniyuki Jan 26, 2021
3222e43
Tiny test code improvement for lhost-code
azumakuniyuki Jan 26, 2021
4a1d34f
Sisimai::Data -> Sisimai::Fact
azumakuniyuki Jan 26, 2021
e2762c1
Add test code for Sisimai::Fact->softbounce
azumakuniyuki Jan 26, 2021
9cb304d
Fix the value of "Diagnostic-Code:" field
azumakuniyuki Jan 27, 2021
80313fb
Test code for Sisimai::Lhost improved: Explicitly skip some sample em…
azumakuniyuki Jan 27, 2021
644f21f
Variable names have been changed
azumakuniyuki Jan 28, 2021
94bac9a
Fix array syntax, result values
azumakuniyuki Jan 28, 2021
f1e64c2
Remove blank lines
azumakuniyuki Jan 28, 2021
b44d5ca
Code improvement at Sisimai::RFC5322->fillet() for deleting lines aft…
azumakuniyuki Jan 29, 2021
5d6b099
Private sample RFC3464/1259 -> Exim/1188
azumakuniyuki Jan 30, 2021
cfc25cf
Strictly checks the value of "smtpagent"
azumakuniyuki Jan 30, 2021
870a15b
Some private sample files have been removed or moved to other directory
azumakuniyuki Jan 30, 2021
27f42ae
Code improvement for picking text blocks of message/rfc822 part
azumakuniyuki Jan 31, 2021
05d877c
Fix test code for checking the value of "smtpagent"
azumakuniyuki Jan 31, 2021
32e042b
Some private samples have been removed or moved to other directories
azumakuniyuki Jan 31, 2021
7601182
Update test for all the sample email files
azumakuniyuki Feb 1, 2021
e83609c
Test code files begin with 6** have been renamed
azumakuniyuki Feb 1, 2021
d9a458d
Strictly checks each directory
azumakuniyuki Feb 1, 2021
066ea5b
Update file check code
azumakuniyuki Feb 1, 2021
3b4d86c
Fix comment at code for checking the value of Diagnostic-Code and Sta…
azumakuniyuki Feb 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 22 additions & 20 deletions lib/Sisimai.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ sub version { return substr($VERSION->stringify, 1).($PATCHLV > 0 ? 'p'.$PATCHLV
sub libname { 'Sisimai' }

sub make {
# Emulate "rise" method for the backward compatible
warn ' ***warning: Sisimai->make will be removed at v5.1.0. Use Sisimai->rise instead';
my $class = shift;
my $argv0 = shift // return undef; die ' ***error: wrong number of arguments' if scalar @_ % 2;
my $argv1 = { @_ };
return __PACKAGE__->rise($argv0, %$argv1);
}

sub rise {
# Wrapper method for parsing mailbox or Maildir/
# @param [String] argv0 Path to mbox or Maildir/
# @param [Hash] argv0 or Hash (decoded JSON)
Expand All @@ -16,43 +25,36 @@ sub make {
# @options argv1 [Integer] delivered 1 = Including "delivered" reason
# @options argv1 [Array] c___ Code references to a callback method for the message and each file
# @return [Array] Parsed objects
# @return [Undef] Undef if the argument was wrong or an empty array
# @return [undef] undef if the argument was wrong or an empty array
my $class = shift;
my $argv0 = shift // return undef; die ' ***error: wrong number of arguments' if scalar @_ % 2;
my $argv1 = { @_ };

require Sisimai::Data;
require Sisimai::Message;
require Sisimai::Mail;
require Sisimai::Fact;

my $list = [];
my $mail = Sisimai::Mail->new($argv0) || return undef;
my $kind = $mail->kind;
my $c___ = ref $argv1->{'c___'} eq 'ARRAY' ? $argv1->{'c___'} : [undef, undef];
my $sisi = [];

while( my $r = $mail->data->read ) {
# Read and parse each email file
my $args = { 'data' => $r, 'hook' => $c___->[0] };
my $path = $mail->data->path;
my $sisi = [];

if( my $mesg = Sisimai::Message->new(%$args) ) {
# Sisimai::Message object was created successfully
$args = { 'data' => $mesg, 'delivered' => $argv1->{'delivered'}, 'origin' => $path };
$sisi = Sisimai::Data->make(%$args);
}
my $args = { 'data' => $r, 'hook' => $c___->[0], 'origin' => $path, 'delivered' => $argv1->{'delivered'} };
my $fact = Sisimai::Fact->rise($args) || [];

if( $c___->[1] ) {
# Run the callback function specified with "c___" parameter of Sisimai->make after reading
# each email file in Maildir/ every time
$args = { 'kind' => $kind, 'mail' => \$r, 'path' => $path, 'sisi' => $sisi };
$args = { 'kind' => $kind, 'mail' => \$r, 'path' => $path, 'fact' => $fact };
eval { $c___->[1]->($args) if ref $c___->[1] eq 'CODE' };
warn sprintf(" ***warning: Something is wrong in the second element of the 'c___': %s", $@) if $@;
}
push @$list, @$sisi if scalar @$sisi;
push @$sisi, @$fact if scalar @$fact;
}
return undef unless scalar @$list;
return $list;
return undef unless scalar @$sisi;
return $sisi;
}

sub dump {
Expand All @@ -67,7 +69,7 @@ sub dump {
my $class = shift;
my $argv0 = shift // return undef; die ' ***error: wrong number of arguments' if scalar @_ % 2;
my $argv1 = { @_ };
my $nyaan = __PACKAGE__->make($argv0, %$argv1) // [];
my $nyaan = __PACKAGE__->rise($argv0, %$argv1) // [];

for my $e ( @$nyaan ) {
# Set UTF8 flag before converting to JSON string
Expand Down Expand Up @@ -173,7 +175,7 @@ C<make> method provides feature for getting parsed data from bounced email messa

if( defined $v ) {
for my $e ( @$v ) {
print ref $e; # Sisimai::Data
print ref $e; # Sisimai::Fact
print ref $e->recipient; # Sisimai::Address
print ref $e->timestamp; # Sisimai::Time

Expand Down Expand Up @@ -269,7 +271,7 @@ message body. The second element of the C<c___> is called at the end of each ema
my $kind = $args->{'kind'}; # (String) Sisimai::Mail->kind
my $mail = $args->{'mail'}; # (*String) Entire email message
my $path = $args->{'path'}; # (String) Sisimai::Mail->path
my $sisi = $args->{'sisi'}; # (*Array) List of Sisimai::Data
my $sisi = $args->{'sisi'}; # (*Array) List of Sisimai::Fact

for my $e ( @$sisi ) {
# Insert custom fields into the parsed results
Expand Down Expand Up @@ -346,7 +348,7 @@ C<version> method returns the version number of Sisimai.

=item L<Sisimai::Mail> - Mailbox or Maildir object

=item L<Sisimai::Data> - Parsed data object
=item L<Sisimai::Fact> - Parsed data object

=item L<https://libsisimai.org/> - Sisimai — A successor to bounceHammer, Library to parse error mails

Expand Down
5 changes: 2 additions & 3 deletions lib/Sisimai/ARF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sub make {
# @param [Hash] mhead Message headers of a bounce email
# @param [String] mbody Message body of a bounce email
# @return [Hash] Bounce data list and message/rfc822 part
# @return [Undef] failed to parse or the arguments are missing
# @return [undef] failed to parse or the arguments are missing
my $class = shift;
my $mhead = shift // return undef;
my $mbody = shift // return undef;
Expand Down Expand Up @@ -290,7 +290,6 @@ sub make {
$e->{ $_ } ||= $arfheaders->{ $_ } for keys %$arfheaders;
delete $e->{'authres'};

$e->{'softbounce'} = -1;
$e->{'diagnosis'} ||= $commondata->{'diagnosis'};
$e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'});
$e->{'date'} ||= $mhead->{'date'};
Expand Down Expand Up @@ -362,7 +361,7 @@ azumakuniyuki

=head1 COPYRIGHT

Copyright (C) 2014-2020 azumakuniyuki, All rights reserved.
Copyright (C) 2014-2021 azumakuniyuki, All rights reserved.

=head1 LICENSE

Expand Down