package Haineko::JSON;
use feature ':5.10';
use strict;
use warnings;
use Carp;
use IO::File;
use JSON::Syck;
sub loadfile {
my $class = shift;
my $argvs = shift // return undef;
return
k $!;
my $jsonstring = do { local $/; <$filehandle> };
$filehandle->close;
return JSON::Syck::Load( $jsonstring );
}
sub dumpfile {
# Not implemented yet
}
sub loadjson {
my $cl
= shift // return undef;;
return JSON::Syck::Load( $argvs );
}
sub dumpjson {
my $class = shift;
my $argvs = shift // return undef;
return JSON::Syck::Dump( $argvs );
}
1;
__END__
dsn is 5.6.0
in this method.
=head4 C<B<EMAIL_BODY>>
Value defined in "body" field in HTTP POST JSON data.
=head1 SEE ALSO
https://www.milter.org/developers/api/
=head1 REPOSITORY
https://github
'charset' => 'UTF-8',
},
},
];
return $httpd->res->json( 200, Haineko::JSON->dumpjson( $samplemail ) );
}
1;
__END__
=encoding utf-8
=head1 NAME
Haineko::Sample - Co
ample email
=head1 DESCRIPTION
Haineko::Sample is a controller for displaying email sample as a JSON.
=head2 URL
http://127.0.0.1:2794/sample/mail
=head1 REPOSITORY
https://github.com/azumak
my $neko1 = { 'name' => $httpd->name, 'version' => $Haineko::VERSION };
return $httpd->res->json( 200, $neko1 );
}
sub info {
# GET /dump, /conf
my $class = shift;
my $httpd = shift
00, Data::Dumper::Dumper $httpd );
} else {
# /conf
use Haineko::JSON;
use File::Basename;
if( defined $ENV{'HAINEKO_CONF'} ) {
$configdata->{ $h }->{'path'} = $g;
$configdata->{ $h }->{'data'} = Haineko::JSON->loadfile( $g );
next unless $h eq 'authinfo';
for my $i
ngs;
use Encode;
use Try::Tiny;
use Time::Piece;
use Scalar::Util;
use Haineko::Log;
use Haineko::JSON;
use Haineko::Default;
use Haineko::SMTPD::Milter;
use Haineko::SMTPD::Session;
use Haineko::SMTP
$responsecn = 'Haineko::SMTPD::Response';
my $responsejk = 'response'; # (String) Response json key name
my $exceptions = 0; # (Integer) Flag, be set in try {...} catch { ... }
( $esresponse );
$nekosyslog->w( 'err', $esresponse->damn );
return $httpd->res->json( 405, $tmpsession->damn );
}
CONN: {
# ____ ___ _ _ _ _
# / ___
{
my $class = shift;
my $ctype = shift || 'plain';
my $types = {
'json' => 'application/json',
'html' => 'text/html; charset=utf-8',
'plain' => 'text/plain; char
);
}
sub json {
my $self = shift;
my $code = shift || 200;
my $data = shift; # (Ref->[HASH|ARRAY]) or JSON as a string
my $json = q();
require Haineko::JSON;
$json = ref $d
o::JSON->dumpjson( $data ) : $data;
$self->code( $code );
return $self->_res( $json, 'json' );
}
sub _res {
my $self = shift;
my $text = shift || q();
my $type = shift || 'json';
TTPD;
use feature ':5.10';
use strict;
use warnings;
use Try::Tiny;
use Path::Class;
use Haineko::JSON;
use Haineko::Default;
use Class::Accessor::Lite;
use Haineko::HTTPD::Router;
use Haineko::HTTPD:
->{'root'} = Path::Class::Dir->new( $hainekodir ) if $hainekodir;
$argvs->{'conf'} = Haineko::JSON->loadfile( $hainekocfg ) || Haineko::Default->conf;
$milterlibs = $argvs->{'conf'}->{'smtpd'}
as a JSON.
require Haineko::SMTPD::Response;
$mesg = Haineko::SMTPD::Response->r( 'http', 'not-found' )->damn;
}
if( ref $mesg eq 'HASH' ) {
# Respond as a JSON
return undef unless -f -r -s $passworddb;
require Haineko::JSON;
try {
$credential = Haineko::JSON->loadfile( $passworddb );
} catch {
$exceptions =
psgi.
=head1 SYNOPSIS
use Haineko::HTTPD::Auth;
use Haineko::JSON;
$Haineko::HTTPD::Auth::PasswordDB = Haineko::JSON->loadfile('/path/to/password');
builder {
enable 'Auth::B
es is 521 in this method.
=head4 C<B<HELO_HOST>>
Value defined in C<ehlo> field in C<HTTP POST> JSON data, which should be the
domain name of the sending host or IP address enclosed square brackets
n is 5.1.8
in this method.
=head4 B<ENVELOPE_SENDER>
Value defined in "mail" field in HTTP POST JSON data, which should be the
valid email address.
=head2 C<B<rcpt( I<Haineko::SMTPD::Response>, I<
.7.1
in this method.
=head4 B<ENVELOPE_RECIPIENTS>
Values defined in C<rcpt> field in HTTP POST JSON data, which should be the
valid email address.
=head2 B<head( I<Haineko::SMTPD::Response>, I<
codes is 521 in this method.
=head4 C<B<HELO_HOST>>
Value defined in C<ehlo> field in HTTP POST JSON data, which should be the domain
name of the sending host or IP address enclosed square brackets.
5.1.8
in this method.
=head4 C<B<ENVELOPE_SENDER>>
Value defined in C<mail> field in HTTP POST JSON data, which should be the valid
email address.
=head2 C<B<rcpt( I<Haineko::SMTPD::Response>, I<
1
in this method.
=head4 C<B<ENVELOPE_RECIPIENTS>>
Values defined in C<rcpt> field in HTTP POST JSON data, which should be the
valid email address.
=head2 C<B<head( I<Haineko::SMTPD::Response>, I
::SMTPD::Relay';
use strict;
use warnings;
use Furl;
use Try::Tiny;
use Time::Piece;
use Haineko::JSON;
use Haineko::SMTPD::Response;
sub new {
my $class = shift;
my $argvs = { @_ };
$ar
rameters->{'header'}->{'replyto'} = $self->{'head'}->{'Reply-To'};
}
my $jsonstring = Haineko::JSON->dumpjson( $parameters );
my $httpheader = [];
my $httpobject = undef;
my $htre
;
my $sendmailto = sub {
$htresponse = $httpobject->post( $hainekourl, $httpheader, $jsonstring );
return 0 unless defined $htresponse;
return 0 unless $htresponse->is_su
::SMTPD::Relay';
use strict;
use warnings;
use Furl;
use Try::Tiny;
use Time::Piece;
use Haineko::JSON;
use Haineko::SMTPD::Response;
use Encode;
use constant 'SENDGRID_ENDPOINT' => 'sendgrid.com';
u
se->new( %$r ) );
return 0
}
my $sendgridep = sprintf( "https://%s/api/mail.send.json", SENDGRID_ENDPOINT );
my $parameters = {
'to' => $self->{'rcpt'},
'fr
,
'x-smtpapi' => q(),
};
my $usedheader = [ 'Date', 'Subject', 'From' ];
my $jsonheader = {};
my $identifier = [ split( '@', $self->{'head'}->{'Message-Id'} ) ]->[0];
for
::SMTPD::Relay';
use strict;
use warnings;
use Furl;
use Try::Tiny;
use Time::Piece;
use Haineko::JSON;
use Haineko::SMTPD::Response;
use Email::MIME;
use Encode;
use Class::Accessor::Lite;
use const
/1.0/SOME-METHOD.OUTPUT_FORMAT
my $mandrillep = sprintf( "https://%s/api/%s/messages/send-raw.json", MANDRILL_ENDPOINT, MANDRILL_APIVERSION );
my $timestamp1 = Time::Piece->new;
my $header
=> 0 }
};
my $httpclient = Furl->new( %$methodargv );
my $htrequest1 = Haineko::JSON->dumpjson( $parameters );
my $htresponse = undef;
my $retryuntil = $self->{'retry'} || 0;
t supported' ],
},
'malformed-json' => {
'dsn' => undef,
'code' => 421,
'message' => [ 'Malformed JSON string' ],
},
'not-found' =>
=%s", $e, $v );
}
} catch {
# It was not JSON
require Haineko::E;
my $v = $htresponse->body || q();
http://127.0.0.1:2794/submit
=head2 PARAMETERS
To send email via Haineko, POST email data as a JSON format like the following:
{
ehlo: 'your-host-name.as.fqdn'
mail: 'kijitora
ype: application/json' \
-d '{ ehlo: "[127.0.0.1]", mail: "kijitora@example.jp", ... }'
OR
$ curl 'http://127.0.0.1:2794/submit' -X POST -H 'Content-Type application/json' \
-d '
.1:2794/conf
C</conf> can be accessed from 127.0.0.1 and display Haineko configuration data as a
JSON.
=head1 ENVIRONMENT VARIABLES
=head2 C<HAINEKO_ROOT>
Haineko decides the root directory by C<H