-# Only called by PSGI interface, not NNTP
-sub from_mitem {
- my ($mitem, $srch) = @_;
- return $srch->retry_reopen(\&from_mitem, $mitem) if $srch;
- my $self = bless {}, __PACKAGE__;
- psgi_cull(load_expand($self, $mitem->get_document));
-}
+# for Import and v1 non-SQLite WWW code paths
+sub populate {
+ my ($self, $hdr, $sync) = @_;
+ for my $f (qw(From To Cc Subject)) {
+ my @all = $hdr->header($f);
+ my $val = join(', ', @all);
+ $val =~ tr/\r//d;
+ # MIME decoding can create NULs, replace them with spaces
+ # to protect git and NNTP clients
+ $val =~ tr/\0\t\n/ /;
+
+ # rare: in case headers have wide chars (not RFC2047-encoded)
+ utf8::decode($val);
+
+ # lower-case fields for read-only stuff
+ $self->{lc($f)} = $val;
+
+ # Capitalized From/Subject for git-fast-import
+ next if $f eq 'To' || $f eq 'Cc';
+ if (scalar(@all) > 1) {
+ $val = $all[0];
+ $val =~ tr/\r//d;
+ $val =~ tr/\0\t\n/ /;
+ }
+ $self->{$f} = $val if $val ne '';
+ }
+ $sync //= {};
+ $self->{-ds} = [ my @ds = msg_datestamp($hdr, $sync->{autime}) ];
+ $self->{-ts} = [ my @ts = msg_timestamp($hdr, $sync->{cotime}) ];
+ $self->{ds} //= $ds[0]; # no zone
+ $self->{ts} //= $ts[0];