| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## MIME Email Builder - ~/lib/Mail/Make/Headers/ContentDisposition.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.1.1 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2026/03/02 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2026/05/11 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | package Mail::Make::Headers::ContentDisposition; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 10 | warnings::register_categories( 'Mail::Make' ); | |||||||||||||||||||||||||||
| 20 | 10 | ▶ | use parent qw( Mail::Make::Headers::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use vars qw( $VERSION $EXCEPTION_CLASS $VALID_DISPOSITIONS ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use Mail::Make::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 10 | our $EXCEPTION_CLASS = 'Mail::Make::Exception'; | |||||||||||||||||||||||||||
| 24 | 10 | our $VALID_DISPOSITIONS = qr/^(?:inline|attachment|form-data)$/i; | |||||||||||||||||||||||||||
| 25 | 10 | our $VERSION = 'v0.1.1'; | |||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub init | ||||||||||||||||||||||||||||
| 32 | 62 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 62 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 34 | 62 | $self->{filename_charset} = undef; | |||||||||||||||||||||||||||
| 35 | 62 | $self->{filename_lang} = undef; | |||||||||||||||||||||||||||
| 36 | 62 | $self->{_exception_class} = $EXCEPTION_CLASS; | |||||||||||||||||||||||||||
| 37 | 62 | my $disposition = shift( @_ ); | |||||||||||||||||||||||||||
| 38 | 62 | ▶ | if( !defined( $disposition ) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $disposition and length "$disposition"
MC/DC50%1/2
defined $disposition and length "$disposition"
defined $disposition
length "$disposition"
Truth table66%2/3
A and B
A= defined $dispositionB= length "$disposition"
| |||||||||||||||||||||||||||||
| 39 | !length( "$disposition" ) ) | ||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 1 | return( $self->error( "No value was provided for Content-Disposition field." ) ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 61 | my $params = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 44 | 61 | my $debug = delete( $params->{debug} ); | |||||||||||||||||||||||||||
| 45 | 61 | $self->debug( $debug ); | |||||||||||||||||||||||||||
| 46 | 61 | ▶ | $self->disposition( $disposition, ( scalar( %$params ) ? %$params : () ) ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 47 | 60 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 60 | $self->_field_name( 'Content-Disposition' ); | |||||||||||||||||||||||||||
| 49 | 60 | return( $self ); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 53 | ▶ | sub as_string { return( shift->_hv_as_string( [qw( filename )] ) ); } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub disposition | ||||||||||||||||||||||||||||
| 55 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
disposition: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 74 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 57 | 74 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 67 | ▶ | my $dispo = shift( @_ ) || return( $self->error( "No content disposition was provided." ) ); | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No content disposition was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No content disposition was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 60 | 67 | ▶ | unless( $dispo =~ $VALID_DISPOSITIONS ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 2 | return( $self->error( "Invalid disposition '$dispo': must be one of inline, attachment, form-data." ) ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 65 | my $params = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 65 | 65 | $dispo = lc( $dispo ); | |||||||||||||||||||||||||||
| 66 | 65 | my $hv = $self->_hv; | |||||||||||||||||||||||||||
| 67 | 65 | ▶ | if( $hv ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 5 | $hv->value( $dispo ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 60 | ▶ | $hv = $self->_parse_header_value( $dispo ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_parse_header_value($dispo) || (return $self->pass_error)
MC/DC0%0/1
$self->_parse_header_value($dispo) || (return $self->pass_error)
$self->_parse_header_value($dispo)
Truth table50%1/2
A
A= $self->_parse_header_value($dispo)
| |||||||||||||||||||||||||||||
| 74 | 60 | $self->_hv( $hv ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 65 | ▶ | $hv->params( $params ) if( scalar( keys( %$params ) ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 65 | return( $dispo ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else | ||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 7 | ▶ | my $hv = $self->_hv || return( '' ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_hv || (return '')
MC/DC0%0/1
$self->_hv || (return '')
$self->_hv
Truth table50%1/2
A
A= $self->_hv
| |||||||||||||||||||||||||||||
| 82 | 7 | return( $hv->value_data ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Sets or gets the filename parameter. | ||||||||||||||||||||||||||||
| 87 | # On assignment, applies RFC 2231 encoding automatically when the filename | ||||||||||||||||||||||||||||
| 88 | # contains non-ASCII or RFC 2045 special characters (including commas). | ||||||||||||||||||||||||||||
| 89 | # This is the fix for the MIME::Entity silent failure bug. | ||||||||||||||||||||||||||||
| 90 | sub filename | ||||||||||||||||||||||||||||
| 91 | 38 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=11 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 38 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 93 | 38 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 37 | my( $fname, $lang ) = @_; | |||||||||||||||||||||||||||
| 96 | 37 | ▶ | if( !defined( $fname ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | # Remove both the plain and extended forms | ||||||||||||||||||||||||||||
| 99 | 1 | my $hv = $self->_hv; | |||||||||||||||||||||||||||
| 100 | 1 | ▶ | if( $hv ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | 1 | $hv->params->delete( 'filename' ); | |||||||||||||||||||||||||||
| 103 | 1 | $hv->params->delete( 'filename*' ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 1 | return( $self ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 36 | ▶ | $lang //= $self->filename_lang; | ||||||||||||||||||||||||||
|
Condition66%2/3
$lang //= $self->filename_lang
MC/DC50%1/2
$lang //= $self->filename_lang
$lang
$self->filename_lang
Truth table66%2/3
A //= B
A= $langB= $self->filename_lang
| |||||||||||||||||||||||||||||
| 108 | 36 | my $encoded = $self->_filename_encode( $fname, $lang ); | |||||||||||||||||||||||||||
| 109 | 36 | ▶ | if( defined( $encoded ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | # Non-trivial filename: use RFC 2231 extended notation (filename*) | ||||||||||||||||||||||||||||
| 112 | 7 | ▶ | $self->_set_get_param( 'filename*' => $encoded ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | else | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | # Pure safe ASCII: use plain quoted filename | ||||||||||||||||||||||||||||
| 117 | 29 | $self->_set_get_qparam( filename => $fname ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 36 | return( $fname ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | else | ||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | # Prefer filename* (RFC 2231) over plain filename | ||||||||||||||||||||||||||||
| 124 | 1 | my $v = $self->_set_get_param( 'filename*' ); | |||||||||||||||||||||||||||
| 125 | 1 | ▶ | if( defined( $v ) && length( "$v" ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v and length "$v"
MC/DC0%0/2
defined $v and length "$v"
defined $v
length "$v"
Truth table33%1/3
A and B
A= defined $vB= length "$v"
| |||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 0 | my( $decoded, $charset, $lang ) = $self->_filename_decode( $v ); | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | $self->filename_charset( $charset ) if( defined( $charset ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $self->filename_lang( $lang ) if( defined( $lang ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | return( $decoded ); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 1 | $v = $self->_set_get_qparam( 'filename' ); | |||||||||||||||||||||||||||
| 133 | 1 | return( $v ); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub filename_charset | ||||||||||||||||||||||||||||
| 138 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
filename_charset: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||
| 139 | 2 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 140 | 2 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | 2 | my $v = shift( @_ ); | |||||||||||||||||||||||||||
| 143 | 2 | ▶ | if( defined( $v ) && length( $v ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v and length $v
MC/DC0%0/2
defined $v and length $v
defined $v
length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
| |||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 2 | ▶ | if( lc( $v ) ne 'utf-8' && lc( $v ) ne 'utf8' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
lc $v ne "utf-8" and lc $v ne "utf8"
MC/DC50%1/2
lc $v ne "utf-8" and lc $v ne "utf8"
lc $v ne "utf-8"
lc $v ne "utf8"
Truth table66%2/3
A and B
A= lc $v ne "utf-8"B= lc $v ne "utf8"
| |||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | 1 | return( $self->error( "Only 'utf-8' is supported as filename charset." ) ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 1 | $v = 'UTF-8'; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 1 | return( $self->_set_get_scalar_as_object( 'filename_charset', $v ) ); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 0 | return( $self->_set_get_scalar_as_object( 'filename_charset' ) ); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 37 | ▶ | sub filename_lang { return( shift->_set_get_scalar_as_object( 'filename_lang', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
filename_lang: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 2 | ▶ | sub name { return( shift->_set_get_param( name => @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 10 | 1; | |||||||||||||||||||||||||||
| 161 | # NOTE: POD | ||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||