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 $_: $!";
38 my ($time, $id) = split /\./, basename $_;
39 my $mid = "$time.$id";
42 my ($from, $subj, $date) = ('', '', undef);
47 $from = s/.*?: //r if /^From:/;
48 $subj = s/.*?: //r if /^Subject:/;
49 $date = str2time(s/.*?: //r) if /^Date:/;
54 # leave open for the body
55 print $sqlite "\"$mid\",\"$from\",\"$date\",\"$subj\",\"";
67 die "sqlite3 exited with $?\n" unless $? == 0;