Text-JSContact-0.02/000755 000765 000024 00000000000 15245132131 014454 5ustar00brongstaff000000 000000 Text-JSContact-0.02/LICENSE000644 000765 000024 00000046315 15245122464 015502 0ustar00brongstaff000000 000000 This software is copyright (c) 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) 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) 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 Text-JSContact-0.02/PaxHeader/Changes000644 000765 000024 00000000210 15245122662 017721 xustar00brongstaff000000 000000 30 mtime=1788126642.141496914 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/Changes000644 000765 000024 00000001574 15245122662 015766 0ustar00brongstaff000000 000000 Revision history for Perl extension Text::JSContact 0.02 2026-08-31 - clarify licensing: same terms as Perl itself (Artistic License 1.0 or GPL version 1 or later) - include a LICENSE file in the distribution - add POD with NAME/AUTHOR/LICENSE (the module had none) - README previously claimed Artistic License 2.0, which contradicted the Perl_5 metadata; the README was wrong 0.01 2026-04-05 - Initial release - Bidirectional vCard <=> JSContact conversion - Follows RFCs 9553 (JSContact), 9554 (extensions), 9555 (vCard mapping) - Covers: name, emails, phones, addresses, organizations, titles, anniversaries, notes, onlineServices, media, links, calendars, schedulingAddresses, cryptoKeys, directories, keywords, members, relatedTo, speakToAs, preferredLanguages, personalInfo - 192 unit tests including RFC 9555 test vectors - Cyrus CardDAV integration tests Text-JSContact-0.02/MANIFEST000644 000765 000024 00000000473 15245132131 015611 0ustar00brongstaff000000 000000 Changes lib/Text/JSContact.pm LICENSE Makefile.PL MANIFEST This list of files README t/apple.t t/basic.t t/cyrus-carddav.t t/patch.t t/rfc9555.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Text-JSContact-0.02/t/000755 000765 000024 00000000000 15245132130 014716 5ustar00brongstaff000000 000000 Text-JSContact-0.02/PaxHeader/README000644 000765 000024 00000000210 15245122632 017303 xustar00brongstaff000000 000000 30 mtime=1788126618.304295456 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/README000644 000765 000024 00000015037 15245122632 015347 0ustar00brongstaff000000 000000 Text::JSContact - Convert between vCard and JSContact DESCRIPTION Text::JSContact provides bidirectional conversion between vCard (RFC 6350) and JSContact (RFC 9553), following the mapping rules in RFC 9555 and the extensions in RFC 9554. The module handles both standard vCard properties and widely-used vendor extensions, particularly those from Apple's Contacts/AddressBook framework. FUNCTIONS vcard_to_jscontact($vcard_string) Parse a vCard string and return a JSContact Card hashref. jscontact_to_vcard($card_hashref) Convert a JSContact Card hashref to a vCard string (version 4.0). patch_vcard($original_vcard_string, $old_card, $new_card) Apply changes to a vCard while preserving unrecognized properties and vendor extensions. Compares $old_card and $new_card to determine what changed, then applies only those changes to the original vCard string. This is the recommended way to update contacts via CardDAV, because it preserves Apple extensions, custom X-properties, and any other data in the vCard that JSContact does not model. $original_vcard_string - the raw vCard text as fetched from the server $old_card - the JSContact Card parsed from that vCard $new_card - the modified JSContact Card to write back Returns a new vCard string with minimal changes applied. APPLE VCARD EXTENSIONS Apple's Contacts framework (macOS/iOS) uses several non-standard vCard properties and parameters. These are not part of any RFC but are widely used by Apple clients, iCloud, and third-party applications that need to interoperate with the Apple ecosystem. There is no formal Apple specification for these extensions. Our implementation is based on reverse-engineering Apple-exported vCards and community documentation, including: - iOS full vCard examples from cozy/cozy-vcard test suite https://github.com/cozy/cozy-vcard/blob/master/test/ios-full.vcf - X-ABLabel discussion and behavior analysis https://github.com/mstilkerich/rcmcarddav/issues/310 https://github.com/FossifyOrg/Contacts/issues/187 - Apple group contact format (X-ADDRESSBOOKSERVER-KIND/MEMBER) https://github.com/nextcloud/server/issues/9369 - RFC 9554 standardization of SOCIALPROFILE (replacing X-SOCIALPROFILE) https://datatracker.ietf.org/doc/rfc9554/ - X-ABCROP-RECTANGLE format analysis https://gitlab.com/CardBook/CardBook/-/issues/283 Policy: Reading Apple Extensions When parsing vCards, we recognize and convert the following Apple extensions to their JSContact equivalents: X-ABLabel -> label field on the associated property Parsed from itemN.X-ABLabel grouped with the labeled property. Apple standard labels like _$!!$_ are unwrapped to just "HomePage". X-ADDRESSBOOKSERVER-KIND -> kind (e.g. "group") X-ADDRESSBOOKSERVER-MEMBER -> members (Apple's vCard 3.0 equivalent of the standard KIND + MEMBER properties) X-ABRELATEDNAMES -> relatedTo, with relation type derived from the associated X-ABLabel. Mappings: Mother/Father/Parent -> parent Brother/Sister -> sibling Child -> child Friend -> friend Spouse/Partner -> spouse Assistant/Manager -> colleague X-ABDATE -> anniversaries, with kind derived from X-ABLabel. "Anniversary" label maps to kind "wedding". X-ABADR -> addresses[].countryCode (ISO country code, grouped with the associated ADR property) X-PHONETIC-FIRST-NAME -> name.phoneticComponents (kind: given) X-PHONETIC-MIDDLE-NAME -> name.phoneticComponents (kind: given2) X-PHONETIC-LAST-NAME -> name.phoneticComponents (kind: surname) X-SOCIALPROFILE -> onlineServices (with service from TYPE param and user from x-user param) X-AIM, X-ICQ, X-MSN, X-YAHOO, X-JABBER, X-SKYPE, X-TWITTER, X-GOOGLE-TALK -> onlineServices (legacy IM properties) Policy: Writing Apple Extensions When generating vCards, we write standard vCard 4.0 properties. Apple extensions are generated in the following cases: - When a JSContact property has a "label" field, we generate a grouped itemN.X-ABLabel property alongside the main property. This ensures custom labels survive round-trips through Apple clients. - Standard vCard 4.0 equivalents are used where they exist: KIND instead of X-ADDRESSBOOKSERVER-KIND MEMBER instead of X-ADDRESSBOOKSERVER-MEMBER RELATED instead of X-ABRELATEDNAMES ANNIVERSARY instead of X-ABDATE SOCIALPROFILE instead of X-SOCIALPROFILE (per RFC 9554) - Legacy X-service IM properties (X-AIM, X-SKYPE, etc.) are written as IMPP properties with SERVICE-TYPE parameter. The intent is that vCards generated by this module are valid vCard 4.0 that Apple clients can read, while vCards from Apple clients are fully parsed without data loss. Preserving Unknown Properties (patch_vcard) When updating a contact via CardDAV, a naive approach of converting JSContact -> vCard and PUT-ing the result will lose any vCard properties that JSContact does not model. This includes vendor extensions, custom X-properties, and any standard properties we don't yet handle. The patch_vcard() function solves this by: 1. Parsing the original vCard to identify all properties 2. Comparing old_card and new_card to find what actually changed 3. Modifying only the changed properties in the original vCard 4. Preserving everything else verbatim This is important for interoperability with Apple and other clients that store data in properties we may not understand. SPECIFICATIONS RFC 6350 - vCard Format Specification RFC 9553 - JSContact: A JSON Representation of Contact Data RFC 9554 - vCard Format Extensions for JSContact RFC 9555 - JSContact: Converting from and to vCard AUTHOR Bron Gondwana LICENSE Copyright 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. Text-JSContact-0.02/META.yml000644 000765 000024 00000001224 15245132131 015724 0ustar00brongstaff000000 000000 --- abstract: 'Convert between vCard and JSContact (RFC 9553/9555)' author: - 'Bron Gondwana ' build_requires: 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: Text-JSContact no_index: directory: - t - inc requires: Encode: '0' JSON: '0' MIME::Base64: '0' Scalar::Util: '0' Text::VCardFast: '0.06' perl: '5.014' version: '0.02' x_serialization_backend: 'CPAN::Meta::YAML version 0.020' Text-JSContact-0.02/lib/000755 000765 000024 00000000000 15245132130 015221 5ustar00brongstaff000000 000000 Text-JSContact-0.02/PaxHeader/Makefile.PL000644 000765 000024 00000000207 15164516177 020416 xustar00brongstaff000000 000000 29 mtime=1775410303.82235651 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/Makefile.PL000644 000765 000024 00000001525 15164516177 016451 0ustar00brongstaff000000 000000 use 5.014; use strict; use warnings FATAL => 'all'; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Text::JSContact', AUTHOR => q{Bron Gondwana }, VERSION_FROM => 'lib/Text/JSContact.pm', ABSTRACT => 'Convert between vCard and JSContact (RFC 9553/9555)', LICENSE => 'Perl_5', PL_FILES => {}, MIN_PERL_VERSION => 5.014, CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => 0, }, BUILD_REQUIRES => { 'Test::More' => 0, }, PREREQ_PM => { 'Text::VCardFast' => '0.06', 'Encode' => 0, 'MIME::Base64' => 0, 'JSON' => 0, 'Scalar::Util' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Text-JSContact-*' }, ); Text-JSContact-0.02/META.json000644 000765 000024 00000002120 15245132131 016070 0ustar00brongstaff000000 000000 { "abstract" : "Convert between vCard and JSContact (RFC 9553/9555)", "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" : "Text-JSContact", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Encode" : "0", "JSON" : "0", "MIME::Base64" : "0", "Scalar::Util" : "0", "Text::VCardFast" : "0.06", "perl" : "5.014" } } }, "release_status" : "stable", "version" : "0.02", "x_serialization_backend" : "JSON::PP version 4.16" } Text-JSContact-0.02/lib/Text/000755 000765 000024 00000000000 15245132130 016145 5ustar00brongstaff000000 000000 Text-JSContact-0.02/lib/Text/JSContact.pm000644 000765 000024 00000147144 15245122602 020351 0ustar00brongstaff000000 000000 #!/usr/bin/perl -cw use strict; use warnings; package Text::JSContact; our $VERSION = '0.02'; # vCard <=> JSContact (RFC 9553) conversion # Follows RFC 9555 for vCard mapping and RFC 9554 for extensions use Text::VCardFast qw(vcard2hash hash2vcard); use Encode qw(decode_utf8 encode_utf8); use MIME::Base64 qw(decode_base64 encode_base64); use JSON; use Scalar::Util qw(looks_like_number); use Exporter 'import'; our @EXPORT_OK = qw(vcard_to_jscontact jscontact_to_vcard patch_vcard); ############################################################################### # HELPERS ############################################################################### sub _first_prop { my ($props, $name) = @_; my $items = $props->{$name}; return undef unless $items && @$items; return $items->[0]; } sub _first_value { my ($props, $name) = @_; my $prop = _first_prop($props, $name); return undef unless $prop; return $prop->{value}; } sub _param { my ($prop, $name) = @_; my $val = $prop->{params}{$name}; return undef unless defined $val; return ref $val eq 'ARRAY' ? $val->[0] : $val; } sub _params_list { my ($prop, $name) = @_; my $val = $prop->{params}{$name}; return () unless defined $val; # Split comma-separated values (e.g. TYPE=work,voice) return map { split /,/ } (ref $val eq 'ARRAY' ? @$val : ($val)); } sub _prop_id { my ($prop, $new_id) = @_; my $pid = _param($prop, 'prop-id'); return $pid if defined $pid && $pid ne ''; return $new_id->(); } sub _decode_value { my $val = shift; return undef unless defined $val; if ($val =~ /[\x80-\xff]/) { $val = eval { decode_utf8($val) } // $val; } return $val; } sub _make_contexts { my @types = @_; my %ctx; for my $t (@types) { my $lt = lc $t; if ($lt eq 'home') { $ctx{private} = JSON::true } elsif ($lt eq 'work') { $ctx{work} = JSON::true } } return %ctx ? \%ctx : undef; } sub _make_pref { my $prop = shift; # vCard 4: PREF parameter my $pref = _param($prop, 'pref'); if (defined $pref && looks_like_number($pref)) { return $pref + 0; } # vCard 3: TYPE=pref for my $t (_params_list($prop, 'type')) { return 1 if lc $t eq 'pref'; } return undef; } sub _to_utc_datetime { my $val = shift; return undef unless defined $val; # Normalize compact timestamps (e.g. 19940930T143510Z -> 1994-09-30T14:35:10Z) if ($val =~ /^(\d{4})-?(\d{2})-?(\d{2})T(\d{2}):?(\d{2}):?(\d{2})/) { return "$1-$2-$3T$4:$5:$6Z"; } return $val; } sub _generate_uid { my @hex = ('0'..'9', 'a'..'f'); my $uuid = ''; for my $i (1..32) { $uuid .= $hex[int(rand(16))]; $uuid .= '-' if $i == 8 || $i == 12 || $i == 16 || $i == 20; } substr($uuid, 14, 1) = '4'; substr($uuid, 19, 1) = $hex[8 + int(rand(4))]; return "urn:uuid:$uuid"; } sub _set_if { my ($hash, $key, $val, $transform) = @_; return unless defined $val && $val ne ''; $val = $transform->($val) if $transform; $hash->{$key} = $val if defined $val; } # Collect X-ABLabel associations (Apple extension) sub _collect_labels { my $props = shift; my %labels; for my $lp (@{$props->{'x-ablabel'} // []}) { my $group = $lp->{group} or next; my $val = $lp->{value} // ''; $val = $1 if $val =~ m{^_\$\!<([^>]*)>\!\$_$}; $labels{$group} = $val; } return \%labels; } sub _apply_label { my ($obj, $prop, $labels) = @_; if (my $group = $prop->{group}) { if (my $label = $labels->{$group}) { $obj->{label} = $label; } } } sub _convert_vcard_date { my $val = shift; return undef unless defined $val; # vCard 4 compact: YYYYMMDD or --MMDD if ($val =~ /^(\d{4}|--)-?(\d{2})-?(\d{2})(?:T|$)/) { my ($y, $m, $d) = ($1, $2, $3); $y = '0000' if $y eq '--'; $y = '0000' if $y eq '1604'; # iOS "no year" magic return "$y-$m-$d"; } # Already ISO format return $val if $val =~ /^\d{4}-\d{2}-\d{2}/; return $val; } sub _adr_values { my ($values, $idx) = @_; my $val = $values->[$idx]; return () unless defined $val; if (ref $val eq 'ARRAY') { return grep { defined $_ && $_ ne '' } @$val; } return ($val) if $val ne ''; return (); } ############################################################################### # VCARD -> JSCONTACT ############################################################################### sub vcard_to_jscontact { my ($vcard_string) = @_; my $parsed = eval { vcard2hash($vcard_string, multival => [qw(n adr org)]) }; return undef unless $parsed && $parsed->{objects} && @{$parsed->{objects}}; my $vcard = $parsed->{objects}[0]; return undef unless $vcard && $vcard->{type} eq 'vcard'; my $props = $vcard->{properties}; my $id_counter = 0; my $new_id = sub { return '' . ++$id_counter }; my $card = { '@type' => 'Card', version => '1.0', }; # UID (required) $card->{uid} = _first_value($props, 'uid') // _generate_uid(); # Simple scalar properties _set_if($card, 'kind', _first_value($props, 'kind') // _first_value($props, 'x-addressbookserver-kind'), sub { lc $_[0] }); _set_if($card, 'prodId', _first_value($props, 'prodid')); _set_if($card, 'updated', _first_value($props, 'rev'), \&_to_utc_datetime); _set_if($card, 'created', _first_value($props, 'created'), \&_to_utc_datetime); _set_if($card, 'language', _first_value($props, 'language')); # Complex properties _convert_name($card, $props); _convert_nicknames($card, $props, $new_id); _convert_emails($card, $props, $new_id); _convert_phones($card, $props, $new_id); _convert_addresses($card, $props, $new_id); _convert_organizations($card, $props, $new_id); _convert_titles($card, $props, $new_id); _convert_anniversaries($card, $props, $new_id); _convert_notes($card, $props, $new_id); _convert_online_services($card, $props, $new_id); _convert_media($card, $props, $new_id); _convert_links($card, $props, $new_id); _convert_calendars($card, $props, $new_id); _convert_scheduling_addresses($card, $props, $new_id); _convert_crypto_keys($card, $props, $new_id); _convert_directories($card, $props, $new_id); _convert_preferred_languages($card, $props, $new_id); _convert_personal_info($card, $props, $new_id); _convert_keywords($card, $props); _convert_members($card, $props); _convert_related($card, $props); _convert_speak_to_as($card, $props, $new_id); return $card; } ############################################################################### # INDIVIDUAL VCARD -> JSCONTACT CONVERTERS ############################################################################### # FN + N -> name sub _convert_name { my ($card, $props) = @_; my $name = {}; my $fn = _first_value($props, 'fn'); $name->{full} = _decode_value($fn) if defined $fn; my $n_prop = _first_prop($props, 'n'); if ($n_prop) { my $values = $n_prop->{values} || []; # N component order: surname, given, given2, title(prefix), credential(suffix), surname2, generation my @kind_map = qw(surname given given2 title credential surname2 generation); my @components; for my $idx (0..$#kind_map) { my $raw = $values->[$idx]; next unless defined $raw; # Handle both arrayref and string; split comma-separated values my @vals; for my $v (ref $raw eq 'ARRAY' ? @$raw : ($raw)) { push @vals, split /,/, $v; } for my $v (@vals) { next unless defined $v && $v ne ''; push @components, { '@type' => 'NameComponent', kind => $kind_map[$idx], value => _decode_value($v), }; } } $name->{components} = \@components if @components; # SORT-AS parameter my $sort_as_param = _param($n_prop, 'sort-as'); if ($sort_as_param) { my @sa = split /,/, $sort_as_param; my %sort_map; for my $i (0..$#sa) { $sort_map{$kind_map[$i]} = $sa[$i] if $i <= $#kind_map && defined $sa[$i] && $sa[$i] ne ''; } $name->{sortAs} = \%sort_map if %sort_map; } } # Apple X-PHONETIC-*-NAME -> phonetic name components my $phonFirst = _first_value($props, 'x-phonetic-first-name'); my $phonLast = _first_value($props, 'x-phonetic-last-name'); my $phonMid = _first_value($props, 'x-phonetic-middle-name'); if ($phonFirst || $phonLast || $phonMid) { my @phon; push @phon, { '@type' => 'NameComponent', kind => 'given', value => _decode_value($phonFirst), phonetic => 'ipa' } if $phonFirst; push @phon, { '@type' => 'NameComponent', kind => 'given2', value => _decode_value($phonMid), phonetic => 'ipa' } if $phonMid; push @phon, { '@type' => 'NameComponent', kind => 'surname', value => _decode_value($phonLast), phonetic => 'ipa' } if $phonLast; $name->{phoneticComponents} = \@phon; } $card->{name} = $name if %$name; } # NICKNAME -> nicknames sub _convert_nicknames { my ($card, $props, $new_id) = @_; my $items = $props->{nickname} || return; my %map; for my $item (@$items) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'Nickname', name => $val }; if (my $ctx = _make_contexts(_params_list($item, 'type'))) { $obj->{contexts} = $ctx; } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } $map{$id} = $obj; } $card->{nicknames} = \%map if %map; } # EMAIL -> emails sub _convert_emails { my ($card, $props, $new_id) = @_; my $items = $props->{email} || return; my $labels = _collect_labels($props); my %map; for my $item (@$items) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'EmailAddress', address => $val }; if (my $ctx = _make_contexts(_params_list($item, 'type'))) { $obj->{contexts} = $ctx; } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } $card->{emails} = \%map if %map; } # TEL -> phones sub _convert_phones { my ($card, $props, $new_id) = @_; my $items = $props->{tel} || return; my $labels = _collect_labels($props); my %tel_feature_map = ( cell => 'mobile', voice => 'voice', fax => 'fax', video => 'video', pager => 'pager', text => 'text', textphone => 'textphone', ); my %map; for my $item (@$items) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'Phone', number => $val }; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx; } my %features; for my $t (@types) { my $feat = $tel_feature_map{lc $t}; $features{$feat} = JSON::true if $feat; } $obj->{features} = \%features if %features; if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } $card->{phones} = \%map if %map; } # ADR -> addresses (+ GEO, TZ by group association) sub _convert_addresses { my ($card, $props, $new_id) = @_; my $items = $props->{adr} || return; my $labels = _collect_labels($props); # Collect grouped GEO/TZ for association with ADR my %geo_by_group; my %tz_by_group; for my $geo (@{$props->{geo} // []}) { $geo_by_group{$geo->{group}} = $geo->{value} if $geo->{group}; } for my $tz (@{$props->{tz} // []}) { $tz_by_group{$tz->{group}} = $tz->{value} if $tz->{group}; } my %map; for my $item (@$items) { my $id = _prop_id($item, $new_id); my $values = $item->{values} || []; my $obj = { '@type' => 'Address' }; # Build components from ADR structured value # Indices: 0=POBox 1=Extended 2=Street 3=Locality 4=Region 5=PostCode 6=Country my @components; for my $v (_adr_values($values, 2)) { push @components, { '@type' => 'AddressComponent', kind => 'name', value => _decode_value($v) }; } for my $v (_adr_values($values, 1)) { push @components, { '@type' => 'AddressComponent', kind => 'apartment', value => _decode_value($v) }; } for my $v (_adr_values($values, 3)) { push @components, { '@type' => 'AddressComponent', kind => 'locality', value => _decode_value($v) }; } for my $v (_adr_values($values, 4)) { push @components, { '@type' => 'AddressComponent', kind => 'region', value => _decode_value($v) }; } for my $v (_adr_values($values, 5)) { push @components, { '@type' => 'AddressComponent', kind => 'postcode', value => _decode_value($v) }; } for my $v (_adr_values($values, 6)) { push @components, { '@type' => 'AddressComponent', kind => 'country', value => _decode_value($v) }; } $obj->{components} = \@components if @components; # Parameters my $label_param = _param($item, 'label'); $obj->{full} = $label_param if defined $label_param; my $geo = _param($item, 'geo'); $geo //= $geo_by_group{$item->{group}} if $item->{group}; $obj->{coordinates} = $geo if defined $geo; my $tz = _param($item, 'tz'); $tz //= $tz_by_group{$item->{group}} if $item->{group}; $obj->{timeZone} = $tz if defined $tz; my $cc = _param($item, 'cc'); # Apple X-ABADR grouped with ADR if (!$cc && $item->{group}) { for my $xabadr (@{$props->{'x-abadr'} // []}) { if (($xabadr->{group} // '') eq $item->{group}) { $cc = $xabadr->{value}; last; } } } $obj->{countryCode} = $cc if defined $cc; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx; } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } $card->{addresses} = \%map if %map; } # ORG -> organizations sub _convert_organizations { my ($card, $props, $new_id) = @_; my $items = $props->{org} || return; my %map; for my $item (@$items) { my $id = _prop_id($item, $new_id); my $values = $item->{values} || []; my $obj = { '@type' => 'Organization' }; # First component -> name my @name_vals = ref $values->[0] eq 'ARRAY' ? @{$values->[0]} : ($values->[0] // ()); my $org_name = join(' ', grep { defined $_ && $_ ne '' } @name_vals); $obj->{name} = $org_name if $org_name ne ''; # Subsequent components -> units my @units; for my $i (1..$#$values) { my @vals = ref $values->[$i] eq 'ARRAY' ? @{$values->[$i]} : ($values->[$i]); for my $v (@vals) { next unless defined $v && $v ne ''; push @units, { '@type' => 'OrgUnit', name => _decode_value($v) }; } } $obj->{units} = \@units if @units; # SORT-AS my $sort_as = _param($item, 'sort-as'); if (defined $sort_as) { my @sa = split /,/, $sort_as; $obj->{sortAs} = $sa[0] if defined $sa[0] && $sa[0] ne ''; for my $i (0..$#units) { $units[$i]{sortAs} = $sa[$i+1] if defined $sa[$i+1] && $sa[$i+1] ne ''; } } my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx; } $map{$id} = $obj; } $card->{organizations} = \%map if %map; } # TITLE + ROLE -> titles sub _convert_titles { my ($card, $props, $new_id) = @_; my %map; for my $spec (['title', 'title'], ['role', 'role']) { my ($propname, $kind) = @$spec; for my $item (@{$props->{$propname} // []}) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); $map{$id} = { '@type' => 'Title', kind => $kind, name => $val }; } } $card->{titles} = \%map if %map; } # BDAY, ANNIVERSARY, DEATHDATE, X-ABDATE -> anniversaries sub _convert_anniversaries { my ($card, $props, $new_id) = @_; my $labels = _collect_labels($props); my %map; for my $spec (['bday', 'birth'], ['anniversary', 'wedding'], ['deathdate', 'death']) { my ($propname, $kind) = @$spec; for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); $map{$id} = { '@type' => 'Anniversary', kind => $kind, date => _convert_vcard_date($val), }; } } # Apple X-ABDATE + X-ABLabel -> anniversaries for my $item (@{$props->{'x-abdate'} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $kind = 'other'; if (my $group = $item->{group}) { my $label = $labels->{$group}; if ($label) { my $lt = lc $label; if ($lt eq 'anniversary') { $kind = 'wedding' } elsif ($lt eq 'other') { $kind = 'other' } else { $kind = $lt } } } $map{$id} = { '@type' => 'Anniversary', kind => $kind, date => _convert_vcard_date($val), }; } $card->{anniversaries} = \%map if %map; } # NOTE -> notes sub _convert_notes { my ($card, $props, $new_id) = @_; my $items = $props->{note} || return; my %map; for my $item (@$items) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'Note', note => $val }; my $created = _param($item, 'created'); $obj->{created} = _to_utc_datetime($created) if defined $created; my $author_name = _param($item, 'author-name'); my $author_uri = _param($item, 'author'); if ($author_name || $author_uri) { my $author = {}; $author->{name} = $author_name if $author_name; $author->{uri} = $author_uri if $author_uri; $obj->{author} = $author; } $map{$id} = $obj; } $card->{notes} = \%map if %map; } # IMPP, SOCIALPROFILE, X-SOCIALPROFILE -> onlineServices sub _convert_online_services { my ($card, $props, $new_id) = @_; my $labels = _collect_labels($props); my %map; for my $item (@{$props->{impp} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'OnlineService', uri => $val }; my $service = _param($item, 'x-service-type'); $obj->{service} = $service if defined $service; my $user = _param($item, 'x-user'); $obj->{user} = $user if defined $user; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } for my $propname (qw(socialprofile x-socialprofile)) { for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'OnlineService' }; if ($val =~ m{://}) { $obj->{uri} = $val } else { $obj->{user} = $val } my $service = _param($item, 'service-type') // _param($item, 'x-service-type'); unless ($service) { for my $t (_params_list($item, 'type')) { my $lt = lc $t; if ($lt ne 'home' && $lt ne 'work' && $lt ne 'pref') { $service = $lt; last; } } } $obj->{service} = $service if defined $service; my $user = _param($item, 'x-user') // _param($item, 'username'); $obj->{user} = $user if defined $user && !$obj->{user}; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } } # Legacy X-service IM properties (Apple/others) my %xservice_map = ( 'x-aim' => 'AIM', 'x-icq' => 'ICQ', 'x-msn' => 'MSN', 'x-yahoo' => 'Yahoo', 'x-jabber' => 'Jabber', 'x-skype' => 'Skype', 'x-skype-username' => 'Skype', 'x-twitter' => 'Twitter', 'x-google-talk' => 'GoogleTalk', ); for my $propname (sort keys %xservice_map) { for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'OnlineService', user => $val, service => $xservice_map{$propname} }; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } } $card->{onlineServices} = \%map if %map; } # PHOTO, LOGO, SOUND -> media sub _convert_media { my ($card, $props, $new_id) = @_; my $labels = _collect_labels($props); my %map; for my $spec (['photo', 'photo'], ['logo', 'logo'], ['sound', 'sound']) { my ($propname, $kind) = @$spec; for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'Media', kind => $kind }; my $encoding = _param($item, 'encoding'); if ($encoding && lc($encoding) eq 'b') { my $mediatype = _param($item, 'mediatype') // _param($item, 'type'); $mediatype = "image/$mediatype" if $mediatype && $mediatype !~ m{/}; $mediatype //= 'application/octet-stream'; $obj->{uri} = "data:$mediatype;base64," . encode_base64($val, ''); $obj->{mediaType} = $mediatype; } else { $obj->{uri} = $val; my $mt = _param($item, 'mediatype'); $obj->{mediaType} = $mt if defined $mt; } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } } $card->{media} = \%map if %map; } # Generic resource converter for URI-based properties sub _convert_resource_to { my ($card, $key, $props, $propname, $kind, $new_id, $type) = @_; my $labels = _collect_labels($props); my %map; for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => $type, uri => $val }; $obj->{kind} = $kind if defined $kind; my $mt = _param($item, 'mediatype'); $obj->{mediaType} = $mt if defined $mt; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } _apply_label($obj, $item, $labels); $map{$id} = $obj; } if (%map) { $card->{$key} = { %{$card->{$key} // {}}, %map }; } } # URL, FBURL, CONTACT-URI -> links sub _convert_links { my ($card, $props, $new_id) = @_; _convert_resource_to($card, 'links', $props, 'url', undef, $new_id, 'Link'); _convert_resource_to($card, 'links', $props, 'fburl', 'freeBusy', $new_id, 'Link'); _convert_resource_to($card, 'links', $props, 'contact-uri', 'contact', $new_id, 'Link'); } # CALURI -> calendars sub _convert_calendars { my ($card, $props, $new_id) = @_; _convert_resource_to($card, 'calendars', $props, 'caluri', undef, $new_id, 'Calendar'); } # CALADRURI -> schedulingAddresses sub _convert_scheduling_addresses { my ($card, $props, $new_id) = @_; _convert_resource_to($card, 'schedulingAddresses', $props, 'caladruri', undef, $new_id, 'SchedulingAddress'); } # KEY -> cryptoKeys sub _convert_crypto_keys { my ($card, $props, $new_id) = @_; _convert_resource_to($card, 'cryptoKeys', $props, 'key', undef, $new_id, 'CryptoKey'); } # SOURCE, ORG-DIRECTORY -> directories sub _convert_directories { my ($card, $props, $new_id) = @_; _convert_resource_to($card, 'directories', $props, 'source', 'entry', $new_id, 'Directory'); _convert_resource_to($card, 'directories', $props, 'org-directory', 'directory', $new_id, 'Directory'); } # LANG -> preferredLanguages sub _convert_preferred_languages { my ($card, $props, $new_id) = @_; my $items = $props->{lang} || return; my %map; for my $item (@$items) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'LanguagePref', language => $val }; my @types = _params_list($item, 'type'); if (my $ctx = _make_contexts(@types)) { $obj->{contexts} = $ctx } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } $map{$id} = $obj; } $card->{preferredLanguages} = \%map if %map; } # EXPERTISE, HOBBY, INTEREST -> personalInfo sub _convert_personal_info { my ($card, $props, $new_id) = @_; my %level_map = (beginner => 'low', average => 'medium', expert => 'high'); my %map; for my $spec (['expertise', 'expertise'], ['hobby', 'hobby'], ['interest', 'interest']) { my ($propname, $kind) = @$spec; for my $item (@{$props->{$propname} // []}) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'PersonalInfo', kind => $kind, value => $val }; my $level = _param($item, 'level'); if ($level) { $obj->{level} = $level_map{lc $level} // lc $level; } my $index = _param($item, 'index'); $obj->{listAs} = $index + 0 if defined $index; $map{$id} = $obj; } } $card->{personalInfo} = \%map if %map; } # CATEGORIES -> keywords sub _convert_keywords { my ($card, $props) = @_; my $items = $props->{categories} || return; my %keywords; for my $item (@$items) { my $val = $item->{value}; next unless defined $val; for my $cat (split /,/, $val) { $cat =~ s/^\s+//; $cat =~ s/\s+$//; $keywords{$cat} = JSON::true if $cat ne ''; } } $card->{keywords} = \%keywords if %keywords; } # MEMBER / X-ADDRESSBOOKSERVER-MEMBER -> members sub _convert_members { my ($card, $props) = @_; my %members; for my $propname (qw(member x-addressbookserver-member)) { for my $item (@{$props->{$propname} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; $members{$val} = JSON::true; } } $card->{members} = \%members if %members; } # RELATED / X-ABRELATEDNAMES -> relatedTo sub _convert_related { my ($card, $props) = @_; my $labels = _collect_labels($props); my %related; # Standard RELATED property for my $item (@{$props->{related} // []}) { my $val = $item->{value}; next unless defined $val && $val ne ''; my $rel = { '@type' => 'Relation' }; my %relation; for my $t (_params_list($item, 'type')) { my $lt = lc $t; $relation{$lt} = JSON::true if $lt =~ /^(acquaintance|agent|child|co-resident|co-worker|colleague|contact|crush|date|emergency|friend|kin|me|met|muse|neighbor|parent|sibling|spouse|sweetheart)$/; } $rel->{relation} = \%relation if %relation; $related{$val} = $rel; } # Apple X-ABRELATEDNAMES + X-ABLabel -> relatedTo my %ablabel_relation = ( 'mother' => 'parent', 'father' => 'parent', 'parent' => 'parent', 'brother' => 'sibling', 'sister' => 'sibling', 'child' => 'child', 'friend' => 'friend', 'spouse' => 'spouse', 'partner' => 'spouse', 'assistant' => 'colleague', 'manager' => 'colleague', ); for my $item (@{$props->{'x-abrelatednames'} // []}) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $rel = { '@type' => 'Relation' }; my %relation; # Get relation type from X-ABLabel my $label; if (my $group = $item->{group}) { $label = $labels->{$group}; } if ($label) { my $lt = lc $label; if (my $mapped = $ablabel_relation{$lt}) { $relation{$mapped} = JSON::true; } } $rel->{relation} = \%relation if %relation; $related{$val} = $rel; } $card->{relatedTo} = \%related if %related; } # GRAMGENDER, PRONOUNS (RFC 9554) -> speakToAs sub _convert_speak_to_as { my ($card, $props, $new_id) = @_; my $speak = {}; if (my $gg = _first_value($props, 'gramgender')) { $speak->{grammaticalGender} = lc $gg; } if (my $items = $props->{pronouns}) { my %pronouns; for my $item (@$items) { my $val = _decode_value($item->{value}); next unless defined $val && $val ne ''; my $id = _prop_id($item, $new_id); my $obj = { '@type' => 'Pronouns', pronouns => $val }; if (my $ctx = _make_contexts(_params_list($item, 'type'))) { $obj->{contexts} = $ctx; } if (my $pref = _make_pref($item)) { $obj->{pref} = $pref } $pronouns{$id} = $obj; } $speak->{pronouns} = \%pronouns if %pronouns; } $card->{speakToAs} = $speak if %$speak; } ############################################################################### # JSCONTACT -> VCARD ############################################################################### sub jscontact_to_vcard { my ($card) = @_; _reset_groups(); my @props; # VERSION (always 4.0) push @props, { name => 'version', value => '4.0' }; # UID push @props, { name => 'uid', value => $card->{uid} } if $card->{uid}; # KIND push @props, { name => 'kind', value => $card->{kind} } if $card->{kind} && $card->{kind} ne 'individual'; # PRODID push @props, { name => 'prodid', value => $card->{prodId} } if $card->{prodId}; # REV push @props, { name => 'rev', value => $card->{updated} } if $card->{updated}; # CREATED (RFC 9554) push @props, { name => 'created', value => $card->{created} } if $card->{created}; # LANGUAGE (RFC 9554) push @props, { name => 'language', value => $card->{language} } if $card->{language}; # Name -> N + FN _unconvert_name(\@props, $card); # All map-based properties _unconvert_nicknames(\@props, $card); _unconvert_emails(\@props, $card); _unconvert_phones(\@props, $card); _unconvert_addresses(\@props, $card); _unconvert_organizations(\@props, $card); _unconvert_titles(\@props, $card); _unconvert_anniversaries(\@props, $card); _unconvert_notes(\@props, $card); _unconvert_online_services(\@props, $card); _unconvert_media(\@props, $card); _unconvert_links(\@props, $card); _unconvert_calendars(\@props, $card); _unconvert_scheduling_addresses(\@props, $card); _unconvert_crypto_keys(\@props, $card); _unconvert_directories(\@props, $card); _unconvert_preferred_languages(\@props, $card); _unconvert_personal_info(\@props, $card); _unconvert_keywords(\@props, $card); _unconvert_members(\@props, $card); _unconvert_related(\@props, $card); _unconvert_speak_to_as(\@props, $card); # Build vcard hash structure my %by_name; for my $prop (@props) { $prop->{params} //= {}; push @{$by_name{$prop->{name}}}, $prop; } my $vcard = { type => 'vcard', properties => \%by_name, }; return hash2vcard({ objects => [$vcard] }); } ############################################################################### # INDIVIDUAL JSCONTACT -> VCARD CONVERTERS ############################################################################### sub _contexts_to_types { my $contexts = shift; return () unless $contexts && ref $contexts eq 'HASH'; my @types; push @types, 'home' if $contexts->{private}; push @types, 'work' if $contexts->{work}; return @types; } sub _add_pref_params { my ($params, $pref) = @_; $params->{pref} = [$pref] if defined $pref; } { my $group_counter = 0; sub _reset_groups { $group_counter = 0 } sub _add_label { my ($out, $prop, $obj) = @_; my $label = $obj->{label}; return unless defined $label && $label ne ''; $group_counter++; my $group = "item$group_counter"; $prop->{group} = $group; push @$out, { name => 'x-ablabel', value => $label, params => {}, group => $group, }; } } sub _add_context_params { my ($params, $obj) = @_; if ($obj->{contexts}) { my @types = _contexts_to_types($obj->{contexts}); push @{$params->{type}}, @types if @types; } } sub _unconvert_name { my ($out, $card) = @_; my $name = $card->{name} || return; # FN if (my $full = $name->{full}) { push @$out, { name => 'fn', value => $full, params => {} }; } # N from components if (my $components = $name->{components}) { my %by_kind; for my $c (@$components) { push @{$by_kind{$c->{kind}}}, $c->{value}; } # N order: surname, given, given2(additional), title(prefix), credential(suffix), surname2, generation my @n_values; for my $kind (qw(surname given given2 title credential surname2 generation)) { my $vals = $by_kind{$kind}; push @n_values, $vals ? join(',', grep { defined $_ } @$vals) : ''; } # Trim trailing empty components pop @n_values while @n_values && $n_values[-1] eq ''; my $params = {}; if ($name->{sortAs} && ref $name->{sortAs} eq 'HASH') { my @sa; for my $kind (qw(surname given given2 title credential surname2 generation)) { push @sa, $name->{sortAs}{$kind} // ''; } pop @sa while @sa && $sa[-1] eq ''; $params->{'sort-as'} = [join(',', @sa)] if @sa; } push @$out, { name => 'n', values => \@n_values, params => $params }; } # Generate FN from components if no full name given if (!$name->{full} && $name->{components}) { my @parts; for my $c (@{$name->{components}}) { next if ($c->{kind} // '') eq 'separator'; push @parts, $c->{value}; } push @$out, { name => 'fn', value => join(' ', @parts), params => {} } if @parts; } } sub _unconvert_nicknames { my ($out, $card) = @_; my $nicknames = $card->{nicknames} || return; for my $id (sort keys %$nicknames) { my $nn = $nicknames->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $nn); _add_pref_params($params, $nn->{pref}); push @$out, { name => 'nickname', value => $nn->{name}, params => $params }; } } sub _unconvert_emails { my ($out, $card) = @_; my $emails = $card->{emails} || return; for my $id (sort keys %$emails) { my $em = $emails->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $em); _add_pref_params($params, $em->{pref}); my $prop = { name => 'email', value => $em->{address}, params => $params }; _add_label($out, $prop, $em); push @$out, $prop; } } sub _unconvert_phones { my ($out, $card) = @_; my $phones = $card->{phones} || return; my %feature_to_type = ( mobile => 'cell', voice => 'voice', fax => 'fax', video => 'video', pager => 'pager', text => 'text', textphone => 'textphone', ); for my $id (sort keys %$phones) { my $ph = $phones->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $ph); _add_pref_params($params, $ph->{pref}); if ($ph->{features}) { for my $feat (sort keys %{$ph->{features}}) { my $type = $feature_to_type{$feat}; push @{$params->{type}}, $type if $type; } } my $prop = { name => 'tel', value => $ph->{number}, params => $params }; _add_label($out, $prop, $ph); push @$out, $prop; } } sub _unconvert_addresses { my ($out, $card) = @_; my $addresses = $card->{addresses} || return; my %kind_to_idx = ( name => 2, apartment => 1, locality => 3, region => 4, postcode => 5, country => 6, ); for my $id (sort keys %$addresses) { my $adr = $addresses->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $adr); _add_pref_params($params, $adr->{pref}); $params->{label} = [$adr->{full}] if $adr->{full}; $params->{geo} = [$adr->{coordinates}] if $adr->{coordinates}; $params->{tz} = [$adr->{timeZone}] if $adr->{timeZone}; $params->{cc} = [$adr->{countryCode}] if $adr->{countryCode}; # Build ADR values (7 standard components) my @values = ('') x 7; if (my $components = $adr->{components}) { my %by_idx; for my $c (@$components) { next if ($c->{kind} // '') eq 'separator'; my $idx = $kind_to_idx{$c->{kind}}; push @{$by_idx{$idx}}, $c->{value} if defined $idx; } for my $idx (keys %by_idx) { $values[$idx] = join(',', @{$by_idx{$idx}}); } } push @$out, { name => 'adr', values => \@values, params => $params }; } } sub _unconvert_organizations { my ($out, $card) = @_; my $orgs = $card->{organizations} || return; for my $id (sort keys %$orgs) { my $org = $orgs->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $org); my @values = ($org->{name} // ''); if ($org->{units}) { for my $unit (@{$org->{units}}) { push @values, $unit->{name}; } } if (defined $org->{sortAs}) { my @sa = ($org->{sortAs}); if ($org->{units}) { for my $unit (@{$org->{units}}) { push @sa, $unit->{sortAs} // ''; } } pop @sa while @sa && $sa[-1] eq ''; $params->{'sort-as'} = [join(',', @sa)] if @sa; } push @$out, { name => 'org', values => \@values, params => $params }; } } sub _unconvert_titles { my ($out, $card) = @_; my $titles = $card->{titles} || return; for my $id (sort keys %$titles) { my $t = $titles->{$id}; my $propname = ($t->{kind} // 'title') eq 'role' ? 'role' : 'title'; my $params = { 'prop-id' => [$id] }; push @$out, { name => $propname, value => $t->{name}, params => $params }; } } sub _unconvert_anniversaries { my ($out, $card) = @_; my $anns = $card->{anniversaries} || return; my %kind_to_prop = (birth => 'bday', wedding => 'anniversary', death => 'deathdate'); for my $id (sort keys %$anns) { my $ann = $anns->{$id}; my $kind = $ann->{kind} // ''; my $propname = $kind_to_prop{$kind} // 'anniversary'; my $params = { 'prop-id' => [$id] }; my $date = $ann->{date} // ''; # Convert unknown-year dates to vCard 4 format $date = "--$1$2" if $date =~ /^0000-(\d{2})-(\d{2})/; push @$out, { name => $propname, value => $date, params => $params }; } } sub _unconvert_notes { my ($out, $card) = @_; my $notes = $card->{notes} || return; for my $id (sort keys %$notes) { my $note = $notes->{$id}; my $params = { 'prop-id' => [$id] }; if ($note->{created}) { $params->{created} = [$note->{created}]; } if ($note->{author}) { $params->{'author-name'} = [$note->{author}{name}] if $note->{author}{name}; $params->{author} = [$note->{author}{uri}] if $note->{author}{uri}; } push @$out, { name => 'note', value => $note->{note}, params => $params }; } } sub _unconvert_online_services { my ($out, $card) = @_; my $services = $card->{onlineServices} || return; for my $id (sort keys %$services) { my $svc = $services->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $svc); _add_pref_params($params, $svc->{pref}); $params->{'service-type'} = [$svc->{service}] if $svc->{service}; $params->{username} = [$svc->{user}] if $svc->{user}; my $uri = $svc->{uri} // $svc->{user} // ''; push @$out, { name => 'impp', value => $uri, params => $params }; } } sub _unconvert_media { my ($out, $card) = @_; my $media = $card->{media} || return; my %kind_to_prop = (photo => 'photo', logo => 'logo', sound => 'sound'); for my $id (sort keys %$media) { my $m = $media->{$id}; my $propname = $kind_to_prop{$m->{kind} // 'photo'} // 'photo'; my $params = { 'prop-id' => [$id] }; _add_pref_params($params, $m->{pref}); $params->{mediatype} = [$m->{mediaType}] if $m->{mediaType}; push @$out, { name => $propname, value => $m->{uri}, params => $params }; } } sub _unconvert_links { my ($out, $card) = @_; my $links = $card->{links} || return; for my $id (sort keys %$links) { my $link = $links->{$id}; my $kind = $link->{kind} // ''; my $propname = $kind eq 'freeBusy' ? 'fburl' : $kind eq 'contact' ? 'contact-uri' : 'url'; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $link); _add_pref_params($params, $link->{pref}); $params->{mediatype} = [$link->{mediaType}] if $link->{mediaType}; push @$out, { name => $propname, value => $link->{uri}, params => $params }; } } sub _unconvert_resource { my ($out, $card, $key, $propname) = @_; my $resources = $card->{$key} || return; for my $id (sort keys %$resources) { my $r = $resources->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $r); _add_pref_params($params, $r->{pref}); $params->{mediatype} = [$r->{mediaType}] if $r->{mediaType}; push @$out, { name => $propname, value => $r->{uri}, params => $params }; } } sub _unconvert_calendars { _unconvert_resource($_[0], $_[1], 'calendars', 'caluri'); } sub _unconvert_scheduling_addresses { _unconvert_resource($_[0], $_[1], 'schedulingAddresses', 'caladruri'); } sub _unconvert_crypto_keys { _unconvert_resource($_[0], $_[1], 'cryptoKeys', 'key'); } sub _unconvert_directories { my ($out, $card) = @_; my $dirs = $card->{directories} || return; for my $id (sort keys %$dirs) { my $dir = $dirs->{$id}; my $kind = $dir->{kind} // ''; my $propname = $kind eq 'entry' ? 'source' : 'org-directory'; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $dir); _add_pref_params($params, $dir->{pref}); $params->{mediatype} = [$dir->{mediaType}] if $dir->{mediaType}; push @$out, { name => $propname, value => $dir->{uri}, params => $params }; } } sub _unconvert_preferred_languages { my ($out, $card) = @_; my $langs = $card->{preferredLanguages} || return; for my $id (sort keys %$langs) { my $lp = $langs->{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $lp); _add_pref_params($params, $lp->{pref}); push @$out, { name => 'lang', value => $lp->{language}, params => $params }; } } sub _unconvert_personal_info { my ($out, $card) = @_; my $info = $card->{personalInfo} || return; my %level_map = (low => 'beginner', medium => 'average', high => 'expert'); for my $id (sort keys %$info) { my $pi = $info->{$id}; my $propname = $pi->{kind} // 'expertise'; my $params = { 'prop-id' => [$id] }; if ($pi->{level}) { $params->{level} = [$level_map{$pi->{level}} // $pi->{level}]; } if (defined $pi->{listAs}) { $params->{index} = [$pi->{listAs}]; } push @$out, { name => $propname, value => $pi->{value}, params => $params }; } } sub _unconvert_keywords { my ($out, $card) = @_; my $keywords = $card->{keywords} || return; return unless ref $keywords eq 'HASH' && %$keywords; push @$out, { name => 'categories', value => join(',', sort keys %$keywords), params => {} }; } sub _unconvert_members { my ($out, $card) = @_; my $members = $card->{members} || return; for my $uid (sort keys %$members) { push @$out, { name => 'member', value => $uid, params => {} }; } } sub _unconvert_members_apple { my ($out, $card) = @_; my $members = $card->{members} || return; for my $uid (sort keys %$members) { # Apple uses urn:uuid: prefix for member UIDs my $val = $uid; $val = "urn:uuid:$val" unless $val =~ /^urn:uuid:/; push @$out, { name => 'x-addressbookserver-member', value => $val, params => {} }; } } sub _unconvert_related { my ($out, $card) = @_; my $related = $card->{relatedTo} || return; for my $uid (sort keys %$related) { my $rel = $related->{$uid}; my $params = {}; if ($rel->{relation} && ref $rel->{relation} eq 'HASH') { my @types = sort keys %{$rel->{relation}}; $params->{type} = \@types if @types; } push @$out, { name => 'related', value => $uid, params => $params }; } } sub _unconvert_speak_to_as { my ($out, $card) = @_; my $sta = $card->{speakToAs} || return; if ($sta->{grammaticalGender}) { push @$out, { name => 'gramgender', value => $sta->{grammaticalGender}, params => {} }; } if ($sta->{pronouns}) { for my $id (sort keys %{$sta->{pronouns}}) { my $p = $sta->{pronouns}{$id}; my $params = { 'prop-id' => [$id] }; _add_context_params($params, $p); _add_pref_params($params, $p->{pref}); push @$out, { name => 'pronouns', value => $p->{pronouns}, params => $params }; } } } ############################################################################### # PATCH: Apply JSContact changes to an existing vCard with minimal disruption ############################################################################### sub patch_vcard { my ($original_vcard, $old_card, $new_card) = @_; # Determine which top-level JSContact properties changed my %changed = _diff_cards($old_card, $new_card); # If nothing changed, return original return $original_vcard unless %changed; # Parse the original vCard into its raw structure my $parsed = eval { vcard2hash($original_vcard, multival => [qw(n adr org)]) }; return jscontact_to_vcard($new_card) unless $parsed; my $vcard = $parsed->{objects}[0]; return jscontact_to_vcard($new_card) unless $vcard && $vcard->{type} eq 'vcard'; my $props = $vcard->{properties}; # Detect which property names the original vCard actually uses, so we # generate matching ones (e.g. X-ADDRESSBOOKSERVER-MEMBER vs MEMBER) my %original_has; for my $name (keys %$props) { $original_has{lc $name} = 1 if $props->{$name} && @{$props->{$name}}; } # For each changed property, regenerate just that part # Map JSContact property names to the vCard properties they affect my %jscontact_to_vcard_props = ( name => [qw(fn n x-phonetic-first-name x-phonetic-middle-name x-phonetic-last-name)], nicknames => [qw(nickname)], emails => [qw(email)], phones => [qw(tel)], addresses => [qw(adr x-abadr)], organizations => [qw(org)], titles => [qw(title role)], anniversaries => [qw(bday anniversary deathdate x-abdate)], notes => [qw(note)], onlineServices => [qw(impp socialprofile x-socialprofile x-aim x-icq x-msn x-yahoo x-jabber x-skype x-twitter x-google-talk x-skype-username)], media => [qw(photo logo sound)], links => [qw(url fburl contact-uri)], calendars => [qw(caluri)], schedulingAddresses => [qw(caladruri)], cryptoKeys => [qw(key)], directories => [qw(source org-directory)], keywords => [qw(categories)], members => [qw(member x-addressbookserver-member)], relatedTo => [qw(related x-abrelatednames)], speakToAs => [qw(gramgender pronouns)], preferredLanguages => [qw(lang)], personalInfo => [qw(expertise hobby interest)], # Simple scalar properties uid => [qw(uid)], kind => [qw(kind x-addressbookserver-kind)], prodId => [qw(prodid)], updated => [qw(rev)], created => [qw(created)], language => [qw(language)], ); for my $js_prop (keys %changed) { my $vcard_names = $jscontact_to_vcard_props{$js_prop}; next unless $vcard_names; # Remove old vCard properties for this JSContact property # Also remove any associated X-ABLabel grouped properties my %groups_to_remove; for my $vname (@$vcard_names) { for my $item (@{$props->{$vname} // []}) { $groups_to_remove{$item->{group}} = 1 if $item->{group}; } delete $props->{$vname}; } # Remove orphaned X-ABLabel entries for removed groups if (%groups_to_remove && $props->{'x-ablabel'}) { $props->{'x-ablabel'} = [ grep { !$groups_to_remove{$_->{group} // ''} } @{$props->{'x-ablabel'}} ]; delete $props->{'x-ablabel'} unless @{$props->{'x-ablabel'}}; } } # Generate the new properties from the new card _reset_groups(); my @new_props; # Generate only the changed properties if ($changed{name}) { _unconvert_name(\@new_props, $new_card) } if ($changed{nicknames}) { _unconvert_nicknames(\@new_props, $new_card) } if ($changed{emails}) { _unconvert_emails(\@new_props, $new_card) } if ($changed{phones}) { _unconvert_phones(\@new_props, $new_card) } if ($changed{addresses}) { _unconvert_addresses(\@new_props, $new_card) } if ($changed{organizations}) { _unconvert_organizations(\@new_props, $new_card) } if ($changed{titles}) { _unconvert_titles(\@new_props, $new_card) } if ($changed{anniversaries}) { _unconvert_anniversaries(\@new_props, $new_card) } if ($changed{notes}) { _unconvert_notes(\@new_props, $new_card) } if ($changed{onlineServices}){ _unconvert_online_services(\@new_props, $new_card) } if ($changed{media}) { _unconvert_media(\@new_props, $new_card) } if ($changed{links}) { _unconvert_links(\@new_props, $new_card) } if ($changed{calendars}) { _unconvert_calendars(\@new_props, $new_card) } if ($changed{schedulingAddresses}) { _unconvert_scheduling_addresses(\@new_props, $new_card) } if ($changed{cryptoKeys}) { _unconvert_crypto_keys(\@new_props, $new_card) } if ($changed{directories}) { _unconvert_directories(\@new_props, $new_card) } if ($changed{keywords}) { _unconvert_keywords(\@new_props, $new_card) } if ($changed{members}) { if ($original_has{'x-addressbookserver-member'}) { _unconvert_members_apple(\@new_props, $new_card); } else { _unconvert_members(\@new_props, $new_card); } } if ($changed{relatedTo}) { _unconvert_related(\@new_props, $new_card) } if ($changed{speakToAs}) { _unconvert_speak_to_as(\@new_props, $new_card) } if ($changed{preferredLanguages}) { _unconvert_preferred_languages(\@new_props, $new_card) } if ($changed{personalInfo}) { _unconvert_personal_info(\@new_props, $new_card) } # Simple scalar properties — use Apple property names when original has them for my $spec (['uid', 'uid'], ['prodId', 'prodid'], ['updated', 'rev'], ['created', 'created'], ['language', 'language']) { my ($js, $vc) = @$spec; if ($changed{$js}) { if (defined $new_card->{$js} && $new_card->{$js} ne '') { push @new_props, { name => $vc, value => $new_card->{$js}, params => {} }; } } } if ($changed{kind}) { if (defined $new_card->{kind} && $new_card->{kind} ne '') { my $propname = $original_has{'x-addressbookserver-kind'} ? 'x-addressbookserver-kind' : 'kind'; push @new_props, { name => $propname, value => $new_card->{kind}, params => {} }; } } # Merge new properties into the existing vCard for my $prop (@new_props) { $prop->{params} //= {}; push @{$props->{$prop->{name}}}, $prop; } return hash2vcard({ objects => [$vcard] }); } # Compare two JSContact cards and return hash of changed property names sub _diff_cards { my ($old, $new) = @_; my $json = JSON->new->canonical->utf8; my %changed; # Check all keys in both old and new my %all_keys; $all_keys{$_} = 1 for keys %$old, keys %$new; # Skip internal/metadata keys delete $all_keys{$_} for qw(@type version CPath href _raw meta); for my $key (keys %all_keys) { my $old_val = $old->{$key}; my $new_val = $new->{$key}; # Both undef/missing -> no change next if !defined $old_val && !defined $new_val; # One exists, other doesn't -> changed if (!defined $old_val || !defined $new_val) { $changed{$key} = 1; next; } # Compare via canonical JSON encoding my $old_json = $json->encode([$old_val]); my $new_json = $json->encode([$new_val]); $changed{$key} = 1 if $old_json ne $new_json; } return %changed; } 1; __END__ =head1 NAME Text::JSContact - Convert between vCard and JSContact (RFC 9553/9555) =head1 AUTHOR Bron Gondwana, C<< >> =head1 LICENSE AND COPYRIGHT Copyright 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 Text-JSContact-0.02/t/PaxHeader/cyrus-carddav.t000644 000765 000024 00000000210 15164515017 021625 xustar00brongstaff000000 000000 30 mtime=1775409679.446107411 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/t/cyrus-carddav.t000644 000765 000024 00000017304 15164515017 017670 0ustar00brongstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; use JSON::XS; use LWP::UserAgent; use HTTP::Request; use lib 'lib'; use Text::JSContact qw(vcard_to_jscontact jscontact_to_vcard); unless ($ENV{CYRUS_URL}) { plan skip_all => "Set CYRUS_URL, CYRUS_USER, CYRUS_PASS to enable Cyrus integration tests" . " (e.g. CYRUS_URL=http://localhost:8080 CYRUS_USER=user1 CYRUS_PASS=password)"; } my $base = $ENV{CYRUS_URL}; my $user = $ENV{CYRUS_USER} || 'user1'; my $pass = $ENV{CYRUS_PASS} || 'password'; my $abpath = "$base/dav/addressbooks/user/$user/Default"; my $ua = LWP::UserAgent->new(timeout => 5); my $probe = $ua->get("$base/dav/principals/user/$user/"); unless ($probe->code < 500) { plan skip_all => "Cyrus not reachable at $base"; } my $json = JSON::XS->new->pretty(1)->canonical(1); sub carddav_put { my ($uid, $vcard) = @_; my $req = HTTP::Request->new(PUT => "$abpath/$uid.vcf"); $req->authorization_basic($user, $pass); $req->content_type('text/vcard; charset=utf-8'); $req->content($vcard); return $ua->request($req); } sub carddav_get { my ($uid) = @_; my $req = HTTP::Request->new(GET => "$abpath/$uid.vcf"); $req->authorization_basic($user, $pass); return $ua->request($req); } sub carddav_delete { my ($uid) = @_; my $req = HTTP::Request->new(DELETE => "$abpath/$uid.vcf"); $req->authorization_basic($user, $pass); return $ua->request($req); } # ============================================================ # Test 1: Simple contact round-trip through Cyrus # ============================================================ my $uid1 = 'jscontact-test-' . time(); my $vcard = <<"VCARD"; BEGIN:VCARD VERSION:4.0 UID:urn:uuid:$uid1 FN:Jane Q. Smith N:Smith;Jane;Quincy;Dr.;PhD NICKNAME:Janey EMAIL;TYPE=work:jane\@example.com EMAIL;TYPE=home;PREF=1:jane.home\@example.com TEL;TYPE=work,voice:+1-555-0100 TEL;TYPE=cell:+1-555-0101 ADR;TYPE=home:;;42 Wallaby Way;Sydney;NSW;2000;Australia ORG:Acme Corp;R&D TITLE:Lead Scientist BDAY:1985-03-15 NOTE:Test contact for JSContact CATEGORIES:testing,jscontact URL:https://jane.example.com REV:20250101T120000Z END:VCARD VCARD my $resp = carddav_put($uid1, $vcard); ok($resp->is_success || $resp->code == 201 || $resp->code == 204, "PUT contact: " . $resp->status_line); # GET it back $resp = carddav_get($uid1); ok($resp->is_success, "GET contact back"); my $returned_vcard = $resp->content; # Parse with Text::JSContact my $card = eval { vcard_to_jscontact($returned_vcard) }; ok(!$@, "Parse returned vCard") or diag $@; ok($card, "Got JSContact Card"); # Verify core fields is($card->{name}{full}, 'Jane Q. Smith', 'name.full preserved'); ok($card->{name}{components}, 'has name components'); my @surnames = grep { $_->{kind} eq 'surname' } @{$card->{name}{components}}; is($surnames[0]{value}, 'Smith', 'surname'); my @given = grep { $_->{kind} eq 'given' } @{$card->{name}{components}}; is($given[0]{value}, 'Jane', 'given name'); # Emails ok($card->{emails}, 'has emails'); my @emails = sort { $a->{address} cmp $b->{address} } values %{$card->{emails}}; is(scalar @emails, 2, 'two emails'); is($emails[0]{address}, 'jane.home@example.com', 'home email'); is($emails[1]{address}, 'jane@example.com', 'work email'); # Phones ok($card->{phones}, 'has phones'); is(scalar keys %{$card->{phones}}, 2, 'two phones'); # Addresses ok($card->{addresses}, 'has addresses'); # Organizations ok($card->{organizations}, 'has organizations'); my @orgs = values %{$card->{organizations}}; is($orgs[0]{name}, 'Acme Corp', 'org name'); # Titles ok($card->{titles}, 'has titles'); # Anniversaries ok($card->{anniversaries}, 'has anniversaries'); # Keywords ok($card->{keywords}, 'has keywords'); ok($card->{keywords}{testing}, 'keyword: testing'); ok($card->{keywords}{jscontact}, 'keyword: jscontact'); # Round-trip: JSContact -> vCard -> JSContact my $generated_vcard = eval { jscontact_to_vcard($card) }; ok(!$@, "Generate vCard from JSContact") or diag $@; ok($generated_vcard, "Generated vCard"); like($generated_vcard, qr/BEGIN:VCARD/, "Valid vCard"); my $card2 = eval { vcard_to_jscontact($generated_vcard) }; ok(!$@, "Re-parse generated vCard") or diag $@; is($card2->{name}{full}, $card->{name}{full}, "Round-trip: name.full"); is(scalar keys %{$card2->{emails}}, scalar keys %{$card->{emails}}, "Round-trip: email count"); is(scalar keys %{$card2->{phones}}, scalar keys %{$card->{phones}}, "Round-trip: phone count"); carddav_delete($uid1); # ============================================================ # Test 2: Create via JMAP, read via CardDAV, parse, compare # ============================================================ my $uid2 = 'jscontact-jmap-' . time(); my $jmap_create = $ua->post( "$base/jmap/", Authorization => "Basic " . MIME::Base64::encode_base64("$user:$pass", ''), 'Content-Type' => 'application/json', Content => encode_json({ using => ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:contacts", "https://cyrusimap.org/ns/jmap/contacts"], methodCalls => [ ["ContactCard/set", { create => { "c1" => { "\@type" => "Card", "version" => "1.0", "uid" => "urn:uuid:$uid2", "name" => { "full" => "JMAP Test Contact" }, "emails" => { "e1" => { "address" => 'jmap@example.com', "contexts" => { "work" => JSON::true } }, }, "phones" => { "p1" => { "number" => '+1-555-9999', "features" => { "voice" => JSON::true } }, }, "addressBookIds" => { "Default" => JSON::true }, } } }, "0"] ] }), ); my $jmap_result = eval { decode_json($jmap_create->content) }; my $method_resp = $jmap_result->{methodResponses}[0]; if ($method_resp->[0] eq 'ContactCard/set' && $method_resp->[1]{created}{c1}) { pass("Created contact via JMAP"); my $jmap_id = $method_resp->[1]{created}{c1}{id}; # Read back via JMAP to get the x-href for CardDAV my $jmap_get = $ua->post( "$base/jmap/", Authorization => "Basic " . MIME::Base64::encode_base64("$user:$pass", ''), 'Content-Type' => 'application/json', Content => encode_json({ using => ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:contacts", "https://cyrusimap.org/ns/jmap/contacts"], methodCalls => [ ["ContactCard/get", { ids => [$jmap_id], properties => ["uid", "name", "emails", "cyrusimap.org:href"] }, "0"] ] }), ); my $jmap_card = eval { decode_json($jmap_get->content)->{methodResponses}[0][1]{list}[0] }; my $xhref = $jmap_card->{'cyrusimap.org:href'}; if ($xhref) { # Read via CardDAV using the real href my $req = HTTP::Request->new(GET => "$base$xhref"); $req->authorization_basic($user, $pass); my $get_resp = $ua->request($req); if ($get_resp->is_success) { pass("GET JMAP-created contact via CardDAV"); my $card_from_cyrus = eval { vcard_to_jscontact($get_resp->content) }; ok(!$@, "Parse Cyrus-generated vCard") or diag $@; is($card_from_cyrus->{name}{full}, "JMAP Test Contact", "JMAP->CardDAV: name matches"); my @em = values %{$card_from_cyrus->{emails} || {}}; ok(scalar @em, "JMAP->CardDAV: has emails"); is($em[0]{address}, 'jmap@example.com', "JMAP->CardDAV: email matches"); # Cleanup via CardDAV my $del = HTTP::Request->new(DELETE => "$base$xhref"); $del->authorization_basic($user, $pass); $ua->request($del); } else { pass("SKIP: Could not GET via CardDAV: " . $get_resp->status_line); for (1..4) { pass("SKIP") } } } else { pass("SKIP: No x-href from JMAP"); for (1..4) { pass("SKIP") } } } else { my $err = $method_resp->[1]{notCreated}{c1}{description} // $method_resp->[0] // 'unknown'; pass("SKIP: JMAP ContactCard/set: $err"); for (1..5) { pass("SKIP") } } done_testing(); Text-JSContact-0.02/t/PaxHeader/basic.t000644 000765 000024 00000000210 15162263466 020145 xustar00brongstaff000000 000000 30 mtime=1774806838.650106773 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/t/basic.t000644 000765 000024 00000013266 15162263466 016213 0ustar00brongstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; use JSON; use lib 'lib'; use Text::JSContact qw(vcard_to_jscontact jscontact_to_vcard); my $j = JSON->new->utf8->canonical->pretty; # Basic vCard 4.0 my $vcard = <<'VCARD'; BEGIN:VCARD VERSION:4.0 UID:urn:uuid:1234-5678 FN:John Q. Doe N:Doe;John;Quincy;Mr.;Jr. NICKNAME:Johnny EMAIL;TYPE=work:john@example.com EMAIL;TYPE=home;PREF=1:john@home.example TEL;TYPE=work,voice:+1-555-1234 TEL;TYPE=cell:+1-555-5678 ADR;TYPE=home:;;123 Main St;Anytown;CA;90210;USA ORG:Acme Corp;Engineering TITLE:Senior Engineer ROLE:Lead Developer BDAY:1990-05-15 NOTE:A test contact URL:https://example.com CATEGORIES:friends,work PHOTO;MEDIATYPE=image/jpeg:https://example.com/photo.jpg KEY:https://example.com/key.asc REV:20230101T120000Z PRODID:-//Test//Test//EN END:VCARD VCARD # Test vCard -> JSContact my $card = vcard_to_jscontact($vcard); ok($card, 'parsed vCard to JSContact'); is($card->{'@type'}, 'Card', '@type is Card'); is($card->{version}, '1.0', 'version is 1.0'); is($card->{uid}, 'urn:uuid:1234-5678', 'uid preserved'); # Name ok($card->{name}, 'has name'); is($card->{name}{full}, 'John Q. Doe', 'full name'); ok($card->{name}{components}, 'has name components'); my @surnames = grep { $_->{kind} eq 'surname' } @{$card->{name}{components}}; is($surnames[0]{value}, 'Doe', 'surname is Doe'); my @given = grep { $_->{kind} eq 'given' } @{$card->{name}{components}}; is($given[0]{value}, 'John', 'given name is John'); my @given2 = grep { $_->{kind} eq 'given2' } @{$card->{name}{components}}; is($given2[0]{value}, 'Quincy', 'given2 is Quincy'); my @titles = grep { $_->{kind} eq 'title' } @{$card->{name}{components}}; is($titles[0]{value}, 'Mr.', 'title is Mr.'); my @creds = grep { $_->{kind} eq 'credential' } @{$card->{name}{components}}; is($creds[0]{value}, 'Jr.', 'credential is Jr.'); # Nicknames ok($card->{nicknames}, 'has nicknames'); my @nn = values %{$card->{nicknames}}; is($nn[0]{name}, 'Johnny', 'nickname is Johnny'); # Emails ok($card->{emails}, 'has emails'); my @emails = sort { $a->{address} cmp $b->{address} } values %{$card->{emails}}; is(scalar @emails, 2, 'two emails'); is($emails[0]{address}, 'john@example.com', 'work email'); ok($emails[0]{contexts}{work}, 'work context'); is($emails[1]{address}, 'john@home.example', 'home email'); ok($emails[1]{contexts}{private}, 'home -> private context'); is($emails[1]{pref}, 1, 'pref=1'); # Phones ok($card->{phones}, 'has phones'); my @phones = sort { $a->{number} cmp $b->{number} } values %{$card->{phones}}; is(scalar @phones, 2, 'two phones'); is($phones[0]{number}, '+1-555-1234', 'work phone'); ok($phones[0]{contexts}{work}, 'work context on phone'); ok($phones[0]{features}{voice}, 'voice feature'); is($phones[1]{number}, '+1-555-5678', 'cell phone'); ok($phones[1]{features}{mobile}, 'cell -> mobile feature'); # Addresses ok($card->{addresses}, 'has addresses'); my @addrs = values %{$card->{addresses}}; is(scalar @addrs, 1, 'one address'); ok($addrs[0]{contexts}{private}, 'home -> private context'); my @locality = grep { $_->{kind} eq 'locality' } @{$addrs[0]{components}}; is($locality[0]{value}, 'Anytown', 'locality'); my @region = grep { $_->{kind} eq 'region' } @{$addrs[0]{components}}; is($region[0]{value}, 'CA', 'region'); my @postcode = grep { $_->{kind} eq 'postcode' } @{$addrs[0]{components}}; is($postcode[0]{value}, '90210', 'postcode'); # Organizations ok($card->{organizations}, 'has organizations'); my @orgs = values %{$card->{organizations}}; is($orgs[0]{name}, 'Acme Corp', 'org name'); is($orgs[0]{units}[0]{name}, 'Engineering', 'org unit'); # Titles ok($card->{titles}, 'has titles'); my @t = sort { $a->{kind} cmp $b->{kind} } values %{$card->{titles}}; is(scalar @t, 2, 'title and role'); my ($role_t) = grep { $_->{kind} eq 'role' } @t; my ($title_t) = grep { $_->{kind} eq 'title' } @t; is($role_t->{name}, 'Lead Developer', 'role'); is($title_t->{name}, 'Senior Engineer', 'title'); # Anniversaries ok($card->{anniversaries}, 'has anniversaries'); my @ann = values %{$card->{anniversaries}}; is($ann[0]{kind}, 'birth', 'birthday'); is($ann[0]{date}, '1990-05-15', 'birthday date'); # Notes ok($card->{notes}, 'has notes'); my @notes = values %{$card->{notes}}; is($notes[0]{note}, 'A test contact', 'note text'); # Keywords ok($card->{keywords}, 'has keywords'); ok($card->{keywords}{friends}, 'friends keyword'); ok($card->{keywords}{work}, 'work keyword'); # Links ok($card->{links}, 'has links'); my @links = values %{$card->{links}}; is($links[0]{uri}, 'https://example.com', 'url'); # Media ok($card->{media}, 'has media'); my @media = values %{$card->{media}}; is($media[0]{kind}, 'photo', 'photo kind'); is($media[0]{uri}, 'https://example.com/photo.jpg', 'photo uri'); # Crypto Keys ok($card->{cryptoKeys}, 'has cryptoKeys'); my @keys = values %{$card->{cryptoKeys}}; is($keys[0]{uri}, 'https://example.com/key.asc', 'key uri'); # Metadata is($card->{updated}, '2023-01-01T12:00:00Z', 'updated'); is($card->{prodId}, '-//Test//Test//EN', 'prodId'); # Test round-trip: JSContact -> vCard -> JSContact my $vcard_out = jscontact_to_vcard($card); ok($vcard_out, 'generated vCard from JSContact'); like($vcard_out, qr/BEGIN:VCARD/, 'has BEGIN'); like($vcard_out, qr/VERSION:4\.0/, 'version 4.0'); like($vcard_out, qr/FN:John Q\. Doe/, 'has FN'); like($vcard_out, qr/UID:urn:uuid:1234-5678/, 'has UID'); my $card2 = vcard_to_jscontact($vcard_out); ok($card2, 'parsed round-tripped vCard'); is($card2->{uid}, $card->{uid}, 'uid round-trips'); is($card2->{name}{full}, $card->{name}{full}, 'name round-trips'); is(scalar keys %{$card2->{emails}}, scalar keys %{$card->{emails}}, 'email count round-trips'); is(scalar keys %{$card2->{phones}}, scalar keys %{$card->{phones}}, 'phone count round-trips'); done_testing(); Text-JSContact-0.02/t/PaxHeader/rfc9555.t000644 000765 000024 00000000206 15162263466 020173 xustar00brongstaff000000 000000 28 mtime=1774806838.6503359 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/t/rfc9555.t000644 000765 000024 00000024317 15162263466 016233 0ustar00brongstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; use JSON; use lib 'lib'; use Text::JSContact qw(vcard_to_jscontact jscontact_to_vcard); my $j = JSON->new->utf8->canonical; # Helper to test a single property conversion from a vCard snippet sub test_vcard { my ($label, $vcard_body, $tests) = @_; my $fn = $vcard_body =~ /^FN[;:]/m ? '' : "FN:Test\n"; my $vcard = "BEGIN:VCARD\nVERSION:4.0\nUID:urn:uuid:test\n${fn}${vcard_body}END:VCARD\n"; my $card = vcard_to_jscontact($vcard); ok($card, "$label: parsed"); $tests->($card) if $card; } # RFC 9555 Figure 7: KIND test_vcard('KIND', "KIND:individual\n", sub { is($_[0]->{kind}, 'individual', 'kind=individual'); }); # RFC 9555 Figure 8: SOURCE test_vcard('SOURCE', "SOURCE:https://dir.example.com/addrbook/jdoe/Jean%20Dupont.vcf\n", sub { ok($_[0]->{directories}, 'has directories'); my @dirs = values %{$_[0]->{directories}}; is($dirs[0]{kind}, 'entry', 'kind=entry'); is($dirs[0]{uri}, 'https://dir.example.com/addrbook/jdoe/Jean%20Dupont.vcf', 'uri'); }); # RFC 9555 Figure 10: FN test_vcard('FN', "FN:John Q. Public\\, Esq.\n", sub { is($_[0]->{name}{full}, 'John Q. Public, Esq.', 'full name with comma'); }); # RFC 9555 Figure 11: GRAMGENDER + PRONOUNS test_vcard('GRAMGENDER+PRONOUNS', "GRAMGENDER:NEUTER\nPRONOUNS;PREF=2:they/them\nPRONOUNS;PREF=1:xe/xir\n", sub { my $sta = $_[0]->{speakToAs}; ok($sta, 'has speakToAs'); is($sta->{grammaticalGender}, 'neuter', 'grammaticalGender'); ok($sta->{pronouns}, 'has pronouns'); my @p = sort { $a->{pref} <=> $b->{pref} } values %{$sta->{pronouns}}; is($p[0]{pronouns}, 'xe/xir', 'first pronoun by pref'); is($p[0]{pref}, 1, 'pref=1'); is($p[1]{pronouns}, 'they/them', 'second pronoun by pref'); is($p[1]{pref}, 2, 'pref=2'); }); # RFC 9555 Figure 12: N with SORT-AS and multiple values test_vcard('N-complex', "N;SORT-AS=\"Stevenson,John Philip\":Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.;;Jr.\n", sub { my $name = $_[0]->{name}; ok($name->{components}, 'has components'); my @surnames = grep { $_->{kind} eq 'surname' } @{$name->{components}}; is($surnames[0]{value}, 'Stevenson', 'surname'); my @given = grep { $_->{kind} eq 'given' } @{$name->{components}}; is($given[0]{value}, 'John', 'given'); my @given2 = grep { $_->{kind} eq 'given2' } @{$name->{components}}; is(scalar @given2, 2, 'two given2 values'); is($given2[0]{value}, 'Philip', 'given2[0]'); is($given2[1]{value}, 'Paul', 'given2[1]'); my @title = grep { $_->{kind} eq 'title' } @{$name->{components}}; is($title[0]{value}, 'Dr.', 'title prefix'); my @cred = grep { $_->{kind} eq 'credential' } @{$name->{components}}; ok(scalar @cred >= 2, 'has credentials'); my @gen = grep { $_->{kind} eq 'generation' } @{$name->{components}}; is($gen[0]{value}, 'Jr.', 'generation'); is($name->{sortAs}{surname}, 'Stevenson', 'sortAs surname'); is($name->{sortAs}{given}, 'John Philip', 'sortAs given'); }); # RFC 9555 Figure 13: NICKNAME test_vcard('NICKNAME', "NICKNAME:Johnny\n", sub { ok($_[0]->{nicknames}, 'has nicknames'); my @nn = values %{$_[0]->{nicknames}}; is($nn[0]{name}, 'Johnny', 'nickname'); }); # RFC 9555 Figure 14: PHOTO test_vcard('PHOTO', "PHOTO:https://www.example.com/pub/photos/jqpublic.gif\n", sub { ok($_[0]->{media}, 'has media'); my @m = values %{$_[0]->{media}}; is($m[0]{kind}, 'photo', 'photo kind'); is($m[0]{uri}, 'https://www.example.com/pub/photos/jqpublic.gif', 'photo uri'); }); # RFC 9555 Figure 16: EMAIL test_vcard('EMAIL', "EMAIL;TYPE=work:jqpublic\@xyz.example.com\nEMAIL;PREF=1:jane_doe\@example.com\n", sub { ok($_[0]->{emails}, 'has emails'); my @em = sort { $a->{address} cmp $b->{address} } values %{$_[0]->{emails}}; is(scalar @em, 2, 'two emails'); is($em[1]{address}, 'jqpublic@xyz.example.com', 'work email'); ok($em[1]{contexts}{work}, 'work context'); is($em[0]{address}, 'jane_doe@example.com', 'personal email'); is($em[0]{pref}, 1, 'pref=1'); }); # RFC 9555 Figure 17: IMPP test_vcard('IMPP', "IMPP;PREF=1:xmpp:alice\@example.com\n", sub { ok($_[0]->{onlineServices}, 'has onlineServices'); my @os = values %{$_[0]->{onlineServices}}; is($os[0]{uri}, 'xmpp:alice@example.com', 'impp uri'); is($os[0]{pref}, 1, 'pref=1'); }); # RFC 9555 Figure 18: LANG test_vcard('LANG', "LANG;TYPE=work;PREF=1:en\nLANG;TYPE=work;PREF=2:fr\nLANG;TYPE=home:fr\n", sub { ok($_[0]->{preferredLanguages}, 'has preferredLanguages'); my @langs = sort { ($a->{pref}//99) <=> ($b->{pref}//99) } values %{$_[0]->{preferredLanguages}}; is(scalar @langs, 3, 'three language prefs'); is($langs[0]{language}, 'en', 'first lang'); is($langs[0]{pref}, 1, 'pref=1'); ok($langs[0]{contexts}{work}, 'work context'); }); # RFC 9555 Figure 19: LANGUAGE test_vcard('LANGUAGE', "LANGUAGE:de-AT\n", sub { is($_[0]->{language}, 'de-AT', 'language'); }); # RFC 9555 Figure 20: SOCIALPROFILE test_vcard('SOCIALPROFILE', "SOCIALPROFILE;SERVICE-TYPE=Mastodon:https://example.com/\@foo\n", sub { ok($_[0]->{onlineServices}, 'has onlineServices'); my @os = values %{$_[0]->{onlineServices}}; is($os[0]{service}, 'Mastodon', 'service'); is($os[0]{uri}, 'https://example.com/@foo', 'uri'); }); # RFC 9555 Figure 21: TEL with multiple types test_vcard('TEL', "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+1-555-555-5555;ext=5555\nTEL;VALUE=uri;TYPE=home:tel:+33-01-23-45-67\n", sub { ok($_[0]->{phones}, 'has phones'); my @ph = sort { ($a->{pref}//99) <=> ($b->{pref}//99) } values %{$_[0]->{phones}}; is(scalar @ph, 2, 'two phones'); is($ph[0]{number}, 'tel:+1-555-555-5555;ext=5555', 'first phone number'); ok($ph[0]{contexts}{private}, 'home -> private'); ok($ph[0]{features}{voice}, 'voice feature'); is($ph[0]{pref}, 1, 'pref=1'); }); # RFC 9555 Figure 25: ORG with SORT-AS test_vcard('ORG', "ORG;SORT-AS=\"ABC\":ABC\\, Inc.;North American Division;Marketing\n", sub { ok($_[0]->{organizations}, 'has organizations'); my @orgs = values %{$_[0]->{organizations}}; is($orgs[0]{name}, 'ABC, Inc.', 'org name'); is(scalar @{$orgs[0]{units}}, 2, 'two units'); is($orgs[0]{units}[0]{name}, 'North American Division', 'first unit'); is($orgs[0]{units}[1]{name}, 'Marketing', 'second unit'); is($orgs[0]{sortAs}, 'ABC', 'sortAs'); }); # RFC 9555 Figure 26: RELATED test_vcard('RELATED', "RELATED;TYPE=friend:urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6\nRELATED;TYPE=contact:https://example.com/directory/john.vcf\n", sub { ok($_[0]->{relatedTo}, 'has relatedTo'); my $r1 = $_[0]->{relatedTo}{'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'}; ok($r1, 'related friend'); ok($r1->{relation}{friend}, 'friend relation'); my $r2 = $_[0]->{relatedTo}{'https://example.com/directory/john.vcf'}; ok($r2, 'related contact'); ok($r2->{relation}{contact}, 'contact relation'); }); # RFC 9555 Figure 28: EXPERTISE test_vcard('EXPERTISE', "EXPERTISE;LEVEL=beginner;INDEX=2:Chinese literature\nEXPERTISE;INDEX=1;LEVEL=expert:chemistry\n", sub { ok($_[0]->{personalInfo}, 'has personalInfo'); my @pi = sort { ($a->{listAs}//0) <=> ($b->{listAs}//0) } values %{$_[0]->{personalInfo}}; is($pi[0]{kind}, 'expertise', 'expertise kind'); is($pi[0]{value}, 'chemistry', 'chemistry'); is($pi[0]{level}, 'high', 'expert -> high'); is($pi[0]{listAs}, 1, 'listAs=1'); is($pi[1]{value}, 'Chinese literature', 'Chinese literature'); is($pi[1]{level}, 'low', 'beginner -> low'); is($pi[1]{listAs}, 2, 'listAs=2'); }); # RFC 9555 Figure 32: CATEGORIES test_vcard('CATEGORIES', "CATEGORIES:internet,IETF,Industry,Information Technology\n", sub { ok($_[0]->{keywords}, 'has keywords'); ok($_[0]->{keywords}{internet}, 'internet'); ok($_[0]->{keywords}{IETF}, 'IETF'); ok($_[0]->{keywords}{Industry}, 'Industry'); ok($_[0]->{keywords}{'Information Technology'}, 'Information Technology'); }); # RFC 9555 Figure 33: CREATED test_vcard('CREATED', "CREATED:19940930T143510Z\n", sub { is($_[0]->{created}, '1994-09-30T14:35:10Z', 'created normalized'); }); # RFC 9555 Figure 34: NOTE with author and created test_vcard('NOTE', "NOTE;CREATED=20221123T150132Z;AUTHOR-NAME=\"John\":Office hours are from 0800 to 1715 EST\\, Mon-Fri.\n", sub { ok($_[0]->{notes}, 'has notes'); my @n = values %{$_[0]->{notes}}; is($n[0]{note}, 'Office hours are from 0800 to 1715 EST, Mon-Fri.', 'note text'); is($n[0]{created}, '2022-11-23T15:01:32Z', 'note created'); is($n[0]{author}{name}, 'John', 'note author name'); }); # RFC 9555 Figure 35: PRODID test_vcard('PRODID', "PRODID:ACME Contacts App version 1.23.5\n", sub { is($_[0]->{prodId}, 'ACME Contacts App version 1.23.5', 'prodId'); }); # RFC 9555 Figure 36: REV test_vcard('REV', "REV:19951031T222710Z\n", sub { is($_[0]->{updated}, '1995-10-31T22:27:10Z', 'updated normalized'); }); # RFC 9555 Figure 24: MEMBER (group) test_vcard('GROUP', "KIND:group\nMEMBER:urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af\nMEMBER:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\n", sub { is($_[0]->{kind}, 'group', 'kind=group'); ok($_[0]->{members}, 'has members'); ok($_[0]->{members}{'urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af'}, 'member 1'); ok($_[0]->{members}{'urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519'}, 'member 2'); }); # RFC 9555 Figure 9: BDAY + ANNIVERSARY + DEATHDATE test_vcard('ANNIVERSARIES', "BDAY:19531015\nANNIVERSARY:19860201\n", sub { ok($_[0]->{anniversaries}, 'has anniversaries'); my @anns = values %{$_[0]->{anniversaries}}; my ($bday) = grep { $_->{kind} eq 'birth' } @anns; my ($wedding) = grep { $_->{kind} eq 'wedding' } @anns; ok($bday, 'has birthday'); is($bday->{date}, '1953-10-15', 'birthday date'); ok($wedding, 'has wedding'); is($wedding->{date}, '1986-02-01', 'wedding date'); }); # RFC 9555 Figure 22: CONTACT-URI test_vcard('CONTACT-URI', "CONTACT-URI;PREF=1:mailto:contact\@example.com\n", sub { ok($_[0]->{links}, 'has links'); my @l = values %{$_[0]->{links}}; is($l[0]{kind}, 'contact', 'kind=contact'); is($l[0]{uri}, 'mailto:contact@example.com', 'uri'); is($l[0]{pref}, 1, 'pref=1'); }); # RFC 9555 Figure 23: LOGO test_vcard('LOGO', "LOGO:https://www.example.com/pub/logos/abccorp.jpg\n", sub { ok($_[0]->{media}, 'has media'); my @m = values %{$_[0]->{media}}; is($m[0]{kind}, 'logo', 'logo kind'); is($m[0]{uri}, 'https://www.example.com/pub/logos/abccorp.jpg', 'logo uri'); }); done_testing(); Text-JSContact-0.02/t/PaxHeader/patch.t000644 000765 000024 00000000210 15164523776 020170 xustar00brongstaff000000 000000 30 mtime=1775413246.841353138 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/t/patch.t000644 000765 000024 00000013615 15164523776 016234 0ustar00brongstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; use JSON; use lib 'lib'; use Text::JSContact qw(vcard_to_jscontact jscontact_to_vcard patch_vcard); # Original vCard with Apple extensions and custom X-properties my $original = <<'VCARD'; BEGIN:VCARD VERSION:3.0 PRODID:-//Apple Inc.//iOS 17//EN UID:urn:uuid:patch-test-001 N:Smith;Jane;;; FN:Jane Smith EMAIL;type=HOME:jane@home.example item1.EMAIL;type=INTERNET:jane@work.example item1.X-ABLabel:Work Email TEL;type=CELL:+1-555-0100 ADR;type=HOME:;;42 Wallaby Way;Sydney;NSW;2000;Australia ORG:Acme Corp NOTE:Original note X-CUSTOM-PROP:this should be preserved X-ANOTHER-CUSTOM:also preserved item2.X-ABRELATEDNAMES:John Smith item2.X-ABLabel:_$!!$_ BDAY:1985-03-15 END:VCARD VCARD # Parse the original my $old_card = vcard_to_jscontact($original); ok($old_card, 'parsed original'); # ============================================================ # Test 1: Change only the name, everything else preserved # ============================================================ my $new_card = { %$old_card }; $new_card->{name} = { %{$old_card->{name}}, full => 'Jane Q. Smith' }; my $patched = patch_vcard($original, $old_card, $new_card); ok($patched, 'patch_vcard returned result'); # Custom properties should be preserved like($patched, qr/X-CUSTOM-PROP:this should be preserved/, 'X-CUSTOM-PROP preserved'); like($patched, qr/X-ANOTHER-CUSTOM:also preserved/, 'X-ANOTHER-CUSTOM preserved'); # Name should be updated like($patched, qr/FN:Jane Q\. Smith/, 'FN updated'); # Other properties should still be there like($patched, qr/jane\@home\.example/, 'home email preserved'); like($patched, qr/\+1-555-0100/, 'phone preserved'); like($patched, qr/Acme Corp/, 'org preserved'); # Re-parse and verify my $reparsed = vcard_to_jscontact($patched); is($reparsed->{name}{full}, 'Jane Q. Smith', 'name updated after reparsing'); is(scalar keys %{$reparsed->{emails}}, 2, 'email count unchanged'); # ============================================================ # Test 2: Add a new email, keep everything else # ============================================================ my $new_card2 = { %$old_card }; my %new_emails = %{$old_card->{emails}}; $new_emails{new1} = { address => 'jane@new.example', contexts => { work => JSON::true } }; $new_card2->{emails} = \%new_emails; my $patched2 = patch_vcard($original, $old_card, $new_card2); ok($patched2, 'patch with new email'); like($patched2, qr/X-CUSTOM-PROP/, 'custom props still preserved'); like($patched2, qr/jane\@new\.example/, 'new email present'); my $reparsed2 = vcard_to_jscontact($patched2); is(scalar keys %{$reparsed2->{emails}}, 3, 'now three emails'); # ============================================================ # Test 3: Change nothing -> original preserved exactly # ============================================================ my $patched3 = patch_vcard($original, $old_card, $old_card); is($patched3, $original, 'no changes -> original returned verbatim'); # ============================================================ # Test 4: Update phone number, verify labels on other props survive # ============================================================ my $new_card4 = { %$old_card }; my %new_phones = %{$old_card->{phones}}; my ($phone_id) = keys %new_phones; $new_phones{$phone_id} = { %{$new_phones{$phone_id}}, number => '+1-555-9999' }; $new_card4->{phones} = \%new_phones; my $patched4 = patch_vcard($original, $old_card, $new_card4); ok($patched4, 'patch with changed phone'); like($patched4, qr/\+1-555-9999/, 'new phone number present'); # Email label should still be there like($patched4, qr/Work Email/, 'email X-ABLabel preserved'); like($patched4, qr/X-CUSTOM-PROP/, 'custom props preserved'); # ============================================================ # Test 5: Delete a property # ============================================================ my $new_card5 = { %$old_card }; delete $new_card5->{notes}; my $patched5 = patch_vcard($original, $old_card, $new_card5); ok($patched5, 'patch with deleted notes'); unlike($patched5, qr/NOTE:/, 'NOTE removed'); like($patched5, qr/X-CUSTOM-PROP/, 'custom props still preserved'); like($patched5, qr/jane\@home\.example/, 'emails still there'); # ============================================================ # Test 6: Patch Apple group - adding member uses X-ADDRESSBOOKSERVER-MEMBER # ============================================================ my $apple_group = <<'VCARD'; BEGIN:VCARD VERSION:3.0 X-ADDRESSBOOKSERVER-KIND:group N:Family FN:Family X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:member-1 X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:member-2 X-CUSTOM-GROUP-PROP:keep me END:VCARD VCARD my $old_group = vcard_to_jscontact($apple_group); ok($old_group, 'parsed Apple group'); # Add a new member my $new_group = { %$old_group }; my %new_members = %{$old_group->{members}}; $new_members{'urn:uuid:member-3'} = JSON::true; $new_group->{members} = \%new_members; my $patched_group = patch_vcard($apple_group, $old_group, $new_group); ok($patched_group, 'patched Apple group'); # Should use X-ADDRESSBOOKSERVER-MEMBER, NOT standard MEMBER like($patched_group, qr/X-ADDRESSBOOKSERVER-MEMBER/, 'uses Apple member property'); unlike($patched_group, qr/^MEMBER:/m, 'does NOT use standard MEMBER'); like($patched_group, qr/member-3/, 'new member present'); like($patched_group, qr/member-1/, 'old member-1 preserved'); like($patched_group, qr/member-2/, 'old member-2 preserved'); # Should use X-ADDRESSBOOKSERVER-KIND, NOT standard KIND like($patched_group, qr/X-ADDRESSBOOKSERVER-KIND:group/, 'uses Apple kind property'); unlike($patched_group, qr/^KIND:/m, 'does NOT use standard KIND'); # Custom properties preserved like($patched_group, qr/X-CUSTOM-GROUP-PROP:keep me/, 'custom group prop preserved'); # Re-parse to verify my $reparsed_group = vcard_to_jscontact($patched_group); is($reparsed_group->{kind}, 'group', 'kind still group'); is(scalar keys %{$reparsed_group->{members}}, 3, 'now three members'); done_testing(); Text-JSContact-0.02/t/PaxHeader/apple.t000644 000765 000024 00000000210 15164523245 020161 xustar00brongstaff000000 000000 30 mtime=1775412901.319648206 57 LIBARCHIVE.xattr.com.apple.provenance=AQIA7l1WdRyXcOQ 49 SCHILY.xattr.com.apple.provenance=î]Vu—pä Text-JSContact-0.02/t/apple.t000644 000765 000024 00000013337 15164523245 016226 0ustar00brongstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More; use JSON; use lib 'lib'; use Text::JSContact qw(vcard_to_jscontact jscontact_to_vcard); # Test Apple iOS-style vCard with all extensions my $apple_vcard = <<'VCARD'; BEGIN:VCARD VERSION:3.0 PRODID:-//Apple Inc.//iOS 8.1.1//EN N:Smith;Jane;Marie;Dr.;PhD FN:Dr. Jane Marie Smith PhD NICKNAME:Janey X-PHONETIC-FIRST-NAME:Jeyn X-PHONETIC-LAST-NAME:Smith ORG:SuperCorp;Engineering TITLE:CTO EMAIL;type=INTERNET;type=HOME;type=pref:jane@home.example item1.EMAIL;type=INTERNET:jane@icloud.example item1.X-ABLabel:iCloud item2.EMAIL;type=INTERNET:jane@custom.example item2.X-ABLabel:Customemail TEL;type=HOME;type=VOICE;type=pref:+1-555-0100 item3.TEL:+1-555-0199 item3.X-ABLabel:Customphone item4.ADR;type=HOME;type=pref:;;42 Wallaby Way;Sydney;NSW;2000;Australia item4.X-ABADR:au BDAY:1985-03-15 item5.X-ABDATE;type=pref:2010-06-20 item5.X-ABLabel:_$!!$_ item6.X-ABDATE:2020-01-01 item6.X-ABLabel:Customdate item7.X-ABRELATEDNAMES;type=pref:John Smith item7.X-ABLabel:_$!!$_ item8.X-ABRELATEDNAMES:Bob Smith item8.X-ABLabel:_$!!$_ item9.X-ABRELATEDNAMES:Alice Smith item9.X-ABLabel:_$!!$_ X-SOCIALPROFILE;type=twitter;x-user=janesmith:http://twitter.com/janesmith X-SOCIALPROFILE;type=linkedin;x-user=janesmith:http://www.linkedin.com/in/janesmith item10.IMPP;X-SERVICE-TYPE=Skype;type=pref:skype:janeskype item10.X-ABLabel:Skype X-AIM:janeaim X-JABBER:jane@jabber.example URL;type=HOME:https://jane.example.com NOTE:Apple test contact END:VCARD VCARD my $card = vcard_to_jscontact($apple_vcard); ok($card, 'parsed Apple vCard'); # Name is($card->{name}{full}, 'Dr. Jane Marie Smith PhD', 'full name'); # Phonetic names ok($card->{name}{phoneticComponents}, 'has phonetic components'); my @phon_given = grep { $_->{kind} eq 'given' } @{$card->{name}{phoneticComponents}}; is($phon_given[0]{value}, 'Jeyn', 'phonetic first name'); my @phon_surname = grep { $_->{kind} eq 'surname' } @{$card->{name}{phoneticComponents}}; is($phon_surname[0]{value}, 'Smith', 'phonetic last name'); # Emails with X-ABLabel ok($card->{emails}, 'has emails'); my @emails = values %{$card->{emails}}; my ($icloud_email) = grep { ($_->{address} // '') eq 'jane@icloud.example' } @emails; ok($icloud_email, 'found iCloud email'); is($icloud_email->{label}, 'iCloud', 'iCloud label preserved'); my ($custom_email) = grep { ($_->{address} // '') eq 'jane@custom.example' } @emails; ok($custom_email, 'found custom email'); is($custom_email->{label}, 'Customemail', 'custom email label preserved'); # Phones with X-ABLabel ok($card->{phones}, 'has phones'); my @phones = values %{$card->{phones}}; my ($custom_phone) = grep { ($_->{label} // '') eq 'Customphone' } @phones; ok($custom_phone, 'found custom-labeled phone'); # Address with X-ABADR country code ok($card->{addresses}, 'has addresses'); my @addrs = values %{$card->{addresses}}; is($addrs[0]{countryCode}, 'au', 'X-ABADR country code'); # Anniversaries from BDAY + X-ABDATE ok($card->{anniversaries}, 'has anniversaries'); my @anns = values %{$card->{anniversaries}}; my ($bday) = grep { $_->{kind} eq 'birth' } @anns; ok($bday, 'has birthday'); is($bday->{date}, '1985-03-15', 'birthday date'); my ($wedding) = grep { $_->{kind} eq 'wedding' } @anns; ok($wedding, 'X-ABDATE Anniversary -> wedding'); is($wedding->{date}, '2010-06-20', 'anniversary date'); my ($custom_date) = grep { ($_->{kind} // '') eq 'customdate' } @anns; ok($custom_date, 'X-ABDATE custom date'); # Related from X-ABRELATEDNAMES ok($card->{relatedTo}, 'has relatedTo'); my $spouse_rel = $card->{relatedTo}{'John Smith'}; ok($spouse_rel, 'found spouse relation'); ok($spouse_rel->{relation}{spouse}, 'spouse relation type'); my $father_rel = $card->{relatedTo}{'Bob Smith'}; ok($father_rel, 'found father relation'); ok($father_rel->{relation}{parent}, 'father -> parent relation type'); my $friend_rel = $card->{relatedTo}{'Alice Smith'}; ok($friend_rel, 'found friend relation'); ok($friend_rel->{relation}{friend}, 'friend relation type'); # Online services from X-SOCIALPROFILE + IMPP + legacy X-properties ok($card->{onlineServices}, 'has onlineServices'); my @services = values %{$card->{onlineServices}}; my ($twitter) = grep { ($_->{service} // '') =~ /twitter/i } @services; ok($twitter, 'found twitter'); is($twitter->{user}, 'janesmith', 'twitter username'); my ($skype) = grep { ($_->{service} // '') =~ /skype/i } @services; ok($skype, 'found skype'); my ($aim) = grep { ($_->{service} // '') eq 'AIM' } @services; ok($aim, 'found AIM from X-AIM'); is($aim->{user}, 'janeaim', 'AIM username'); my ($jabber) = grep { ($_->{service} // '') eq 'Jabber' } @services; ok($jabber, 'found Jabber from X-JABBER'); # Test X-ABLabel round-trip on output my $vcard_out = jscontact_to_vcard($card); ok($vcard_out, 'generated vCard from JSContact'); like($vcard_out, qr/X-ABLabel/i, 'output contains X-ABLabel'); # Re-parse and verify labels survive my $card2 = vcard_to_jscontact($vcard_out); my @emails2 = values %{$card2->{emails}}; my ($icloud2) = grep { ($_->{label} // '') eq 'iCloud' } @emails2; ok($icloud2, 'iCloud label survives round-trip'); # Apple group contact my $group_vcard = <<'VCARD'; BEGIN:VCARD VERSION:3.0 X-ADDRESSBOOKSERVER-KIND:group N:Family FN:Family X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:member-1 X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:member-2 X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:member-3 END:VCARD VCARD my $group = vcard_to_jscontact($group_vcard); ok($group, 'parsed Apple group vCard'); is($group->{kind}, 'group', 'kind is group'); ok($group->{members}, 'has members'); ok($group->{members}{'urn:uuid:member-1'}, 'member 1'); ok($group->{members}{'urn:uuid:member-2'}, 'member 2'); ok($group->{members}{'urn:uuid:member-3'}, 'member 3'); is(scalar keys %{$group->{members}}, 3, 'three members'); done_testing();