]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Hval.pm
mbox: support inline filename via Content-Disposition header
[public-inbox.git] / lib / PublicInbox / Hval.pm
index 8d36fc2ba6a38189193360e0059647688346eabf..00a923eaecba6768e4ff5153983c0080b90f8309 100644 (file)
@@ -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;