/[suikacvs]/messaging/manakai/lib/Message/Header/Default.pm
Suika

Contents of /messaging/manakai/lib/Message/Header/Default.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Sun Jul 28 00:31:38 2002 UTC (22 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: before-dis2-200411, manakai-release-0-3-2, manakai-release-0-3-1, manakai-release-0-4-0, manakai-200612, msg-0-1, HEAD
Branch point for: branch-suikawiki-1, experimental-xml-parser-200401, stable
Changes since 1.7: +6 -6 lines
2002-07-28  Wakaba <w@suika.fam.cx>

	* Entity.pm (destination, sender): New methods.

1
2 =head1 NAME
3
4 Message::Header::Default --- Internet Messages -- Definition
5 for Default Namespace of Header Fields
6
7 =cut
8
9 package Message::Header::Default;
10 use strict;
11 use vars qw($VERSION);
12 $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
13 require Message::Header;
14
15 our %OPTION;
16
17 ## Case sensibility of field name
18 $OPTION{case_sensible} = 1;
19 #$OPTION{to_be_goodcase} = \&...;
20 $OPTION{n11n_name} = \&_name_n11n;
21 $OPTION{n11n_prefix} = \&_name_n11n;
22
23 ## Namespace URI of this namespace
24 $OPTION{namespace_uri} = 'urn:x-suika-fam-cx:msgpm:header:default';
25
26 ## Force & hyphened prefix name of this namespace (ex. "prefix-name")
27 $OPTION{use_ph_namespace} = 1;
28 $OPTION{namespace_phname} = 'default';
29 $OPTION{namespace_phname_goodcase} = 'default';
30
31 ## `Good' & dotted prefix name of this namespace (ex. "prefix.name", "prefix2.name")
32 $OPTION{namespace_good_prefix} = 'DEFAULT';
33
34 ## Sort fields (0 / 'alphabetic' / ref(CODE)
35 $OPTION{field_sort} = 0;
36
37 ## Field body data type (specified by package name)
38 $OPTION{value_type} = {
39 ':default' => ['Message::Field::Unstructured'],
40 };
41
42 ## mailto: URL safe level
43 $OPTION{uri_mailto_safe} = {
44 ## 1 all (no check) 2 no trace & bcc & from
45 ## 3 no sender's info 4 (default) (currently not used)
46 ## 5 only a few
47 ':default' => 1,
48 };
49
50 ##
51
52 $Message::Header::NS_phname2uri{$OPTION{namespace_phname}} = $OPTION{namespace_uri};
53 $Message::Header::NS_uri2phpackage{$OPTION{namespace_uri}} = __PACKAGE__;
54
55 ## $self->_goodcase ($namespace_package_name, $field_name, \%option)
56 sub _goodcase ($$$\%) {
57 no strict 'refs';
58 my $self = shift;
59 my ($nspack, $name, $option) = @_;
60 if (${$nspack.'::OPTION'}{goodcase}->{$name}) {
61 return ${$nspack.'::OPTION'}{goodcase}->{$name};
62 }
63 $name =~ s/(?:^|-)[a-z]/uc $&/ge;
64 $name;
65 }
66
67 sub _name_n11n ($$$) {
68 no strict 'refs';
69 my $self = shift;
70 my $nspack = shift;
71 my $name = shift;
72 unless (${$nspack.'::OPTION'}{case_sensible}) {
73 lc $name;
74 } else {
75 $name;
76 }
77 }
78
79 sub sort_good_practice ($$\@\%) {
80 my ($hdr, $array, $nspack, $option) = @_;
81 if ($option->{field_sort} eq 'good-practice') {
82 no strict 'refs';
83 my $order = ${ $nspack.'::OPTION' }{field_sort_good_practice_order};
84 my $mynsuri = ${ $nspack.'::OPTION' }{namespace_uri};
85 my $mynsprefix = ${ $nspack.'::OPTION' }{namespace_phname};
86 return sort {
87 if ($a->{ns} eq $b->{ns}) {
88 if ($a->{ns} eq $mynsuri) {
89 $order->{ $a->{name} } ||= 999;
90 $order->{ $b->{name} } ||= 999;
91
92 $order->{ $a->{name} } <=> $order->{ $b->{name} }
93 || $a->{name} cmp $b->{name};
94 } else { #($a->{ns} eq $b->{ns})
95 my $nspack = Message::Header::_NS_uri2package ($a->{ns});
96 my $sort = ${ $nspack.'::OPTION' }{field_sort};
97 if ($sort->{'good-practice'}) {
98 my $order = ${ $nspack.'::OPTION' }{field_sort_good_practice_order};
99 $order->{ $a->{name} } ||= 999;
100 $order->{ $b->{name} } ||= 999;
101
102 $order->{ $a->{name} } <=> $order->{ $b->{name} }
103 || $a->{name} cmp $b->{name};
104 } elsif ($sort->{alphabetic}) {
105 $a->{name} cmp $b->{name};
106 } else {
107 1; ## Isn't supported
108 }
109 }
110 } else { ## $a->{ns} ne $b->{ns}
111 if ($a->{ns} eq $mynsuri) {
112 my $bp = ($hdr->{ns}->{uri2phname}->{ $b->{ns} } || '~'.$b->{ns}).'-';
113 $bp =~ s/^\Q$mynsprefix\E-//;
114 $order->{ $a->{name} } ||= 999;
115 $order->{ $bp } ||= 999;
116
117 $order->{ $a->{name} } <=> $order->{ $bp }
118 || $a->{name} cmp $bp;
119 } elsif ($b->{ns} eq $mynsuri) {
120 my $ap = ($hdr->{ns}->{uri2phname}->{ $a->{ns} } || '~'.$a->{ns}).'-';
121 $ap =~ s/^\Q$mynsprefix\E-//;
122 $order->{ $ap } ||= 999;
123 $order->{ $b->{name} } ||= 999;
124
125 $order->{ $ap } <=> $order->{ $b->{name} }
126 || $ap cmp $b->{name};
127 } else {
128 my $ap = ($hdr->{ns}->{uri2phname}->{ $a->{ns} } || '~'.$a->{ns}).'-';
129 my $bp = ($hdr->{ns}->{uri2phname}->{ $b->{ns} } || '~'.$b->{ns}).'-';
130 $ap =~ s/^\Q$mynsprefix\E-//;
131 $bp =~ s/^\Q$mynsprefix\E-//;
132
133 $order->{ $ap } ||= 999;
134 $order->{ $bp } ||= 999;
135
136 $order->{ $ap } <=> $order->{ $bp }
137 || $ap cmp $bp;
138 }
139 }
140 } @$array;
141 }
142 @$array;
143 }
144
145 package Message::Header::XCGI;
146 our %OPTION = %Message::Header::Default::OPTION;
147 $OPTION{namespace_uri} = 'urn:x-suika-fam-cx:msgpm:header:http:cgi:x';
148 $OPTION{namespace_phname} = 'x-cgi';
149 $OPTION{namespace_phname_goodcase} = 'X-CGI';
150
151 $OPTION{case_sensible} = 0;
152 $OPTION{to_be_goodcase} = \&Message::Header::Default::_goodcase;
153
154 $Message::Header::NS_phname2uri{$OPTION{namespace_phname}} = $OPTION{namespace_uri};
155 $Message::Header::NS_uri2phpackage{$OPTION{namespace_uri}} = __PACKAGE__;
156
157
158 ##
159
160 require Message::Header::RFC822;
161 require Message::Header::HTTP;
162 require Message::Header::Message;
163
164 =head1 LICENSE
165
166 Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
167
168 This program is free software; you can redistribute it and/or modify
169 it under the terms of the GNU General Public License as published by
170 the Free Software Foundation; either version 2 of the License, or
171 (at your option) any later version.
172
173 This program is distributed in the hope that it will be useful,
174 but WITHOUT ANY WARRANTY; without even the implied warranty of
175 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176 GNU General Public License for more details.
177
178 You should have received a copy of the GNU General Public License
179 along with this program; see the file COPYING. If not, write to
180 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
181 Boston, MA 02111-1307, USA.
182
183 =head1 CHANGE
184
185 See F<ChangeLog>.
186 $Date: 2002/07/27 04:43:03 $
187
188 =cut
189
190 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24