This file is indexed.

/usr/share/otrs/Kernel/System/Spelling.pm is in otrs2 5.0.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# --
# Copyright (C) 2001-2016 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::System::Spelling;

use strict;
use warnings;
use utf8;

our @ObjectDependencies = (
    'Kernel::Config',
    'Kernel::System::Encode',
    'Kernel::System::FileTemp',
    'Kernel::System::Log',
);

=head1 NAME

Kernel::System::Spelling - spelling lib

=head1 SYNOPSIS

This module is the spellchecker backend wrapper of OTRS.
Currently, ispell and aspell are supported as spellchecker backends.

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create an object. Do not use it directly, instead use:

    use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $SpellingObject = $Kernel::OM->Get('Kernel::System::Spelling');

=cut

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    return $Self;
}

=item Check()

spelling check for some text

    my %Result = $SpellingObject->Check(
        Text          => 'Some Text to check.',
        SpellLanguage => 'en',
        RichText      => 1, # default: 0
    );

    # a result could be
    $Result{'SomeWordWithError'} = {
        Replace => [
            'SomeWord A',
            'SomeWord B',
            'SomeWord C',
        ],
        Line => 123,
    };

=cut

sub Check {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !defined $Param{Text} ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Need Text!"
        );
        return;
    }

    # default ignored words
    my @Ignore = qw(com org de net Cc www Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Sun Mon Tue Wed Thu Fri
        Sat Fwd Re DNS Date To Cc Bcc ca tm COM Co op netscape bcc jpg gif email Tel ie eg otrs suse redhat debian
        caldera php perl java html unsubscribe queue event day month year ticket
    );

    # get config object
    my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

    # spell checker config options
    my $SpellChecker = $ConfigObject->Get('SpellCheckerBin') || 'ispell';

    # add configured ignored words
    if ( ref $ConfigObject->Get('SpellCheckerIgnore') eq 'ARRAY' ) {
        for ( @{ $ConfigObject->Get('SpellCheckerIgnore') } ) {
            push @Ignore, $_;
        }
    }

    # don't correct emails
    $Param{Text} =~ s/<.+?\@.+?>//g;
    $Param{Text} =~ s/\s.+?\@.+?\s/ /g;

    # don't correct quoted text
    $Param{Text} =~ s/^>.*$//gm;

    # ispell encoding:
    if ( $SpellChecker =~ /ispell/ ) {
        $Param{Text} =~ s/ä/a"/g;
        $Param{Text} =~ s/ö/o"/g;
        $Param{Text} =~ s/ü/u"/g;
        $Param{Text} =~ s/Ä/A"/g;
        $Param{Text} =~ s/Ö/O"/g;
        $Param{Text} =~ s/Ü/U"/g;
        $Param{Text} =~ s/ß/sS/g;
    }

    # check if spell checker exists in file system
    if ( !-e $ConfigObject->Get('SpellCheckerBin') ) {
        $Self->{Error} = 1;
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Can't find spellchecker ("
                . $ConfigObject->Get('SpellCheckerBin') . "): $!",
        );
        return;
    }

    # add -a
    $SpellChecker .= ' -a ';

    # set dict
    if ( $Param{SpellLanguage} ) {
        $SpellChecker .= " -d $Param{SpellLanguage}";
    }

    # get spell output

    # write text to file and read it with (i|a)spell
    # - can't use IPC::Open* because it's not working with mod_perl* :-/
    my ( $FH, $TmpFile ) = $Kernel::OM->Get('Kernel::System::FileTemp')->TempFile();
    if ( !$FH ) {
        $Self->{Error} = 1;
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Can't write spell tmp text to $TmpFile: $!",
        );
        return;
    }

    # get encode object
    my $EncodeObject = $Kernel::OM->Get('Kernel::System::Encode');

    $EncodeObject->EncodeOutput( \$Param{Text} );
    print $FH $Param{Text};

    # aspell encoding
    if ( $SpellChecker =~ /aspell/ ) {
        $SpellChecker .= ' --encoding=utf-8';
    }

    # open spell checker
    my $Spell;
    if ( !open( $Spell, "-|", "$SpellChecker < $TmpFile" ) ) {    ## no critic
        $Self->{Error} = 1;
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Can't open spellchecker: $!",
        );
        return;
    }

    my $Output      = '';
    my $Lines       = 1;
    my $CurrentLine = 0;
    my %Data;
    while ( my $Line = <$Spell> ) {

        $CurrentLine++;

        # set utf8 stamp if running in utf8 mode
        $EncodeObject->EncodeInput( \$Line );

        # ispell encoding:
        if ( $SpellChecker =~ /ispell/ ) {
            $Line =~ s/a"/ä/g;
            $Line =~ s/o"/ö/g;
            $Line =~ s/u"/ü/g;
            $Line =~ s/A"/Ä/g;
            $Line =~ s/O"/Ö/g;
            $Line =~ s/U"/Ü/g;
            $Line =~ s/sS/ß/g;
        }

        # '#' words with no suggestions
        if ( $Line =~ /^# (.+?) .+?$/ ) {
            $Data{$CurrentLine} = {
                Word    => $1,
                Replace => '',
                Line    => $Lines,
            };
        }

        # '&' words with suggestions
        elsif ( $Line =~ /^& (.+?) .+?: (.*)$/ ) {
            my @Replace = split /, /, $2;
            $Data{$CurrentLine} = {
                Word    => $1,
                Replace => \@Replace,
                Line    => $Lines,
            };
        }

        # increase line count
        elsif ( $Line =~ /^\n$/ ) {
            $Lines++;
        }
    }

    # drop double words and add line of double word
    # bug#9914: only delete double words for non-wysiwyg spellchecker
    if ( !$Param{RichText} ) {
        my %DoubleWords;
        for ( sort { $a <=> $b } keys %Data ) {
            if ( $DoubleWords{ $Data{$_}->{Word} } ) {
                $DoubleWords{ $Data{$_}->{Word} }->{Line} .= "/" . $Data{$_}->{Line};
                delete $Data{$_};
            }
            else {
                $DoubleWords{ $Data{$_}->{Word} } = $Data{$_};
            }
        }
    }

    # remove ignored words
    for my $Word ( sort keys %Data ) {
        for my $IgnoreWord (@Ignore) {
            if (
                defined $Data{$Word}
                && $Data{$Word}->{Word}
                && $Data{$Word}->{Word} =~ /^$IgnoreWord$/i
                )
            {
                delete $Data{$Word};
            }
        }
    }

    close($Spell);

    return %Data;
}

=item Error()

check if spelling check returns a system error (read log backend for error message)

    my $TrueIfError = $SpellObject->Error();

=cut

sub Error {
    my ( $Self, %Param ) = @_;

    return $Self->{Error};
}

1;

=back

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (L<http://otrs.org/>).

This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.

=cut