1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#! @im_path_perl@
################################################################
###
### imtar
###
### Copyright (C) 1997 Internet Message Group
###
### This Perl5 library conforms
### GNU GENERAL PUBLIC LICENSE Version 2.
###
###
### Author: Internet Message Group <img@mew.org>
### Created: Apr 08, 1998
### Revised: @im_revised@
###
my $VERSION = "imtar @im_version@";
$Prog = 'imtar';
##
## Require packages
##
use IM::Config;
use IM::Folder;
use IM::Util;
use integer;
use strict;
use vars qw($Prog $EXPLANATION @OptConfig
$opt_src $opt_dst $opt_noharm $opt_verbose $opt_debug $opt_help);
##
## Environments
##
$EXPLANATION = "
$Prog :: compress folder into a single file.
$VERSION
usage: $Prog [options] [+folder]
";
@OptConfig =(
'src;F;;' => "Set source folder.",
'dst;s;./msgbox;' => "Destination MMDF file.",
'noharm;b;;' => "No operation. Show what will happen.",
'verbose;b;;' => 'With verbose messages.',
'debug;d;;' => "With debug message.",
'help;b;;' => "Show this message.",
);
##
## Profile and option processing
##
init_opt(\@OptConfig);
read_cfg();
read_opt(\@ARGV); # help?
help($EXPLANATION) && exit $EXIT_SUCCESS if $opt_help;
debug_option($opt_debug) if $opt_debug;
##
## Main
##
my @msgs = @ARGV;
@msgs = ('all') if (!@ARGV);
$opt_dst = "stdout" if ($opt_noharm);
make_mmdf($opt_src, $opt_dst, \@msgs);
exit $EXIT_SUCCESS;
##################################################
##
## Work horse
##
sub make_mmdf ($$$) {
my ($src, $dst, $msgs) = @_;
my $msg;
my @msg_paths;
@msg_paths = get_impath($src, @{$msgs});
if ($dst eq "stdout") {
binmode(stdout);
} else {
if (open(MMDF,">>$dst")) {
binmode(MMDF);
select MMDF; # xxx
} else {
im_die("cannot open $dst\n");
}
}
foreach (@msg_paths){
$msg = $_;
&open_msg($msg);
}
close(MMDF) if ($dst ne "stdout");
print stderr "done\n" unless $opt_noharm;
}
sub open_msg ($) {
my $msg = $_;
my $mmdf_delimiter="\001\001\001\001";
if (open(MSG, "<$msg")) {
binmode(MSG);
print "$mmdf_delimiter\n";
print while(<MSG>);
print "$mmdf_delimiter\n";
close(MSG);
} else {
im_die("cannot open $msg\n");
}
}
### Local Variables:
### mode: perl
### End:
|