From 78042ed9abb2bbe9783adcc485365a8672e4b36f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 19 May 2016 02:42:05 +0000 Subject: www: support downloading attachments This can be useful for lists where the convention is to attach (rather than inline) patches into the message body. --- lib/PublicInbox/WWW.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/PublicInbox/WWW.pm') diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 465dcb26..f87f4171 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -23,6 +23,7 @@ use PublicInbox::GitHTTPBackend; our $INBOX_RE = qr!\A/([\w\.\-]+)!; our $MID_RE = qr!([^/]+)!; our $END_RE = qr!(T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!; +our $ATTACH_RE = qr!(\d[\.\d]*)-([\w-]+\.[a-z0-9]+)!i; sub new { my ($class, $pi_config) = @_; @@ -73,6 +74,10 @@ sub call { } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$END_RE\z!o) { msg_page($self, $ctx, $1, $2, $3); + } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$ATTACH_RE\z!o) { + my ($idx, $fn) = ($3, $4); + invalid_inbox_mid($self, $ctx, $1, $2) || + get_attach($ctx, $idx, $fn); # in case people leave off the trailing slash: } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/(T|t|R)\z!o) { my ($inbox, $mid, $suffix) = ($1, $2, $3); @@ -442,4 +447,10 @@ sub news_www { $self->{news_www} = PublicInbox::NewsWWW->new($self->{pi_config}); } +sub get_attach { + my ($ctx, $idx, $fn) = @_; + require PublicInbox::WwwAttach; + PublicInbox::WwwAttach::get_attach($ctx, $idx, $fn); +} + 1; -- cgit v1.2.3-24-ge0c7