Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 22. júl 2024

Súbor: [Platon] / scripts / perl / kphone / vcf2kphone.pl (stiahnutie)

Revízia 1.1, Mon Oct 10 03:33:39 2011 UTC (12 years, 9 months ago) by nepto

Added kphone/vcf2kphone.pl utility

#!/usr/bin/perl -w

#
# vcf2kphone.pl
#
# Developed by Ondrej Jombik <nepto@platon.sk>
# Copyright (c) 2011 Platon Group, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2011-10-09 - created
#

#
# HOW TO USE EXAMPLE:
#
# cat /mnt/sdb/Others/Contacts/* | ./vcf2kphone.pl  > ~/.kphone-phonebook.xml
#

# $Platon$

use strict;
use Data::Dumper;

$| = 1;

my %entry;

print <<EOS;
<?xml version="1.0" encoding="iso-8859-1"?>
<phonebook>
EOS

while (<>)
{
    $_ =~ s/^\s*//g;
    $_ =~ s/\s*$//g;

    ##print "LINE: $_\n";

    if ($_ eq 'BEGIN:VCARD') {
        %entry = (
            name    => undef,
            numbers => undef
        );
        next;
    }

    if ($_ eq 'END:VCARD') {
        if (not defined $entry{name} or length $entry{name} <= 0) {
            next;
        }
        print "<person name='$entry{name}'>\n";
        foreach my $numtype (keys %{$entry{numbers}}) {
            printf("  <identity uri='sip:%s' contact='Yes' description='%s [%s]' />\n",
                $entry{numbers}{$numtype}, $entry{name}, $numtype);
        }
        print "</person>\n";
        next;
    }

    if ($_ =~ /^N:(.*)$/) {
        $entry{name} = $1;
        $entry{name} =~ s/;/, /g;
        next;
    }

    if ($_ =~ /^TEL;(.*)$/) {
        my ($type, $number) = split /:/, $1, 2;
        while (defined $entry{numbers}{$type}) {
            $type .= 'X';
        }
        $number =~ s/^\+//g;
        $entry{numbers}{$type} = $number;
        next;
    }
}

print <<EOS;
</phonebook>
EOS

# vim: ts=4
# vim600: fdm=marker fdl=0 fdc=3


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok