I don't trust the MIME type to not munge my email messages in horrible
ways upon occasion.  Therefore  allow for passing in the raw message
value instead of trusting the mime object to preserve it.

Signed-off-by: "Eric W. Biederman" <[email protected]>
---

The context here is because the only copy of messages that I save
I save in public-inbox I don't want to have to worry about losing
information.  So I just pass the raw email_str to add.

I expect if I were to export these lists public I would want to do
some more but for now I am just putting them in public-inbox
so that I can read and archive the lists locally.

 lib/PublicInbox/Import.pm     | 10 +++++-----
 lib/PublicInbox/V2Writable.pm |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 81a38fb6987d..0a63784414f2 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -359,7 +359,7 @@ sub clean_tree_v2 ($$$) {
 # returns undef on duplicate
 # returns the :MARK of the most recent commit
 sub add {
-       my ($self, $mime, $check_cb) = @_; # mime = Email::MIME
+       my ($self, $mime, $check_cb, $email_str) = @_; # mime = Email::MIME
 
        my ($name, $email) = extract_author_info($mime);
        my $hdr = $mime->header_obj;
@@ -396,16 +396,16 @@ sub add {
        }
 
        my $blob = $self->{mark}++;
-       my $str = $mime->as_string;
-       my $n = length($str);
+       $email_str ||= $mime->as_string;
+       my $n = length($email_str);
        $self->{bytes_added} += $n;
        print $w "blob\nmark :$blob\ndata ", $n, "\n" or wfail;
-       print $w $str, "\n" or wfail;
+       print $w $email_str, "\n" or wfail;
 
        # v2: we need this for Xapian
        if ($self->{want_object_info}) {
                my $oid = $self->get_mark(":$blob");
-               $self->{last_object} = [ $oid, $n, \$str ];
+               $self->{last_object} = [ $oid, $n, \$email_str ];
        }
        my $ref = $self->{ref};
        my $commit = $self->{mark}++;
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index afcac4d2db86..713d3817cc59 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -109,14 +109,14 @@ sub init_inbox {
 # returns undef on duplicate or spam
 # mimics Import::add and wraps it for v2
 sub add {
-       my ($self, $mime, $check_cb) = @_;
+       my ($self, $mime, $check_cb, $email_str) = @_;
        $self->{-inbox}->with_umask(sub {
-               _add($self, $mime, $check_cb)
+               _add($self, $mime, $check_cb, $email_str)
        });
 }
 
 sub _add {
-       my ($self, $mime, $check_cb) = @_;
+       my ($self, $mime, $check_cb, $email_str) = @_;
 
        # spam check:
        if ($check_cb) {
@@ -135,7 +135,7 @@ sub _add {
        defined $num or return; # duplicate
        defined $mid0 or die "BUG: $mid0 undefined\n";
        my $im = $self->importer;
-       my $cmt = $im->add($mime);
+       my $cmt = $im->add($mime, undef, $email_str);
        $cmt = $im->get_mark($cmt);
        $self->{last_commit}->[$self->{epoch_max}] = $cmt;
 
-- 
2.17.1

--
unsubscribe: [email protected]
archive: https://public-inbox.org/meta/

Reply via email to