Sponsored Content
Top Forums Shell Programming and Scripting Fixing corrupted vcard files. Post 302247221 by dotancohen on Wednesday 15th of October 2008 07:49:08 AM
Old 10-15-2008
Thanks. I'm going through the docs as we speak. Perl is _complicated_! That does not seem to be my own opinion, either. Googling some example leads me to lots of frustrated people!

In any case, I probably should have posted the entire vcard file. Here it is, along with the results of the code:
Code:
hardy2@hardy2-laptop:~/test$ cat test.vcf
BEGIN:VCARD
FN:First Last
N:Last;First;;;
NOTE;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:First Line.\nThe Second Line i
 s long so that it will wrap. Long\, long\, and wrapping!=\n\nThird Line.\n
UID:frh74xvYZ9
VERSION:2.1
END:VCARD

BEGIN:VCARD
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D7=90=D7=90=D7=A4=D7=A8=D7=98=D
 7=99 =D7=9E=D7=A9=D7=A4=D7=97=D7=94
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D7=9E=D7=A9=D7=A4=D7=97=D7=94;=D
 7=90=D7=90=D7=A4=D7=A8=D7=98=D7=99;;;
NOTE;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D7=A9=D7=95=D7=A8=D7=94 =D7=A
 8=D7=90=D7=A9=D7=95=D7=A0=D7=94.\n=D7=A9=D7=95=D7=A8=D7=94 =D7=A9=D7=A0=D7=
 99=D7=94 =D7=94=D7=99=D7=90 =D7=\n=90=D7=A8=D7=95=D7=9B=D7=94\, =D7=9B=D7=9
 3=D7=99 =D7=A9=D7=A0=D7=A8=D7=90=\n =D7=90=D7=95=D7=AA=D7=94 =D7=92=D7=95=D
 7=9C=D7=A9=D7=AA. =D7=90=D7=A8=D7=\n=95=D7=9B=D7=94\, =D7=90=D7=A8=D7=95=D7
 =9B=D7=94\, =D7=95=D7=92=D7=95=D7=9C=\n=D7=A9=D7=AA!\n=D7=A9=D7=95=D7=A8=D7
 =94 =D7=A9=D7=9C=D7=99=D7=A9=D7=99=D7=AA.\n
UID:KqbQKbfBaF
VERSION:2.1
END:VCARD

hardy2@hardy2-laptop:~/test$ perl -pi.bak -e 'BEGIN { $/=""; } s/\n //gm' *.vcf
hardy2@hardy2-laptop:~/test$ cat test.vcf
BEGIN:VCARD
FN:First Last
N:Last;First;;;
s long so that it will wrap. Long\, long\, and wrapping!=\n\nThird Line.\ni
UID:frh74xvYZ9
VERSION:2.1
END:VCARD

BEGIN:VCARD
7=99 =D7=9E=D7=A9=D7=A4=D7=97=D7=94INTABLE:=D7=90=D7=90=D7=A4=D7=A8=D7=98=D
7=90=D7=90=D7=A4=D7=A8=D7=98=D7=99;;;ABLE:=D7=9E=D7=A9=D7=A4=D7=97=D7=94;=D
=94 =D7=A9=D7=9C=D7=99=D7=A9=D7=99=D7=AA.\nA9=D7=AA!\n=D7=A9=D7=95=D7=A8=D7
UID:KqbQKbfBaF
VERSION:2.1
END:VCARD

hardy2@hardy2-laptop:~/test$

As can be easily seen, the lines still wrap, and worse, critical parts of the file are destroyed. I have been playing around with the line of code, but it is slow going and I could really use a hand with this. I do appreciate your patience and willingness to teach a noob.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Corrupted files from Windows to Unix Sco

I downloaded some applications from CD on a windows2000 PC to a Unix Sco machine using the WS-FTP program. When I tried to run the applications on the Unix machines I got an error. The files must have been corrupted in the process of transferring files from a Windows 2000 to a Unix Sco... (9 Replies)
Discussion started by: BAM
9 Replies

2. UNIX for Dummies Questions & Answers

Extracting files from corrupted tape

