Table of Contents

概要

  • ファイルとして保存された Quoted Printable をデコードする。
  • デコードされたファイルの名前は元のファイル名に「.html」を付けたものになる。
  • 既存ファイルは問い合わせなしに上書きされる。
  • 対象のファイルを選択し、コンテキストメニューの「送る」(SendTo) からスクリプトを呼び出す。
  • スクリプトへのショートカットのリンク先には「%1」を付けてはいけない。
    C:\Perl\bin\perl.exe "D:\myscripts\decodeQuotedPrintable.pl"

ソース

  • decodeQuotedPrintable.zip
    # quoted-printable のデコード
    
    use strict;
    use warnings;
    use utf8;
    use Encode;
    use MIME::QuotedPrint;
    use Term::ReadKey;
    
    my $charset = 'CP932';
    
    binmode( STDIN,  ":encoding($charset)" );
    binmode( STDOUT, ":encoding($charset)" );
    binmode( STDERR, ":encoding($charset)" );
    
    @ARGV = map{ decode( $charset, $_ ); } @ARGV;
    
    foreach my $fileNameIn ( @ARGV ){
    	warn( "$fileNameIn\n" );
    	my $fileNameOut = $fileNameIn . '.html';
    
    	open( my $fin, "<:utf8", encode( $charset, $fileNameIn ) ) or die( "$fileNameIn: $!\n" );
    	my @lines = <$fin>;
    	close( $fin );
    	my $body = join( '', @lines );
    
    	$body = decode_qp( $body );
    
    	open( my $fout, ">:utf8", encode( $charset, $fileNameOut ) ) or die( "$fileNameOut: $!\n" );
    	print $fout $body;
    	close( $fout );
    }
    
    warn( "Hit Enter.\n" );
    ReadKey(0);
    
    # EOF

リンク