line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::BIMI::App::Command::svgfromvmc; |
2
|
|
|
|
|
|
|
# ABSTRACT: Extract the SVG from a VMC |
3
|
|
|
|
|
|
|
our $VERSION = '3.20210301'; # VERSION |
4
|
1
|
|
|
1
|
|
634
|
use 5.20.0; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
20
|
BEGIN { $ENV{MAIL_BIMI_CACHE_DEFAULT_BACKEND} = 'Null' }; |
6
|
1
|
|
|
1
|
|
5
|
use Mail::BIMI::Prelude; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
231
|
use Mail::BIMI::App -command; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
219
|
use Mail::BIMI; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
9
|
1
|
|
|
1
|
|
4
|
use Mail::BIMI::Indicator; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
4
|
use Mail::BIMI::VMC; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
11
|
1
|
|
|
1
|
|
6
|
use File::Slurp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
612
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
1
|
|
sub description { 'Extract the SVG from a VMC' } |
15
|
0
|
|
|
0
|
1
|
|
sub usage_desc { "%c svgfromvmc %o" } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub opt_spec { |
18
|
|
|
|
|
|
|
return ( |
19
|
0
|
|
|
0
|
1
|
|
[ 'domain=s', 'Extract SVG from VMC in BIMI record at domain' ], |
20
|
|
|
|
|
|
|
[ 'selector=s', 'Optional selector when domain specified' ], |
21
|
|
|
|
|
|
|
[ 'uri=s', 'Extract SVG from VMC at URI' ], |
22
|
|
|
|
|
|
|
[ 'file=s', 'Extract SVG from VMC in file' ], |
23
|
|
|
|
|
|
|
[ 'output=s', 'Write SVG to this file, if not specified will write to STDOUT' ], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
|
sub validate_args($self,$opt,$args) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
$self->usage_error('Extra args specified') if scalar @$args; |
29
|
0
|
|
|
|
|
|
my $options; |
30
|
0
|
0
|
|
|
|
|
$options++ if $opt->domain; |
31
|
0
|
0
|
|
|
|
|
$options++ if $opt->uri; |
32
|
0
|
0
|
|
|
|
|
$options++ if $opt->file; |
33
|
0
|
0
|
|
|
|
|
$self->usage_error('Must specify domain, uri, or file') if $options==0; |
34
|
0
|
0
|
|
|
|
|
$self->usage_error('Must specify ONLY ONE of domain, uri, or file') if $options>1; |
35
|
0
|
0
|
0
|
|
|
|
$self->usage_error('Selector cannot be specified without domain') if $opt->selector && !$opt->domain; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
1
|
|
sub execute($self,$opt,$args) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $indicator; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
|
my $domain = $opt->domain // 'example.com'; |
43
|
0
|
|
0
|
|
|
|
my $selector = $opt->selector // 'default'; |
44
|
0
|
|
|
|
|
|
my $dmarc = Mail::DMARC::PurePerl->new; |
45
|
0
|
|
|
|
|
|
$dmarc->header_from($domain); |
46
|
0
|
|
|
|
|
|
$dmarc->validate; |
47
|
0
|
|
|
|
|
|
$dmarc->result->result('pass'); |
48
|
0
|
|
|
|
|
|
my %bimi_options = ( |
49
|
|
|
|
|
|
|
dmarc_object => $dmarc, |
50
|
|
|
|
|
|
|
domain => $domain, |
51
|
|
|
|
|
|
|
selector => $selector, |
52
|
|
|
|
|
|
|
options => { |
53
|
|
|
|
|
|
|
vmc_no_check_alt => 1, |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
); |
56
|
0
|
0
|
|
|
|
|
$bimi_options{options}->{vmc_from_file} = $opt->file if $opt->file; |
57
|
0
|
|
|
|
|
|
my $bimi = Mail::BIMI->new(%bimi_options); |
58
|
0
|
|
|
|
|
|
my $vmc; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($opt->domain) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$vmc = eval{$bimi->record->authority->vmc}; |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$indicator = eval{$vmc->indicator}; |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif($opt->uri) { |
65
|
0
|
|
|
|
|
|
$vmc = Mail::BIMI::VMC->new( check_domain => $domain, check_selector => $selector, uri => $opt->uri, bimi_object => $bimi ); |
66
|
0
|
|
|
|
|
|
$indicator = eval{$vmc->indicator}; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif($opt->file) { |
69
|
0
|
|
|
|
|
|
$vmc = Mail::BIMI::VMC->new( check_domain => $domain, check_selector => $selector, uri => $opt->file, bimi_object => $bimi ); |
70
|
0
|
|
|
|
|
|
$indicator = eval{$vmc->indicator}; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $svg = eval{$indicator->data_uncompressed}; |
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (!$svg) { |
75
|
0
|
|
|
|
|
|
warn "Could not extract SVG"; |
76
|
0
|
|
|
|
|
|
exit 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ($opt->output) { |
80
|
0
|
0
|
|
|
|
|
write_file($opt->output, $svg) || warn "Could not write file"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
|
say $svg; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding UTF-8 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Mail::BIMI::App::Command::svgfromvmc - Extract the SVG from a VMC |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 VERSION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
version 3.20210301 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
App::Cmd class implementing the 'mailbimi svgfromvmc' command |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 REQUIRES |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * L<File::Slurp|File::Slurp> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * L<Mail::BIMI|Mail::BIMI> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * L<Mail::BIMI::App|Mail::BIMI::App> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * L<Mail::BIMI::Indicator|Mail::BIMI::Indicator> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * L<Mail::BIMI::VMC|Mail::BIMI::VMC> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Marc Bradshaw. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |