Files
oddmuse/scripts/mimedecode.pl

49 lines
1.5 KiB
Perl
Raw Permalink Normal View History

2007-11-07 20:16:15 +00:00
#! /usr/bin/perl
# Copyright (C) 2007 Alex Schroeder <alex@emacswiki.org>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
=head1 mimedecode.pl
This script opens all files given as parameters on the command line
and destructively converts them to binary files.
Something similar could be achieved using command line tools.
Unfortunately, they are not always available. If Perl's MIME library
is available instead, you can use this script.
2007-11-07 20:22:04 +00:00
This particular version preserves the file's mtime in order to play
nice with raw.pl which relies on mtime.
2007-11-07 20:16:15 +00:00
=cut
use MIME::Base64;
local $/;
while (<>) {
close ARGV;
if (substr($_,0,6) eq '#FILE ') {
2007-11-07 20:43:18 +00:00
print "decoding $ARGV\n";
2007-11-07 20:22:04 +00:00
my $ts = (stat($ARGV))[9];
2007-11-07 20:16:15 +00:00
s/^.*\n//;
my $bytes = decode_base64($_);
open(F, "> $ARGV");
print F $bytes;
close F;
2007-11-07 20:22:04 +00:00
# restore mtime to collaborate with raw.pl
2007-11-07 20:29:25 +00:00
utime $ts, $ts, $ARGV;
2007-11-07 20:16:15 +00:00
}
}