Sisimai::Message::JSON(3pm) | User Contributed Perl Documentation | Sisimai::Message::JSON(3pm) |
Sisimai::Message::JSON - Convert bounce object (decoded JSON) to data structure.
use JSON; use Sisimai::Message; my $jsonparser = JSON->new; my $jsonobject = $jsonparser->decode($jsonstring); my $messageobj = Sisimai::Message->new('data' => $jsonobject, 'input' => 'json');
Sisimai::Message::JSON convert bounce object (decode JSON) to data structure. When the email given as a argument of "new()" method is not a decoded JSON, the method returns "undef".
"new()" is a constructor of Sisimai::Message
my $jsonparser = JSON->new; my $jsonstring = '{"neko":2, "nyaan": "meow", ...}'; my $jsonobject = $jsonparser->decode($jsonstring); my $messageobj = Sisimai::Message->new('data' => $jsonobject, 'input' => 'json');
If you have implemented a custom MTA module and use it, set the value of "load" in the argument of this method as an array reference like following code:
my $messageobj = Sisimai::Message->new( 'data' => $jsonobject, 'load' => ['Your::Custom::MTA::Module'] 'input' => 'json', );
Beginning from v4.19.0, `hook` argument is available to callback user defined method like the following codes:
my $callbackto = sub { my $argv = shift; my $data = { 'feedback-id' => '', 'account-id' => '' }; my $mesg = $argv->{'message'} || {}; if( exists $mesg->{'feedbackId'} ) { $data->{'feedback-id'} = $mesg->{'feedback-Id'}; } if( exists $mesg->{'sendingAccountId'} ) { $data->{'account-id'} = $mesg->{'sendingAccountId'}; } return $data; }; my $messageobj = Sisimai::Message->new( 'data' => $jsonobject, 'hook' => $callbackto, 'input' => 'json' ); print $message->catch->{'feedback-id'}; # 01010157e48fa03f-c7e948fe-...
"from()" returns empty string
print $message->from; # ''
"header()" returns empty Hash
print $message->header; # {}
"ds()" returns an array reference which include contents of delivery status.
for my $e ( @{ $message->ds } ) { print $e->{'status'}; # 5.1.1 print $e->{'recipient'};# neko@example.jp }
"rfc822()" returns a hash reference which include the header part of the original message.
print $message->rfc822->{'from'}; # cat@example.com print $message->rfc822->{'to'}; # neko@example.jp
"catch()" returns any data generated by user-defined method passed at the `hook` argument of new() constructor.
azumakuniyuki
Copyright (C) 2014-2018 azumakuniyuki, All rights reserved.
This software is distributed under The BSD 2-Clause License.
2018-11-15 | perl v5.28.0 |