summaryrefslogtreecommitdiff
path: root/parse-wiki
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2007-05-23 21:25:21 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2007-05-23 21:25:21 +0000
commitc0e8f01a25ed8f81daa4f6a56fee81c2053477bd (patch)
tree36f3d39b4422cd3efce56401116b4f5ac0b18fe7 /parse-wiki
Add nsa
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@270 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'parse-wiki')
-rwxr-xr-xparse-wiki111
1 files changed, 111 insertions, 0 deletions
diff --git a/parse-wiki b/parse-wiki
new file mode 100755
index 0000000..822857b
--- /dev/null
+++ b/parse-wiki
@@ -0,0 +1,111 @@
+#!/usr/bin/perl -wT
+
+use strict;
+use English;
+use MIME::Base64;
+
+
+my $HOME = '/home/commit/';
+my $MAX_LINES = 4;
+my $ENVELOPE_FROM = 'nobody@commit.noreply.org';
+my $HEADER_FROM = 'nobody@commit.noreply.org';
+my $BOT_ADDRESS = 'commit@commit.noreply.org';
+my $SENDMAIL = '/usr/sbin/sendmail';
+
+$ENV{'PATH'} = '/bin:/usr/bin';
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
+
+die ("Usage: $PROGRAM_NAME <project> <mailfile>\n") unless (scalar @ARGV == 2);
+my $project = $ARGV[0];
+
+umask 077;
+
+my $TMPDIR = "$HOME/cvs-tmp/";
+-d $TMPDIR or
+ mkdir $TMPDIR or
+ die ("Cannot mkdir $TMPDIR: $0\n");
+
+$project =~ m/^([a-zA-Z-]+(\.[a-zA-Z-]+)*)+$/;
+$project = $1;
+die ("Project is not a nice name.\n") unless defined $project;
+
+
+my $from;
+my $what;
+my $is_base64 = 0;
+
+
+open (MAIL, $ARGV[1]) || die ("Cannot open $ARGV[1]: $!\n");
+my @mail = <MAIL>;
+close(MAIL);
+my $line;
+
+my @headers;
+my $lastline = undef;
+while (defined($line = shift @mail)) {
+ my $chomped = $line;
+ chomp $chomped;
+ if ($chomped =~ m/^\s+/) {
+ $lastline .= ' '.$line;
+ } elsif ($chomped =~ m/^$/) {
+ push @headers, $lastline if defined $lastline;
+ push @headers, $line;
+ push @headers, @mail;
+ last
+ } else {
+ push @headers, $lastline if defined $lastline;
+ $lastline = $line;
+ }
+}
+
+while (defined($line = shift @headers)) {
+ if ($line =~ m/^Subject:\s+(?:\[.*?\]\s+)?(?:Trivial )?Update\s+of\s+"(.*)"\s+by\s+(.*?)\s*$/s) {
+ $what = $1;
+ $from = $2;
+ # =?utf-8?q?=5BOFTC=5D_Update_of_=22OFTC=22_by_PeterPalfrader?=
+ # =?utf-8?q?=5BOFTC=5D_Update_of_=22Staff=22_by_SethArnold?=
+ } elsif ($line =~ m/^Subject: (?:\[.*?\] )?=\?utf-8\?q\?=5BOFTC=5D_(?:Trivial_)?Update_of_=22(.*)=22_by_(.*?)\?=$/s) {
+ $what = $1;
+ $from = $2;
+ } elsif ($line =~ m/^Content-Transfer-Encoding: base64$/s) {
+ $is_base64 = 1;
+ } elsif ($line =~ m/^$/) {
+ last;
+ }
+};
+
+$from =~ s/\?=\s*=\?utf-8\?q\?//sg;
+
+die ("$PROGRAM_NAME - $project: No author found.\n") unless defined $from;
+die ("$PROGRAM_NAME - $project: No what found.\n") unless defined $what;
+
+my $body = join '', @mail;
+$body = decode_base64($body) if ($is_base64);
+
+my $message;
+my $url;
+my @lines = split(/\n/, $body);
+while (defined($line = shift @lines)) {
+ if ($line =~ m/^The following page has been changed by /) {
+ $url = shift @lines
+ } elsif ($line =~ m/^The comment on the change is:/) {
+ $message = shift @lines;
+ last;
+ };
+};
+
+my $notice = (defined $message) ?
+ "$from updated $what: $message" :
+ "$from updated $what";
+$notice .= " - $url" if defined $url;
+
+#open(MAIL, "|cat") or
+open(MAIL, "|$SENDMAIL -t -oi -f $ENVELOPE_FROM") or
+ die ("Cannot exec sendmail: $!\n");
+print MAIL "From: $HEADER_FROM\n";
+print MAIL "To: $BOT_ADDRESS\n";
+print MAIL "Subject: Announce $project\n";
+print MAIL "Precedence: junk\n";
+print MAIL "\n";
+print MAIL "[wiki] $notice\n";
+close(MAIL);