]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: fix encoding issues from weird "raw" emails
authorEric Wong <e@80x24.org>
Tue, 20 Jun 2017 22:06:54 +0000 (22:06 +0000)
committerEric Wong <e@80x24.org>
Tue, 20 Jun 2017 22:06:54 +0000 (22:06 +0000)
This seems to allow weirdly-encoded "raw" emails in
  blade.nagaokaut.ac.jp/ruby/ruby-core/*
to be handled without difficulties.

lib/PublicInbox/Import.pm

index 65da4ddf466ad4a7309655e6436a4abb58abf742..31dc769583bd32777e2d25e16de743fd507a65c0 100644 (file)
@@ -54,6 +54,8 @@ sub gfi_start {
        $self->{lockfh} = $lockfh;
        $self->{pid} = $pid;
        $self->{nchg} = 0;
        $self->{lockfh} = $lockfh;
        $self->{pid} = $pid;
        $self->{nchg} = 0;
+       binmode $out_w, ':raw' or die "binmode :raw failed: $!";
+       binmode $in_r, ':raw' or die "binmode :raw failed: $!";
        ($in_r, $out_w);
 }
 
        ($in_r, $out_w);
 }
 
@@ -187,13 +189,14 @@ sub add {
                print $w "reset $ref\n" or wfail;
        }
 
                print $w "reset $ref\n" or wfail;
        }
 
+       utf8::encode($email);
+       utf8::encode($name);
+       utf8::encode($subject);
        # quiet down wide character warnings:
        # quiet down wide character warnings:
-       binmode $w, ':utf8' or die "binmode :utf8 failed: $!";
        print $w "commit $ref\nmark :$commit\n",
                "author $name <$email> $date\n",
                "committer $self->{ident} ", now2822(), "\n" or wfail;
        print $w "commit $ref\nmark :$commit\n",
                "author $name <$email> $date\n",
                "committer $self->{ident} ", now2822(), "\n" or wfail;
-       binmode $w, ':raw' or die "binmode :raw failed: $!";
-       print $w "data ", (bytes::length($subject) + 1), "\n",
+       print $w "data ", (length($subject) + 1), "\n",
                $subject, "\n\n" or wfail;
        if ($tip ne '') {
                print $w 'from ', ($parent ? $parent : $tip), "\n" or wfail;
                $subject, "\n\n" or wfail;
        if ($tip ne '') {
                print $w 'from ', ($parent ? $parent : $tip), "\n" or wfail;