about summary refs log tree commit homepage
path: root/lib/PublicInbox/Hval.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-10-04 22:54:23 +0000
committerEric Wong <e@80x24.org>2017-10-04 23:35:28 +0000
commitec24b4af88d7922e4bf9846e76b9455fb6a5bda4 (patch)
tree435c91ff81c59448db3fd4ee3c919985ab9d521e /lib/PublicInbox/Hval.pm
parent38c481a5438593cff686709493a70b8a6b3033d1 (diff)
downloadpublic-inbox-ec24b4af88d7922e4bf9846e76b9455fb6a5bda4.tar.gz
This is hopefully more sensical than "raw" files from
resulting downloads.
Diffstat (limited to 'lib/PublicInbox/Hval.pm')
-rw-r--r--lib/PublicInbox/Hval.pm12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 8d36fc2b..00a923ea 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -9,7 +9,7 @@ use warnings;
 use Encode qw(find_encoding);
 use PublicInbox::MID qw/mid_clean mid_escape/;
 use base qw/Exporter/;
-our @EXPORT_OK = qw/ascii_html obfuscate_addrs/;
+our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename/;
 
 # for user-generated content (UGC) which may have excessively long lines
 # and screw up rendering on some browsers.  This is the only CSS style
@@ -106,4 +106,14 @@ sub obfuscate_addrs ($$) {
                 /sge;
 }
 
+# like format_sanitized_subject in git.git pretty.c with '%f' format string
+sub to_filename ($) {
+        my ($s, undef) = split(/\n/, $_[0]);
+        $s =~ s/[^A-Za-z0-9_\.]+/-/g;
+        $s =~ tr/././s;
+        $s =~ s/[\.\-]+\z//;
+        $s =~ s/\A[\.\-]+//;
+        $s
+}
+
 1;