]> Sergey Matveev's repositories - public-inbox.git/commitdiff
eml: each_part: single part $idx is 1
authorEric Wong <e@yhbt.net>
Wed, 10 Jun 2020 07:04:10 +0000 (07:04 +0000)
committerEric Wong <e@yhbt.net>
Sat, 13 Jun 2020 07:55:45 +0000 (07:55 +0000)
Instead of counts starting at 0, we start the single-part
message at 1 like we do with subparts of a multipart message.
This will make it easier to map offsets for "BODY[$SECTION]"
when using IMAP FETCH, since $SECTION must contain non-zero
numbers according to RFC 3501.

This doesn't make any difference for WWW URLs, since single part
messages cannot have downloadable attachments.

lib/PublicInbox/Eml.pm
lib/PublicInbox/MsgIter.pm
t/eml.t

index d2bd391554566d2e7939dfea36141e8660e013f5..ec682b919eab0d796d6d49089f94ed594a00f2f8 100644 (file)
@@ -237,7 +237,7 @@ sub mp_descend ($$) {
 sub each_part {
        my ($self, $cb, $arg, $once, $all) = @_;
        my $p = mp_descend($self, $once // 0) or
-                                       return $cb->([$self, 0, 0], $arg);
+                                       return $cb->([$self, 0, 1], $arg);
 
        $cb->([$self, 0, 0], $arg) if ($all || $self->{-call_cb}); # rare
 
index 5ec2a4d9c7f1d3e06f76d4c4abb639ddacb00ac4..bb1dfeadc291857f993b68dd297da46de3a9728c 100644 (file)
@@ -34,7 +34,7 @@ sub em_each_part ($$;$$) {
                        }
                }
        } else {
-               $cb->([$mime, 0, 0], $cb_arg);
+               $cb->([$mime, 0, 1], $cb_arg);
        }
 }
 
diff --git a/t/eml.t b/t/eml.t
index a2479f6f068187071d35cc441679eb012b06eb70..8d131b1418eb7c510b55297ef2cbeed4632fd038 100644 (file)
--- a/t/eml.t
+++ b/t/eml.t
@@ -169,7 +169,7 @@ EOF
        is(scalar(@tmp), 1, 'got one part even w/o boundary');
        is($tmp[0]->[0]->[0]->body, "hello world\n", 'body preserved');
        is($tmp[0]->[0]->[1], 0, '$depth is zero');
-       is($tmp[0]->[0]->[2], 0, '@idx is zero');
+       is($tmp[0]->[0]->[2], 1, '@idx is one');
 }
 
 # I guess the following only worked in PI::M because of a happy accident