/usr/share/perl5/Debian/L10n/Utils.pm is in dl10n 3.00.
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 | =head1 NAME
Debian::L10n::Utils - Utilities for the dl10n tools
=cut
package Debian::L10n::Utils;
use strict;
use utf8;
use Mail::Address;
use Date::Parse;
use Date::Format;
use Encode;
my $VERSION = "1.0"; # External Version Number
our %Status = (
todo => 0,
itt => 1,
rfr => 2,
itr => 3,
lcfc => 4,
bts => 5,
fix => 6,
done => 7,
hold => 8,
maj => 9,
);
our %Status_syn = (
ddr => 'rfr',
relu => 'lcfc',
lfcf => 'lcfc', #this seems to be a current typo
taf => 'todo',
);
our %Type_syn = (
'debian-installer' => 'podebconf', # debian-installer is a sub-category
'debconf-po' => 'podebconf', # typo
'po-debconf' => 'podebconf', # That's the way it should be witten in DB
'po-man' => 'man', # nobody uses po4a so far, but it may come
);
our %LanguageList = (
ar => 'arabic',
ca => 'catalan',
cs => 'czech',
de => 'german',
en => 'english',
es => 'spanish',
fr => 'french',
gl => 'galician',
nl => 'dutch',
# pt => 'portuguese',
pt_BR => 'portuguese',
ro => 'romanian',
ru => 'russian',
sk => 'slovak',
sv => 'swedish',
tr => 'turkish',
);
our %Language = (
ar => 'arabic',
ca => 'catalan',
cs => 'czech',
de => 'german',
en => 'english',
es => 'spanish',
fr => 'french',
gl => 'galician',
nl => 'dutch',
# pt => 'portuguese',
pt_BR => 'brazilian',
ro => 'romanian',
ru => 'russian',
sk => 'slovak',
sv => 'swedish',
tr => 'turkish',
);
=head2 parse_subject(SUBJECT)
parse_subject extract valuable informations from a subject line.
It gets a string containing the subject line (SUBJECT).
It returns an array containing the status, type, filename strings and bug
number if provided or 'undef' if no status is found.
=cut
sub parse_subject($) {
my $subject = shift;
$subject =~ s/^Subject: //;
$subject =~ s/ / /;
$subject =~ m/^\p{IsSpace}*\[([^\]]*)\].*?([^:\p{IsSpace}]*):\/\/(\P{IsSpace}*)(.*)$/;
return undef unless $1;
my $status = lc $1;
my $type = lc $2;
my $names = $3;
my $subject_end = $4;
# Mutt split long subject and can introduce tabulations even if there were no spaces.
# We remove the tabulations if inside {}, which deals with most of the long subjects.
while ( defined $subject_end
and $names =~ m/\{[^\}]*$/
and $subject_end =~ m/^\t+(\S*)(.*)\}(.*)$/) {
$names .= $1;
$subject_end = $2."\}".$3;
}
if (defined $subject_end) {
if ($subject_end =~ m/^(\S+)/) {
$names .= $1;
}
}
$status =~ s/\p{IsSpace}//g;
$status =~ s/#?\p{IsDigit}*$//;
$status = $Status_syn{$status} if (defined $Status_syn{$status} && defined $Status{$Status_syn{$status}});
return undef unless defined $Status{$status};
$type = $Type_syn{$type} if defined $Type_syn{$type};
$subject =~ m/#\p{IsSpace}*(\p{IsDigit}+)/;
my $bug_nb = $1 || undef;
my @names;
if ($names =~ m/{/) {
$names =~ m/^([^{]*){([^}]*)}(.*)$/;
my $begin = $1 || "";
my $end = $3 || "";
if (defined $2) {
@names = map { "$begin$_$end" } split(/,/, $2);
} else {
warn "Could not parse Subject: '$subject'\n";
}
} else {
@names = ($names);
}
# print "Status='$status'; Type='$type'; ". (defined $bug_nb ? "bug_nb='$bug_nb'":"[no bug]")."\n";
return ($status, $type, $bug_nb, @names);
}
=head2 parse_from(FROM)
parse_from extract the sender name from the 'From:' field.
The name is build from the phrase part of the field, or if none is found, from
the comment part where parentheses are removed, or if none is found, from the
address where all non-alphanumeric characters are turned into spaces.
It gets a string containing the 'From:' field (FROM).
It returns a string containing the name.
=cut
sub parse_from($) {
$_ = shift;
return "UNDEF" if not defined $_;
# No need to recode anything at this point, at least for the BTS
# # http://lists.debian.org/debian-l10n-english/2009/07/msg00039.html
# # Do not recode with a broken encoding
# unless ($_ =~ m/=?unknown-8bit?b?/) {
# Encode::from_to($_, 'MIME-Header', 'utf8');
# }
s/^From: //;
s/"//g;
s/;/SEMICOLON/g;
my @from = Mail::Address -> parse($_);
$_ = $from[0]->phrase;
s/SEMICOLON/;/g;
s/ ; /;/g;
unless ($_) {
$_ = $from[0]->comment;
s/^\p{IsSpace}*\(?//;
s/\)?\p{IsSpace}*$//;
s/SEMICOLON/;/g;
s/ ; /;/g;
}
unless ($_) {
$_ = $from[0]->address;
s/\P{IsAlnum}/ /g;
}
$_ =~ s/^\s*"(.*)"\s*$/$1/g;
return $_;
}
=head2 parse_date(DATE)
parse_date extract the date from a 'Date:' field.
It gets a string containing the 'Date:' field (DATE).
It returns a string containing the date in ISO format yyyy-mm-dd hh:mm:ss
±hh:mm based on GMT
=cut
sub parse_date($) {
my $d = shift;
my $date;
if ($d =~ m/^Date: (.*)$/) {
$date = Date::Format::time2str("%Y-%m-%d %T %z", Date::Parse::str2time($1), "GMT");
} else {
$date = Date::Format::time2str("%Y-%m-%d %T %z", $d, "GMT");
}
return $date;
}
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=head1 COPYRIGHT (C)
2003,2004 Tim Dijkstra
2004 Nicolas Bertolissio
2004 Martin Quinson
2008 Nicolas François
=cut
1;
|