| 1 | package WWW::MailboxOrg::API::Utils; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Utility API (parse_headers, parse_date, generate_message_id) | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooX::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Params::ValidationCompiler qw(validation_for); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Types::Standard qw(Str HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = '0.001'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | has client => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | weak_ref => 1, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | sub _rpc { | ||||||||||
| 20 | 0 | ▶ | my ($self, $method, @params) = @_; | ||||||||
|
Subroutine
_rpc: not called CC=2 SCAR=17.9
| |||||||||||
| 21 | 0 | ▶ | my $client = $self->client or croak "No client set"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | return $client->call($method, @params); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 1 | my %validators = ( | |||||||||
| 26 | parse_headers => validation_for( | ||||||||||
| 27 | params => { | ||||||||||
| 28 | headers => { type => Str, optional => 0 }, | ||||||||||
| 29 | }, | ||||||||||
| 30 | ), | ||||||||||
| 31 | parse_date => validation_for( | ||||||||||
| 32 | params => { | ||||||||||
| 33 | date => { type => Str, optional => 0 }, | ||||||||||
| 34 | }, | ||||||||||
| 35 | ), | ||||||||||
| 36 | generate_message_id => validation_for( | ||||||||||
| 37 | params => { | ||||||||||
| 38 | account => { type => Str, optional => 0 }, | ||||||||||
| 39 | }, | ||||||||||
| 40 | ), | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | sub parse_headers { | ||||||||||
| 44 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
parse_headers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 45 | 0 | my $v = $validators{'parse_headers'}; | |||||||||
| 46 | 0 | ▶ | %params = $v->(%params) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | return $self->_rpc('utils.parse_headers', \%params); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub parse_date { | ||||||||||
| 51 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
parse_date: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 52 | 0 | my $v = $validators{'parse_date'}; | |||||||||
| 53 | 0 | ▶ | %params = $v->(%params) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return $self->_rpc('utils.parse_date', \%params); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub generate_message_id { | ||||||||||
| 58 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
generate_message_id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 59 | 0 | my $v = $validators{'generate_message_id'}; | |||||||||
| 60 | 0 | ▶ | %params = $v->(%params) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | return $self->_rpc('utils.generate_message_id', \%params); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||
| 67 | |||||||||||
| 68 | =pod | ||||||||||
| 69 | |||||||||||
| 70 | =encoding UTF-8 | ||||||||||
| 71 | |||||||||||
| 72 | =head1 NAME | ||||||||||
| 73 | |||||||||||
| 74 | WWW::MailboxOrg::API::Utils - Utility API (parse_headers, parse_date, generate_message_id) | ||||||||||
| 75 | |||||||||||
| 76 | =head1 VERSION | ||||||||||
| 77 | |||||||||||
| 78 | version 0.001 | ||||||||||
| 79 | |||||||||||
| 80 | =head1 NAME | ||||||||||
| 81 | |||||||||||
| 82 | WWW::MailboxOrg::API::Utils - Utility API | ||||||||||
| 83 | |||||||||||
| 84 | =head2 parse_headers | ||||||||||
| 85 | |||||||||||
| 86 | my $parsed = $api->utils->parse_headers( | ||||||||||
| 87 | headers => "From: user@example.com\r\nSubject: Hello", | ||||||||||
| 88 | ); | ||||||||||
| 89 | |||||||||||
| 90 | Parse email headers. Required: C<headers>. | ||||||||||
| 91 | |||||||||||
| 92 | =head2 parse_date | ||||||||||
| 93 | |||||||||||
| 94 | my $parsed = $api->utils->parse_date(date => 'Mon, 01 Jan 2024 12:00:00 +0000'); | ||||||||||
| 95 | |||||||||||
| 96 | Parse an email date. Required: C<date>. | ||||||||||
| 97 | |||||||||||
| 98 | =head2 generate_message_id | ||||||||||
| 99 | |||||||||||
| 100 | my $msg_id = $api->utils->generate_message_id; | ||||||||||
| 101 | my $msg_id = $api->utils->generate_message_id(account => 'user@example.com'); | ||||||||||
| 102 | |||||||||||
| 103 | Generate a message ID. Optional: C<account>. | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | =head1 SUPPORT | ||||||||||
| 108 | |||||||||||
| 109 | =head2 Issues | ||||||||||
| 110 | |||||||||||
| 111 | Please report bugs and feature requests on GitHub at | ||||||||||
| 112 | L<https://github.com/getty/p5-www-mailboxorg/issues>. | ||||||||||
| 113 | |||||||||||
| 114 | =head2 IRC | ||||||||||
| 115 | |||||||||||
| 116 | Join C<#perl-help> on C<irc.perl.org> or message Getty directly. | ||||||||||
| 117 | |||||||||||
| 118 | =head1 CONTRIBUTING | ||||||||||
| 119 | |||||||||||
| 120 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||
| 121 | |||||||||||
| 122 | =head1 AUTHOR | ||||||||||
| 123 | |||||||||||
| 124 | Torsten Raudssus <getty@cpan.org> | ||||||||||
| 125 | |||||||||||
| 126 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 127 | |||||||||||
| 128 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||||||||||
| 129 | |||||||||||
| 130 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 131 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||