… | |
… | |
30 | %arg, |
30 | %arg, |
31 | }, $class; |
31 | }, $class; |
32 | |
32 | |
33 | $self->{last_check} = (-M $self->{db_file}) + 1; |
33 | $self->{last_check} = (-M $self->{db_file}) + 1; |
34 | unless (-e $self->{db_file}) { |
34 | unless (-e $self->{db_file}) { |
35 | write_file ($self->{db_file}, cf::to_json ({})); |
35 | write_file ($self->{db_file}, cf::encode_json ({})); |
36 | } |
36 | } |
37 | $self->check_maildb (); |
37 | $self->check_maildb (); |
38 | |
38 | |
39 | $self; |
39 | $self; |
40 | } |
40 | } |
… | |
… | |
43 | my ($self) = @_; |
43 | my ($self) = @_; |
44 | |
44 | |
45 | if ($self->{last_check} > (-M $self->{db_file})) { |
45 | if ($self->{last_check} > (-M $self->{db_file})) { |
46 | $self->{last_check} = -M $self->{db_file}; |
46 | $self->{last_check} = -M $self->{db_file}; |
47 | |
47 | |
48 | my $maildb = eval { my $m = cf::from_json read_file $self->{db_file}; return $m }; |
48 | my $maildb = eval { my $m = cf::decode_json read_file $self->{db_file}; return $m }; |
49 | if ($@) { |
49 | if ($@) { |
50 | warn "ERROR when reading mail database $self->{db_file}: $@\n"; |
50 | warn "ERROR when reading mail database $self->{db_file}: $@\n"; |
51 | $self->{db_file} = $self->{db_file} . ".after_failure"; |
51 | $self->{db_file} = $self->{db_file} . ".after_failure"; |
52 | } else { |
52 | } else { |
53 | $self->{maildb} = $maildb; |
53 | $self->{maildb} = $maildb; |
… | |
… | |
59 | # XXX: A second process will (of course) terribly damage the maildatabase |
59 | # XXX: A second process will (of course) terribly damage the maildatabase |
60 | # but i assume there wont be any second process. |
60 | # but i assume there wont be any second process. |
61 | sub sync_maildb { |
61 | sub sync_maildb { |
62 | my ($self) = @_; |
62 | my ($self) = @_; |
63 | |
63 | |
64 | write_file ($self->{db_file}, cf::to_json ($self->{maildb})); |
64 | write_file ($self->{db_file}, cf::encode_json ($self->{maildb})); |
65 | $self->{last_check} = -M $self->{db_file}; |
65 | $self->{last_check} = -M $self->{db_file}; |
66 | } |
66 | } |
67 | |
67 | |
68 | sub get { |
68 | sub get { |
69 | my ($self, $key) = @_; |
69 | my ($self, $key) = @_; |