3 # gmimport was written by Omar Polo <op@openbsd.org> and is placed in the
4 # public domain. The author hereby disclaims copyright to this source
18 die "usage: $0 dbpath\n" if @ARGV != 1;
19 my $dbpath = shift @ARGV;
21 open(my $sqlite, "|-", "/usr/local/bin/sqlite3", $dbpath)
22 or die "can't spawn sqlite3";
24 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
25 pledge("stdio proc exec") or die "pledge: $!";
27 say $sqlite ".import --csv /dev/stdin email"
28 or die "can't speak to sqlite: $!";
33 open(my $fh, "-|", "/usr/local/bin/mshow", "-Atext/plain", "-NF", $_)
34 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 # leave open for the body
54 print $sqlite "\"$mid\",\"$from\",\"$date\",\"$subj\",\"";
66 die "sqlite3 exited with $?\n" unless $? == 0;