+ my ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
+
+ unless (defined $x38) {
+ # compatibility with old links (or short Message-IDs :)
+ $mid = mid_clean($mid);
+ utf8::encode($mid);
+ $mid = sha1_hex($mid);
+ ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
+ }
+ "$x2/$x38";
+}
+
+# Only for v1 code paths:
+sub mid_mime ($) { mids($_[0]->header_obj)->[0] }
+
+sub mids ($) {
+ my ($hdr) = @_;
+ my @mids;
+ my @v = $hdr->header_raw('Message-Id');
+ foreach my $v (@v) {
+ my @cur = ($v =~ /<([^>]+)>/sg);
+ if (@cur) {
+ push(@mids, @cur);
+ } else {
+ push(@mids, $v);
+ }
+ }
+ uniq_mids(\@mids);
+}
+
+# last References should be IRT, but some mail clients do things
+# out of order, so trust IRT over References iff IRT exists
+sub references ($) {
+ my ($hdr) = @_;
+ my @mids;
+ foreach my $f (qw(References In-Reply-To)) {
+ my @v = $hdr->header_raw($f);
+ foreach my $v (@v) {
+ push(@mids, ($v =~ /<([^>]+)>/sg));
+ }
+ }
+ uniq_mids(\@mids);