#!/usr/bin/perl -w ########################## # $Id: memoarchive 22 2003-01-16 00:26:34Z steve $ ########################## # $Log$ # Revision 1.2 2003/01/16 00:26:34 steve # cleaned up usage info # # Revision 1.1 2002/12/13 21:08:47 steve # Initial revision # ########################## use Getopt::Std; use Palm::PDB; use Palm::Memo; use Palm::StdAppInfo; our( $opt_d, $opt_h, $opt_q ); getopts('dhq'); my $delete = 0; my $quiet = 0; $delete = $opt_d if defined $opt_d; $quiet = $opt_q if defined $opt_q; usage() if ($opt_h || @ARGV != 1); my $category = $ARGV[0]; my $db = "$ENV{'HOME'}/.palm/sync/MemoDB.pdb"; $db = $ENV{'PALM_MEMO_DATABASE'} if exists $ENV{'PALM_MEMO_DATABASE'}; # done initializing my $pdb = new Palm::Memo; $pdb->Load( $db ); # find the category number my $catnum = -1; for( my $i = 0; $i < scalar @{$pdb->{'appinfo'}->{'categories'}}; $i++ ){ $catnum = $i if $pdb->{'appinfo'}->{'categories'}[$i] =~/^$category$/i; } if($catnum == -1) { print "Error: Not a category\n"; exit; } $category = $pdb->{'appinfo'}->{'categories'}[$catnum]; print STDERR "Archiving Memopad category \"$category\":\n" unless $quiet; my $count = 0; my $i; for( $i = 0; $i < scalar @{$pdb->{records}}; $i++){ my $record = $pdb->{records}[$i]; use Data::Dumper; if( exists $record->{category} && $record->{category} == $catnum ){ $record->{data} =~ /(.{0,40})/; print STDERR "Deleting and " if ($delete && !$quiet); print STDERR "Dumping: $1\n" unless $quiet; print "Subject: [$category] $1\n\n"; print $record->{data}."\n"; $pdb->delete_Record($record, 1) if $delete; $count++; } } print STDERR "Looked through $i records" unless $quiet; print STDERR ", deleted" if ($delete && !$quiet); print STDERR " and dumped $count from $category\n" unless $quiet; if( $delete ){ print STDERR "Deleting category \"$category\"..." unless $quiet; $pdb->{'appinfo'}->{'categories'}[$catnum] = ""; print STDERR "done\n" unless $quiet; } $pdb->Write("$db") if $delete; sub usage{ die< Released under the terms of the GNU GPL EOF }