user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] www: show To/Cc destinations in conversation view
@ 2016-06-25  9:44 Eric Wong
  2016-06-25  9:44 ` [PATCH 1/2] address: beef up the module with name list extaction Eric Wong
  2016-06-25  9:44 ` [PATCH 2/2] view: show To/Cc destinations in conversation view Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2016-06-25  9:44 UTC (permalink / raw)
  To: meta

And improve our name/address extraction to do it.

Eric Wong (2):
      address: beef up the module with name list extaction
      view: show To/Cc destinations in conversation view

 MANIFEST                   |  1 +
 lib/PublicInbox/Address.pm | 13 ++++++++++++-
 lib/PublicInbox/View.pm    | 18 +++++++++++++++---
 t/address.t                | 21 +++++++++++++++++++++
 4 files changed, 49 insertions(+), 4 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] address: beef up the module with name list extaction
  2016-06-25  9:44 [PATCH 0/2] www: show To/Cc destinations in conversation view Eric Wong
@ 2016-06-25  9:44 ` Eric Wong
  2016-06-25  9:44 ` [PATCH 2/2] view: show To/Cc destinations in conversation view Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2016-06-25  9:44 UTC (permalink / raw)
  To: meta

We may remove from_name in the future.

...And disallow quotes in email addresses.
Technically I believe they're allowed, but they're definitely
uncommon and unlikely to show up in legitimate mail.
---
 MANIFEST                   |  1 +
 lib/PublicInbox/Address.pm | 13 ++++++++++++-
 t/address.t                | 21 +++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 t/address.t

diff --git a/MANIFEST b/MANIFEST
index 834cb5d..2156caf 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -99,6 +99,7 @@ scripts/import_slrnspool
 scripts/report-spam
 scripts/slrnspool2maildir
 scripts/ssoma-replay
+t/address.t
 t/cgi.t
 t/check-www-inbox.perl
 t/common.perl
diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm
index 772aded..abba43d 100644
--- a/lib/PublicInbox/Address.pm
+++ b/lib/PublicInbox/Address.pm
@@ -7,7 +7,18 @@ use warnings;
 # very loose regexes, here.  We don't need RFC-compliance,
 # just enough to make thing sanely displayable and pass to git
 
-sub emails { ($_[0] =~ /([^<\s,]+\@[^>\s,]+)/g) }
+sub emails { ($_[0] =~ /([\w\.\+=\-]+\@[\w\.\-]+)>?\s*(?:,\s*|\z)/g) }
+
+sub names {
+	map {
+		tr/\r\n\t/ /;
+		s/\s*<([^<]+)\z//;
+		my $e = $1;
+		s/\A['"\s]*//;
+		s/['"\s]*\z//;
+		$_ =~ /\S/ ? $_ : $e;
+	} split(/\@+[\w\.\-]+>?\s*(?:,\s*|\z)/, $_[0]);
+}
 
 sub from_name {
 	my ($val) = @_;
diff --git a/t/address.t b/t/address.t
new file mode 100644
index 0000000..c488a8e
--- /dev/null
+++ b/t/address.t
@@ -0,0 +1,21 @@
+# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use warnings;
+use Test::More;
+use_ok 'PublicInbox::Address';
+
+is_deeply([qw(e@example.com e@example.org)],
+	[PublicInbox::Address::emails('User <e@example.com>, e@example.org')],
+	'address extraction works as expected');
+
+is_deeply([PublicInbox::Address::emails('"ex@example.com" <ex@example.com>')],
+	[qw(ex@example.com)]);
+
+my @names = PublicInbox::Address::names(
+	'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>');
+is_deeply(['User', 'e', 'John A. Doe', 'x'], \@names,
+	'name extraction works as expected');
+
+
+done_testing;
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] view: show To/Cc destinations in conversation view
  2016-06-25  9:44 [PATCH 0/2] www: show To/Cc destinations in conversation view Eric Wong
  2016-06-25  9:44 ` [PATCH 1/2] address: beef up the module with name list extaction Eric Wong
@ 2016-06-25  9:44 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2016-06-25  9:44 UTC (permalink / raw)
  To: meta

It is important to show the decentralized nature of
communication in our web views.
---
 lib/PublicInbox/View.pm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 9fa2a9b..d906276 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -83,6 +83,12 @@ sub in_reply_to {
 	undef;
 }
 
+sub _hdr_names ($$) {
+	my ($hdr, $field) = @_;
+	my $val = $hdr->header($field) or return '';
+	ascii_html(join(', ', PublicInbox::Address::names($val)));
+}
+
 # this is already inside a <pre>
 sub index_entry {
 	my ($mime, $level, $state) = @_;
@@ -98,7 +104,6 @@ sub index_entry {
 	$seen->{$id} = "#$id"; # save the anchor for children, later
 
 	my $mid = PublicInbox::Hval->new_msgid($mid_raw);
-	my $from = PublicInbox::Address::from_name($hdr->header('From'));
 
 	my $root_anchor = $state->{root_anchor} || '';
 	my $path = $root_anchor ? '../../' : '';
@@ -106,7 +111,6 @@ sub index_entry {
 	my $irt = in_reply_to($hdr);
 	my $parent_anchor = $seen->{anchor_for($irt)} if defined $irt;
 
-	$from = ascii_html($from);
 	$subj = ascii_html($subj);
 	$subj = "<a\nhref=\"${path}$href/\">$subj</a>";
 	$subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id;
@@ -116,7 +120,15 @@ sub index_entry {
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	my $txt = "${path}$href/raw";
 	my $fh = $state->{fh};
-	$fh->write($rv .= "- $from @ $ts UTC (<a\nhref=\"$txt\">raw</a>)\n\n");
+	my $from = _hdr_names($hdr, 'From');
+	$rv .= "- $from @ $ts UTC (<a\nhref=\"$txt\">raw</a>)\n";
+	my @tocc;
+	foreach my $f (qw(To Cc)) {
+		my $dst = _hdr_names($hdr, $f);
+		push @tocc, "$f: $dst" if $dst ne '';
+	}
+	$rv .= '  '.join('; +', @tocc) . "\n" if @tocc;
+	$fh->write($rv .= "\n");
 
 	my $mhref = "${path}$href/";
 
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-25  9:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-25  9:44 [PATCH 0/2] www: show To/Cc destinations in conversation view Eric Wong
2016-06-25  9:44 ` [PATCH 1/2] address: beef up the module with name list extaction Eric Wong
2016-06-25  9:44 ` [PATCH 2/2] view: show To/Cc destinations in conversation view Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).