From: short <> Date: Fri, 17 Dec 2004 21:14:39 +0000 (+0000) Subject: Split out "PerlMail::Contacts" implementation to: PerlMail::Contacts::9000 X-Git-Tag: bp_lace~16 X-Git-Url: http://git.jankratochvil.net/?p=PerlMail.git;a=commitdiff_plain;h=77c63c5ed9fa4b3c5d2110e70c3d66701dec763c Split out "PerlMail::Contacts" implementation to: PerlMail::Contacts::9000 --- diff --git a/PerlMail/Contacts.pm b/PerlMail/Contacts.pm index 4f04cca..0767261 100644 --- a/PerlMail/Contacts.pm +++ b/PerlMail/Contacts.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # # $Id$ -# Copyright (C) 2002-2003 Jan Kratochvil +# Copyright (C) 2002-2004 Jan Kratochvil # # 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 @@ -35,54 +35,10 @@ my $self=bless { return $self; } -sub _parse -{ -my($self,$data,@headers)=@_; - - my $re=join("(.*?)(\r\n)?",map("\Q[$_]\E\r\n",@headers)); - $re=qr/^$re/s; - my @r=(); - while (my @items=($data=~/$re/s)) { - my %h=(); - for my $i (0..$#headers) { - $h{$headers[$i]}=(!$items[2*$i+1] ? undef : $items[2*$i+0]) - } - push @r,\%h; - $data=substr($data,length $&); - } - die "Unrecognized data (parsing ".join("/",@headers)."): $data" if $data; - return @r; -} - -sub in -{ -my($self,$data)=@_; - - $self=$self->new() if !ref $self; - push @{$self->{"data"}},map({ - [ $self->_parse($_->{"RECORD"}."\r\n","FIELD","FIELD-NAME","FIELD-DATA","FIELD-END") ]; - } $self->_parse($data,"RECORD","RECORD-END")); - return (wantarray() ? @{$self->{"data"}} : $self->{"data"}); -} +# sub in +# my($self,$data)=@_; -sub _join -{ -my($self,$href,@headers)=@_; - - my $trailer=pop @headers; - return join("",map(("[$_]\r\n".(!defined $href->{$_} ? "" : $href->{$_}."\r\n")),@headers))."[$trailer]\r\n"; -} - -sub out -{ -my($self,$data)=@_; - - $data=$self->{"data"} if !$data; - return join("",map({ - "[RECORD]\r\n".join("",map({ - $self->_join($_,"FIELD","FIELD-NAME","FIELD-DATA","FIELD-END"); - } @$_))."[RECORD-END]\r\n"; - } @$data)); -} +# sub out +# my($self,$data)=@_; 1; diff --git a/PerlMail/Contacts/9000.pm b/PerlMail/Contacts/9000.pm new file mode 100644 index 0000000..ebc7195 --- /dev/null +++ b/PerlMail/Contacts/9000.pm @@ -0,0 +1,81 @@ +#! /usr/bin/perl +# +# $Id$ +# Copyright (C) 2002-2004 Jan Kratochvil +# +# 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 2 of the License, 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +package PerlMail::Contacts::9000; +use vars qw($VERSION); +$VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; }; +use strict; +use warnings; +use vars qw(@ISA); +require PerlMail::Contacts; +@ISA=qw(PerlMail::Contacts); + + +sub _parse +{ +my($self,$data,@headers)=@_; + + my $re=join("(.*?)(\r\n)?",map("\Q[$_]\E\r\n",@headers)); + $re=qr/^$re/s; + my @r=(); + while (my @items=($data=~/$re/s)) { + my %h=(); + for my $i (0..$#headers) { + $h{$headers[$i]}=(!$items[2*$i+1] ? undef : $items[2*$i+0]) + } + push @r,\%h; + $data=substr($data,length $&); + } + die "Unrecognized data (parsing ".join("/",@headers)."): $data" if $data; + return @r; +} + +sub in +{ +my($self,$data)=@_; + + $self=$self->new() if !ref $self; + push @{$self->{"data"}},map({ + [ $self->_parse($_->{"RECORD"}."\r\n","FIELD","FIELD-NAME","FIELD-DATA","FIELD-END") ]; + } $self->_parse($data,"RECORD","RECORD-END")); + return (wantarray() ? @{$self->{"data"}} : $self->{"data"}); +} + +sub _join +{ +my($self,$href,@headers)=@_; + + my $trailer=pop @headers; + return join("",map(("[$_]\r\n".(!defined $href->{$_} ? "" : $href->{$_}."\r\n")),@headers))."[$trailer]\r\n"; +} + +sub out +{ +my($self,$data)=@_; + + $data=$self->{"data"} if !$data; + return join("",map({ + "[RECORD]\r\n".join("",map({ + $self->_join($_,"FIELD","FIELD-NAME","FIELD-DATA","FIELD-END"); + } @$_))."[RECORD-END]\r\n"; + } @$data)); +} + +1; diff --git a/contacts-n9k2mutt b/contacts-n9k2mutt index 915ad44..81aa704 100755 --- a/contacts-n9k2mutt +++ b/contacts-n9k2mutt @@ -24,7 +24,7 @@ use strict; use warnings; require Getopt::Long; -require PerlMail::Contacts; +require PerlMail::Contacts::9000; require Mail::Address; @@ -50,7 +50,7 @@ while (<>) { "iscompany"=>($record{"Name"} && $record{"Company"} && $record{"Name"} eq $record{"Company"}), })); } @record); - } PerlMail::Contacts->in($_)); + } PerlMail::Contacts::9000->in($_)); my @nicked=map({ my $data=$_; my($name,$mail,$attr,$iscompany)=map(($data->{$_}),qw(name mail attr iscompany));