home *** CD-ROM | disk | FTP | other *** search
/ ftp.f-secure.com / 2014.06.ftp.f-secure.com.tar / ftp.f-secure.com / support / hotfix / fsis / IS-SpamControl.fsfix / iufssc / lib / Mail / SpamAssassin / Locales.pm < prev    next >
Text File  |  2006-11-29  |  4KB  |  114 lines

  1. # <@LICENSE>
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements.  See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to you under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License.  You may obtain a copy of the License at:
  8. #     http://www.apache.org/licenses/LICENSE-2.0
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # </@LICENSE>
  15.  
  16. package Mail::SpamAssassin::Locales;
  17.  
  18. use strict;
  19. use warnings;
  20. use bytes;
  21.  
  22. use vars qw{
  23.   %charsets_for_locale
  24. };
  25.  
  26. ###########################################################################
  27.  
  28. # A mapping of known country codes to frequent charsets used therein.
  29. # note that the ISO and CP charsets will already have been permitted,
  30. # so only "unusual" charsets should be listed here.
  31. #
  32. # Country codes should be lowercase, charsets uppercase.
  33. #
  34. # A good listing is in /usr/share/config/charsets from KDE 2.2.1
  35. #
  36. %charsets_for_locale = (
  37.  
  38.   # Japanese: Peter Evans writes: iso-2022-jp = rfc approved, rfc 1468, created
  39.   # by Jun Murai in 1993 back when he didnt have white hair!  rfc approved.
  40.   # (rfc 2237) <-- by M$. 
  41.   'ja' => 'EUCJP JISX020119760 JISX020819830 JISX020819900 JISX020819970 '.
  42.     'JISX021219900 JISX021320001 JISX021320002 SHIFT_JIS SHIFTJIS '.
  43.     'ISO2022JP SJIS JIS7 JISX0201 JISX0208 JISX0212',
  44.  
  45.   # Korea
  46.   'ko' => 'EUCKR KSC56011987',
  47.  
  48.   # Cyrillic: Andrew Vasilyev notes CP866 is common (bug 2278)
  49.   'ru' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  50.   'ka' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  51.   'tg' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  52.   'be' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  53.   'uk' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  54.   'bg' => 'KOI8R KOI8U KOI8T ISOIR111 CP1251 GEORGIANPS CP1251 PT154 CP866',
  55.  
  56.   # Thai
  57.   'th' => 'TIS620',
  58.  
  59.   # Chinese (simplified and traditional).   Peter Evans writes: new government
  60.   # mandated chinese encoding = gb18030, chinese mail is supposed to be
  61.   # iso-2022-cn (rfc 1922?)
  62.   'zh' => 'GB1988 GB2312 GB231219800 GB18030 GBK BIG5HKSCS BIG5 EUCTW ISO2022CN',
  63.  
  64.   # Chinese Traditional charsets only
  65.   'zh.big5' => 'BIG5HKSCS BIG5 EUCTW',
  66.  
  67.   # Chinese Simplified charsets only
  68.   'zh.gb2312' => 'GB1988 GB2312 GB231219800 GB18030 GBK ISO2022CN',
  69. );
  70.  
  71. ###########################################################################
  72.  
  73. sub is_charset_ok_for_locales {
  74.   my ($cs, @locales) = @_;
  75.  
  76.   $cs = uc $cs; $cs =~ s/[^A-Z0-9]//g;
  77.   $cs =~ s/^3D//gs;        # broken by quoted-printable
  78.   $cs =~ s/:.*$//gs;            # trim off multiple charsets, just use 1st
  79.  
  80.   study $cs;
  81.   #warn "JMD $cs";
  82.  
  83.   # always OK (the net speaks mostly roman charsets)
  84.   return 1 if ($cs eq 'USASCII');
  85.   return 1 if ($cs =~ /^ISO8859/);
  86.   return 1 if ($cs =~ /^ISO10646/);
  87.   return 1 if ($cs =~ /^UTF/);
  88.   return 1 if ($cs =~ /^UCS/);
  89.   return 1 if ($cs =~ /^CP125/);
  90.   return 1 if ($cs =~ /^WINDOWS/);      # argh, Windows
  91.   return 1 if ($cs eq 'IBM852');
  92.   return 1 if ($cs =~ /^UNICODE11UTF[78]/);    # wtf? never heard of it
  93.   return 1 if ($cs eq 'XUNKNOWN'); # added by sendmail when converting to 8bit
  94.   return 1 if ($cs eq 'ISO');    # Magellan, sending as 'charset=iso 8859-15'. grr
  95.  
  96.   foreach my $locale (@locales) {
  97.     if (!defined($locale) || $locale eq 'C') { $locale = 'en'; }
  98.     $locale =~ s/^([a-z][a-z]).*$/$1/;    # zh_TW... => zh
  99.  
  100.     my $ok_for_loc = $charsets_for_locale{$locale};
  101.     next if (!defined $ok_for_loc);
  102.  
  103.     if ($ok_for_loc =~ /(?:^| )\Q${cs}\E(?:$| )/) {
  104.       return 1;
  105.     }
  106.   }
  107.  
  108.   return 0;
  109. }
  110.  
  111. 1;
  112.