]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
cgi: flesh out bug display
authorIan Campbell <ijc@hellion.org.uk>
Thu, 1 Nov 2012 08:18:19 +0000 (09:18 +0100)
committerIan Campbell <ijc@hellion.org.uk>
Thu, 1 Nov 2012 08:18:19 +0000 (09:18 +0100)
Bugs/Message.pm
CGI/bug.pl
CGI/bugs.pl
config.pl
createdb.sql

index 1231dd30c353656876d43d441a491b4160cfe687..6738bb5b2475c8a10adb622aab375f974c8936f2 100644 (file)
@@ -11,17 +11,24 @@ sub lookup_id {
     my $id = shift;
 
     my $sth = $dbh->prepare(q{
-        SELECT messageid,present,subject FROM messages WHERE id = ?
+        SELECT messageid,present,inserttime,msgdate,msgfrom,msgto,msgcc,subject
+          FROM messages
+         WHERE id = ?
     });
 
     $sth->execute($id);
 
-    my ($msgid,$present,$subj) = @{$sth->fetch};
+    my ($msgid,$present,$inserted,$date,$from,$to,$cc,$subj) = @{$sth->fetch};
 
     $sth->finish;
 
     my $self = { dbh     => $dbh,
                 present => $present eq "true",
+                inserted => $inserted,
+                date    => $date,
+                from    => $from,
+                to      => $to,
+                cc      => $cc,
                 id      => $id,
                 msgid   => $msgid,
                 subject => $subj
@@ -40,7 +47,9 @@ sub lookup_msgid {
     $args{Insert} = 0 unless exists $args{Insert};
 
     my $sth = $dbh->prepare(q{
-        SELECT id,present,subject FROM messages WHERE messageid = ?
+        SELECT id,present,inserttime,msgdate,msgfrom,msgto,msgcc,subject
+          FROM messages
+         WHERE messageid = ?
     });
 
     $sth->execute($msgid);
@@ -49,9 +58,9 @@ sub lookup_msgid {
 
     $sth->finish;
 
-    my ($id,$present,$subj);
+    my ($id,$present,$inserted,$date,$from,$to,$cc,$subj);
     if ( defined $row ) {
-       ($id,$present,$subj) = @{$row};
+       ($id,$present,$inserted,$date,$from,$to,$cc,$subj) = @{$row};
     } elsif ( $args{Insert} ) {
        my $sth = $dbh->prepare(q{
            INSERT into messages (messageid) VALUES (?)
@@ -65,25 +74,55 @@ sub lookup_msgid {
 
     my $self = { dbh     => $dbh,
                 present => $present eq "true",
+                inserted => $inserted,
+                date    => $date,
+                from    => $from,
+                to      => $to,
+                cc      => $cc,
                 id      => $id,
                 msgid   => $msgid,
-                subject => $subj
+                subject => $subj,
     };
 
     bless $self, $class;
     return $self;    
 }
 
+sub getfield {
+    my $header = shift;
+    my $name = shift;
+
+    my $val = $header->get($name);
+    return undef unless $val;
+
+    chomp($val);
+    return $val;
+}
+
 sub update {
     my $self = shift;
     my $header = shift;
 
     die "NOT FRESH" unless ! $self->{present};
 
-    chomp(my $subj = $header->get('subject'));
-
-    my $sth = $self->{dbh}->prepare(q{UPDATE messages SET present="true",subject=?2 WHERE id = ?1});
-    $sth->execute($self->{id},$subj) or die "execute insert";
+    my $subj = getfield($header,'subject');
+    my $date = getfield($header,'date');
+    my $from = getfield($header,'from');
+    my $to = getfield($header,'to');
+    my $cc = getfield($header,'cc');
+
+    my $sth = $self->{dbh}->prepare(q{
+        UPDATE messages
+           SET present="true",
+               subject=?2,
+               inserttime=strftime('%s', 'now'),
+               msgdate=?3,
+               msgfrom=?4,
+               msgto=?5,
+               msgcc=?6
+         WHERE id = ?1});
+    $sth->execute($self->{id},$subj,$date,$from,$to,$cc)
+       or die "execute insert";
     $sth->finish or die "finish insert";
     
     my $irt = $header->get('in-reply-to');
index f0eeda9403c96b79f4a6b1bfb2d48d9425dbece6..5b3a01f0a6ee7b1c54ea3fa9e4dd09143a0baf78 100755 (executable)
@@ -21,7 +21,7 @@ if ( ! $bug ) {
     print header;
 
     print start_html(-title=>$c{TrackerName}.": #$bugid - Unknown Bug Number",
-                    -style  => { 'src' => '/css/style.css'});
+                    -style  => { 'src' => $c{StyleSheet}});
 
     print h1("#$bugid - Unknown Bug Number");
     print p(["Ooops. This bug doesn't seem to exist."]);
@@ -32,7 +32,7 @@ if ( ! $bug ) {
 print header;
 
 print start_html(-title=>$c{TrackerName}.": #$bugid - ".$bug->{title},
-                -style=>{'src' => '/css/style.css'});
+                -style=>{'src' => $c{StyleSheet}});
 
 print h1("#$bugid - ".$bug->{title});
 
@@ -46,31 +46,44 @@ sub htmlsanit {
     return $in;
 }
 
+print "\n\n";
+
 our $msgs = $bug->messages;
 
 print "\n";
+
+sub hdr {
+    my ($tag,$value) = @_;
+    return undef unless $value;
+    return b($tag).": ".htmlsanit($value);
+}
+
 foreach my $msgid ( keys $msgs ) {
     my $m = Bugs::Message->lookup_id($dbh, $msgid);
-    my $body = $m->body;
-    my @body = <$body>;
-    print p({-class=>"message"},
-           [pre({-class=>"headers"},
-                join("\n", (b("From: ") . "Foo;",
-                            b("To: ") . "Bar;",
-                            b("Subject: ") . $m->{subject},
-                            b("Date: ") . "Baz"))),
-            pre({-class=>"body"}, join("\n",@body)),
-           ]);
-           print hr . "\n";
+    print comment("Message $msgid: ". $m->{msgid}) . "\n";
+
+    if ( $m->{present} ) {
+       my $body = $m->body;
+       my @body = <$body>;
+       print p({-class=>"message"},
+               [pre({-class=>"headers"},
+                    join("\n", grep { $_ } (hdr("From", $m->{from}),
+                                            hdr("To", $m->{to}),
+                                            hdr("Cc", $m->{cc}),
+                                            hdr("Subject", $m->{subject}),
+                                            hdr("Date", $m->{date})))),
+                pre({-class=>"body"}, htmlsanit(join("\n",@body))),
+               ]);
+    } else {
+       my $alturl = $c{AltArchive};
+       $alturl =~ s/<MSGID>/$m->{msgid}/;
+       print p({-class=>"message"},
+               [b("Unknown message: ") .
+                a({href=>$alturl}, htmlsanit($m->{msgid}))]);
+    }
+    print hr . "\n";
 }
 
-#print ul_start;
-#foreach my $msgid ( keys $msgs ) {
-#    my $m = Bugs::Message->lookup_id($dbh, $msgid);
-#    print li("$msgid = ".$m->{subject} . " (".$msgs->{$msgid}.") = ".htmlsanit(#$m->{msgid}));
-#}
-#print ul_end;
-
 print end_html;
 
 
index 5db1b25d17acb0a9cafbcddfbaeec2c25c4d2ba2..9e156034c339da04bc8fc1318e66ac58c96d1808 100755 (executable)
@@ -14,8 +14,10 @@ require 'common.pl';
 readconfig;
 my $dbh = opendb;
 
-print header,
-    start_html($c{TrackerName}.": All Bugs");
+print header;
+
+print start_html(-title=>$c{TrackerName}.": All Bugs",
+                -style=>{'src' => $c{StyleSheet}});
 
 my @bugs = Bugs::Bug->listall($dbh);
 
index 959563f7515f59b29a04841004683c230c1ef211..0d585ffac8843f86035b2e7d24b3a6c75a3b4219 100644 (file)
--- a/config.pl
+++ b/config.pl
@@ -2,3 +2,8 @@ $c{DB} = "/tmp/bugs.sqlite";
 $c{RawMailBase} = "/tmp/bugs.raw";
 
 $c{TrackerName} = "Bug Tracker";
+
+$c{StyleSheet} = "/css/style.css";
+
+# <MSGID> is replaced by the real message id.
+$c{AltArchive} = "http://marc.info/?i=<MSGID>";
index aab469722178b122b4ecdaae1436df555691cd34..b1577ba46a97441bf293a22bda809dd5dba3e5f9 100644 (file)
@@ -1,13 +1,15 @@
 create table messages (
        id integer primary key autoincrement,
        messageid varchar not null unique,
-       present bool default false, -- other fields valid iff true
+       present bool default false, -- following fields valid iff true
 
-       raw blob, -- the raw mail
+       inserttime integer default 0,
 
        -- Selected header values
-       inserttime integer default 0,
-       sendtime integer default 0,
+       msgdate integer default 0,
+       msgfrom varchar,
+       msgto varchar,
+       msgcc varchar,
        subject varchar
 );