]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
Add a msgtype field to db.
authorIan Campbell <ijc@hellion.org.uk>
Mon, 28 Jan 2013 21:29:15 +0000 (21:29 +0000)
committerIan Campbell <ijc@hellion.org.uk>
Mon, 28 Jan 2013 21:29:15 +0000 (21:29 +0000)
Emesinae/Message.pm
db/createdb.sql

index f60676e2fb7d23bacff4d193c55cd7c753ea5114..5af5db344b8a8afa178c2ee8445efa7f0b539c43 100644 (file)
@@ -16,7 +16,7 @@ sub lookup_id {
 
     my $sth = $dbh->prepare(
         q{
-        SELECT messageid,present,inserttime,msgdate,msgfrom,msgto,msgcc,subject
+        SELECT messageid,present,inserttime,msgtype,msgdate,msgfrom,msgto,msgcc,subject
           FROM messages
          WHERE id = ?
     }
@@ -24,8 +24,8 @@ sub lookup_id {
 
     $sth->execute($id);
 
-    my ( $msgid, $present, $inserted, $date, $from, $to, $cc, $subj ) =
-      @{ $sth->fetch };
+    my ( $msgid, $present, $inserted, $msgtype, $date, $from, $to, $cc, $subj )
+      @{ $sth->fetch };
 
     $sth->finish;
 
@@ -33,6 +33,7 @@ sub lookup_id {
         dbh      => $dbh,
         present  => $present eq "true",
         inserted => $inserted,
+        msgtype  => $msgtype,
         date     => Mail::Field::Date->new( 'date', $date ),
         from     => Mail::Field::AddrList->new( 'from', $from ),
         to       => Mail::Field::AddrList->new( 'to', $to ),
@@ -56,7 +57,7 @@ sub lookup_msgid {
 
     my $sth = $dbh->prepare(
         q{
-        SELECT id,present,inserttime,msgdate,msgfrom,msgto,msgcc,subject
+        SELECT id,present,inserttime,msgtype,msgdate,msgfrom,msgto,msgcc,subject
           FROM messages
          WHERE messageid = ?
     }
@@ -68,9 +69,10 @@ sub lookup_msgid {
 
     $sth->finish;
 
-    my ( $id, $present, $inserted, $date, $from, $to, $cc, $subj );
+    my ( $id, $present, $inserted, $msgtype, $date, $from, $to, $cc, $subj );
     if ( defined $row ) {
-        ( $id, $present, $inserted, $date, $from, $to, $cc, $subj ) = @{$row};
+        ( $id, $present, $inserted, $msgtype, $date, $from, $to, $cc, $subj ) =
+          @{$row};
     }
     elsif ( $args{Insert} ) {
         my $sth = $dbh->prepare(
@@ -78,6 +80,9 @@ sub lookup_msgid {
            INSERT into messages (messageid) VALUES (?)
         }
         );
+
+        $msgtype = "normal";
+
         $sth->execute($msgid) or die "Inserting new message";
         $id      = $dbh->sqlite_last_insert_rowid();
         $present = 0;
@@ -92,6 +97,7 @@ sub lookup_msgid {
         inserted => $inserted,
         id       => $id,
         msgid    => $msgid,
+        msgtype  => $msgtype,
         date     => Mail::Field::Date->new( 'date', $date ),
         from     => Mail::Field::AddrList->new( 'from', $from ),
         to       => Mail::Field::AddrList->new( 'to', $to ),
@@ -103,6 +109,24 @@ sub lookup_msgid {
     return $self;
 }
 
+sub set_type {
+    my $self = shift;
+    my $type = shift;
+
+    # XXX check type
+
+    my $sth = $self->{dbh}->prepare(
+        q{
+        UPDATE messages
+           SET msgtype=?2
+         WHERE id = ?1}
+    ) or die "prepare type update";
+    $sth->execute( $self->{id}, $type ) or die "execute type update";
+    $sth->finish or die "finish type update";
+
+    $self->{msgtype} = $type;
+}
+
 sub update {
     my $self   = shift;
     my $header = shift;
@@ -135,8 +159,8 @@ sub update {
         $from ? $from->stringify : undef,
         $to   ? $to->stringify   : undef,
         $cc   ? $cc->stringify   : undef
-    ) or die "execute insert";
-    $sth->finish or die "finish insert";
+    ) or die "execute update";
+    $sth->finish or die "finish update";
 
     my $irt = $header->get('in-reply-to');
     if ( defined $irt ) {
index 104ed34bf608223524b8144187dd8b0c0dde2e8b..c17e20df625ca71d9637fcf3cda8921b010e7a11 100644 (file)
@@ -5,6 +5,9 @@ create table messages (
 
        inserttime integer default 0,
 
+       -- XXX enum "normal", "control", "control-reply"
+       msgtype char(16) default "normal", -- control / control-reply
+
        -- Selected header values
        msgdate varchar,
        msgfrom varchar,