From: Sebastian Date: Sun, 15 Jun 2014 18:18:05 +0000 (+0200) Subject: multi: new msgbase structure X-Git-Url: http://sraa.de/git/%22%24img/static/gitweb.js?a=commitdiff_plain;h=84d5be71b932022cf2e3e006751e171fc280324f;p=fido.git multi: new msgbase structure apps/scan.pl: updated to use FTNMAIL.pm docs/msgbase.txt: updated modules/MSGBASE.pm: updated modules/FTNMAIL.pm: small fixes --- diff --git a/apps/scan.pl b/apps/scan.pl index 0ce3682..1658447 100755 --- a/apps/scan.pl +++ b/apps/scan.pl @@ -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"); diff --git a/docs/msgbase.txt b/docs/msgbase.txt index 5f78b95..f84eb90 100644 --- a/docs/msgbase.txt +++ b/docs/msgbase.txt @@ -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 diff --git a/modules/FTNMAIL.pm b/modules/FTNMAIL.pm index 0f5ea32..bcceebe 100644 --- a/modules/FTNMAIL.pm +++ b/modules/FTNMAIL.pm @@ -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 diff --git a/modules/MSGBASE.pm b/modules/MSGBASE.pm index e773d2a..01c7b13 100644 --- a/modules/MSGBASE.pm +++ b/modules/MSGBASE.pm @@ -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;