use POSIX qw(strftime);
use Date::Parse qw(strptime);
use constant DATEFMT => '%Y-%m-%dT%H:%M:%SZ';
+use PublicInbox::View;
# main function
# FIXME: takes too many args, cleanup
my ($pi_config, $listname, $cgi) = @_;
my %rv;
if ($pi_config && defined $listname && length $listname) {
- foreach my $key (qw(description address url atomurl midurl)) {
+ foreach my $key (qw(description address)) {
$rv{$key} = $pi_config->get($listname, $key);
}
}
my $url_base = $cgi_url;
$url_base =~ s!/?(?:index|all)\.atom\.xml\z!!;
$rv{url} ||= "$url_base/";
- $rv{midurl} ||= "$url_base/mid/%s.html";
+ $rv{midurl} = "$url_base/mid/";
+ $rv{fullurl} = "$url_base/full/";
$rv{atomurl} = $cgi_url;
}
return 0;
}
- my $content = msg_content($mime);
+ my $midurl = $feed_opts->{midurl} || 'http://example.com/mid/';
+ my $fullurl = $feed_opts->{fullurl} || 'http://example.com/full/';
+
+ my $content = PublicInbox::View->as_feed_entry($mime, $fullurl);
defined($content) or return 0;
- my $midurl = $feed_opts->{midurl} || "http://example.com/mid/%s.html";
my $mid = utf8_header($mime, "Message-ID") or return 0;
$mid =~ s/\A<//;
$mid =~ s/>\z//;
my $email = $from[0]->address;
defined $email or $email = "";
- my $url = sprintf($midurl, uri_escape($mid));
+ my $url = $midurl . uri_escape($mid);
my $date = utf8_header($mime, "Date");
$date or return 0;
$date = feed_date($date) or return 0;
1;
}
-# returns a plain-text message body without quoted text
-# returns undef if there was nothing
-sub msg_content {
- my ($mime) = @_;
- my $rv;
-
- # scan through all parts, looking for displayable text
- $mime->walk_parts(sub {
- return if $rv;
- my ($part) = @_;
- return if $part->subparts; # walk_parts already recurses
- my $ct = $part->content_type || 'text/plain';
- return if $ct !~ m!\btext/[a-z0-9\+\._-]+\b!i;
- my @body;
- my $killed_wrote; # omit "So-and-so wrote:" line
-
- # no quoted text in Atom feed summary
- # $part->body should already be decoded for us (no QP)
-
- my $state = 0; # 0: beginning, 1: keep, 2: quoted
- foreach my $l (split(/\r?\n/, $part->body)) {
- if ($state == 0) {
- # drop leading blank lines
- next if $l =~ /\A\s*\z/;
-
- $state = ($l =~ /\A>/) ? 2 : 1; # fall-through
- }
- if ($state == 2) { # quoted text, drop it
- if ($l !~ /\A>/) {
- push @body, "<quoted text snipped>";
- if ($l =~ /\S/) {
- push @body, $l;
- }
- $state = 1;
- }
- }
- if ($state == 1) { # stuff we may keep
- if ($l =~ /\A>/) {
- # drop "So-and-so wrote:" line
- if (@body && !$killed_wrote &&
- $body[-1] =~ /:\z/) {
- $killed_wrote = 1;
- pop @body;
- }
- $state = 2;
- } else {
- push @body, $l;
- }
- }
- }
- $rv = "<pre>" .
- join("\n", map { escapeHTML($_) } @body) .
- "</pre>";
- });
-
- $rv;
-}
-
1;
Subject: zzz #$i
Date: Thu, 01 Jan 1970 00:00:00 +0000
-> drop me
+> This is a long multi line quote so it should not be allowed to
+> show up in its entirty in the Atom feed. drop me
msg $i
-> drop me again
+> inline me here, short quote
keep me
EOF
is($p->format, "Atom", "parsed atom feed");
is(scalar $p->entries, 3, "parsed three entries");
}
- unlike($feed, qr/drop me/, "quoted text dropped");
+ unlike($feed, qr/drop me/, "long quoted text dropped");
+ like($feed, qr/inline me here/, "short quoted text kept");
like($feed, qr/keep me/, "unquoted text saved");
}