diff options
| author | fukachan <fukachan> | 2001-11-04 13:46:34 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-11-04 13:46:34 +0000 |
| commit | 52a99648af1d65ce9eaee35078e4860037a5dbca (patch) | |
| tree | 92554b8cab8a82e021f354ab3b70fc3d8af148ec /fml/lib/Mail/Message | |
| parent | 6e912f75030ac2d84448231ae6be308a481aaa3a (diff) | |
| download | fml8-52a99648af1d65ce9eaee35078e4860037a5dbca.tar.gz fml8-52a99648af1d65ce9eaee35078e4860037a5dbca.tar.bz2 fml8-52a99648af1d65ce9eaee35078e4860037a5dbca.zip | |
Mail::Message::MH::expand() expand MH style parameter to array of
article id numbers.
Diffstat (limited to 'fml/lib/Mail/Message')
| -rw-r--r-- | fml/lib/Mail/Message/MH.pm | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/fml/lib/Mail/Message/MH.pm b/fml/lib/Mail/Message/MH.pm new file mode 100644 index 00000000..a174e919 --- /dev/null +++ b/fml/lib/Mail/Message/MH.pm @@ -0,0 +1,118 @@ +#-*- perl -*- +# +# Copyright (C) 2000 Ken'ichi Fukamachi +# +# $FML: MH.pm,v 1.1 2001/11/03 08:03:30 fukachan Exp $ +# + +package Mail::Message::MH; + +=head1 NAME + +Mail::Message::MH - utilities for MH style format + +=head1 SYNOPSIS + + use Mail::Message::MH; + my $mh = new Mail::Message::MH; + +=head1 DESCRIPTION + +=head1 METHODS + +=head2 expand($str, [$min, $max]) + +return HASH ARRAY of numbers specified by the following format: + + 100 + 100-110 + first-110 + 100-last + first + first:100 + last + last:100 + +=cut + + +sub expand +{ + my ($self, $str, $min, $max) = @_; + my $ra = []; + + unless (defined $min) { $min = 1;} + + if ($str eq 'all') { + unless (defined $max) { return undef;} + return _expand_range($min, $max); + } + elsif ($str =~ /^\d+$/) { + return [ $str ]; + } + elsif ($str =~ /^(\d+)\-(\d+)$/) { + my ($first, $last) = ($1, $2); + return _expand_range($first, $last); + } + elsif ($str =~ /^(first)\-(\d+)$/) { + my ($first, $last) = ($1, $2); + return _expand_range($min, $last); + } + elsif ($str =~ /^(\d+)\-(last)$/) { + unless (defined $max) { return undef;} + my ($first, $last) = ($1, $2); + return _expand_range($first, $max); + } + elsif ($str eq 'first') { + return [ $min ]; + } + elsif ($str eq 'last' || $str eq 'cur') { + unless (defined $max) { return undef;} + return [ $max ]; + } + elsif ($str =~ /^first:(\d+)$/) { + return _expand_range($min, $min + $1); + } + elsif ($str =~ /^last:(\d+)$/) { + unless (defined $max) { return undef;} + return _expand_range($max - $1, $max); + } + + undef; +} + + +# Descriptions: make an array from $fist to $last number +# Arguments: $first_number $last_number +# Side Effects: none +# Return Value: HASH ARRAY as [ $first .. $last ] +sub _expand_range +{ + my ($first, $last) = @_; + + my (@fn); + for ($first .. $last) { push(@fn, $_);} + return \@fn; +} + + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +Mail::Message::MH appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; |
