3 # smingest was written by Omar Polo <op@openbsd.org> and is placed in the
4 # public domain. The author hereby disclaims copyright to this source
15 die "usage: $0 dbpath\n" if @ARGV != 1;
16 my $dbpath = shift @ARGV;
18 open(my $sqlite, "|-", "sqlite3", $dbpath) or die "can't spawn sqlite3";
20 if (`uname` =~ "OpenBSD") {
24 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
25 pledge("stdio proc exec") or die "pledge: $!";
28 say $sqlite ".import --csv /dev/stdin email"
29 or die "can't speak to sqlite: $!";
34 open(my $fh, "-|", "mshow", "-Atext/plain", "-NF", $_)
35 or die "can't run mshow $_: $!";
37 my ($time, $id) = split /\./, basename $_;
38 my $mid = "$time.$id";
41 my ($from, $subj, $date) = ('', '', undef);
46 $from = s/.*?: //r if /^From:/;
47 $subj = s/.*?: //r if /^Subject:/;
48 $date = str2time(s/.*?: //r) if /^Date:/;
53 print $sqlite "\"$mid\",\"$from\",\"$date\",\"$subj\",\"";
58 print $sqlite "\"\r\n";
64 die "sqlite3 exited with $?\n" unless $? == 0;