File: import_mboxes

package info (click to toggle)
pronto 2.4.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,112 kB
  • ctags: 488
  • sloc: perl: 22,159; makefile: 140; sh: 34; sql: 7
file content (57 lines) | stat: -rwxr-xr-x 1,321 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#script to import a bunch of mboxes at the command line

require "prontolib.pl";
use Pronto::Data::Message;

	if (!@ARGV) { die "usage: import box1 box2 box3 .. \n" }	
	
	read_prefs();
	$conn = open_db_conn();
	
	make_filter_and_get_account();
	import_boxes();	


sub import_boxes
{

	foreach my $file (@ARGV) {
		open(MBOX, $file);
		$/ = "\nFrom ";
		while ($body = <MBOX>) {
			$body =~ s/\nFrom $//s;
			$body =~ s/^.*\n//m;
			$error = &save_message($conn, $body, \%filter, $account);
		}
		$/="\n";
		close(MBOX);
	}	
	
}

sub make_filter_and_get_account
{
	$sql = "select sorder, type, boxid, regex, addr, trueregex, count, id from filters  order by sorder";
	$query=$conn->prepare($sql);
	$query->execute();
	while (@row = $query->fetchrow_array()) {
		$filter{$row[0]} = {
			'id' => $row[7],
			'type' => $row[1],
			'boxid' => $row[2],
			'regex' => $row[3],
			'addr' => $row[4],
			'trueregex' => $row[5],
			'count' => $row[6]
		}
	}

	$sql = "select id, friendly, reply from accounts where def = ?";
       	$query=$conn->prepare($sql);
	$query->execute("y");
	($account->{'id'}, $account->{'friendly'}, $account->{'reply'}) = $query->fetchrow_array();
	($account->{'dm'} = "n");
	($account->{'dupecheck'}='y');
	unless (defined $account->{'id'} && $account->{'id'}){$account->{'id'}=1;}
}