I've got a backuptape in cpio format that was accidentally overwritten with a very small batch file. As I assume that the cpio header has been overwritten, I cannot extract files from the backup in the conventional manner: ( cpio -itv </dev/rct0 cpio: this is not a cpio file, bad header) ... (0 Replies)
Discussion started by: mart4179
0 Replies

3. Linux

fixing with sed

I am trying to replace the value of $f3 but its not working . I don't know what I am missing here . cat dim_copy.20080516.sql | grep -i "create view" | grep -v OPSDM002 | while read f1 f2 f3 f4 f5 f6 f7 f8 f9 do echo " $f3 " sed -e... (13 Replies)
Discussion started by: capri_drm
13 Replies

4. Solaris

PAM login library files corrupted, have ILOM, can I get root?

I was installing sfw sudo and its dependencies (libiconv, libintl, libgcc)on Solaris 10, running on an x86 x4200 and I corrupted some PAM library files. It's a standard Solaris 10 base install, with some added software & libraries from a vendor. I am on console trying to get root access back,... (1 Reply)
Discussion started by: Mariognarly
1 Replies

5. HP-UX

WinRAR files are corrupted after FTP

In my Windows 2003 server machine I have a winrar or winzip file that i around 3GB. This zip/rar file is ftped to a unix mahine (HPUX) . FTP is successful. But when it get this file to check if its has been ftped correctly, the file is corrupted. Is there something wrong that i am doing while... (4 Replies)
Discussion started by: maroli
4 Replies

6. Shell Programming and Scripting

Help fixing awk code to print values from 2 files

Hi everyone, Please help on this: I have file1: <file title="Title 1 and 2"> <report> <title>Title 1</title> <number>No. 1234</number> <address>Address 1</address> <date>October 07, 2009</date> <description>Some text</description> </report> ... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

7. Shell Programming and Scripting

help fixing awk statement

