| 1 | # This code is part of Perl distribution Mail-Box-IMAP4 version 4.01. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.05. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2025 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Mail::Server::IMAP4::List;{ | ||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '4.01'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Log::Report 'mail-box-imap4', import => []; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #-------------------- | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub new($) | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | { my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 2 | (bless {}, $class)->init(\%args); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init($) | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 2 | my $user = $self->{MSIL_user} = $args->{user}; | |||||||||||||||||||||||||||
| 32 | 2 | $self->{MSIL_folders} = $args->{folders}; | |||||||||||||||||||||||||||
| 33 | 2 | $self->{MSIL_inbox} = $args->{inbox}; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | $self->{MSIL_delim} = exists $args->{delimiter} ? $args->{delimiter} : '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | $self; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #-------------------- | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub delimiter(;$) | ||||||||||||||||||||||||||||
| 41 | 32 | ▶ | { my $delim = shift->{MSIL_delim}; | ||||||||||||||||||||||||||
|
Subroutine
delimiter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 32 | ▶ | ref $delim ? $delim->(shift) : $delim; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub user() { $_[0]->{MSIL_user} } | ||||||||||||||||||||||||||
|
Subroutine
user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub folders() | ||||||||||||||||||||||||||||
| 50 | 28 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
folders: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 28 | ▶ | $self->{MSIL_folders} || $self->user->topfolder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub inbox() | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
inbox: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $self->{MSIL_inbox} || $self->user->inbox; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #-------------------- | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub list($$) | ||||||||||||||||||||||||||||
| 63 | 32 | ▶ | { my ($self, $base, $pattern) = @_; | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 32 | ▶ | return [ '(\Noselect)', $self->delimiter($base), '' ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | if $pattern eq ''; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 28 | my $delim = $self->delimiter($base); | |||||||||||||||||||||||||||
| 69 | 28 | my @path = split $delim, $base; | |||||||||||||||||||||||||||
| 70 | 28 | my $folder = $self->folders; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 28 | ▶ | while(@path && defined $folder) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@path and defined $folder
MC/DC50%1/2
@path and defined $folder
@path
defined $folder
Truth table66%2/3
A and B
A= @pathB= defined $folder
| |||||||||||||||||||||||||||||
| 73 | 35 | { $folder = $folder->folder(shift @path); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 28 | ▶ | defined $folder or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 26 | my @pattern = split $delim, $pattern; | |||||||||||||||||||||||||||
| 78 | 26 | return $self->_list($folder, $delim, @pattern); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub _list($$@) | ||||||||||||||||||||||||||||
| 82 | 127 | ▶ | { my ($self, $folder, $delim) = (shift, shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
_list: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 127 | ▶ | if(!@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 36 | { my @flags; | |||||||||||||||||||||||||||
| 86 | 36 | ▶ | push @flags, '\Noselect' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$folder->onlySubfolders or $folder->deleted
MC/DC100%2/2
$folder->onlySubfolders or $folder->deleted
$folder->onlySubfolders
$folder->deleted
Truth table100%3/3
A or B
A= $folder->onlySubfoldersB= $folder->deleted
| |||||||||||||||||||||||||||||
| 87 | if $folder->onlySubfolders || $folder->deleted; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 36 | ▶ | push @flags, '\Noinferiors' unless $folder->inferiors; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 36 | my $marked = $folder->marked; | |||||||||||||||||||||||||||
| 91 | 36 | ▶ | push @flags, ($marked ? '\Marked' : '\Unmarked') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 92 | if defined $marked; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 36 | local $" = ' '; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # This is not always correct... should compose the name from the | ||||||||||||||||||||||||||||
| 97 | # parts... but in nearly all cases, the following is sufficient. | ||||||||||||||||||||||||||||
| 98 | 36 | my $name = $folder->fullname; | |||||||||||||||||||||||||||
| 99 | 36 | for($name) | |||||||||||||||||||||||||||
| 100 | 36 | { s/^=//; | |||||||||||||||||||||||||||
| 101 | 36 | s![/\\]!$delim!g; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 36 | return [ "(@flags)", $delim, $name ]; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 91 | my $pat = shift; | |||||||||||||||||||||||||||
| 107 | 91 | ▶ | if($pat eq '%') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 3 | ▶ | { my $subs = $folder->subfolders | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | or return $self->_list($folder, $delim); | ||||||||||||||||||||||||||||
| 110 | 2 | return map $self->_list($_, $delim, @_), $subs->sorted; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 88 | ▶ | if($pat eq '*') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 40 | { my @own = $self->_list($folder, $delim, @_); | |||||||||||||||||||||||||||
| 115 | 40 | ▶ | my $subs = $folder->subfolders or return @own; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 13 | return @own, map $self->_list($_, $delim, '*', @_), $subs->sorted; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 48 | ▶ | $folder = $folder->find(subfolders => $pat) or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 20 | $self->_list($folder, $delim, @_); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | #-------------------- | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | 1; | |||||||||||||||||||||||||||