# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# ref: https://cr.yp.to/proto/maildir.html
-# httsp://wiki2.dovecot.org/MailboxFormat/Maildir
+# https://wiki2.dovecot.org/MailboxFormat/Maildir
package PublicInbox::Watch;
use strict;
use v5.10.1;
# indefinitely...
foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) {
my $k = "$pfx.watchspam";
- defined(my $dirs = $cfg->{$k}) or next;
- $dirs = PublicInbox::Config::_array($dirs);
+ my $dirs = $cfg->get_all($k) // next;
for my $dir (@$dirs) {
my $uri;
if (is_maildir($dir)) {
PublicInbox::DirIdle->new([keys %{$self->{mdmap}}], $cb);
}
-sub imap_import_msg ($$$$$) {
- my ($self, $uri, $uid, $raw, $flags) = @_;
- # our target audience expects LF-only, save storage
- $$raw =~ s/\r\n/\n/sg;
-
- my $inboxes = $self->{imap}->{$$uri};
- if (ref($inboxes)) {
- for my $ibx (@$inboxes) {
- my $eml = PublicInbox::Eml->new($$raw);
- import_eml($self, $ibx, $eml);
- }
- } elsif ($inboxes eq 'watchspam') {
- return if $flags !~ /\\Seen\b/; # don't remove unseen messages
- local $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
- my $eml = PublicInbox::Eml->new($raw);
- $self->{pi_cfg}->each_inbox(\&remove_eml_i,
- $self, $eml, "$uri UID:$uid");
- } else {
- die "BUG: destination unknown $inboxes";
- }
-}
-
sub net_cb { # NetReader::(nntp|imap)_each callback
my ($uri, $art, $kw, $eml, $self, $inboxes) = @_;
+ return if grep(/\Adraft\z/, @$kw);
local $self->{cur_uid} = $art; # IMAP UID or NNTP article
if (ref($inboxes)) {
my @ibx = @$inboxes;
}
import_eml($self, $last, $eml);
} elsif ($inboxes eq 'watchspam') {
+ if ($uri->scheme =~ /\Aimaps?\z/ && !grep(/\Aseen\z/, @$kw)) {
+ return;
+ }
$self->{pi_cfg}->each_inbox(\&remove_eml_i,
$self, $eml, "$uri #$art");
} else {
sub watch_imap_idle_1 ($$$) {
my ($self, $uri, $intvl) = @_;
my $sec = uri_section($uri);
- my $mic_arg = $self->{mic_arg}->{$sec} or
+ my $mic_arg = $self->{net_arg}->{$sec} or
die "BUG: no Mail::IMAPClient->new arg for $sec";
my $mic;
local $0 = $uri->mailbox." $sec";
until ($self->{quit}) {
- $mic //= PublicInbox::IMAPClient->new(%$mic_arg);
+ $mic //= PublicInbox::IMAPClient->new(%$mic_arg,Keepalive => 1);
my $err;
if ($mic && $mic->IsConnected) {
local $self->{mics_cached}->{$sec} = $mic;
sub watch_imap_init ($$) {
my ($self, $poll) = @_;
- my $mics = imap_common_init($self); # read args from config
+ my $mics = PublicInbox::NetReader::imap_common_init($self);
my $idle = []; # [ [ uri1, intvl1 ], [uri2, intvl2] ]
for my $uri (@{$self->{imap_order}}) {
my $sec = uri_section($uri);
my $mic = $mics->{$sec};
- my $intvl = $self->{imap_opt}->{$sec}->{pollInterval};
+ my $intvl = $self->{cfg_opt}->{$sec}->{pollInterval};
if ($mic->has_capability('IDLE') && !$intvl) {
- $intvl = $self->{imap_opt}->{$sec}->{idleInterval};
+ $intvl = $self->{cfg_opt}->{$sec}->{idleInterval};
push @$idle, [ $uri, $intvl // () ];
} else {
push @{$poll->{$intvl || 120}}, $uri;
sub watch_nntp_init ($$) {
my ($self, $poll) = @_;
- nntp_common_init($self); # read args from config
+ PublicInbox::NetReader::nntp_common_init($self);
for my $uri (@{$self->{nntp_order}}) {
my $sec = uri_section($uri);
- my $intvl = $self->{nntp_opt}->{$sec}->{pollInterval};
+ my $intvl = $self->{cfg_opt}->{$sec}->{pollInterval};
push @{$poll->{$intvl || 120}}, $uri;
}
}
undef;
}
+sub folder_select { 'select' } # for PublicInbox::NetReader
+
1;