Mail-JMAPTalk-0.18/000755 000765 000024 00000000000 15245140314 014136 5ustar00brongstaff000000 000000 Mail-JMAPTalk-0.18/LICENSE000644 000765 000024 00000046334 15245136173 015165 0ustar00brongstaff000000 000000 This software is copyright (c) 2015-2026 by Fastmail Pty Ltd. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2015-2026 by Fastmail Pty Ltd. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Moe Ghoul, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 2015-2026 by Fastmail Pty Ltd. This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Mail-JMAPTalk-0.18/Changes000644 000765 000024 00000004630 15245136203 015436 0ustar00brongstaff000000 000000 Revision history for Perl extension Mail::JMAPTalk. 0.18 Mon Aug 31 2026 - clarify licensing: same terms as Perl itself (Artistic License 1.0 or GPL version 1 or later) - include a LICENSE file in the distribution - use core MIME::Base64 instead of Convert::Base64 - File::LibMagic is now optional: it is loaded only when Upload() is called without an explicit mimetype, and falls back to "application/octet-stream" if it isn't installed. Moved from requires to recommends - declare Test::More in TEST_REQUIRES - uncomment LICENSE => Perl_5 in Makefile.PL (metadata previously said "unknown") 0.17 Sun Jan 26 23:31:00 AEST 2025 - pass through SSL_options to HTTP::Tiny 0.16 Thu Oct 17 20:01:00 EDT 2024 - add the ability to pass extra headers to the Upload function 0.15 Tue May 26 11:01:00 AEST 2019 - Actually encode the filename when creating a URI 0.14 Mon May 25 18:34:12 AEST 2019 - User-Agent should be Mail:: rather than Net:: - new() takes lowercase using, not "Using". - add Call() helper method - change dependency from JSON::XS to just JSON - request createdIds from the server (no API hooked up yet) - allow up to 2048 levels of JSON nesting - no longer die on Download() error - much better documentation 0.13 Wed Apr 17 14:00:42 CEST 2019 - Added DefaultUsing subroutine to get/set 'using' argument 0.12 Mon Jul 16 03:02:21 AEST 2018 - Changed 'using' default to standard params 0.11 Mon Apr 23 11:47:33 AEDT 2018 - Added optional Headers argument to Download function 0.10 Fri Dec 29 12:38:24 AEDT 2017 - added CallMethods() API for wrapping new-style JMAP - change Request() back to raw wire control 0.09 Fri Dec 29 12:38:24 AEDT 2017 - changed Request to new JMAP style 0.08 Tue Aug 8 16:45:54 AEST 2017 - add support for accountId in blob upload (thanks rsto) 0.07 Thu Mar 2 19:04:00 CET 2017 - implement JMAP auth 0.06 Tue Dec 6 13:41:05 2016 - fix Download API 0.05 Tue Dec 6 13:41:05 2016 - add Download API 0.04 Wed Nov 30 14:57:15 2016 - depend on HTTP::Tiny 0.03 Mon Nov 28 22:57:19 2016 - add upload support - add DEBUGJMAP environment variable 0.02 Tue Aug 11 16:04:30 2015 - add JSON::XS dependency 0.01 Thu Jul 2 14:34:54 2015 - original version; created by h2xs 1.23 with options -AX --skip-exporter --use-new-tests -n Mail::JMAPTalk Mail-JMAPTalk-0.18/MANIFEST000644 000765 000024 00000000373 15245140314 015272 0ustar00brongstaff000000 000000 Changes LICENSE Makefile.PL MANIFEST README t/Mail-JMAPTalk.t lib/Mail/JMAPTalk.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Mail-JMAPTalk-0.18/t/000755 000765 000024 00000000000 15245140314 014401 5ustar00brongstaff000000 000000 Mail-JMAPTalk-0.18/README000644 000765 000024 00000002375 15245136173 015035 0ustar00brongstaff000000 000000 Mail-JMAPTalk ============= The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: blah blah blah COPYRIGHT AND LICENCE Copyright 2015-2026 Fastmail Pty Ltd. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself; that is, either the GNU General Public License as published by the Free Software Foundation (version 1, or at your option any later version), or the Artistic License. See http://dev.perl.org/licenses/ and the LICENSE file included with this distribution for more information. Mail-JMAPTalk-0.18/META.yml000644 000765 000024 00000001212 15245140314 015403 0ustar00brongstaff000000 000000 --- abstract: 'Basic interface to talk to JMAP Servers' author: - 'Bron Gondwana ' build_requires: ExtUtils::MakeMaker: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.76, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Mail-JMAPTalk no_index: directory: - t - inc recommends: File::LibMagic: '0' requires: HTTP::Tiny: '0' JSON: '0' MIME::Base64: '0' version: '0.18' x_serialization_backend: 'CPAN::Meta::YAML version 0.020' Mail-JMAPTalk-0.18/lib/000755 000765 000024 00000000000 15245140314 014704 5ustar00brongstaff000000 000000 Mail-JMAPTalk-0.18/Makefile.PL000644 000765 000024 00000002027 15245136203 016113 0ustar00brongstaff000000 000000 use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Mail::JMAPTalk', VERSION_FROM => 'lib/Mail/JMAPTalk.pm', # finds $VERSION, requires EU::MM from perl >= 5.5 PREREQ_PM => { 'MIME::Base64' => 0, 'JSON' => 0, 'HTTP::Tiny' => 0, }, TEST_REQUIRES => { 'Test::More' => 0, }, ABSTRACT_FROM => 'lib/Mail/JMAPTalk.pm', # retrieve abstract from module AUTHOR => 'Bron Gondwana ', LICENSE => 'Perl_5', META_MERGE => { 'meta-spec' => { version => 2 }, prereqs => { runtime => { # only needed to guess the type of an Upload() with no # explicit mimetype; needs the C libmagic library recommends => { 'File::LibMagic' => 0, }, }, }, }, ); Mail-JMAPTalk-0.18/META.json000644 000765 000024 00000002215 15245140314 015557 0ustar00brongstaff000000 000000 { "abstract" : "Basic interface to talk to JMAP Servers", "author" : [ "Bron Gondwana " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.76, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Mail-JMAPTalk", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "recommends" : { "File::LibMagic" : "0" }, "requires" : { "HTTP::Tiny" : "0", "JSON" : "0", "MIME::Base64" : "0" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.18", "x_serialization_backend" : "JSON::PP version 4.16" } Mail-JMAPTalk-0.18/lib/Mail/000755 000765 000024 00000000000 15245140314 015566 5ustar00brongstaff000000 000000 Mail-JMAPTalk-0.18/lib/Mail/JMAPTalk.pm000644 000765 000024 00000043175 15245136203 017503 0ustar00brongstaff000000 000000 #!/usr/bin/perl -cw use strict; use warnings; package Mail::JMAPTalk; use HTTP::Tiny; use JSON; use MIME::Base64; use Carp qw(confess); use Data::Dumper; our $VERSION = '0.18'; our $CLIENT = "Mail-JMAPTalk"; our $AGENT = "$CLIENT/$VERSION"; our $JSON = JSON->new->utf8->max_depth(2048); =head1 NAME Mail::JMAPTalk - Basic interface to talk to JMAP Servers =head1 VERSION Version 0.18 =head1 SYNOPSIS Mail::JMAPTalk was originally written as a very small wrapper around HTTP::Tiny to talk to a JMAP server and mapping between Perl hashes and JSON on the wire. It doesn't do anything smart with specific JMAP objects. Example: use Mail::JMAPTalk; use JSON; # using basic auth my $jtalk = Mail::JMAPTalk->new( url => "https://jmap.example.com/", user => "foo\@example.com", password => "letmein", ); # using non-standard JMAPAuth token establishment my $jtalk = Mail::JMAPTalk->new( url => "https://jmap.example.com/", ); $jtalk->Login("foo\@example.com", "letmein"); my $res = $jtalk->Call('Mailbox/get'); my %byname = map { $_->{name} -> $_->{id} } @{$res->{ids}); my $data = $jtalk->Upload($emailbytes, 'message/rfc822'); $res = $jtalk->CallMethods([['Email/import', { emails => { "1" => { blobId => $data->{blobId}, keywords => { '$seen' => JSON::true }, mailboxIds => { $byname{Inbox} => JSON::true }, }, }, }, "R1"], ["Email/get", { ids => ["#1"] }, "R2" ]]); # all properties of the email in $res->[1][1]{list}[0] my $response = $jtalk->Download($res->[1][1]{accountId}, $data->{blobId}); =head1 SUBROUTINES/METHODS =head2 $class->new(%Options) Create a new Mail::JMAPTalk object. Takes options for a variety of purposes: Override the UserAgent used for all connections: * ua => HTTP::Tiny->new(...) Host Options: * scheme => 'http' or 'https' (default 'http') * host => hostname (default 'localhost') * port => port number (default 443 for https, otherwise 80) URI Options: (absolute URI, or use options above to set the scope) * authurl => auth endpoint (default '/jmap/auth/') * uploadurl => upload endpoint (default '/jmap/upload/{accountId}/') * downloadurl => download endpoint (default '/jmap/download/{accountId}/{blobId}/{name}') * url => JMAP API endpoint (default '/jmap/') Authentication Options: (basic auth) * user => $username * password => $password Other Options: * SSL_options => a hashref of SSL options to pass down to the default user agent Request Defaults: * using => \@urns (default ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail']) =cut sub new { my ($Proto, %Args) = @_; my $Class = ref($Proto) || $Proto; my $Self = bless { %Args }, $Class; $Self->{using} ||= ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail']; return $Self; } =head2 my $ua = $Self->ua(); =head2 $Self->ua($setua); Get or set the useragent (HTTP::Tiny or compatible) that will be used to make the requests: e.g. my $ua = $Self->ua(); $Self->ua(HTTP::Tiny->new(agent => "MyAgent/1.0", timeout => 5)); =cut sub ua { my $Self = shift; unless ($Self->{ua}) { $Self->{ua} = HTTP::Tiny->new(agent => $AGENT, SSL_options => $Self->{SSL_options}); } return $Self->{ua}; } =head2 my $header = $Self->auth_header(); Returns the basic-auth value for the 'Authentication' header. =cut sub auth_header { my $Self = shift; return 'Basic ' . encode_base64("$Self->{user}:$Self->{password}", ''); } =head2 my $uri = $Self->authuri(); Returns the URI for JMAPAuth authentication (non-standard). Default depends on the parameters passed to new. Most simple would be: http://localhost/jmap/auth/ =cut sub authuri { my $Self = shift; my $scheme = $Self->{scheme} // 'http'; my $host = $Self->{host} // 'localhost'; my $port = $Self->{port} // ($scheme eq 'http' ? 80 : 443); my $url = $Self->{authurl} // '/jmap/auth/'; return $url if $url =~ m/^http/; return "$scheme://$host:$port$url"; } =head2 my $uri = $Self->uploaduri($accountId); Returns the URI for JMAP uploads. Default depends on the parameters passed to new. Most simple would be: http://localhost/jmap/upload/${accountId}/ =cut sub uploaduri { my $Self = shift; my $accountId = shift; die "need account" unless $accountId; my $scheme = $Self->{scheme} // 'http'; my $host = $Self->{host} // 'localhost'; my $port = $Self->{port} // ($scheme eq 'http' ? 80 : 443); my $url = $Self->{uploadurl} // '/jmap/upload/{accountId}/'; my %map = ( accountId => $accountId, ); $url =~ s/\{([a-zA-Z0-9_]+)\}/$map{$1}||''/ges; return $url if $url =~ m/^http/; return "$scheme://$host:$port$url"; } =head2 my $uri = $Self->downloaduri($accountId, $blobId, $name); Returns the URI for JMAP downloads. Default depends on the parameters passed to new. Most simple would be: http://localhost/jmap/download/${accountId}/${blobId}/{$name} Where name is utf8 and uri encoded to be safe. =cut sub downloaduri { my $Self = shift; my ($accountId, $blobId, $name) = @_; die "need account and blob" unless ($accountId and $blobId); $name ||= "download"; my $scheme = $Self->{scheme} // 'http'; my $host = $Self->{host} // 'localhost'; my $port = $Self->{port} // ($scheme eq 'http' ? 80 : 443); my $url = $Self->{downloadurl} // '/jmap/download/{accountId}/{blobId}/{name}'; # needs to be encoded as bytes for URI encoding utf8::encode($name); my %map = ( accountId => $accountId, blobId => $blobId, name => $name =~ s/([^a-zA-Z0-9])/sprintf('%%%02X', ord($1))/egr ); $url =~ s/\{([a-zA-Z0-9_]+)\}/$map{$1}||''/ges; return $url if $url =~ m/^http/; return "$scheme://$host:$port$url"; } =head2 my $uri = $Self->uri() Returns the URI for JMAP API Calls. Default depends on the parameters passed to new. Most simple would be: http://localhost/jmap/ =cut sub uri { my $Self = shift; my $scheme = $Self->{scheme} // 'http'; my $host = $Self->{host} // 'localhost'; my $port = $Self->{port} // ($scheme eq 'http' ? 80 : 443); my $url = $Self->{url} // '/jmap/'; return $url if $url =~ m/^http/; return "$scheme://$host:$port$url"; } =head2 my $uri = $Self->JSONPOST($Uri, $Request, %Headers) Makes a POST request to the given URI with the body being the value of $Request (which must be a reference) encoded as JSON, and with the Headers added. Will set Content-Type and Accept headers to 'application/json' unless overridden. Generally you won't call this directly, but through one of the helper methods. This method will die if the response is not successful or does not contain valid json. =cut sub JSONPOST { my ($Self, $Uri, $Request, %Headers) = @_; $Headers{'Content-Type'} //= "application/json"; $Headers{'Accept'} //= "application/json"; my $Response = $Self->ua->post($Uri, { headers => \%Headers, content => $JSON->encode($Request), }); my $jdata; $jdata = eval { $JSON->decode($Response->{content}) } if $Response->{success}; if ($ENV{DEBUGJMAP}) { warn "JMAP " . Dumper($Uri, \%Headers, $Request, $Response); } # check your own success on the Response object if (wantarray) { return ($Response, $jdata); } confess "JMAP request for $Self->{user} failed ($Uri): $Response->{status} $Response->{reason}: $Response->{content}" unless $Response->{success}; confess "INVALID JSON $Response->{content}" unless $jdata; return $jdata; } =head2 $Self->AuthRequest($Request, %Headers) Makes a JSONPOST request to the authurl. =cut sub AuthRequest { my ($Self, $Request, %Headers) = @_; return $Self->JSONPOST($Self->authuri(), $Request, %Headers); } =head2 $Self->Login($Username, $Password) Uses the non-standard JMAPAuth protocol to login. On success will set the upload, download and api urls as well as a token which is used to authenticate all further requests. On failure will die. =cut sub Login { my ($Self, $Username, $Password) = @_; my $data = $Self->AuthRequest({ username => $Username, clientName => $CLIENT, clientVersion => $VERSION, deviceName => $Self->{deviceName} || 'api', }); while ($data->{loginId}) { die "Unknown method" unless grep { $_->{type} eq 'password' } @{$data->{methods}}; $data = $Self->AuthRequest({ loginId => $data->{loginId}, type => 'password', password => $Password, }); } die "Failed to get a token" unless $data->{accessToken}; $Self->{token} = $data->{accessToken}; $Self->{url} = $data->{apiUrl}; $Self->{uploaduri} = $data->{uploadUrl}; $Self->{downloaduri} = $data->{downloadUrl}; $Self->{eventSource} = $data->{eventSource}; return 1; } =head2 $Self->Request($Request, %Headers) Makes a JSONPOST request to the API url, authenticated with either the basic auth parameters given at creation, or the token obtained via Login. =cut sub Request { my ($Self, $Request, %Headers) = @_; if ($Self->{user}) { $Headers{'Authorization'} = $Self->auth_header(); } if ($Self->{token}) { $Headers{'Authorization'} = "Bearer $Self->{token}"; } return $Self->JSONPOST($Self->uri(), $Request, %Headers); } =head2 my $using = $Self->DefaultUsing() =head2 $Self->DefaultUsing(\@urns) Returns or replaces the default 'using' value for method calls. =cut sub DefaultUsing { my ($Self, $Using) = @_; return $Self->{using} unless $Using; $Self->{using} = $Using; } =head2 $Self->AddUsing(@urns) Appends any urns given to the default 'using' if they aren't already registered. =cut sub AddUsing { my $Self = shift; foreach my $Using (@_) { next if grep { $_ eq $Using } @{$Self->{using}}; push @{$Self->{using}}, $Using; } } =head2 $Self->CallMethods($MethodCalls, $Using, %Headers) Generates a JMAP request from the given method calls, optionally overriding the using and header values. MethodCalls is an array of arrays, each of the sub arrays is a single "Invocation" per RFC8620 as follows: 3.2. The Invocation Data Type Method calls and responses are represented by the *Invocation* data type. This is a tuple, represented as a JSON array containing three elements: 1. A "String" *name* of the method to call or of the response. 2. A "String[*]" object containing named *arguments* for that method or response. 3. A "String" *method call id*: an arbitrary string from the client to be echoed back with the responses emitted by that method call (a method may return 1 or more responses, as it may make implicit calls to other methods; all responses initiated by this method call get the same method call id in the response). In perl, this is [string, hashref, string]. Example: my $res = $jtalk->CallMethods([ ['Email/query', { }, 'R1'], ['Email/get', { '#ids' => { resultOf => 'R1', name => 'Email/query', path => '/ids' }, properties => [ 'subject', 'header:x-mood:asText', 'from', 'to' ], }, 'R2'], ]); The response is an arrayref containing the value of methodResponses from the JSON reply defined in JMAP. This method will die if the server returns an error or invalid JSON. =cut sub CallMethods { my ($Self, $MethodCalls, $Using, %Headers) = @_; $Using ||= $Self->{using}; my $Request = { using => $Using, methodCalls => $MethodCalls, createdIds => $Self->{CreatedIds} || {}, }; my $Response = $Self->Request($Request, %Headers); $Self->{CreatedIds} = $Response->{createdIds}; $Self->{SessionState} = $Response->{sessionState}; return $Response->{methodResponses}; } =head2 $Self->Call($Method, $Params, $Using, %Headers) A convenience method to call a single method. This method generates a single invocation with call id 'c1' and will return undef unless the first response from the server has the same method name (i.e. is not an error) and the same call id. The return value is the response section (middle field) of the first methodResponse Invocation object. Example: my $res = $jtalk->Call('Calendar/get', { properties => ['name'] }); my %byname = map { $_->{name} => $_->{id} } @{$res->{list}}; =cut sub Call { my ($Self, $Method, $Params, @Args) = @_; $Params ||= {}; my $Res = $Self->CallMethods([[$Method, $Params, "c1"]], @Args); return undef unless ref $Res; return undef unless ref $Res->[0]; return undef unless $Res->[0][0] eq $Method; return undef unless $Res->[0][2] eq 'c1'; return $Res->[0]->[1]; } sub _get_type { my $data = shift; # XXX - escape file names? # File::LibMagic is optional - it needs the C libmagic library, and every # known caller passes an explicit type anyway, so only load it if we're # actually asked to guess. return 'application/octet-stream' unless eval { require File::LibMagic; 1 }; my $magic = File::LibMagic->new(); my $info = $magic->info_from_string($data); return $info->{mime_type}; } =head2 $Self->Upload($Headers?, $data, $mimetype, $accountId) If the first argument is a hash reference, it will be shifted and used as additional headers. Uploads the bytes in $data with either the given mimetype or, if the mimetype is not given, the type picked by File::LibMagic. File::LibMagic is optional. If it isn't installed, an unspecified mimetype falls back to "application/octet-stream", so pass $mimetype explicitly if you care what the blob is typed as. The POST request is authenticated with either the basic auth parameters given at creation, or the token obtained via Login. If called in scalar context, will die unless the request was successful - and returns a hashref with the content returned by the server as defined in RFC8620: A successful request MUST return a single JSON object with the following properties as the response: o accountId: "Id" The id of the account used for the call. o blobId: "Id" The id representing the binary data uploaded. The data for this id is immutable. The id *only* refers to the binary data, not any metadata. o type: "String" The media type of the file (as specified in [RFC6838], Section 4.2) as set in the Content-Type header of the upload HTTP request. o size: "UnsignedInt" The size of the file in octets. If called in array context, returns two values - the first is the raw HTTP::Tiny response hash, and the second is the JSON as above. Example: my ($Response, $data) = $jtalk->Upload($bytes); if ($Response->{success}) { say "Uploaded $data->{size} bytes as $data->{blobId}"; ... } =cut sub Upload { my $Self = shift; my %Headers; if (ref($_[0]) eq 'HASH') { %Headers = %{ (shift) }; } my ($data, $type, $accountId) = @_; $Headers{'Content-Type'} = $type || _get_type($data); $accountId = $accountId || $Self->{user}; if ($Self->{user}) { $Headers{'Authorization'} = $Self->auth_header(); } if ($Self->{token}) { $Headers{'Authorization'} = "Bearer $Self->{token}"; } my $uri = $Self->uploaduri($accountId); my $Response = $Self->ua->post($uri, { headers => \%Headers, content => $data, }); if ($ENV{DEBUGJMAP}) { warn "JMAP UPLOAD " . Dumper($Response); } my $jdata; $jdata = eval { $JSON->decode($Response->{content}) } if $Response->{success}; # check your own success on the Response object if (wantarray) { return ($Response, $jdata); } confess "JMAP request for $Self->{user} failed ($uri): $Response->{status} $Response->{reason}: $Response->{content}" unless $Response->{success}; confess "INVALID JSON $Response->{content}" unless $jdata; return $jdata; } =head2 $Self->Download($cb?, $Headers?, $accountId, $blobId, $name) Makes a GET request authenticated with either the basic auth parameters given at creation, or the token obtained via Login. If the first argument is a code reference, it will be shifted and used as the data_callback (see HTTP::Tiny). Then - if the first argument is a hash reference, it will be shifted and used as additional headers. Then - the remaining parameters are passed to $Self->downloadurl() to generate the link to download. The response is a HTTP::Tiny Response object. Example: my $res = $jtalk->Download($accountId, $data->{blobId}, "image.gif"); if ($res->{success}) { open(FH, ">image.gif"); print FH $res->{content}; close(FH); } =cut sub Download { my $Self = shift; my $cb; if (ref($_[0]) eq 'CODE') { $cb = shift; } my %Headers; if (ref($_[0]) eq 'HASH') { %Headers = %{ (shift) }; } my $uri = $Self->downloaduri(@_); if ($Self->{user}) { $Headers{'Authorization'} = $Self->auth_header(); } if ($Self->{token}) { $Headers{'Authorization'} = "Bearer $Self->{token}"; } my %getopts = (headers => \%Headers); $getopts{data_callback} = $cb if $cb; my $Response = $Self->ua->get($uri, \%getopts); if ($ENV{DEBUGJMAP}) { warn "JMAP DOWNLOAD @_ " . Dumper($Response); } return $Response; } 1; __END__ =head1 ENVIRONMENT If the environment variable DEBUGJMAP is set to a true value, all API requests and responses plus Upload responses will be warn()ed. =head1 SEE ALSO https://jmap.io/ - protocol documentation and client guide. =head1 AUTHOR Bron Gondwana, Ebrong@E =head1 LICENSE AND COPYRIGHT Copyright 2015-2026 Fastmail Pty Ltd. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself; that is, either the GNU General Public License as published by the Free Software Foundation (version 1, or at your option any later version), or the Artistic License. See L and the LICENSE file included with this distribution for more information. =cut Mail-JMAPTalk-0.18/t/PaxHeader/Mail-JMAPTalk.t000644 000765 000024 00000000210 15154402172 020755 xustar00brongstaff000000 000000 30 mtime=1773274234.814437079 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Mail-JMAPTalk-0.18/t/Mail-JMAPTalk.t000644 000765 000024 00000000770 15154402172 017017 0ustar00brongstaff000000 000000 # Before 'make install' is performed this script should be runnable with # 'make test'. After 'make install' it should work as 'perl Mail-JMAPTalk.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok('Mail::JMAPTalk') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script.