summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera2008-11-12 01:06:21 +0000
committerAlvaro Herrera2008-11-12 01:06:21 +0000
commite4e1564213d3005e7a2b078a33a3af599caea04a (patch)
treedff816262c0d3d73eb95712eb5f6ee06a3d0bb1c
parent03eb8672c6cede5d73d11d1bc2980312481e861a (diff)
Add script to convert Message-Id headers into archives.pg.org/message-id/-style
links, courtesy of Bruce Momjian. Call it in the appropriate place of mk-mhonarc so that our archives are updated with it. git-svn-id: file:///Users/dpage/pgweb/svn-repo/trunk@2276 8f5c7a92-453e-0410-a47f-ad33c8a6b003
-rwxr-xr-xarchives/bin/mk-mhonarc1
-rwxr-xr-xarchives/bin/msgid2link.pl60
2 files changed, 61 insertions, 0 deletions
diff --git a/archives/bin/mk-mhonarc b/archives/bin/mk-mhonarc
index cdc77d70..9f102517 100755
--- a/archives/bin/mk-mhonarc
+++ b/archives/bin/mk-mhonarc
@@ -96,6 +96,7 @@ for list in `ls $MAJORDOMO_FILES`; do
-definevar YEAR=$year \
-definevar MONTH=$month \
> $temp 2>&1
+ $ARCHIVES_BIN/msgid2link.pl $ydashm >> $temp 2>&1
$ARCHIVES_BIN/createmsgid.pl -i $ydashm -o $ARCHIVES_ROOT/msgid \
>> $temp 2>&1
if [ -s $temp ]; then
diff --git a/archives/bin/msgid2link.pl b/archives/bin/msgid2link.pl
new file mode 100755
index 00000000..5e8795f5
--- /dev/null
+++ b/archives/bin/msgid2link.pl
@@ -0,0 +1,60 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+sub sysdie { die "$0: @_: $!\n" }
+
+###
+
+use File::Temp 'tempfile';
+use File::stat;
+
+# main
+
+die "Usage: $0 directory\n" if (@ARGV != 1);
+
+my $DIR = $ARGV[0];
+
+die "$DIR is not a directory\n" if (! -d $DIR);
+chdir $DIR or die "Cannot change directory to $DIR\n";
+
+for my $in_filename (glob("*.php"))
+{
+ next if (! -f $in_filename);
+
+ my $changes = 0;
+
+ open(my $IN, '<', $in_filename) or sysdie "Cannot open $in_filename";
+
+ (my $OUT, my $out_filename) = tempfile(UNLINK => 1, DIR => '.');
+ while (<$IN>)
+ {
+ if (!$changes && m/>Message-id(<.*>)?:/ && !m/<a href=/)
+ {
+ s/\(dot\)/./g;
+ s/\(at\)/@/g;
+ m/^(.*&lt;)([^&]*)(&gt;.*)$/;
+ print $OUT qq{$1<a href="http://archives.postgresql.org/message-id/$2">$2</a>$3};
+ $changes = 1;
+ }
+ else
+ {
+ print $OUT $_;
+ }
+ }
+ close $IN;
+ close $OUT;
+
+ if ($changes)
+ {
+ my $stat_in_file = stat($in_filename);
+ rename $out_filename, $in_filename or
+ sysdie "Cannot rename $out_filename to $in_filename";
+ # restore file permissions
+ chmod $stat_in_file->mode & 07777, $in_filename;
+ }
+ else
+ {
+ unlink $out_filename;
+ }
+}