#!/usr/bin/perl

use Encode;
use MIME::EncWords qw(decode_mimewords);
use MIME::Charset qw(default);
use utf8;

use strict;

binmode STDIN, ":utf8" or die;
binmode STDOUT, ":encoding(UTF-8)" or die;

MIME::Charset::default("utf-8");

#open(my $fh, "<:encoding(UTF-8)", "PIM00010.vcf") || die;

while (<>) {
    tr /\r\n//d;
    while (/;CHARSET=[^;]+;ENCODING=QUOTED-PRINTABLE:;;.*=$/) {
	my $next = <>;
	$next =~ tr/\r\n//d;
	chop;
	$_ .= $next;
    }
    s/;CHARSET=([^;]+);ENCODING=QUOTED-PRINTABLE:(.*)$/:=?$1?Q?$2?=/;
    print decode("utf-8", decode_mimewords($_, Charset=>'utf-8')), "\n";
}
