| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## MIME Email Builder - ~/lib/Mail/Make/Headers/ContentTransferEncoding.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2026/03/02 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2026/03/03 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved. | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 11 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 12 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 13 | package Mail::Make::Headers::ContentTransferEncoding; | ||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||
| 15 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 9 | warnings::register_categories( 'Mail::Make' ); | |||||||||||||||||||||||||||
| 19 | 9 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use vars qw( $VERSION $EXCEPTION_CLASS %VALID_ENCODINGS ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Mail::Make::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | use overload | ||||||||||||||||||||||||||||
| 23 | 9 | ▶ | ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | '""' => 'as_string', | ||||||||||||||||||||||||||||
| 25 | 238 | ▶ | bool => sub{1}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 9 | ); | |||||||||||||||||||||||||||
| 27 | # RFC 2045 section 6.1 - defined encodings | ||||||||||||||||||||||||||||
| 28 | 9 | %VALID_ENCODINGS = | |||||||||||||||||||||||||||
| 29 | ( | ||||||||||||||||||||||||||||
| 30 | '7bit' => 1, | ||||||||||||||||||||||||||||
| 31 | '8bit' => 1, | ||||||||||||||||||||||||||||
| 32 | 'binary' => 1, | ||||||||||||||||||||||||||||
| 33 | 'base64' => 1, | ||||||||||||||||||||||||||||
| 34 | 'quoted-printable' => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | 9 | our $EXCEPTION_CLASS = 'Mail::Make::Exception'; | |||||||||||||||||||||||||||
| 37 | 9 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub init | ||||||||||||||||||||||||||||
| 44 | 80 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 80 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 46 | 80 | $self->{_encoding} = undef; | |||||||||||||||||||||||||||
| 47 | 80 | $self->{_exception_class} = $EXCEPTION_CLASS; | |||||||||||||||||||||||||||
| 48 | # Module::Generic passes positional args through init() as-is when | ||||||||||||||||||||||||||||
| 49 | # _init_strict_use_sub is not set. It accepts the encoding as first positional arg. | ||||||||||||||||||||||||||||
| 50 | 80 | my $encoding = shift( @_ ); | |||||||||||||||||||||||||||
| 51 | 80 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 80 | ▶ | if( defined( $encoding ) && length( $encoding ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $encoding and length $encoding
MC/DC0%0/2
defined $encoding and length $encoding
defined $encoding
length $encoding
Truth table33%1/3
A and B
A= defined $encodingB= length $encoding
| |||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 80 | ▶ | $self->encoding( $encoding ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 79 | return( $self ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub as_string | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | return( $self->{_encoding} // '' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"_encoding"} // ""
MC/DC0%0/1
$self->{"_encoding"} // ""
$self->{"_encoding"}
Truth table0%0/2
A
A= $self->{"_encoding"}
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # encoding( [$value] ) | ||||||||||||||||||||||||||||
| 66 | # Gets or sets the encoding token. Validates against VALID_ENCODINGS. | ||||||||||||||||||||||||||||
| 67 | sub encoding | ||||||||||||||||||||||||||||
| 68 | 80 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
encoding: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 80 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 70 | 80 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 80 | ▶ | my $enc = lc( shift( @_ ) // '' ); | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 73 | 80 | ▶ | unless( exists( $VALID_ENCODINGS{ $enc } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 1 | return( $self->error( "Invalid Content-Transfer-Encoding '$enc'; must be one of: " . | |||||||||||||||||||||||||||
| 76 | join( ', ', sort( keys( %VALID_ENCODINGS ) ) ) ) ); | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 79 | $self->{_encoding} = $enc; | |||||||||||||||||||||||||||
| 79 | 79 | return( $self ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return( $self->{_encoding} ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # is_binary() | ||||||||||||||||||||||||||||
| 85 | # Returns true if the encoding is 'binary' (never valid for mail text parts). | ||||||||||||||||||||||||||||
| 86 | 79 | ▶ | sub is_binary { return( ( shift->{_encoding} // '' ) eq 'binary' ? 1 : 0 ); } | ||||||||||||||||||||||||||
|
Subroutine
is_binary: called CC=3 SCAR=12.7
Pod
documented
Branch: 1 branch
Condition50%1/2
+(shift())->{"_encoding"} // ""
MC/DC0%0/1
+(shift())->{"_encoding"} // ""
+(shift())->{"_encoding"}
Truth table50%1/2
A
A= +(shift())->{"_encoding"}
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # is_encoded() | ||||||||||||||||||||||||||||
| 89 | # Returns true if the encoding is base64 or quoted-printable. | ||||||||||||||||||||||||||||
| 90 | sub is_encoded | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_encoded: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $enc = shift->{_encoding} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
+(shift())->{"_encoding"} // ""
MC/DC0%0/1
+(shift())->{"_encoding"} // ""
+(shift())->{"_encoding"}
Truth table0%0/2
A
A= +(shift())->{"_encoding"}
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return( ( $enc eq 'base64' || $enc eq 'quoted-printable' ) ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$enc eq "base64" or $enc eq "quoted-printable"
MC/DC0%0/2
$enc eq "base64" or $enc eq "quoted-printable"
$enc eq "base64"
$enc eq "quoted-printable"
Truth table0%0/3
A or B
A= $enc eq "base64"B= $enc eq "quoted-printable"
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # value() is an alias for as_string | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub value { return( shift->as_string ); } | ||||||||||||||||||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # NOTE: STORABLE support | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 9 | 1; | |||||||||||||||||||||||||||
| 105 | # NOTE: POD | ||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||