Filter#

NAME#

Kernel::System::PostMaster::Filter

DESCRIPTION#

All postmaster database filters

PUBLIC INTERFACE#

new()#

Don’t use the constructor directly, use the ObjectManager instead:

my $PostMasterFilterObject = $Kernel::OM->Get('Kernel::System::PostMaster::Filter');

FilterList()#

get all filter

my %FilterList = $PostMasterFilterObject->FilterList();

FilterAdd()#

add a filter

$PostMasterFilterObject->FilterAdd(
    Name           => 'some name',
    StopAfterMatch => 0,
    Match = [
        {
            Key   => 'Subject',
            Value => '^ADV: 123',
        },
        # ...
    ],
    Not = [
        {
            Key   => 'Subject',
            Value => '1',
        },
        # ...
    ],
    Set = [
        {
            Key   => 'X-OTRS-Queue',
            Value => 'Some::Queue',
        },
        # ...
    ],
);

FilterDelete()#

delete a filter

$PostMasterFilterObject->FilterDelete(
    Name => '123',
);

FilterGet()#

get filter properties, returns HASH ref Match and Set

my %Data = $PostMasterFilterObject->FilterGet(
    Name => '132',
);

FilterLookup()#

lookup for PostMaster filter id or name

my $ID = $PostMasterFilterObject->FilterLookup(
    Name => 'postmaster_filter',
);

# OR

my $Name = $PostMasterFilterObject->FilterLookup(
    ID => 10,
);

FilterExport()#

export a PostMaster filter

my $ExportData = $PostMasterFilterObject->FilterExport(
    # required either Name or ExportAll
    Name                     => 'postmaster1', # required
                                               # or
    ExportAll                => 0,             # required, possible: 0, 1
);

returns PostMaster filters hashes in an array with data:

my $ExportData =
[
    {
        'Name' => 'postmaster1',
        'StopAfterMatch' => 0,
        'Match' => [{
            'Value' => '2',
            'Key' => 'Message-ID'
        }],
        'Set' => [{
            'Value' => '2',
            'Key' => 'X-OTRS-AttachmentExists'
        }],
        'Not' => [{
            'Value' => undef,
            'Key' => 'Message-ID'
        }]
    },
    {
        'Name' => 'postmaster2',
        'StopAfterMatch' => 1,
        'Match' => [{
            'Value' => '3',
            'Key' => 'Precedence'
        }],
        'Set' => [{
            'Value' => '3',
            'Key' => 'X-OTRS-AttachmentExists'
        }],
        'Not' => [{
            'Key' => 'Precedence',
            'Value' => undef
        }],
    }
]

FilterImport()#

import a filter YAML file/content

my $FilterImport = $PostMasterFilterObject->FilterImport(
    Content                  => $YAMLContent, # mandatory, YAML format
    OverwriteExistingFilters => 0,            # optional, possible: 0, 1
);

Returns:

$FilterImport = {
    Success          => 1,                                  # 1 if success or undef if operation could not
                                                            # be performed
    Message          => 'The Message to show.',             # error message
    Added            => 'Filter1, Filter2',                 # string list of Filters correctly added
    Updated          => 'Filter3, Filter4',                 # string list of Filters correctly updated
    NotUpdated       => 'Filter5, Filter6',                 # string of Filters not updated due to existing entity
                                                            # with the same name
    Errors           => 'Filter5',                          # string list of Filters that could not be added or updated
    AdditionalErrors => ['Some error occured!', 'Error2!'], # list of additional error not necessarily related to specified Filter
};

FilterCopy()#

copy a filter

my $NewFilterName = $PostMasterFilterObject->FilterCopy(
    Name    => 'filter1', # mandatory
);

FilterExportDataGet()#

get data to export PostMaster filter

my %PostMasterFilterData = $PostMasterFilterObject->FilterExportDataGet(
    Name => 'postmaster_filter1', # mandatory
);

Returns:

my %PostMasterFilterData = (
    'Name' => 'postmaster_filter1',
    'StopAfterMatch' => 0,
    'Set' => [{
        'Value' => '2',
        'Key' => 'X-OTRS-AttachmentExists'
    }],
    'Match' => [{
        'Value' => '2',
        'Key' => 'Message-ID'
    }],
    'Not' => [{
        'Value' => undef,
        'Key' => 'Message-ID'
    }]
)

FilterExportFilenameGet()#

get export file name based on filter name

my $Filename = $PostMasterFilterObject->FilterExportFilenameGet(
    Name => 'Filter_1',
    Format => 'YAML',
);

FilterInsertErrorsCheck()#

Perform checks for insert filter action. Recommended to use before every add/update function or as additional layer of validation.

my %Errors = $PostMasterFilterObject->FilterInsertErrorsCheck(
    Match => [],
    Set => [],
    Name => 'filter',
    StopAfterMatch => 0,
);

FilterHeadersGet()#

get valid PostMaster headers

my %Headers = $PostMasterFilterObject->FilterHeadersGet();

NameExistsCheck()#

return 1 if another filter with this name already exists

$AlreadyExist = $PostMasterFilterObject->NameExistsCheck(
    Name => 'filter1', # mandatory
);