Sisimai works on any OS where Perl or Ruby
(including some versions of JRuby) can run.
Sisimai can be downloaded from CPAN(Perl) or RubyGems(Ruby). Both the Perl and Ruby versions are also available for download on GitHub.
This article will introduce you to the basics of using Sisimai. We will cover how to decode bounce emails, retrieve structured decoded data, and convert it to JSON.
More advanced topics, such as reading from STDIN, including delivery success in the decoded results, and incorporating custom processing using the callback feature.
Sisimai can run on any OS that supports Perl or Ruby
(including some versions of JRuby), such as *BSD, Mac OS X, and Linux. Additionally, Sisimai
4.22.5 and later
may run with ActivePerl on Windows.
.
It is important to review the release notes and the differences with Sisimai 4 page before installing or upgrading, as there are several breaking changes in Sisimai 5.0.0 that may affect your use of the software.
Sisimai can be downloaded and installed from GitHub, CPAN, and RubyGems.org. Additionally, the Perl version of Sisimai can be installed from the FreeBSD ports collection or Debian packages.
It is important to review the release notes and the differences with Sisimai 4 page before installing or upgrading, as there are several breaking changes in Sisimai 5.0.0 that may affect your use of the software.
The latest version and stable version of Sisimai, including development versions, can be downloaded from the 5-stable branch or the 4-stable branch of the Sisimai GitHub repository. Both the Perl and Ruby versions are available in this repository.
On February 2, 2024, the default branch of the repository was changed to 5-stable.
The repository name for the Perl version of Sisimai is sisimai/p5-sisimai. Sisimai 5.0.0 and later requires Perl 5.26.0 or later, so please check the version of Perl installed on your system before installing.
% perl -v This is perl 5, version 30, subversion 0 (v5.30.0) built for darwin-2level Copyright 1987-2019, Larry Wall ...
% git clone https://github.com/sisimai/p5-sisimai.git % cd ./p5-sisimai % make install-from-local ./cpanm --sudo . || ( make cpm && ./cpm install --sudo -v . ) --> Working on . Configuring Sisimai-v5.0.0 ... OK Building and testing Sisimai-v5.0.0 ... Password: <sudo password here> OK Successfully installed Sisimai-v5.0.0 1 distribution installed % perl -MSisimai -lE 'print Sisimai->version' 5.0.0
As of February 2, 2024, the default branch of the repository has been changed to 5-stable. If you want to use Sisimai, please specify 4-stable as the branch name.
% git clone -b 4-stable https://github.com/sisimai/p5-sisimai.git
The repository name for the Ruby version of Sisimai is sisimai/rb-sisimai. Sisimai 5.0.0 and later requires Ruby 2.4.0 or later, so please check the version of Ruby installed on your system before installing.
% ruby -v ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin21]
% git clone https://github.com/sisimai/rb-sisimai.git % cd ./rb-sisimai % sudo make depend install-from-local gem install bundle rake minitest ... 3 gems installed if [ -d "/usr/local/jr" ]; then \ PATH="/usr/local/jr/bin:$PATH" /usr/local/jr/bin/gem install bundle rake minitest; \ fi ... 3 gems installed /opt/local/bin/rake install sisimai 5.0.0 built to pkg/sisimai-5.0.0.gem. sisimai (5.0.0) installed. if [ -d "/usr/local/jr" ]; then \ PATH="/usr/local/jr/bin:$PATH" /usr/local/jr/bin/rake install; \ fi sisimai 5.0.0 built to pkg/sisimai-5.0.0-java.gem. sisimai (5.0.0) installed.
As of February 2, 2024, the default branch of the repository has been changed to 5-stable. If you want to use Sisimai, please specify 4-stable as the branch name.
% git clone -b 4-stable https://github.com/sisimai/rb-sisimai.git
% cpanm --sudo Sisimai --> Working on Sisimai Fetching http://www.cpan.org/authors/id/A/AK/AKXLIX/Sisimai-5.0.0.tar.gz ... OK ... 1 distribution installed % perldoc -l Sisimai /usr/local/lib/perl5/site_perl/5.30.0/Sisimai.pm
If you want to install an older version, please specify the URL as follows:
% cpanm --sudo https://cpan.metacpan.org/authors/id/A/AK/AKXLIX/Sisimai-v4.25.16.tar.gz % sudo cpm install https://cpan.metacpan.org/authors/id/A/AK/AKXLIX/Sisimai-v4.25.16.tar.gz
The release version of Ruby Sisimai can only be downloaded from
RubyGems.org
and installed with the gem command.
If you are using JRuby, you can also install it with jgem.
% sudo gem install sisimai Fetching: sisimai-5.0.0.gem (100%) Successfully installed sisimai-5.0.0 Parsing documentation for sisimai-5.0.0 Installing ri documentation for sisimai-5.0.0 Done installing documentation for sisimai after 6 seconds 1 gem installed
If you want to install an older version, please specify the desired version with the -v option as follows:
% sudo gem install sisimai -v 4.25.16
The Perl version of Sisimai can be installed from FreeBSD Ports Collection (mail/p5-Sisimai). It can be installed with a single make command, but please note that if the timing of the inclusion of Perl version of Sisimai in the Ports collection is not the latest version, you may not be installing the latest version of Sisimai.
# cd /usr/ports/mail/p5-Sisimai # make install ===> License BSD2CLAUSE accepted by the user ===> p5-sisimai-4.25.16 depends on file: /usr/local/sbin/pkg - found => Sisimai-v4.25.16.tar.gz doesn't seem to exist in /usr/ports/distfiles/. ...
The Perl version of Sisimai can be installed from Debian or Ubuntu package (libsisimai-perl). It can be installed with a single apt copmmand, but please note that if the timing of the inclusion Perl version of Sisimai in the Debian/Ubuntu packages is not the latest version, you may not be installing the latest version of Sisimai
# apt install libsisimai-perl Reading package lists... Done Building dependency tree Reading state information... Done ... Need to get 366 kB/563 kB of archives. After this operation, 1892 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libclass-accessor-lite-perl all 0.08-1 [8136 B] Get:2 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libsisimai-perl all 4.25.5-1 [358 kB] Fetched 366 kB in 2s (171 kB/s) ... Setting up libjson-perl (4.02000-2) ... Setting up libsisimai-perl (4.25.5-1) ... Setting up libjson-xs-perl (4.020-1build1) ... Processing triggers for man-db (2.9.1-1) ...
The following code is an example of how to use the rise() method of Sisimai to decode bounce emails and obtain data from the decoded results. For more information on the other arguments that can be specified for the rise() method, please see the How To Decode. The old make() method was deprecated in Sisimai 5.0.0.
#! /usr/bin/env perl
use Sisimai;
my $v = Sisimai->rise('/path/to/mbox'); # or Path to Maildir
if( defined $v ) {
for my $e ( @$v ) {
print $e->addresser->address; # "michitsuna@example.org" # From
print $e->recipient->address; # "kijitora@example.jp" # To
print $e->recipient->host; # "example.jp"
print $e->deliverystatus; # "5.1.1"
print $e->replycode; # "550"
print $e->reason; # "userunknown"
print $e->origin; # "/var/spool/bounce/new/1740074341.eml"
print $e->hardbounce; # 1
}
} else {
# There is no bounce message in the mailbox
# or Sisimai could not decode
}
#! /usr/bin/env ruby
require 'sisimai'
v = Sisimai.rise('/path/to/mbox') # or Path to Maildir
if v.is_a? Array
v.each do |e|
puts e.class # Sisimai::Fact
puts e.recipient.class # Sisimai::Address
puts e.timestamp.class # Sisimai::Time
puts e.addresser.address # "michitsuna@example.org" # From
puts e.recipient.address # "kijitora@example.jp" # To
puts e.recipient.host # "example.jp"
puts e.deliverystatus # "5.1.1"
puts e.replycode # "550"
puts e.reason # "userunknown"
puts e.origin # "/var/spool/bounce/Maildir/new/1740074341.eml"
puts e.hardbounce # true
end
else
# There is no bounce message in the mailbox
# or Sisimai could not decode
end
The dump() method introduced in Sisimai v4.1.27 is useful for obtaining decoded results in JSON format. As shown below, it can be done with a simple code that only passes the PATH of the email you want to decode.
#! /usr/bin/env perl
use Sisimai;
print Sisimai->dump('/home/postmaster/Maildir/cur');
#! /usr/bin/env ruby
require 'sisimai'
puts Sisimai.dump('/home/postmaster/Maildir/cur')
The jq command is useful for visually inspecting the JSON data of the decoded results. As shown below, the output of the dump() method can be displayed in an easy-to-read format.
% perl -MSisimai -lE 'print Sisimai->dump(shift)' path/to/mbox | jq .
% ruby -rsisimai -e 'puts Sisimai.dump($*.shift)' path/to/mbox | jq .
[ { "destination": "google.example.com", "lhost": "gmail-smtp-in.l.google.com", "hardbounce": 0, "reason": "authfailure", "catch": null, "addresser": "michitsuna@example.jp", "alias": "nekochan@example.co.jp", "smtpagent": "Postfix", "smtpcommand": "DATA", "senderdomain": "example.jp", "listid": "", "action": "failed", "feedbacktype": "", "messageid": "hwK7pzjzJtz0RF9Y@relay3.example.com", "origin": "./gmail-5.7.26.eml", "recipient": "kijitora@google.example.com", "rhost": "gmail-smtp-in.l.google.com", "subject": "Nyaan", "timezoneoffset": "+0900", "replycode": 550, "token": "84656774898baa90660be3e12fe0526e108d4473", "diagnostictype": "SMTP", "timestamp": 1650119685, "diagnosticcode": "host gmail-smtp-in.l.google.com[64.233.187.27] said: This mail has been blocked because the sender is unauthenticated. Gmail requires all senders to authenticate with either SPF or DKIM. Authentication results: DKIM = did not pass SPF [relay3.example.com] with ip: [192.0.2.22] = did not pass For instructions on setting up authentication, go to https://support.google.com/mail/answer/81126#authentication c2-202200202020202020222222cat.127 - gsmtp (in reply to end of DATA command)", "deliverystatus": "5.7.26" } ]