Skip to content

Commit

Permalink
Fix logic for detecting an existing IMAP spam folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Jun 20, 2024
1 parent 359a240 commit 2259d8e
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions mailbox/mailbox-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ sub list_folders
}
}

# When in IMAP inbox mode, we goto this label to skip all my folders
# When in IMAP inbox mode, we goto this label to skip all local folders
IMAPONLY:

# Add user-defined composite folders
Expand All @@ -668,43 +668,41 @@ sub list_folders

# Add spam folder as specified in spamassassin module, in case it is
# outside of the folders we scan
if (&foreign_check("spam")) {
my %suserconfig = &foreign_config("spam", 1);
my $file = $suserconfig{'spam_file'};
$file ||= "";
my %suserconfig;
if ($config{'mail_system'} == 4) {
# In IMAP mode, the first folder named spam is marked
my ($sf) = grep { lc($_->{'name'}) eq 'spam' } @rv;
if ($sf) {
$sf->{'name'} = $text{'folder_spam'};
$sf->{'spam'} = 1;
}
}
elsif (&foreign_check("spam") &&
(%suserconfig = &foreign_config("spam", 1)) &&
(my $file = $suserconfig{'spam_file'})) {
$file =~ s/\.$//;
$file =~ s/\/$//;
$file = "$remote_user_info[7]/$file" if ($file && $file !~ /^\//);
$file =~ s/\~/$remote_user_info[7]/;
if ($file) {
if ($config{'mail_system'} == 4) {
# In IMAP mode, the first folder named spam is marked
my ($sf) = grep { $_->{'name'} =~ /^\.?spam$/i } @rv;
if ($sf) {
$sf->{'name'} = "Spam";
$sf->{'spam'} = 1;
}
}
elsif (!$done{$file}) {
# Need to add
push(@rv, { 'name' => "Spam",
'file' => $file,
'type' => &folder_type($file),
'perpage' => $userconfig{"perpage_$file"},
'fromaddr' => $userconfig{"fromaddr_$file"},
'sent' => $userconfig{"sent_$file"},
'hide' => 0,
'mode' => 0,
'spam' => 1,
'index' => scalar(@rv) } );
$done{$file}++;
}
else {
# Mark as spam folder
my ($sf) = grep { $_->{'file'} eq $file } @rv;
if ($sf) {
$sf->{'spam'} = 1;
}
if (!$done{$file}) {
# Need to add
push(@rv, { 'name' => "Spam",
'file' => $file,
'type' => &folder_type($file),
'perpage' => $userconfig{"perpage_$file"},
'fromaddr' => $userconfig{"fromaddr_$file"},
'sent' => $userconfig{"sent_$file"},
'hide' => 0,
'mode' => 0,
'spam' => 1,
'index' => scalar(@rv) } );
$done{$file}++;
}
else {
# Mark as spam folder
my ($sf) = grep { $_->{'file'} eq $file } @rv;
if ($sf) {
$sf->{'spam'} = 1;
}
}
}
Expand Down

0 comments on commit 2259d8e

Please sign in to comment.