summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/Message/Language.pm
blob: 4f49a2560e7e1be8dbcfa3806c20d1f9f2cb2b82 (plain)
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
#-*- perl -*-
#
# Copyright (C) 2003,2004,2005 Ken'ichi Fukamachi
#
# $FML: Language.pm,v 1.5 2004/07/23 13:16:44 fukachan Exp $
#

package Mail::Message::Language;
use strict;

=head1 NAME

Mail::Message::Language - handle *-Language: field.

=head1 SYNOPSIS

   use Mail::Message::Language;
   my $mh = new Mail::Message::Language;

=head1 DESCRIPTION

=head1 METHODS

=head2 accept_language_list()

return list of languages to accept as ARRAY_REF.

XXX THIS CLASS IS USED ONLY WITHIN Mail::Message CLASS.

=cut


# Descriptions: return list of languages to accept as ARRAY_REF.
#    Arguments: OBJ($self)
# Side Effects: none
# Return Value: ARRAY_REF
sub accept_language_list
{
    my ($self) = @_;
    my $header = $self->whole_message_header();
    my $buf1   = $header->get('Accept-Language')   || '';
    my $buf2   = $header->get('X-Accept-Language') || '';
    my $list   = [];

  LANG:
    for my $s (split(/\s*,\s*/, "$buf1 $buf2")) {
	if ($s =~ /^\s*ja/oi) {
	    push(@$list, 'ja');
	    last LANG;
	}
	elsif ($s =~ /^\s*en/oi) {
	    push(@$list, 'en');
	    last LANG;
	}
    }

    return $list;
}


=head1 CODING STYLE

See C<http://www.fml.org/software/FNF/> on fml coding style guide.

=head1 AUTHOR

Ken'ichi Fukamachi

=head1 COPYRIGHT

Copyright (C) 2003,2004,2005 Ken'ichi Fukamachi

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=cut


1;