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, "|-", "/usr/local/bin/sqlite3", $dbpath)
19 or die "can't spawn sqlite3";
21 if (`uname` =~ "OpenBSD") {
25 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
26 pledge("stdio proc exec") or die "pledge: $!";
29 say $sqlite ".import --csv /dev/stdin email"
30 or die "can't speak to sqlite: $!";
35 open(my $fh, "-|", "/usr/local/bin/mshow", "-Atext/plain", "-NF", $_)
36 or die "can't run mshow $_: $!";
39 my ($time, $id) = split /\./, basename $_;
40 my $mid = "$time.$id";
43 my ($from, $subj, $date) = ('', '', undef);
48 $from = s/.*?: //r if /^From:/;
49 $subj = s/.*?: //r if /^Subject:/;
50 $date = str2time(s/.*?: //r) if /^Date:/;
55 # leave open for the body
56 print $sqlite "\"$mid\",\"$from\",\"$date\",\"$subj\",\"";
68 die "sqlite3 exited with $?\n" unless $? == 0;