about summary refs log tree commit homepage
path: root/lib/PublicInbox/Hval.pm
diff options
context:
space:
mode:
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;