summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-11-01 16:43:22 +0000
committerDries Buytaert <dries@buytaert.net>2001-11-01 16:43:22 +0000
commit3d47ad359ded4cb947b7ada9b3418640cfb3c642 (patch)
tree1f7c0e9c3937873b0b0da239cc0a9c977f047739 /scripts
parent66a3043c492b98bb16d16b6a83f517f758382b23 (diff)
downloadbrdo-3d47ad359ded4cb947b7ada9b3418640cfb3c642.tar.gz
brdo-3d47ad359ded4cb947b7ada9b3418640cfb3c642.tar.bz2
- Added first, preliminary version of mail-to-sql to CVS.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/mail-to-sql.pl38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/mail-to-sql.pl b/scripts/mail-to-sql.pl
new file mode 100644
index 000000000..9085c9af2
--- /dev/null
+++ b/scripts/mail-to-sql.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl -w
+
+use DBI;
+
+# database settings:
+my $db_name = 'drop';
+my $db_user = 'drop';
+my $db_pass = 'drop';
+
+# read data from stdin:
+my @data = <STDIN>;
+my $data = join '', @data;
+
+my @chunks = split(/\n\n/, $data);
+
+# parse the header into an associative array:
+foreach $line (split(/\n/, $chunks[0])) {
+ if ($line =~ /(.*?):\s(.*)/) {
+ $header{lc($1)} = $2;
+ }
+ $header{data} .= "$line\n";
+}
+
+$chunks[0] = "";
+
+# debug output:
+ # foreach $key (sort keys %header) {
+ # print "$key: $header{$key}\n";
+ # }
+
+# construct the mail body:
+foreach $line (@chunks) {
+ $body .= "$line\n\n";
+}
+
+my $db = DBI->connect("DBI:mysql:$db_name", "$db_user", "$db_pass") or die "Couldn't connect recepient database: " . DBI->errstr;
+$db->do("INSERT INTO mail (subject, sender, recepient, header, body, timestamp) VALUES (". $db->quote($header{subject}) .", ". $db->quote($header{from}) .", ". $db->quote($header{to}) .", ". $db->quote($header{data}) .", ". $db->quote($body) .", ". $db->quote(time()) .")") or die "Couldn't execute query: " . $db->errstr;
+$db->disconnect();