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
$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);
$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 (?)
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');
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."]);
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});
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;
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);
$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>";
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
);