Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
package Email::MIME::Kit::Role::Assembler;
# ABSTRACT: things that assemble messages (or parts)
$Email::MIME::Kit::Role::Assembler::VERSION = '3.000006';
use Moose::Role;
with 'Email::MIME::Kit::Role::Component';
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod Classes implementing this role must provide an C<assemble> method. This method
#pod will be passed a hashref of assembly parameters, and should return the fully
#pod assembled Email::MIME object.
#pod
#pod =cut
requires 'assemble';
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::Assembler - things that assemble messages (or parts)
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
Classes implementing this role must provide an C<assemble> method. This method
will be passed a hashref of assembly parameters, and should return the fully
assembled Email::MIME object.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,55 @@
package Email::MIME::Kit::Role::Component;
# ABSTRACT: things that are kit components
$Email::MIME::Kit::Role::Component::VERSION = '3.000006';
use Moose::Role;
#pod =head1 DESCRIPTION
#pod
#pod All (or most, anyway) components of an Email::MIME::Kit will perform this role.
#pod Its primary function is to provide a C<kit> attribute that refers back to the
#pod Email::MIME::Kit into which the component was installed.
#pod
#pod =cut
has kit => (
is => 'ro',
isa => 'Email::MIME::Kit',
required => 1,
weak_ref => 1,
);
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::Component - things that are kit components
=head1 VERSION
version 3.000006
=head1 DESCRIPTION
All (or most, anyway) components of an Email::MIME::Kit will perform this role.
Its primary function is to provide a C<kit> attribute that refers back to the
Email::MIME::Kit into which the component was installed.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,74 @@
package Email::MIME::Kit::Role::KitReader;
# ABSTRACT: things that can read kit contents
$Email::MIME::Kit::Role::KitReader::VERSION = '3.000006';
use Moose::Role;
with 'Email::MIME::Kit::Role::Component';
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod Classes implementing this role must provide a C<get_kit_entry> method. It will
#pod be called with one parameter, the name of a path to an entry in the kit. It
#pod should return a reference to a scalar holding the contents (as octets) of the
#pod named entry. If no entry is found, it should raise an exception.
#pod
#pod A method called C<get_decoded_kit_entry> is provided. It behaves like
#pod C<get_kit_entry>, but assumes that the entry for that name is stored in UTF-8
#pod and will decode it to text before returning.
#pod
#pod =cut
requires 'get_kit_entry';
sub get_decoded_kit_entry {
my ($self, $name) = @_;
my $content_ref = $self->get_kit_entry($name);
require Encode;
my $decoded = Encode::decode('utf-8', $$content_ref);
return \$decoded;
}
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::KitReader - things that can read kit contents
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
Classes implementing this role must provide a C<get_kit_entry> method. It will
be called with one parameter, the name of a path to an entry in the kit. It
should return a reference to a scalar holding the contents (as octets) of the
named entry. If no entry is found, it should raise an exception.
A method called C<get_decoded_kit_entry> is provided. It behaves like
C<get_kit_entry>, but assumes that the entry for that name is stored in UTF-8
and will decode it to text before returning.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,116 @@
package Email::MIME::Kit::Role::ManifestDesugarer;
# ABSTRACT: helper for desugaring manifests
$Email::MIME::Kit::Role::ManifestDesugarer::VERSION = '3.000006';
use Moose::Role;
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod This is a role more likely to be consumed than implemented. It wraps C<around>
#pod the C<read_manifest> method in the consuming class, and "desugars" the contents
#pod of the loaded manifest before returning it.
#pod
#pod At present, desugaring is what allows the C<type> attribute in attachments and
#pod alternatives to be given instead of a C<content_type> entry in the
#pod C<attributes> entry. In other words, desugaring turns:
#pod
#pod {
#pod header => [ ... ],
#pod type => 'text/plain',
#pod }
#pod
#pod Into:
#pod
#pod {
#pod header => [ ... ],
#pod attributes => { content_type => 'text/plain' },
#pod }
#pod
#pod More behavior may be added to the desugarer later.
#pod
#pod =cut
my $ct_desugar;
$ct_desugar = sub {
my ($self, $content) = @_;
for my $thing (qw(alternatives attachments)) {
for my $part (@{ $content->{ $thing } }) {
my $headers = $part->{header} ||= [];
if (my $type = delete $part->{type}) {
confess "specified both type and content_type attribute"
if $part->{attributes}{content_type};
$part->{attributes}{content_type} = $type;
}
$self->$ct_desugar($part);
}
}
};
around read_manifest => sub {
my ($orig, $self, @args) = @_;
my $content = $self->$orig(@args);
$self->$ct_desugar($content);
return $content;
};
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::ManifestDesugarer - helper for desugaring manifests
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
This is a role more likely to be consumed than implemented. It wraps C<around>
the C<read_manifest> method in the consuming class, and "desugars" the contents
of the loaded manifest before returning it.
At present, desugaring is what allows the C<type> attribute in attachments and
alternatives to be given instead of a C<content_type> entry in the
C<attributes> entry. In other words, desugaring turns:
{
header => [ ... ],
type => 'text/plain',
}
Into:
{
header => [ ... ],
attributes => { content_type => 'text/plain' },
}
More behavior may be added to the desugarer later.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,55 @@
package Email::MIME::Kit::Role::ManifestReader;
# ABSTRACT: things that read kit manifests
$Email::MIME::Kit::Role::ManifestReader::VERSION = '3.000006';
use Moose::Role;
with 'Email::MIME::Kit::Role::Component';
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod Classes implementing this role must provide a C<read_manifest> method, which is
#pod expected to locate and read a manifest for the kit. Classes implementing this
#pod role should probably include L<Email::MIME::Kit::Role::ManifestDesugarer>, too.
#pod
#pod =cut
requires 'read_manifest';
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::ManifestReader - things that read kit manifests
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
Classes implementing this role must provide a C<read_manifest> method, which is
expected to locate and read a manifest for the kit. Classes implementing this
role should probably include L<Email::MIME::Kit::Role::ManifestDesugarer>, too.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,59 @@
package Email::MIME::Kit::Role::Renderer;
# ABSTRACT: things that render templates into contents
$Email::MIME::Kit::Role::Renderer::VERSION = '3.000006';
use Moose::Role;
with 'Email::MIME::Kit::Role::Component';
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod Classes implementing this role must provide a C<render> method, which is
#pod expected to turn a template and arguments into rendered output. The method is
#pod used like this:
#pod
#pod my $output_ref = $renderer->render($input_ref, \%arg);
#pod
#pod =cut
requires 'render';
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::Renderer - things that render templates into contents
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
Classes implementing this role must provide a C<render> method, which is
expected to turn a template and arguments into rendered output. The method is
used like this:
my $output_ref = $renderer->render($input_ref, \%arg);
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,60 @@
package Email::MIME::Kit::Role::Validator;
# ABSTRACT: things that validate assembly parameters
$Email::MIME::Kit::Role::Validator::VERSION = '3.000006';
use Moose::Role;
#pod =head1 IMPLEMENTING
#pod
#pod This role also performs L<Email::MIME::Kit::Role::Component>.
#pod
#pod Classes implementing this role are used to validate that the arguments passed
#pod to C<< $mkit->assemble >> are valid. Classes must provide a C<validate> method
#pod which will be called with the hashref of values passed to the kit's C<assemble>
#pod method. If the arguments are not valid for the kit, the C<validate> method
#pod should raise an exception.
#pod
#pod =cut
with 'Email::MIME::Kit::Role::Component';
requires 'validate';
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Email::MIME::Kit::Role::Validator - things that validate assembly parameters
=head1 VERSION
version 3.000006
=head1 IMPLEMENTING
This role also performs L<Email::MIME::Kit::Role::Component>.
Classes implementing this role are used to validate that the arguments passed
to C<< $mkit->assemble >> are valid. Classes must provide a C<validate> method
which will be called with the hashref of values passed to the kit's C<assemble>
method. If the arguments are not valid for the kit, the C<validate> method
should raise an exception.
=head1 AUTHOR
Ricardo Signes <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut