wiki.pl: Port some fixes from upstream
[Orgmuse.git] / mimedecode.pl
blob0b73c0315dc1be1b08900fc8b4f5df6973f83854
1 #! /usr/bin/perl
3 # Copyright (C) 2007 Alex Schroeder <alex@emacswiki.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 =head1 mimedecode.pl
20 This script opens all files given as parameters on the command line
21 and destructively converts them to binary files.
23 Something similar could be achieved using command line tools.
24 Unfortunately, they are not always available. If Perl's MIME library
25 is available instead, you can use this script.
27 This particular version preserves the file's mtime in order to play
28 nice with raw.pl which relies on mtime.
30 =cut
32 use MIME::Base64;
34 local $/;
35 while (<>) {
36 close ARGV;
37 if (substr($_,0,6) eq '#FILE ') {
38 print "decoding $ARGV\n";
39 my $ts = (stat($ARGV))[9];
40 s/^.*\n//;
41 my $bytes = decode_base64($_);
42 open(F, "> $ARGV");
43 print F $bytes;
44 close F;
45 # restore mtime to collaborate with raw.pl
46 utime $ts, $ts, $ARGV;