]> mj.ucw.cz Git - pciids.git/blobdiff - scripts/mailbot
Always jump to list
[pciids.git] / scripts / mailbot
index 9b6bcfc8eae5a76ac0a0560fda49c27c20cadf91..87797baecd666bc87167142cfd62eb32ec8ee8e5 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # Mail robot for processing of PCI ID submissions
 # (c) 2001--2002 Martin Mares <mj@ucw.cz>
-# 2008 Michal Vaner <vorner@ucw.cz>
+# (c) 2008 Michal Vaner <vorner@ucw.cz>
 
 use Mail::Header;
 use Getopt::Long;
@@ -43,12 +43,13 @@ sub getAuthor( $ ) {
        my( $mail ) = @_;
        $hasAuth->execute( $mail );
        if( my( $id ) = $hasAuth->fetchrow_array ) {
+               tlog( "mailbot: Active user ($mail) id: $id" );
                return $id;
        } else {
                tlog( "mailbot: Creating user $mail" );
                $addAuth->execute( $mail );
-               my $nid = $dbh->last_insert_id( undef, undef, undef, undef );
-               tlog( "mailbot: User ($mail) id: $nid" );
+               my $nid = $tables->dbh->last_insert_id( undef, undef, undef, undef );
+               tlog( "mailbot: Active user ($mail) id: $nid" );
                return $nid;
        }
 }
@@ -56,21 +57,30 @@ sub getAuthor( $ ) {
 sub submitItem( $$$$$ ) {
        my( $id, $name, $description, $text, $author ) = @_;
        my $created;
-       $id =~ s/(.{8})(.*)/$1\\$2/;
-       $id =~ s/(.{4})(.*)/$1\\$2/;
+       $id =~ s/(.{8})(.+)/$1\/$2/;
+       $id =~ s/(.{4})(.+)/$1\/$2/;
        $id = "PC/$id";
+       if( length $id > 12 ) {
+               my( $vendor ) = ( $id =~ /^PC\/....\/....\/(....)/ );
+               $vendor = "PC/$vendor";
+               $hasItem->execute( $vendor );
+               error( "Missing subsystem vendor" ) unless( $hasItem->fetchrow_array );
+       }
        $hasItem->execute( $id );
        unless( $hasItem->fetchrow_array ) {
                tlog( "mailbot: Item created (empty) $id" );
                my $parent = $id;
-               $parent =~ s/\/[^\/]*//;
+               $parent =~ s/\/[^\/]*$//;
                $addItem->execute( $id, $parent );
                $created = 1;
        }
        $addComment->execute( $author, $id, $text, $name, $description );
        my $hid = $tables->last();
-       tlog( "mailbot: Comment created $hid $id ".logEscape( $name )." ".logEscape( $description )." ".logEscape( $text ) );
+       tlog( "mailbot: History created $hid $id ".logEscape( $name )." ".logEscape( $description )." ".logEscape( $text ) );
        notify( $tables, $id, $hid, $created ? 2 : 1, $created ? 0 : 1 );
+       if( !$tables->notifExists( $author, $id ) ) {
+               $tables->submitNotification( $author, $id, { 'recursive' => 0, 'notification' => 0, 'way' => 0 } );
+       }
 }
 
 if (!$patch) {
@@ -104,9 +114,9 @@ if (!$patch) {
        $author = $reply_plain;
 }
 
-$tprefix = "tmp/mbot-$$";
-$home = "../..";
-mkdir("tmp", 0777);
+$home = "$ENV{HOME}/";
+$tprefix = "${home}tmp/mbot-$$";
+mkdir("${home}tmp", 0777);
 mkdir($tprefix, 0777) || error("Cannot create tmpdir");
 chdir($tprefix) || error("Cannot chdir to tmpdir");
 
@@ -193,11 +203,11 @@ sub process
                } else {
                        print LOG "Patch succeeded.\n";
                        print LOG "Parsing patched file.\n";
-                       print LOG `$home/tools/ids_to_dbdump <$orig 2>&1 >orig.db.unsorted`;
+                       print LOG `$home/bin/ids_to_dbdump <$orig 2>&1 >orig.db.unsorted`;
                        $? && error("Error parsing original ID database");
                        print LOG `sort +1 <orig.db.unsorted >orig.db`;
                        $? && error("Error sorting original ID database");
-                       print LOG `$home/tools/ids_to_dbdump <pci.ids 2>&1 >new.db.unsorted`;
+                       print LOG `$home/bin/ids_to_dbdump <pci.ids 2>&1 >new.db.unsorted`;
                        $? && error("Error parsing the patched pci.ids file");
                        print LOG `sort +1 <new.db.unsorted >new.db`;
                        $? && error("Error sorting the patched pci.ids file");
@@ -223,11 +233,11 @@ sub process
                                print LOG "$id\t$name\t$cmt\n";
                                submitItem( $id, $name, $cmt, $subject, $authorId ) if $live;
                        }
-                       $dbh->commit();
+                       $tables->dbh->commit();
                        close DIFF;
                        $time = localtime;
-                       `echo >>$home/log/mailbot.log "## $time $reply"`;
-                       `cat result >>$home/log/mailbot.log`;
+                       `echo >>$home/mailbot.log "## $time $reply"`;
+                       `cat result >>$home/mailbot.log`;
                        print LOG "Done.\n";
                        mail_reply("OK");
                        cleanup();
@@ -239,7 +249,7 @@ sub process
 sub mail_reply
 {
        my $reason = shift @_;
-       my $sendmail_opts = "-fmj+iderr\@ucw.cz '$reply_plain' mj+idecho\@ucw.cz";
+       my $sendmail_opts = "-fvorner+iderr\@ucw.cz '$reply_plain' vorner+idecho\@ucw.cz";
        if ($debug || $reply eq "") {
                print "$reason\n";
                return;
@@ -251,7 +261,7 @@ sub mail_reply
                print LOG "Unable to ask mailer for replying!!!\n";
                exit 1;
        }
-       print MAIL "From: The PCI ID Robot <mj+iderr\@ucw.cz>\n";
+       print MAIL "From: The PCI ID Robot <vorner+iderr\@ucw.cz>\n";
        print MAIL "To: $reply\n";
        print MAIL "Subject: IDbot: $reason\n";
        print MAIL "In-Reply-To: $msgid\n" if $msgid ne "";