#!/usr/bin/perl =pod =head1 AUTHOR Imran-UK electr0sphere@yahoo.co.uk =head1 NAME convert.pl =head1 DESCRIPTION Converts a text file that was exported as a memo by YAPS on PalmOS to a KeePassX format XML file. =head1 USAGE Name your YAPS memo to 'yaps.txt'. Make sure this file is "clean" by following the steps in the NOTES below. Put file in same directory as this program. Run program. XML file is in 'yaps.xml'. Import XML into KeePassX and relax. =head1 NOTES OS used: Ubuntu 8.04 You might have a BOM character in the YAPS memo. http://www.perlmonks.org/?node_id=724474 yaps.txt had a BOM at start of file (visible in less) #,AA.com,,megazoid@hotmail.com,corsa,, used the following to get rid of it: $ perl -CD -pe 'tr/\x{feff}//d' yaps.txt > yaps-nobom.txt make sure empty lines are removed: Delete empty lines in vim with: :%s/^\n// YAPS txt file has carriage return and newlines, convert this to UNIX format by installing: Package: tofrodos Description: Converts DOS <-> Unix text files, alias tofromdos DOS text files traditionally have CR/LF (carriage return/line feed) pairs as their new line delimiters while Unix text files traditionally have LFs (line feeds) to terminate each line. aptitude install tofrodos Then: dos2unix yaps.txt (modifies file in place) =cut use strict; use IO::File; use Data::Dumper; my $VERSION = 0.4; ## FORMAT ## Field 0 - unused? ## Field 1 - name ## Field 2 - location - eg. "forum", ## Field 3 - username ## Field 4 - password ## Field 5 - comment - may contain ',', may contain nuts, may be multiline, must NOT begin with #^,# my $input_file = 'yaps.txt'; my $output_file = 'yaps.xml'; my $dest_header = < XML my $dest_footer = < XML my $source_hash = {}; my $count = 0; my $DEBUG = 0; my $name = 'none'; my $start_record = '#,'; ## get them all into a hash, then sort by name my $source = IO::File->new; $source->open($input_file); my $dest = IO::File->new; $dest->open(">$output_file"); ## XXX multiline comments field is not handled properly while(<$source>) { chomp; if(/^\#\,/) { ## Start of new record my @line = split(',', $_, 6); if(exists $source_hash->{$line[1]}) { $name = $line[1] . "-$count"; } else { $name = $line[1]; } $source_hash->{$name} = { name => $line[1], location => $line[2], username => $line[3], password => $line[4], comment => "$line[5]\n" }; } else { ## Continuation of previous record comments $source_hash->{$name}->{'comment'} .= "$_\n"; } } if($DEBUG) { foreach my $name (sort keys %$source_hash) { ## remove the trailing newline from the comment my $comment = $source_hash->{$name}->{'comment'}; chomp($comment); print STDERR Dumper($name, $comment); } } ## Convert to KeePassX XML $dest->print($dest_header); foreach my $name (sort keys %$source_hash) { ## remove the trailing newline from the comment my $comment = $source_hash->{$name}->{'comment'}; chomp($comment); my $title = $source_hash->{$name}->{'location'}; if($title =~ /^\s*$/) { $title = $source_hash->{$name}->{'name'}; } my $group = < $name $title @{[ $source_hash->{$name}->{'username'} ]} @{[ $source_hash->{$name}->{'password'} ]} $comment XML $dest->print($group); } $dest->print($dest_footer);