multi: new msgbase structure
authorSebastian <basti@notizbuch>
Sun, 15 Jun 2014 18:18:05 +0000 (20:18 +0200)
committerSebastian <basti@notizbuch>
Sun, 15 Jun 2014 18:18:05 +0000 (20:18 +0200)
apps/scan.pl:       updated to use FTNMAIL.pm
docs/msgbase.txt:   updated
modules/MSGBASE.pm: updated
modules/FTNMAIL.pm: small fixes

apps/scan.pl
docs/msgbase.txt
modules/FTNMAIL.pm
modules/MSGBASE.pm

index 0ce3682b94f7d51d26ed45f1cf2b2236cfbbde11..165844729b132ab1d3ac929d975b40a887c51d39 100755 (executable)
@@ -7,7 +7,7 @@ use Data::Dumper;
 
 use lib '../modules';
 use CONFIG;
-use FIDOMAIL;
+use FTNMAIL;
 use MSGBASE;
 
 # global structures
@@ -89,20 +89,12 @@ sub dispatch($)
                } elsif($file =~ /[0-9a-f]{8}\.PKT/i) {
                # PACKED MESSAGES
                        say "[PKT] $dirname/$file";
-                       my $messages =
-                               FIDOMAIL::read_packet_file("$dirname/$file");
+                       my @mails = FTNMAIL::unpack_packet("$dirname/$file");
+                       if(!@mails) { $fail++; next; }
 
-                       if(!$messages) {
-                               $fail++;
-                               next;
-                       }
+                       foreach(@mails) {
+                               if(!handle_mail($_)) { $fail++; next; }
 
-                       foreach(@$messages) {
-                               my $mail = FIDOMAIL::read_message($_);
-                               if(!$mail || !handle_mail($mail)) {
-                                       $fail++;
-                                       next;
-                               }
                        }
 
                        unlink("$dirname/$file");
index 5f78b955cdaebe8b5da85cec12c0c8ca5e6d7208..f84eb90592da005065934434b8b2ab02ff393e01 100644 (file)
@@ -3,26 +3,27 @@ Message Base Format
 
 For access functions, see modules/MSGBASE.pm
 
-SQLite: Each AREA is saved in a file AREANAME.area, with a single
+SQLite: Each AREA is saved in a file AREANAME.area, containing a single
         table named AREANAME, with dots replaced by underscores.
 
-AREANAME
---------
-id     - integer, primary key
-area   - text
-from   - text          - convert MISC::fido2text
-fname  - text
-to     - text          - convert MISC::fido2text
-tname  - text
-date   - text          - convert MISC::date2text
-time   - text          - convert MISC::time2text
-subj   - text
-body   - text
-msgid  - text
-reply  - text
-path   - text          - convert MISC::netnodelist2text
-seen   - text          - convert MISC::netnodelist2text
-state  - integer
-transfer- integer
-file   - integer
+Column Name    Data Type               Notes
+-------------------------------------------------------------------------
+id             integer, primary key
+area           text                    NULL for Netmail
+from           text                    (*)
+to             text                    (*)
+fname          text                    (u)
+tname          text                    (u)
+subj           text                    (u)
+body           text                    (u)
+date           text                    "yyyy-mm-dd"
+time           text                    "hh:mm:ss"
+msgid          text                    (*)
+reply          text                    (*)
+path           text
+seen           text
+
+Notes:
+       (*): string depends on network
+       (u): utf-8 encoded strings
 
index 0f5ea327addfe4cd18e326ed986eb3ea2fe2c25d..bcceebeb9e113e2c63f6c4eb3249f04b9715feb1 100644 (file)
@@ -42,17 +42,16 @@ sub pack_mail($$)
        } else {
                # NETMAIL: INTL, FMPT and TOPT
                my @from = str2ftn($mail->{from}) or return(undef);
-
-               my @to   = str2ftn($mail->{to}) or return(undef);
+               my @to   = str2ftn($mail->{to})   or return(undef);
                push(@kludges, "\x01INTL: $to[0]:$to[1]/$to[2] ".
                        "$from[0]:$from[1]/$from[2]\x0D");
                push(@kludges, "\x01FMPT: $from[3]\x0D") if($from[3]);
-               push(@kludges, "\x01TOPT: $to[3]\x0D") if($to[3]);
+               push(@kludges, "\x01TOPT: $to[3]\x0D")   if($to[3]);
        }
        push(@kludges, "\x01MSGID: $mail->{msgid}\x0D") if($mail->{msgid});
        push(@kludges, "\x01REPLY: $mail->{reply}\x0D") if($mail->{reply});
        push(@kludges, "\x01CHRS: $chrs\x0D");
-       push(@kludges, "\x01PID: http://sraa.de/git/?p=fido.git\x0D");
+       push(@kludges, "\x01TID: http://sraa.de/git/?p=fido.git\x0D");
        $output = join("", @kludges) . $body;
 
        # additional kludge lines
index e773d2a829c30aca7892212189bbb4b5ea6c2263..01c7b1317e2a13bc699e435631919adf98297ef6 100644 (file)
@@ -5,6 +5,7 @@ use v5.012;
 use DBI;
 
 use CONFIG;
+use MISC;
 
 # Perl module to handle message base
 # =========================================================================
@@ -31,16 +32,9 @@ use CONFIG;
 #  mail_remove(): remove mail from area
 #    mail_remove($handle, $id)
 #      $handle - handle to area
-#      $id     - 'id' field
+#      $id     - 'id' value
 #    returns true if successful, undef if not found, or dies on error
 #
-#  mail_search(): search for mails
-#    mail_search($handle, $data, $fields)
-#      $handle - handle to area
-#      $data   - hashref { key => value, key => value, ... }
-#      $fields - (optional) arrayref of fieldnames, or undef for 'id'
-#    returns list of hashrefs { field => value }
-#
 # =========================================================================
 
 package MSGBASE;
@@ -87,17 +81,14 @@ sub area_open($)
                        { 'AutoCommit' => 0, 'PrintError' => 1 }
                ) or die("Can't connect to $file");
                $dbh->do("CREATE TABLE IF NOT EXISTS '$table' (
-                       'id'       INTEGER PRIMARY KEY,
-                       'area'     TEXT,
-                       'from'     TEXT, 'fname'    TEXT,
-                       'to'       TEXT, 'tname'    TEXT,
-                       'date'     TEXT, 'time'     TEXT,
-                       'subj'     TEXT, 'body'     TEXT,
-                       'msgid'    TEXT, 'reply'    TEXT,
-                       'path'     TEXT, 'seen'     TEXT,
-                       'state'    INTEGER,
-                       'transfer' INTEGER,
-                       'file'     INTEGER
+                       'id'    INTEGER PRIMARY KEY,
+                       'area'  TEXT,
+                       'from'  TEXT, 'to'    TEXT,
+                       'fname' TEXT, 'tname' TEXT,
+                       'subj'  TEXT, 'body'  TEXT,
+                       'date'  TEXT, 'time'  TEXT,
+                       'msgid' TEXT, 'reply' TEXT,
+                       'path'  TEXT, 'seen'  TEXT
                        )") or die("Can't create table!");
                $dbh->commit or die("Can't commit!");
                my $handle = {
@@ -150,7 +141,7 @@ sub mail_add($$)
                        ( $mail->{msgid} )
                );
                if($dupes) {
-                       say(sprintf("DUPE: msgid='%s', '%s' => '%s'",
+                       say(sprintf("DUPE: '%s', '%s' => '%s'",
                                $dupes->[0], $dupes->[1],
                                $dupes->[2], $dupes->[3]));
                        return(undef);
@@ -162,24 +153,19 @@ sub mail_add($$)
 
        # store mail in msgbase
        my $rows = $handle->{dbh}->do("INSERT INTO '$handle->{table}'
-               ('area', 'from', 'fname', 'to', 'tname', 'date', 'time',
-                'subj', 'body', 'msgid', 'reply', 'path', 'seen',
-                'state', 'transfer', 'file') VALUES
-               (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
+               ('area', 'from', 'to', 'fname', 'tname', 'subj', 'body',
+                'date', 'time', 'msgid', 'reply', 'path', 'seen') VALUES
+               (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
                undef,
                (
                        $mail->{area},
-                       MISC::fido2text($mail->{from}), $mail->{fname},
-                       MISC::fido2text($mail->{to}),   $mail->{tname},
+                       $mail->{from},  $mail->{to},
+                       $mail->{fname}, $mail->{tname},
+                       $mail->{subj},  $mail->{body},
                        MISC::date2text($mail->{date}),
                        MISC::time2text($mail->{time}),
-                       $mail->{subj}, $mail->{body},
                        $mail->{msgid}, $mail->{reply},
-                       MISC::netnodelist2text($mail->{path}),
-                       MISC::netnodelist2text($mail->{seen}),
-                       $mail->{attr}->{state},
-                       $mail->{attr}->{transfer},
-                       $mail->{attr}->{file},
+                       $mail->{path},  $mail->{seen},
                )
        ) or die("Failed to save mail!");
 }
@@ -196,38 +182,4 @@ sub mail_remove($$)
        return($rows);
 }
 
-sub mail_search($$;$)
-{
-       my ($handle, $data, $fields) = @_;
-
-       # COLUMN clause
-       my $columns;
-       if(defined $fields) {
-               my @f = map { "\"$_\"" } @$fields;
-               $columns = join(",", @f);
-       } else {
-               $columns = "\"id\"";
-       }
-
-       # WHERE clause
-       my (@k, @v);
-       foreach(keys %$data) {
-               if(defined $data->{$_}) {
-                       push @k, "\"$_\" = ?";
-                       push @v, "$data->{$_}";
-               } else {
-                       push @k, "\"$_\" IS NULL";
-               }
-       }
-       my $where = join(" AND ", @k);
-
-       my $result = $handle->{dbh}->selectall_arrayref(
-               "SELECT $columns FROM $handle->{table} WHERE $where;",
-               { 'Slice' => {} },
-               @v
-       );
-
-       return(@$result);
-}
-
 1;