1 # subclass Mail::Thread and use this to workaround a memory leak
2 # Based on the patch in: https://rt.cpan.org/Public/Bug/Display.html?id=22817
4 # Additionally, workaround for a bug where $walk->topmost returns undef:
5 # - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795913
6 # - https://rt.cpan.org/Ticket/Display.html?id=106498
8 # License differs from the rest of public-inbox (but is compatible):
9 # This library is free software; you can redistribute it and/or modify
10 # it under the same terms as Perl itself.
11 package PublicInbox::Thread;
14 use base qw(Mail::Thread);
15 # WARNING! both these Mail::Thread knobs were found by inspecting
16 # the Mail::Thread 2.55 source code, and we have some monkey patches
17 # in PublicInbox::Thread to fix memory leaks. Since Mail::Thread
18 # appears unmaintained, I suppose it's safe to depend on these
22 # we want strict threads to expose (and hopefully discourage)
23 # use of broken email clients
24 $Mail::Thread::nosubject = 1;
25 # Keep ghosts with only a single direct child,
26 # don't hide that there may be missing messages.
27 $Mail::Thread::noprune = 1;
30 if ($Mail::Thread::VERSION <= 2.55) {
31 eval q(sub _container_class { 'PublicInbox::Thread::Container' });
34 package PublicInbox::Thread::Container;
37 use base qw(Mail::Thread::Container);
38 use Scalar::Util qw(weaken);
39 sub parent { @_ == 2 ? weaken($_[0]->{parent} = $_[1]) : $_[0]->{parent} }
42 $_[0]->SUPER::topmost || PublicInbox::Thread::CPANRTBug106498->new;
46 # - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795913
47 # - https://rt.cpan.org/Ticket/Display.html?id=106498
48 package PublicInbox::Thread::CPANRTBug106498;
52 sub new { bless {}, $_[0] }