awk "BEGIN {if($MessageREAD<$ThresholdW) {print \"OK\" ; exit 0} else if(($MessageREAD>=$ThresholdW) && ($MessageREAD<$ThresholdC)) {print \"WARNING\" ; exit 1}" else if($MessageREAD<=$ThresholdC) {print \"CRITICAL\" ;... (4 Replies)
Discussion started by: SkySmart
4 Replies

8. Hardware

Files getting corrupted

$ uname -a Linux darksun 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:45 UTC 2014 i686 athlon i686 GNU/Linux My files are getting corrupted on a frequent basis. $ sudo fdisk -l /dev/sda Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total... (10 Replies)
Discussion started by: rlopes
10 Replies
AnyEvent::XMPP::Ext::VCard(3pm) 			User Contributed Perl Documentation			   AnyEvent::XMPP::Ext::VCard(3pm)

NAME
AnyEvent::XMPP::Ext::VCard - VCards (XEP-0054 & XEP-0084) SYNOPSIS
use AnyEvent::XMPP::Ext::VCard; my $vcard = AnyEvent::XMPP::Ext::VCard->new; $con->reg_cb ( stream_ready => sub { $vcard->hook_on ($con) } ); $vcard->retrieve ($con, 'elmex@jabber.org', sub { my ($jid, $vcard, $error) = @_; if ($error) { warn "couldn't get vcard for elmex@jabber.org: " . $error->string . " "; } else { print "vCard nick for elmex@jabber.org: ".$vcard->{NICKNAME}." "; print "Avatar hash for elmex@jabber.org: ".$vcard->{_avatar_hash}." "; } }); $vcard->store ($con, undef, { NICKNAME => 'net-xmpp2' }, sub { my ($error) = @_; if ($error) { warn "upload failed: " . $error->string . " "; } else { print "upload successful "; } }); $disco->enable_feature ($vcard->disco_feature); DESCRIPTION
This extension handles setting and retrieval of the VCard and the VCard based avatars. For example see the test suite of AnyEvent::XMPP. METHODS
new (%args) Creates a new vcard extension. It can take a "cache" argument, which should be a tied hash which should be able to save the retrieved vcards. If no "cache" is set a internal hash will be used and the vcards will be retrieved everytime the program is restarted. The keys will be the stringprepped bare JIDs of the people we got a vcard from and the value will be a non-cyclic hash/array datastructure representing the vcard. About this datastructure see below at VCARD STRUCTURE. If you want to support avatars correctly make sure you hook up the connection via the "hook_on" method. hook_on ($con, $dont_retrieve_vcard) $con must be an object of the class AnyEvent::XMPP::Connection (or derived). Once the vCard extension has been hooked up on a connection it will add the avatar information to all outgoing presence stanzas. IMPORTANT: You need to hook on the connection BEFORE it was connected. The initial presence stanza needs to contain the information that we support avatars. The vcard will automatically retrieved if the session wasn't already started. Otherwise you will have to retrieve the vcard manually if you hook it up after the "session_ready" event was received. You can prevent the automatic retrieval by giving a true value in $dont_retrieve_vcard. However, just make sure to hook up on any connection before it is connected if you want to offer avatar support on it. Best is probably to do it like this: my $vcard = AnyEvent::XMPP::Ext::VCard->new; $con->reg_cb ( stream_ready => sub { $vcard->hook_on ($con) } ); my_vcard ($con) This method returns the vcard for the account connected by $con. This only works if vcard was (successfully) retrieved. If the connection was hoooked up the vcard was automatically retrieved. Alternatively $con can also be a string reprensenting the JID of an account. cache ([$newcache]) See also "new" about the meaning of cache hashes. If no argument is given the current cache is returned. store ($con, $vcard, $cb) This method will store your $vcard on the connected server. $cb is called when either an error occured or the storage was successful. If an error occured the first argument is not undefined and contains an AnyEvent::XMPP::Error::IQ object. $con should be a AnyEvent::XMPP::Connection or an object from some derived class. $vcard has a datastructure as described below in VCARD STRUCTURE. retrieve ($con, $jid, $cb) This method will retrieve the vCard for $jid via the connection $con. If $jid is undefined the vCard of yourself is retrieved. The callback $cb is called when an error occured or the vcard was retrieved. The first argument of the callback will be the JID to which the vCard belongs, the second argument is the vCard itself (as described in VCARD STRUCTURE below) and the thrid argument is the error, if an error occured (undef otherwise). VCARD STRUCTURE
As there are currently no nice DOM implementations in Perl and I strongly dislike the DOM API in general this module has a simple Perl datastructure without cycles to represent the vCard. First an example: A fetched vCard hash may look like this: { 'URL' => ['http://www.ta-sa.org/'], 'ORG' => [{ 'ORGNAME' => 'nethype GmbH' }], 'N' => [{ 'FAMILY' => 'Redeker' }], 'EMAIL' => ['elmex@ta-sa.org'], 'BDAY' => ['1984-06-01'], 'FN' => ['Robin'], 'ADR' => [ { HOME => undef, 'COUNTRY' => 'Germany' }, { WORK => undef, COUNTRY => 'Germany', LOCALITY => 'Karlsruhe' } ], 'NICKNAME' => ['elmex'], 'ROLE' => ['Programmer'] } The keys represent the toplevel element of a vCard, the values are always array references containig one or more values for the key. If the value is a hash reference again it's value will not be an array reference but either undef or plain values. The values of the toplevel keys are all array references because fields like "ADR" may occur multiple times. Consult XEP-0054 for an explanation what these fields mean or contain. There are special fields in this structure for handling avatars: "_avatar" contains the binary data for the avatar image. "_avatar_hash" contains the sha1 hexencoded hash of the binary image data. "_avatar_type" contains the mime type of the avatar. If you want to store the vcard you only have to set "_avatar" and "_avatar_type" if you want to store an avatar. EVENTS
The vcard extension will emit these events: TODO
Implement caching, the cache stuff is just a storage hash at the moment. Or maybe drop it completly and let the application handle caching. retrieve_vcard_error => $iq_error When a vCard retrieval was not successful, this event is emitted. This is neccessary as some retrievals may happen automatically. vcard => $jid, $vcard Whenever a vCard is retrieved, either automatically or manually, this event is emitted with the retrieved vCard. AUTHOR
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" COPYRIGHT &; LICENSE Copyright 2007, 2008 Robin Redeker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-03-19 AnyEvent::XMPP::Ext::VCard(3pm)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy