use warnings;
use base qw(Exporter);
our @EXPORT_OK = qw(subject_normalized);
-use PublicInbox::MID qw/mid_mime/;
+use PublicInbox::MID qw(mid_mime mids);
use PublicInbox::Address;
use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
use Time::Local qw(timegm);
-sub new {
- my ($class, $mime) = @_;
- bless { mime => $mime }, $class;
-}
-
-sub wrap {
- my ($class, $mid) = @_;
- bless { mid => $mid }, $class;
-}
-
sub get_val ($$) {
my ($doc, $col) = @_;
# sortable_unserialise is defined by PublicInbox::Search::load_xapian()
sub to_doc_data {
my ($self) = @_;
join("\n",
- $self->subject,
- $self->from,
+ $self->{subject},
+ $self->{from},
$self->references,
- $self->to,
- $self->cc,
+ $self->{to},
+ $self->{cc},
$self->{blob},
$self->{mid},
$self->{bytes} // '',
};
}
+# for Import and v1 non-SQLite WWW code paths
+sub populate {
+ my ($self, $hdr, $v2w) = @_;
+ 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/ /;
+
+ # 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 '';
+ }
+ $v2w //= {};
+ $self->{-ds} = [ my @ds = msg_datestamp($hdr, $v2w->{autime}) ];
+ $self->{-ts} = [ my @ts = msg_timestamp($hdr, $v2w->{cotime}) ];
+ $self->{ds} //= $ds[0]; # no zone
+ $self->{ts} //= $ts[0];
+
+ # for v1 users w/o SQLite
+ $self->{mid} //= eval { mids($hdr)->[0] } // '';
+}
+
sub subject ($) { __hdr($_[0], 'Subject') }
sub to ($) { __hdr($_[0], 'To') }
sub cc ($) { __hdr($_[0], 'Cc') }