perlfaq9 > 5.0150039 との差分

perlfaq9 5.0150039 と 5.6.1 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55
66=begin original
77
8perlfaq9 - Web, Email and Networking
8perlfaq9 - Networking ($Revision: 1.26 $, $Date: 1999/05/23 16:08:30 $)
99
1010=end original
1111
12perlfaq9 - Web、メール、ネットワーク
12perlfaq9 - ネットワーク ($Revision: 1.26 $, $Date: 1999/05/23 16:08:30 $)
1313
1414=head1 DESCRIPTION
1515
16=begin original
16このセクションでは、ネットワーク、インターネット、web に関する
17質問を扱っています。
1718
18This section deals with questions related to running web sites,
19=head2 My CGI script runs from the command line but not the browser. (500 Server Error)
19sending and receiving email as well as general networking.
2020
21=end original
21(私のCGIスクリプトはコマンドラインでは動くのだけど、ブラウザー上では動きません
22(500 Server Errorになります))
2223
23このセクションでは、web サイトの実行、メールの送受信、および一般的な
24ネットワークに関する質問を扱っています。
25
26=head2 Should I use a web framework?
27
28(web フレームワークを使うべき?)
29
3024=begin original
3125
32Yes. If you are building a web site with any level of interactivity
26If you can demonstrate that you've read the following FAQs and that
33(forms / users / databases), you
27your problem isn't something simple that can be easily answered, you'll
34will want to use a framework to make handling requests
28probably receive a courteous and useful reply to your question if you
35and responses easier.
29post it on comp.infosystems.www.authoring.cgi (if it's something to do
30with HTTP, HTML, or the CGI protocols). Questions that appear to be Perl
31questions but are really CGI ones that are posted to comp.lang.perl.misc
32may not be so well received.
3633
3734=end original
3835
39はい
36FAQの以下の部分を読んで、あなたの問題が簡単に答られるもので
40何らかのレベルの相互作用(フォームユーザー、データベース)を持つ web サイ
37ったなら、(HTTPHTMLやCGIプロコルに関するものなら)
41構築しているなら、リクエストとレスをより簡単に扱えるような
38comp.infosystems.www.authoring.cgiにポストすれば
42フレームワークを使いたいでしょう。
39有用なリプライが得られるでしょう。
40Perlに関する質問のように見えていても、実はCGIに関するものだというものが
41comp.lang.perl.miscに投稿されることがありますが、回答はついていません。
4342
44=begin original
43便利なFAQや関連するドキュメントを以下に挙げます:
4544
46If there is no interactivity then you may still want
45 CGI FAQ
47to look at using something like L<Template Toolkit|https://metacpan.org/module/Template>
46 http://www.webthing.com/tutorials/cgifaq.html
48or L<Plack::Middleware::TemplateToolkit>
49so maintenance of your HTML files (and other assets) is easier.
5047
51=end original
48 Web FAQ
49 http://www.boutell.com/faq/
5250
53相互作用がなくても、HTML ファイル(およびその他の資産)の管理をより
51 WWW Security FAQ
54簡単にするために
52 http://www.w3.org/Security/Faq/
55L<Template Toolkit|https://metacpan.org/module/Template> や
56L<Plack::Middleware::TemplateToolkit> のようなものを使いたいかもしれません。
5753
58=head2 Which web framework should I use?
54 HTTP Spec
59X<framework> X<CGI.pm> X<CGI> X<Catalyst> X<Dancer>
55 http://www.w3.org/pub/WWW/Protocols/HTTP/
6056
61(どの web フレームワークを使うべき?)
57 HTML Spec
58 http://www.w3.org/TR/REC-html40/
59 http://www.w3.org/pub/WWW/MarkUp/
6260
63=begin original
61 CGI Spec
62 http://www.w3.org/CGI/
6463
65There is no simple answer to this question. Perl frameworks can run everything
64 CGI Security FAQ
66from basic file servers and small scale intranets to massive multinational
65 http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt
67multilingual websites that are the core to international businesses.
6866
69=end original
67=head2 How can I get better error messages from a CGI program?
7068
71この質問への単純答えありません。
69(CGIプログラムから、もっとまともエラーメッセージを得るに?)
72Perl のフレームワークには、基本的なファイルサーバとスケールの小さい
73イントラネット用から国際ビジネスのコアとなる巨大国際多言語 web サイトまで
74あらゆるものがあります。
7570
7671=begin original
7772
78Below is a list of a few frameworks with comments which might help you in
73Use the CGI::Carp module. It replaces C<warn> and C<die>, plus the
79making a decision, depending on your specific requirements. Start by reading
74normal Carp modules C<carp>, C<croak>, and C<confess> functions with
80the docs, then ask questions on the relevant mailing list or IRC channel.
75more verbose and safer versions. It still sends them to the normal
76server error log.
8177
8278=end original
8379
84以下は、特定の要求に合わせて決定助けなるであろうコメント付き
80CGI::Carpモジュール使いましょ。このモジュールはC<warn>C<die>
85くつかフレムワーク一覧です。
81置き換えを行、さらに通常CarpモジュC<carp>、C<croak>、
86文書を読むこから始めて、それからるメーリングリストや IRC
82C<confess>いった数をより饒舌で安全なものに置き換えま
87チャンネル質問してください
83その出力は、サーバーの通常のエラーログ送られます
8884
89=over 4
85 use CGI::Carp;
86 warn "This is a complaint";
87 die "But this one is serious";
9088
91=item L<Catalyst>
89以下のCGI::Carpの使用例では、エラーをあなたの選択したファイルへリダイレクトし、
90コンパイル時の警告も同様に補足するためにBEGINブロックに
91置いています:
9292
93=begin original
93 BEGIN {
94 use CGI::Carp qw(carpout);
95 open(LOG, ">>/var/local/cgi-logs/mycgi-log")
96 or die "Unable to append to mycgi-log: $!\n";
97 carpout(*LOG);
98 }
9499
95Strongly object-oriented and fully-featured with a long development history and
100深刻なエラーをクライアントのブラウザーに戻すように変更することもできます。
96a large community and addon ecosystem. It is excellent for large and complex
101これはあなたがデバッグするには良いでしょうが、エンドユーザーを
97applications, where you have full control over the server.
102混乱させてしまうかもしれません。
98103
99=end original
104 use CGI::Carp qw(fatalsToBrowser);
105 die "Bad error here";
100106
101長い開発の歴史と大きなコミュニティおよびアドオン生態系を持ち、
102強力にオブジェクト指向で完全な機能があります。
103サーバに対する完全な制御がある場所での大きく複雑なアプリケーションには
104素晴らしいものです。
105
106=item L<Dancer>
107
108107=begin original
109108
110Young and free of legacy weight, providing a lightweight and easy to learn API.
109Even if the error happens before you get the HTTP header out, the module
111Has a growing addon ecosystem. It is best used for smaller projects and
110will try to take care of this to avoid the dreaded server 500 errors.
112very easy to learn for beginners.
111Normal warnings still go out to the server error log (or wherever
112you've sent them with C<carpout>) with the application name and date
113stamp prepended.
113114
114115=end original
115116
116新しくレガシー重みから解放されていて、軽量で学習しやすい API 提供ます。
117たがHTTPヘッダー受け取るよりも前にエラーが起こったとても、
117アドオン生態系大きくなつつあります。
118モジュールサーバーの500エラーを避けるためにそのエラーを取扱おうと
118より小さいプロジェクトに最適で初心者が学習するのはとても簡単
119するでしょう
120通常の警告はサーバーのエラーログ(もしくはあなたがC<carpout>で指定した場所)に
121アプリケーションの名前と日付を伴って送られます。
119122
120=item L<Mojolicious>
123=head2 How do I remove HTML from a string?
121124
125(ある文字列からHTMLを取り除くには?)
126
122127=begin original
123128
124Fairly young with a focus on HTML5 and real-time web technologies such as
129The most correct way (albeit not the fastest) is to use HTML::Parser
125WebSockets.
130from CPAN. Another mostly correct
131way is to use HTML::FormatText which not only removes HTML but also
132attempts to do a little simple formatting of the resulting plain text.
126133
127134=end original
128135
129比較的若く、HTML5 と WebSockets のようなリアルタイム web 技術に焦点
136(最速ではありませんが)最も正しい方法はCPANにあるHTML::Parser
130当ててす。
137使うとうものです。
138もう一つのまず正しい方法は、HTML::FormatText を使って HTML を
139取り除くだけでなく、結果のプレーンテキストを簡単に整形することです。
131140
132=item L<Web::Simple>
141多くの人が、C<< s/<.*?>//g >>のような単純な(simple-minded)正規表現を
142使ったアプローチを行おうとするのですが、これは多くの場合
143失敗していまいます。なぜなら、タグは行をまたがって継続する可能性があり、
144クォートされたアングルブラケットを含む可能性があり、
145HTML のコメントがあるかもしれないからです。
146さらに、人々はC<&lt;>のようなエンティティを変換することを忘れてしまうのです。
133147
134=begin original
148以下の例は “単純な”アプローチで、ほとんどのファイルに対しては
149うまくいきます:
135150
136Currently experimental, strongly object-oriented, built for speed and intended
151 #!/usr/bin/perl -p0777
137as a toolkit for building micro web apps, custom frameworks or for tieing
152 s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
138together existing Plack-compatible web applications with one central dispatcher.
139153
140=end original
154もし、より完璧な解決策を求めているのなら、
155http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz
156にある 3-stage striphtml プログラムを参照してみてください。
141157
142現在の所実験的で、強力にオブジェクト指向で、速度重視で構築されており、
143ごく小さい web アプリやカスタムフレームワークを構築したり、
144既存の Plack 互換の web アプリケーションを一つの中央ディスパッチャと
145結びつけることを意図しています。
146
147=back
148
149158=begin original
150159
151All of these interact with or use L<Plack> which is worth understanding
160Here are some tricky cases that you should think about when picking
152the basics of when building a website in Perl (there is a lot of useful
161a solution:
153L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>).
154162
155163=end original
156164
157これら全て L<Plack> を使うか相互作用しておりPerl web サイトを
165以下に挙げたのは、あなたが自分やろうとしたときに
158構築るとは基本を理解する価値がります (多くの有用
166考慮ろうトリッキー例です:
159L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware> が
160あります)。
161167
162=head2 What is Plack and PSGI?
168 <IMG SRC = "foo.gif" ALT = "A > B">
163169
164(Plack PSGI って何?)
170 <IMG SRC = "foo.gif"
171 ALT = "A > B">
165172
166=begin original
173 <!-- <A comment> -->
167174
168L<PSGI> is the Perl Web Server Gateway Interface Specification, it is
175 <script>if (a<b && a>c)</script>
169a standard that many Perl web frameworks use, you should not need to
170understand it to build a web site, the part you might want to use is L<Plack>.
171176
172=end original
177 <# Just data #>
173178
174L<PSGI> Perl Web Server Gateway Interface Specification です; これは多くの
179 <![INCLUDE CDATA [ >>>>>>>>>>>> ]]>
175Perl web フレームワークが使う標準で、web サイトを構築するためにこれを
176理解する必要はないはずです; 使いたい部分は L<Plack> でしょう。
177180
178181=begin original
179182
180L<Plack> is a set of tools for using the PSGI stack. It contains
183If HTML comments include other tags, those solutions would also break
181L<middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>
184on text like this:
182components, a reference server and utilities for Web application frameworks.
183Plack is like Ruby's Rack or Python's Paste for WSGI.
184185
185186=end original
186187
187L<Plack> は PSGI タックを使ためツール集合す。
188以下のテキトのよにHTMLコメントが他タグを含んいた場合には、
188これには Web アプリケーションフレームワークための
189せっかく対応策もダメにしてしまうかもしれません:
189L<ミドルウェア|https://metacpan.org/search?q=plack%3A%3Amiddleware> 要素、
190リファレンスサーバ、ユーティリティを含みます。
191Plack は Ruby の Rack や Python の WSGI のための Paste に似ています。
192190
193=begin original
191 <!-- This section commented out.
192 <B>You can't see me!</B>
193 -->
194194
195You could build a web site using L<Plack> and your own code,
195=head2 How do I extract URLs?
196but for anything other than a very basic web site, using a web framework
197(that uses L<Plack>) is a better option.
198196
199=end original
197(URLの展開を行うには?)
200198
201L<Plack> と独自のコードを使って web サイトを構築するともきまが、
199素早いけど完璧ではないやり方はです
202とても基本的な web サイト以外のものなら、(L<Plack> を使った) web
203フレームワークを使うのがよりよい選択肢です。
204200
205=head2 How do I remove HTML from a string?
201 #!/usr/bin/perl -n00
202 # qxurl - tchrist@perl.com
203 print "$2\n" while m{
204 < \s*
205 A \s+ HREF \s* = \s* (["']) (.*?) \1
206 \s* >
207 }gsix;
206208
207(ある文字列から HTML を取り除くには?)
208
209209=begin original
210210
211Use L<HTML::Strip>, or L<HTML::FormatText> which not only removes HTML
211This version does not adjust relative URLs, understand alternate
212but also attempts to do a little simple formatting of the resulting
212bases, deal with HTML comments, deal with HREF and NAME attributes
213plain text.
213in the same tag, understand extra qualifiers like TARGET, or accept
214URLs themselves as arguments. It also runs about 100x faster than a
215more "complete" solution using the LWP suite of modules, such as the
216http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz program.
214217
215218=end original
216219
217L<HTML::Strip>使うか、HTML を取り除くだけでなく結果プレーテキス
220これは相対URLを扱うことができず、alternate base理解できず、HTML のコメント
218少し単純な形式しようとす L<HTML::FormatText> を使ってくださ
221同じタグるHREFやNAMEとったアトリビュートを扱うことができませんし、
222TARGET のような追加の修飾子を理解せず、
223URL自身を引数として受け取ることができません。
224これは
225http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz
226のような、LWPスイートにあるモジュールを使っている、より“完全な”
227解決策よりも百倍の早さで実行されます。
219228
220=head2 How do I extract URLs?
229=head2 How do I download a file from the user's machine? How do I open a file on another machine?
221230
222(URL 展開行うには?)
231(ユーザーマシンからファイルダウンロードするには?
232別のマシンにあるファイルをオープンするには?)
223233
224=begin original
234HTMLフォームのコンテキストにあるのならば、B<multipart/form-data>
235エンコーディングとして知られているものを使うことができるでしょう。
236CGI.pmモジュール(CPANで入手可能です)はこれを start_multipart_form()
237というstarform()メソッドとは異なるメソッドでサポートしています。
225238
226L<HTML::SimpleLinkExtor> will extract URLs from HTML, it handles anchors,
239=head2 How do I make a pop-up menu in HTML?
227images, objects, frames, and many other tags that can contain a URL.
228If you need anything more complex, you can create your own subclass of
229L<HTML::LinkExtor> or L<HTML::Parser>. You might even use
230L<HTML::SimpleLinkExtor> as an example for something specifically
231suited to your needs.
232240
233=end original
241(HTMLでポップアップメニューを作るには?)
234242
235L<HTML::SimpleLinkExtor> は HTML から URL を抽出します; これはアンカー、
236イメージ、オブジェクト、フレームおよび URL を含んでいるその他の多くのタグを
237扱います。
238より複雑なものが必要なら、独自の L<HTML::LinkExtor> や L<HTML::Parser> の
239サブクラスを作ることができます。
240何か特別な用途に合わせるための例として L<HTML::SimpleLinkExtor> を使うことも
241できます。
242
243243=begin original
244244
245You can use L<URI::Find> to extract URLs from an arbitrary text document.
245Use the B<< <SELECT> >> and B<< <OPTION> >> tags. The CGI.pm
246module (available from CPAN) supports this widget, as well as many
247others, including some that it cleverly synthesizes on its own.
246248
247249=end original
248250
249任意のテキスト文書から URL を抽出するためには、L<URI::Find> 使ます。
251B<< <SELECT> >> タグと B<< <OPTION> >> タグを使ます。
252CGI.pmモジュール(CPANから入手可能です)はこのウィジェットを他の多くのものと同様、
253独自のメニューを器用に統合しているものを含めてサポートしています。
250254
255
251256=head2 How do I fetch an HTML file?
252257
253(HTML ファイルをフェッチするには?)
258(HTMLファイルをフェッチするには?)
254259
255=begin original
260一つのやり方は、あなたがlynxというテキストベースのHTMLブラウザーを
261インストールしているとすれば、次のようなものです:
256262
257(contributed by brian d foy)
263 $html_code = `lynx -source $url`;
264 $text_data = `lynx -dump $url`;
258265
259=end original
260
261(brian d foy によって寄贈されました)
262
263266=begin original
264267
265Use the libwww-perl distribution. The L<LWP::Simple> module can fetch web
268The libwww-perl (LWP) modules from CPAN provide a more powerful way
266resources and give their content back to you as a string:
269to do this. They don't require lynx, but like lynx, can still work
270through proxies:
267271
268272=end original
269273
270libwww-perl ディストリビューション使ってください。
274CPANで入手できる libwww-perl (LWP)モジュールはこれ行う、
271L<LWP::Simple> はウェブ上のリソースをェッチして、その内容文字列と
275よりパワルな方法提供ます。
272します:
276これは lynx を必要とせず、プロキシ越でも使えます:
273277
274 use LWP::Simple qw(get);
278 # 最も単純なバージョン
279 use LWP::Simple;
280 $content = get($URL);
275281
276 my $html = get( "http://www.example.com/index.html" );
282 # もしくはURLからHTMLを出力する
283 use LWP::Simple;
284 getprint "http://www.linpro.no/lwp/";
277285
278=begin original
286 # もしくはあるURLのHTMLからASCIIを印字する
287 # HTML-Treeパッケージも必要です。
288 use LWP::Simple;
289 use HTML::Parser;
290 use HTML::FormatText;
291 my ($html, $ascii);
292 $html = get("http://www.perl.com/");
293 defined $html
294 or die "Can't fetch HTML from http://www.perl.com/";
295 $ascii = HTML::FormatText->new->format(parse_html($html));
296 print $ascii;
279297
280It can also store the resource directly in a file:
281
282=end original
283
284リソースを直接ファイルに保存することもできます:
285
286 use LWP::Simple qw(getstore);
287
288 getstore( "http://www.example.com/index.html", "foo.html" );
289
290=begin original
291
292If you need to do something more complicated, you can use
293L<LWP::UserAgent> module to create your own user-agent (e.g. browser)
294to get the job done. If you want to simulate an interactive web
295browser, you can use the L<WWW::Mechanize> module.
296
297=end original
298
299もっと複雑なことをする必要がある場合は、仕事を行うための独自の
300ユーザーエージェント(例えばブラウザ)を作るために
301L<LWP::UserAgent> モジュールを使えます。
302対話的なウェブブラウザをシミュレートしたい場合は、
303L<WWW::Mechanize> モジュールが使えます。
304
305298=head2 How do I automate an HTML form submission?
306299
307(HTML フォームの処理を自動化するには?)
300(HTMLフォームの処理を自動化するには?)
308301
309=begin original
302GETメソッドを使って値を処理しているのであれば、URLを作って、
303さらにC<query_form>メソッドを使ってフォームをエンコードします:
310304
311If you are doing something complex, such as moving through many pages
312and forms or a web site, you can use L<WWW::Mechanize>. See its
313documentation for all the details.
314
315=end original
316
317もし、複数のページとフォームや web サイトを移動するような、複雑なことを
318しようとしているなら、L<WWW::Mechanize> が使えます。
319全ての詳細についてはこれのドキュメントを参照してください。
320
321=begin original
322
323If you're submitting values using the GET method, create a URL and encode
324the form using the C<query_form> method:
325
326=end original
327
328GET メソッドを使って値を処理しているのであれば、URL を作って、
329さらに C<query_form> メソッドを使ってフォームをエンコードします:
330
331305 use LWP::Simple;
332306 use URI::URL;
333307
334 my $url = url('L<http://www.perl.com/cgi-bin/cpan_mod')>;
308 my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
335309 $url->query_form(module => 'DB_File', readme => 1);
336310 $content = get($url);
337311
338=begin original
312POSTメソッドを使っているのであれば、自分用のエージェントを作成して
339
340If you're using the POST method, create your own user agent and encode
341the content appropriately.
342
343=end original
344
345POST メソッドを使っているのであれば、自分用のエージェントを作成して
346313コンテンツを適切にエンコードしてやります。
347314
348315 use HTTP::Request::Common qw(POST);
349316 use LWP::UserAgent;
350317
351 my $ua = LWP::UserAgent->new();
318 $ua = LWP::UserAgent->new();
352 my $req = POST 'L<http://www.perl.com/cgi-bin/cpan_mod'>,
319 my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
353320 [ module => 'DB_File', readme => 1 ];
354 my $content = $ua->request($req)->as_string;
321 $content = $ua->request($req)->as_string;
355322
356=head2 How do I decode or create those %-encodings on the web?
323=head2 how do I decode or create those %-encodings on the web?
357X<URI> X<URI::Escape> X<RFC 2396>
358324
359325(web上で %-encodings をデコードしたり生成したりするには?)
360326
361327=begin original
362328
363Most of the time you should not need to do this as
329If you are writing a CGI script, you should be using the CGI.pm module
364your web framework, or if you are making a request,
330that comes with perl, or some other equivalent module. The CGI module
365the L<LWP> or other module would handle it for you.
331automatically decodes queries for you, and provides an escape()
332function to handle encoding.
366333
367334=end original
368335
369ほとんどの場合、web フレームワーでこれ行う必要はないはずです;
336CGI リプト書いているのら、perl に付属してる CGI.pm モジュール
370リクエストを作っときに、L<LWP> やその他のモジュールが代わりにこれら
337たは等価なモジュールを使うべきです。
371扱います。
338CGI モジュールは自動的にクエリをデコードし、escape() 関数で
339エンコードもできます。
372340
373341=begin original
374342
375To encode a string yourself, use the L<URI::Escape> module. The C<uri_escape>
343The best source of detailed information on URI encoding is RFC 2396.
376function returns the escaped string:
344Basically, the following substitutions do it:
377345
378346=end original
379347
380自分で文字列をエンコーする、L<URI::Escape> モジュールを使ってください
348URI エンコーディングの詳細情報に関する最良のソース RFC 2396 です
381C<uri_escape> 関数エスケープされた文字列を返します:
349基本的に、以下の置換が実行されます:
382350
383 my $original = "Colon : Hash # Percent %";
351 s/([^\w()'*~!.-])/sprintf '%%%02x', $1/eg; # encode
384352
385 my $escaped = uri_escape( $original );
353 s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode
386354
387 print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25'
388
389355=begin original
390356
391To decode the string, use the C<uri_unescape> function:
357However, you should only apply them to individual URI components, not
358the entire URI, otherwise you'll lose information and generally mess
359things up. If that didn't explain it, don't worry. Just go read
360section 2 of the RFC, it's probably the best explanation there is.
392361
393362=end original
394363
395文字列をデコードするには、C<uri_unescape> 関数を使います:
364しかし、これ URI 全体ではなく個々の URI コンポーネントに
365対して適用するべきです。さもなければ、情報が失われ、
366ぐちゃぐちゃになります。
367これが説明になっていなくても、心配はいりません。
368RFC の第 2 章を読んでください。
369おそらくこの問題に関する最良の説明です。
396370
397 my $unescaped = uri_unescape( $escaped );
398
399 print $unescaped; # back to original
400
401371=begin original
402372
403Remember not to encode a full URI, you need to escape each
373RFC 2396 also contains a lot of other useful information, including a
404component separately and then join them together.
374regexp for breaking any arbitrary URI into components (Appendix B).
405375
406376=end original
407377
408URI 全体をエンコードするのではなく、そぞれ要素を別々エスケープして
378RFC 2396 にその他の有用情報が多含まています。そ
409それから互い結合する必要があること忘れないでください
379任意の URI をコンポーネント分割するための正規表現(Appendix B)含みます
410380
411381=head2 How do I redirect to another page?
412382
413383(別のページにリダイレクトするには?)
414384
415385=begin original
416386
417Most Perl Web Frameworks will have a mechanism for doing this,
387According to RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1", the
418using the L<Catalyst> framework it would be:
388preferred method is to send a C<Location:> header instead of a
389C<Content-Type:> header:
419390
420391=end original
421392
422ほとんどの Perl Web フレームワークはこれを行う機構があります; L<Catalyst>
393RFC 2616 "Hypertext Transfer Protocol -- HTTP/1.1" によれば、
423フレームワークを使ってるなら以下ようになます:
394好まし手法は C<Content-Type:> ヘッダ代わに C<Location:> ヘッダを
395送ることです:
424396
425 $c->res->redirect($url);
397 Location: http://www.domain.com/newpage
426 $c->detach();
427398
428399=begin original
429400
430If you are using Plack (which most frameworks do), then
401Note that relative URLs in these headers can cause strange effects
431L<Plack::Middleware::Rewrite> is worth looking at if you
402because of "optimizations" that servers do.
432are migrating from Apache or have URL's you want to always
433redirect.
434403
435404=end original
436405
437(ほとんどフレムワークが使っている) Plack使っていて
406これらヘッダに相対 URL指定するとサーバーが行う“最適化”のために
438Apache からの移動や常にリダイレクトしたい URL があるなら、
407奇妙な効果を引き起こす可能性があることに注意してください。
439L<Plack::Middleware::Rewrite> は見る価値があるでしょう。
408
409 $url = "http://www.perl.com/CPAN/";
410 print "Location: $url\n\n";
411 exit;
440412
441=head2 How do I put a password on my web pages?
442
443(私の web ぺージでパスワードを入力するには?)
444
445413=begin original
446414
447See if the web framework you are using has an
415To target a particular frame in a frameset, include the "Window-target:"
448authentication system and if that fits your needs.
416in the header.
449417
450418=end original
451419
452使っている web フレームクが認証システムを持っていそしてそれが
420フレームセットの特定のフレームを指定すには
453目的合致しているか調べてください
421ヘッダー "Window-target:" 含めます
454422
423 print <<EOF;
424 Location: http://www.domain.com/newpage
425 Window-target: <FrameName>
426
427 EOF
428
455429=begin original
456430
457Alternativly look at L<Plack::Middleware::Auth::Basic>,
431To be correct to the spec, each of those virtual newlines should
458or one of the other L<Plack authentication|https://metacpan.org/search?q=plack+auth>
432really be physical C<"\015\012"> sequences by the time your message is
459options.
433received by the client browser. Except for NPH scripts, though, that
434local newline should get translated by your server into standard form,
435so you shouldn't have a problem here, even if you are stuck on MacOS.
436Everybody else probably won't even notice.
460437
461438=end original
462439
463は、L<Plack::Middleware::Auth::Basic> まはその他の
440仕様を正確に達成すは、クライアントブラウザからメッセージを受け取っ時点で
464L<Plack 認証|https://metacpan.org/search?q=plack+auth> オプション
441全て仮想的な改行にいてC<"\015\012">に置き換えるべきです。
465見てくださ
442しかし、NPH スクリプトを除て、このようなローカルな改行は
443サーバーによって標準的な形式に変換されることが多いので、
444MacOS ではまっていた場合でも問題にはならないことが多いでしょう。
445それ以外ではおそらく誰も気付きすらしないでしょう。
466446
467=head2 How do I make sure users can't enter values into a form that causes my CGI script to do bad things?
447=head2 How do I put a password on my web pages?
468448
469(私の CGI クリプトに悪影響をもたらすようなものを、ユザーがフォームに入力できないようにするには?)
449(私のwebぺージでパドを入力するには?)
470450
471=begin original
451状況によります。あなたの使っているwebサーバーのドキュメントを読む
452必要があるでしょうし、先に例示した他のFAQの幾つかをチェックする
453必要もあるでしょう。
472454
473(contributed by brian d foy)
455=head2 How do I edit my .htpasswd and .htgroup files with Perl?
474456
475=end original
457(Perlを使って.htpasswdや.htgroupといったファイルを編集するには?)
476458
477(brian d foy によって寄贈されました)
459HTTPD::UserAdmin モジュールと HTTPD::GroupAdmin モジュールは、
460ファイルがどのように格納されているかに関係なくこれらのファイルに対する
461首尾一貫したオブジェクト指向インターフェースを提供します。
462HTTPD::UserAdmin は`Basic' および `Digest' 認証スキームで
463使われるファイルをサポートします。以下に例を挙げます:
478464
479=begin original
465 use HTTPD::UserAdmin ();
466 HTTPD::UserAdmin
467 ->new(DB => "/foo/.htpasswd")
468 ->add($username => $password);
480469
481You can't prevent people from sending your script bad data. Even if
470=head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things?
482you add some client-side checks, people may disable them or bypass
483them completely. For instance, someone might use a module such as
484L<LWP> to submit to your web site. If you want to prevent data that
485try to use SQL injection or other sorts of attacks (and you should
486want to), you have to not trust any data that enter your program.
487471
488=end original
472(私のCGIスクリプトに悪影響をもたらすようなものを、ユーザーが
473フォームに入力できないようにするにはどうするのでしょうか?)
489474
490人々がスクリプトに悪いデータを送るのを防ぐことは出来ません。
475http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html,
491例えクライアント側でチェックしたとしても、れを無効にたり
476にある CGI セキュリティ FAQ読んでください。そし
492完全に回避したりできます。
477http://www.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html.
493例えば、L<LWP> のようなモジュールを使って web サイトに
478にあるPerl/CGI FAQを読んでください。
494投稿するかもしれません。
495SQL インジェクションや同様の種類の攻撃を行うようなデータを防ぎたいのなら
496(そしておそらくそうしたいでしょう)、プログラムに入力される
497どんなデータも信用しないようにする必要があります。
498479
499=begin original
480まとめ: スクリプトの外側(たとえばCGIパラメーター)からやってくる
481データを使ってC<eval>やC<system>を使わないようにさせる汚染検査
482(tainting、L<perlsec>を参照してください)を使います。汚染検査に加え、
483一引数形式の system() や exec() を決して使わないようにします。
484その代わりに、シェルのグロビングが行われないように、
485リストとしてコマンドと引数とを与えるようにします。
500486
501The L<perlsec> documentation has general advice about data security.
487=head2 How do I parse an mail header?
502If you are using the L<DBI> module, use placeholder to fill in data.
503If you are running external programs with C<system> or C<exec>, use
504the list forms. There are many other precautions that you should take,
505too many to list here, and most of them fall under the category of not
506using any data that you don't intend to use. Trust no one.
507488
508=end original
509
510L<perlsec> 文書にはデータセキュリティに関する一般的な助言があります。
511L<DBI> モジュールを使っているなら、データを埋めるのにプレースホルダを
512使ってください。
513C<system> や C<exec> で外部プログラムを実行しているなら、リスト形式を
514使ってください。
515その他、ここに書ききれないほどの注意するべき多くの事前注意があり、
516そのほとんどは、使おうとしていないデータは使わないという分野に当てはまります。
517誰も信用しないでください。
518
519=head2 How do I parse a mail header?
520
521489(メールのヘッダーを解析するには?)
522490
523=begin original
491拙速な解決策なら、L<perlfunc/split> から派生した
492以下のやり方を試してみてください。
524493
525Use the L<Email::MIME> module. It's well-tested and supports all the
494 $/ = '';
526craziness that you'll see in the real world (comment-folding whitespace,
495 $header = <MSG>;
527encodings, comments, etc.).
496 $header =~ s/\n\s+/ /g; # 継続行を連結する
497 %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );
528498
529=end original
499このやり方は、たとえば受信した行すべてを保守しようとするときには
500うまくありません。より完璧なアプローチはCPANにあるMail::Header
501モジュールを使うというものです(このモジュールはMailToolsパッケージの
502一部です)。
530503
531L<Email::MIME> モジュールを使ってください。
504=head2 How do I decode a CGI form?
532これはよくテストされていて、現実世界で見ることになるあらゆる狂気
533(コメント畳み込み空白、エンコーディング、コメントなど)に対応しています。
534505
535 use Email::MIME;
506(CGIフォームをデコードするには?)
536507
537 my $message = Email::MIME->new($rfc2822);
538 my $subject = $message->header('Subject');
539 my $from = $message->header('From');
540
541508=begin original
542509
543If you've already got some other kind of email object, consider passing
510You use a standard module, probably CGI.pm. Under no circumstances
544it to L<Email::Abstract> and then using its cast method to get an
511should you attempt to do so by hand!
545L<Email::MIME> object:
546512
547513=end original
548514
549既に何らか他の種類のメールオブジェクトがあるならそれ
515標準モジュール、多分CGI.pm使うとよいでしょう。
550L<Email::Abstract> に渡して、それから L<Email::MIME> オブジェクトを
516あなたが手作業で行うことは多分ありません!
551得るために cast メソッドを使うことを考慮してください:
552517
553 my $mail_message_object = read_message();
554 my $abstract = Email::Abstract->new($mail_message_object);
555 my $email_mime_object = $abstract->cast('Email::MIME');
556
557=head2 How do I check a valid mail address?
558
559(メールアドレスが正しいかチェックするには?)
560
561518=begin original
562519
563(partly contributed by Aaron Sherman)
520You'll see a lot of CGI programs that blindly read from STDIN the number
521of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
522decoding GETs. These programs are very poorly written. They only work
523sometimes. They typically forget to check the return value of the read()
524system call, which is a cardinal sin. They don't handle HEAD requests.
525They don't handle multipart forms used for file uploads. They don't deal
526with GET/POST combinations where query fields are in more than one place.
527They don't deal with keywords in the query string.
564528
565529=end original
566530
567(一部 Aaron Sherman よって寄贈されました)
531あなたPOST対するCONTENT_LENGTHと同じだけのバイトを標準入力から
532闇雲に読み込んだり、GETをデコードするためにQUERY_STRINGを取り込んでいるような
533CGIプログラムを見ることになるでしょう。
534これらのプログラムは非常にまずい書き方をされていて、
535部分的にしか動作しません。これらのプログラムで典型的なものは、
536read()システムコールの戻り値をチェックするのを忘れていたりします。
537それは大きな罪なのです。また、HEADリクエストを
538取り扱っていなかったりする場合もありますし、
539ファイルのアップロードに使われる
540マルチパート形式を扱ってないこともあります。
541あるいは二ヶ所以上で
542問い合わせフィールドがある場合のGET/POSTの組み合わせに対応していません。
543さらに問い合わせ文字列中にあるキーワードの扱いもしていません。
568544
569545=begin original
570546
571This isn't as simple a question as it sounds. There are two parts:
547In short, they're bad hacks. Resist them at all costs. Please do not be
548tempted to reinvent the wheel. Instead, use the CGI.pm or CGI_Lite.pm
549(available from CPAN), or if you're trapped in the module-free land
550of perl1 .. perl4, you might look into cgi-lib.pl (available from
551http://www.bio.cam.ac.uk/web/form.html).
572552
573553=end original
574554
575れは見た目ほど単純質問はありせん
555端的にいって、そ良くい hack す。行わないようにししょう
576二つの部分からります:
556どうか車輪を再発明するようないでください。
557代わりに、CGI.pm か CGI_Lite.pm (CPAN で入手できます)を使ってください。
558あなたが(モジュールを使うことのできない)perl1 〜 perl4 を使っているのなら、
559cgi-lib.pl を調べてみてください
560(http://cgi-lib.stanford.edu/cgi-lib/で入手可能です)
577561
578562=begin original
579563
580a) How do I verify that an email address is correctly formatted?
564Make sure you know whether to use a GET or a POST in your form.
565GETs should only be used for something that doesn't update the server.
566Otherwise you can get mangled databases and repeated feedback mail
567messages. The fancy word for this is ``idempotency''. This simply
568means that there should be no difference between making a GET request
569for a particular URL once or multiple times. This is because the
570HTTP protocol definition says that a GET request may be cached by the
571browser, or server, or an intervening proxy. POST requests cannot be
572cached, because each request is independent and matters. Typically,
573POST requests change or depend on state on the server (query or update
574a database, send mail, or purchase a computer).
581575
582576=end original
583577
584a) メルアドレスが正しい形式か検証するは?
578あなたのフォムで GET や POST どのよう使うかを良く知っておいてください。
579GET はサーバーを更新しないようなものに対してのみ使うべきです。
580あるいは、データベースをいじったりメールメッセージによるフィードバックを
581繰り返し行うようなこともできます。このことを表わすのにぴったりな
582単語は“idempotency”です。その意味は、GET リクエストを作り出したものと
583特定の URL とに違いがないということです。
584これはつまり、HTTP プロトコルは GET リクエストがブラウザーや
585サーバー、あるいは途中にあるプロクシーによってキャッシングしている
586可能性があることを定義しています。POST リクエストは
587キャッシュすることはできません。なぜなら呼び出しのそれぞれは
588独立したものであるからなのです。
589典型的な例では、POST リクエストはサーバーの状態を変更したり、
590状態に依存しています(データベースに対する問い合わせや更新、メールの送信、
591コンピューターの購入など)。
585592
593=head2 How do I check a valid mail address?
594
595(メールアドレスが正しいかチェックするには?)
596
586597=begin original
587598
588b) How do I verify that an email address targets a valid recipient?
599You can't, at least, not in real time. Bummer, eh?
589600
590601=end original
591602
592b) メールアドレスが正当受信者を対象しているかを検証するには?
603できません。少もリアルタイムで。がっかりしたでしょう?
593604
594605=begin original
595606
596Without sending mail to the address and seeing whether there's a human
607Without sending mail to the address and seeing whether it bounces (and
597on the other end to answer you, you cannot fully answer part I<b>, but
608even then you face the halting problem), you cannot determine whether
598the L<Email::Valid> module will do both part I<a> and part I<b> as far
609an email address is valid. Even if you apply the email header
599as you can in real-time.
610standard, you can have problems, because there are deliverable
611addresses that aren't RFC-822 (the mail header standard) compliant,
612and addresses that aren't deliverable which are compliant.
600613
601614=end original
602615
603616そのアドレスにメールを送ってそれが届いたかどうかを確認しなければ
604完全にパート I<b> に答えられません、C<Email::Valid>
617(そしてあなたそのhalting problemに直面したあとでさえも)、
605C<RFC::RFC822::Address> モジュールは、リルタイムる限りの
618のアドレスが正しいものかどうかを決めることはできません。
606ことに対してパト I<a> とパト I<b> 両方行います。
619あなたが電子メルヘッダーの標準適用したとしても、
620問題が起こる可能性があります。
621なぜなら、配達可能なアドレスには RFC-822(電子メールヘッダーの標準)に
622適合していないものがあり、適合していても配達できないアドレスも
623あるからです。
607624
608625=begin original
609626
610Our best advice for verifying a person's mail address is to have them
627Many are tempted to try to eliminate many frequently-invalid
611enter their address twice, just as you normally do to change a
628mail addresses with a simple regex, such as
612password. This usually weeds out typos. If both versions match, send
629C</^[\w.-]+\@(?:[\w-]+\.)+\w+$/>. It's a very bad idea. However,
613mail to that address with a personal message. If you get the message
630this also throws out many valid ones, and says nothing about
614back and they've followed your directions, you can be reasonably
631potential deliverability, so it is not suggested. Instead, see
615assured that it's real.
632http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz,
633which actually checks against the full RFC spec (except for nested
634comments), looks for addresses you may not wish to accept mail to
635(say, Bill Clinton or your postmaster), and then makes sure that the
636hostname given can be looked up in the DNS MX records. It's not fast,
637but it works for what it tries to do.
616638
617639=end original
618640
619私たちができる最善アドバイスは、個メールアドレスをチェックするのに
641多くの人が 不正メールアドレスを C</^[\w.-]+\@(?:[\w-]+\.)+\w+$/>
620パスワードを変更するときと同じようにユーザーにアドレスを
642ように単純な正規表現で削除しようとしています。しかしながら、
621二回入力させるというのです。
643これは正当なアドレス一緒に取り除いてしまい、
622これよっ通常は打ち間違を防ぐことができます。
644潜在的な到達性ついなにも言いません。でからこれはお薦めしません
623二回の入力がマッチしたなら個人的内容のメセージメールとして
645代わりに完全 RFC 仕様に突き合わせてチェ行い
624そのアドレへ送ります。
646(ネトしたコメントを除く)、
625もしメッセージが返ってきて、それがあなたの指示に従っている
647あなたが受け取りたくいメールアドレスを探し出し
626それ実際のものと十分に仮定できます。
648さらにホスト名 DNS 引けかどうかを確かめる
649http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz
650を参照してください。これは速くはありませんが、しかしきちんと動きます。
627651
628652=begin original
629653
630A related strategy that's less open to forgery is to give them a PIN
654Our best advice for verifying a person's mail address is to have them
631(personal ID number). Record the address and PIN (best that it be a
655enter their address twice, just as you normally do to change a password.
632random one) for later processing. In the mail you send, include a link to
656This usually weeds out typos. If both versions match, send
633your site with the PIN included. If the mail bounces, you know it's not
657mail to that address with a personal message that looks somewhat like:
634valid. If they don't click on the link, either they forged the address or
635(assuming they got the message) following through wasn't important so you
636don't need to worry about it.
637658
638659=end original
639660
640より偽造やりにくい別のやり方に、チェックに対象者に対して PIN (Personal ID
661私たちができる最善アドバイスは個人のメールアドレスをチェックするの
641Number) 与えるとものがあります。
662パスワード変更するときと同じよ
642後の処理のためにアドレスと PIN (ランダムであが望まし)を
663ユーザーにアドレスを二回入力させるというものです。
643記録しおくのです。
664これによっ通常は打ち間違いを防ぐことがきます。
644あなたメールを送るときに、PIN が含まれサイトへリンク
665二回の入力マッチしたなら、以下ような内容メッセージメールとして
645含めてください。
666そのアドレスへ送ります:
646メールがバウンスしたなら、不正であることが分かります。
647リンクがクリックされなければ、アドレスが偽造されたか、(メッセージが
648届いたとして) 最後まで行うことが重要ではなかったのでそれについて
649気にする必要はないと言うことです。
650667
651=head2 How do I decode a MIME/BASE64 string?
668 Dear someuser@host.com,
652669
653(MIME/BASE64 文字列のデコードを行うには?)
654
655670=begin original
656671
657The L<MIME::Base64> package handles this as well as the MIME/QP encoding.
672 Please confirm the mail address you gave us Wed May 6 09:38:41
658Decoding base 64 becomes as simple as:
673 MDT 1998 by replying to this message. Include the string
674 "Rumpelstiltskin" in that reply, but spelled in reverse; that is,
675 start with "Nik...". Once this is done, your confirmed address will
676 be entered into our records.
659677
660678=end original
661679
662L<MIME::Base64> パッケージはこの問題と、
680 [あなたがMDTの1998年5月6日(水)9時38分41秒に私たちに送ったメ
663MIME/QP エンコーディング取り扱います。
681 イルアドレスの確認して、このメッセージにリプライしてくださ
664BASE64 のデコード以下のよに単純です:
682 い。リプライに"Rumpelstiltskin" とい文字列を、"Nik..."の
683 ように逆順にして含めてください。それが済めば、あなたのアドレ
684 スの確認は終了し、私たちのレコードに入力されます。]
665685
666 use MIME::Base64;
686あなたがメッセージの返事を受け取り、そのメールの発信者があなたの
667 my $decoded = decode_base64($encoded);
687指示に従っていれば、そのアドレスが本物であると信じることができるでしょう。
668688
669689=begin original
670690
671The L<Email::MIME> module can decode base 64-encoded email message parts
691A related strategy that's less open to forgery is to give them a PIN
672transparently so the developer doesn't need to worry about it.
692(personal ID number). Record the address and PIN (best that it be a
693random one) for later processing. In the mail you send, ask them to
694include the PIN in their reply. But if it bounces, or the message is
695included via a ``vacation'' script, it'll be there anyway. So it's
696best to ask them to mail back a slight alteration of the PIN, such as
697with the characters reversed, one added or subtracted to each digit, etc.
673698
674699=end original
675700
676L<Email::MIME> モジュールは BASE64 でエンコードされたメールセージ部分を
701より偽造やりにくい別のやり方に、チェクに対象者に対してPIN
677透過的にデコードできので、開発者はそれにつて気にする必要はありません
702(Personal ID Number)を与えうものがありま
703後の処理のためにアドレスとPIN(ランダムであることが望ましい)を記録しておくのです。
704あなたがメールを送るときに、宛て先人に対して彼らの出すリプライに
705PINを含めるように依頼するのです。
706しかしそれがそのまま返ってきたり、
707あるいは返ってきたメッセージが``vacation'' スクリプトを通じての
708ものであっても、そのまま PIN が含まれてしまいます。
709ですから、最善なやり方はメールを送るときに返事には
710文字を逆順にするとか、各桁に対して足し算や引き算を行うなどして
711PINを変形したものを含めて返すように依頼するという方法です。
678712
679=head2 How do I find the user's mail address?
713=head2 How do I decode a MIME/BASE64 string?
680714
681(あるユーザールアレス知るには?)
715(MIME/BASE64 文字列デコードを行うには?)
682716
683717=begin original
684718
685Ask them for it. There are so many email providers available that it's
719The MIME-Base64 package (available from CPAN) handles this as well as
686unlikely the local system has any idea how to determine a user's email address.
720the MIME/QP encoding. Decoding BASE64 becomes as simple as:
687721
688722=end original
689723
690人に聞いてください。
724MIME-Base64 パッケージ(CPANで入手可能です)はこ問題と、
691多くのメルプロバイダが利用可能なので、ローカルシステムがユーザーの
725MIME/QP エンコディングを取り扱います。
692ルアレスを決定する方法まずありません。
726BASE64のデコードは以下のように単純です:
693727
694=begin original
728 use MIME::Base64;
729 $decoded = decode_base64($encoded);
695730
696The exception is for organization-specific email (e.g. foo@yourcompany.com)
697where policy can be codified in your program. In that case, you could look at
698$ENV{USER}, $ENV{LOGNAME}, and getpwuid($<) in scalar context, like so:
699
700=end original
701
702例外は、組織に固有のメール (例えば foo@yourcompany.com) で、ポリシーを
703プログラムにコード化できる場合です。
704この場合、以下のように
705$ENV{USER}, $ENV{LOGNAME} およびスカラコンテキストで and getpwuid($<) を
706見ることができます:
707
708 my $user_name = getpwuid($<)
709
710731=begin original
711732
712But you still cannot make assumptions about whether this is correct, unless
733The MIME-Tools package (available from CPAN) supports extraction with
713your policy says it is. You really are best off asking the user.
734decoding of BASE64 encoded attachments and content directly from email
735messages.
714736
715737=end original
716738
717しかし、ポリシがそうなっていない限、こが正しいかどうかに関して
739MIME-Tools パッケジ (CPAN にあます) は BASE64 エンコードさ
718仮定するこはやはりできません
740添付ファイル本文をメールのメッセージから直接抽出できま
719本当に最良なのはユーザーに聞くことです。
720741
721=head2 How do I send email?
742もしデコードしたい文字列が短い(84 文字以下)の場合、
743より直接的なやり方は、ちょっとした変換をした後でunpack()関数の
744“u”フォーマットを使うというものです:
722745
723(メ送るには?)
746 tr#A-Za-z0-9+/##cd; # base64でないキャラクターを取り除く
747 tr#A-Za-z0-9+/# -_#; # uuencodeフォーマットに変換
748 $len = pack("c", 32 + 0.75*length); # 長さを計算する
749 print unpack("u", $len . $_); # uudecodeして出力
724750
725=begin original
751=head2 How do I return the user's email address?
726752
727Use the L<Email::MIME> and L<Email::Sender::Simple> modules, like so:
753(ユーザーのメールアドレスを返すには?)
728754
729=end original
755getpwuidをサポートしているシステムであれば、$< という変数と
756Sys::Hostname モジュール(標準のperl配布キットの一部です)を使って
757以下のようなことが試せるでしょう。
730758
731以下のように、L<Email::MIME> L<Email::Sender::Simple> モジュールを
759 use Sys::Hostname;
732使ってください:
760 $address = sprintf('%s@%s', getpwuid($<), hostname);
733761
734 # first, create your message
735 my $message = Email::MIME->create(
736 header_str => [
737 From => 'you@example.com',
738 To => 'friend@example.com',
739 Subject => 'Happy birthday!',
740 ],
741 attributes => {
742 encoding => 'quoted-printable',
743 charset => 'ISO-8859-1',
744 },
745 body_str => "Happy birthday to you!\n",
746 );
747
748 use Email::Sender::Simple qw(sendmail);
749 sendmail($message);
750
751762=begin original
752763
753By default, L<Email::Sender::Simple> will try `sendmail` first, if it exists
764Company policies on email address can mean that this generates addresses
754in your $PATH. This generally isn't the case. If there's a remote mail
765that the company's email system will not accept, so you should ask for
755server you use to send mail, consider investigating one of the Transport
766users' email addresses when this matters. Furthermore, not all systems
756classes. At time of writing, the available transports include:
767on which Perl runs are so forthcoming with this information as is Unix.
757768
758769=end original
759770
760デフォトでは、L<Email::Sender::Simple> は、$PATH ば `sendmail` を
771会社のメーアドレス関するポリシーが、こが生成するアドレスは
761最初に試します。
772その会社のメールシステムが受け付けないものである可能性があります。
762これは一般的に間違いです。
773ですから、ユーザーに、そのユーザーのメールアドレスを尋ねるべきでしょう
763メールを送るの使うリモートのメールサーバ場合、
774それ加え、Perl動作す全てのシステムで
764Transport クラスの一つを調査することを考慮してください
775の情報が(UNIX同じように)得られるわけではありません
765これを書いている時点では、利用可能な転送層は以下のようなものです:
766776
767=over 4
777CPANにある Mail::Utilモジュール (MailToolsパッケージの一部です)は
778メールアドレスがそのユーザーのものであるかどうかを確かめようとする
779mailaddress()という関数を提供しています。
780これは上で例示したやり方よりも賢く、
781モジュールがインストールされたときの情報を使いますが、
782それでも正しくない可能性があります。
783くり返しますが、最善の方法はユーザーに尋ねること、というのがほとんどです。
768784
769=item L<Email::Sender::Transport::Sendmail>
785=head2 How do I send mail?
770786
771=begin original
787(メールを送るには?)
772788
773This is the default. If you can use the L<mail(1)> or L<mailx(1)>
789C<sendmail>プログラムを直接使います:
774program to send mail from the machine where your code runs, you should
775be able to use this.
776790
777=end original
791 open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
792 or die "Can't fork for sendmail: $!\n";
793 print SENDMAIL <<"EOF";
794 From: メールの発信者 <me\@host>
795 To: 宛て先 <you\@otherhost>
796 Subject: 適切なサブジェクト
778797
779これはデフォルトです。
798 空行に続けてメッセージの本体を書きます。好きな行数書けます。
780コードを実行しているマシンからメールを送るのに L<mail(1)> L<mailx(1)>
799 EOF
781使えるなら、これが使えるはずです。
800 close(SENDMAIL) or warn "sendmail didn't close nicely";
782801
783=item L<Email::Sender::Transport::SMTP>
784
785802=begin original
786803
787This transport contacts a remote SMTP server over TCP. It optionally
804The B<-oi> option prevents sendmail from interpreting a line consisting
788uses SSL and can authenticate to the server via SASL.
805of a single dot as "end of message". The B<-t> option says to use the
806headers to decide who to send the message to, and B<-odq> says to put
807the message into the queue. This last option means your message won't
808be immediately delivered, so leave it out if you want immediate
809delivery.
789810
790811=end original
791812
792この転送層 TCP 使ってリモト SMTP サーバに接続します。
813B<-oi>オプションsendmailがドットだけの行“メッセジの終わり”と
793オプションとして SSL を使って、SASL 経由サーバに認証できます。
814みなさないようにするためのオプションです。B<-t>オプションは
815メッセージを誰に贈るかを決めるかのためにヘッダーを使うことを指示し、
816B<-odq>オプションメッセージをキューに入れることを指示します。
817最後のオプションの意味は、あなたのメッセージがすぐには配送されないことを
818意味します。ですから、すぐに配送させたいのであれば
819このオプションを取り除いてください。
794820
795=item L<Email::Sender::Transport::SMTP::TLS>
796
797821=begin original
798822
799This is like the SMTP transport, but uses TLS security. You can
823Alternate, less convenient approaches include calling mail (sometimes
800authenticate with this module as well, using any mechanisms your server
824called mailx) directly or simply opening up port 25 have having an
801supports after STARTTLS.
825intimate conversation between just you and the remote SMTP daemon,
826probably sendmail.
802827
803828=end original
804829
805これSMTP 転送似ていますが、TLS セキュリティ使います。
830あるい、直接 mail (mailx 呼ばれることもあります)
806このモジュールもSTARTTLS の後サバが対応している任意の機構を使って
831呼びだしたり単純に 25 番ポを使ってリモートの
807認証きます。
832SMTP デーモン(多分 sendmail しょう) との間で
833詳細な通信を行うといったあまり便利でない方法もあります。
808834
809=back
835あるいはCPANにあるモジュールMail::Mailerが使えるかもしれません:
810836
811=begin original
837 use Mail::Mailer;
812838
813Telling L<Email::Sender::Simple> to use your transport is straightforward.
839 $mailer = Mail::Mailer->new();
840 $mailer->open({ From => $from_address,
841 To => $to_address,
842 Subject => $subject,
843 })
844 or die "Can't open: $!\n";
845 print $mailer $body;
846 $mailer->close();
814847
815=end original
848Mail::Internet モジュールは Mail::Mailer より UNIX 的ではない
849Net::SMTP を使っていますが、信頼性も低いです。
850生の SMTP コマンドを無視します。
851sendmail のような mail transport agent を使う理由はたくさんあります。
852その中にはキューイングも含まれますし、MX レコードやセキュリティと
853いったものが含まれます。
816854
817使用する転送層を L<Email::Sender::Simple> に教えるのは簡単です:
818
819 sendmail(
820 $message,
821 {
822 transport => $email_sender_transport_object,
823 }
824 );
825
826855=head2 How do I use MIME to make an attachment to a mail message?
827856
828857(メールメッセージに添付するためにどうやって MIME を使えばいいですか?)
829858
830859=begin original
831860
832L<Email::MIME> directly supports multipart messages. L<Email::MIME>
861This answer is extracted directly from the MIME::Lite documentation.
833objects themselves are parts and can be attached to other L<Email::MIME>
862Create a multipart message (i.e., one with attachments).
834objects. Consult the L<Email::MIME> documentation for more information,
835including all of the supported methods and examples of their use.
836863
837864=end original
838865
839L<Email::MIME> 直接マルチパートメッセージに対応しいます。
866この回答は MIME::Lite のドキュメントから直接持っきたものです。
840L<Email::MIME> 自身はパートで、その他の L<Email::MIME> オブェクトに
867マルチパートメッセージ(つまり 添付つきのメッセー) を作ります。
841添付できます。
842対応している全てのメソッドとその使い方の例を含む、さらなる情報については
843L<Email::MIME> 文書を参照してください。
844868
845=head2 How do I read email?
869 use MIME::Lite;
846870
847(メールを読み出すには?)
871 ### Create a new multipart message:
872 $msg = MIME::Lite->new(
873 From =>'me@myhost.com',
874 To =>'you@yourhost.com',
875 Cc =>'some@other.com, some@more.com',
876 Subject =>'A message with 2 parts...',
877 Type =>'multipart/mixed'
878 );
848879
880 ### Add parts (each "attach" has same arguments as "new"):
881 $msg->attach(Type =>'TEXT',
882 Data =>"Here's the GIF file you wanted"
883 );
884 $msg->attach(Type =>'image/gif',
885 Path =>'aaa000123.gif',
886 Filename =>'logo.gif'
887 );
888
889 $text = $msg->as_string;
890
849891=begin original
850892
851Use the L<Email::Folder> module, like so:
893MIME::Lite also includes a method for sending these things.
852894
853895=end original
854896
855以下のように、L<Email::Folder> モジュール使ってください:
897MIME::Lite はまたこれらのもの送るためのメソッドを含みます。
856898
857 use Email::Folder;
899 $msg->send;
858900
859 my $folder = Email::Folder->new('/path/to/email/folder');
860 while(my $message = $folder->next_message) {
861 # next_message returns Email::Simple objects, but we want
862 # Email::MIME objects as they're more robust
863 my $mime = Email::MIME->new($message->as_string);
864 }
865
866901=begin original
867902
868There are different classes in the L<Email::Folder> namespace for
903This defaults to using L<sendmail(1)> but can be customized to use
869supporting various mailbox types. Note that these modules are generally
904SMTP via L<Net::SMTP>.
870rather limited and only support B<reading> rather than writing.
871905
872906=end original
873907
874様々なメーボックスの種類に対応るための異なったクラス
908これはデフォトでは L<sendmail(1)> を使いますが
875L<Email::Folder> 名前空間あります。
909L<Net::SMTP> 経由で SMTP を使うようカスタマイズできます。
876これらのモジュールは一般的に B<読み込み> にのみ対応していて書き込みには
877対応していないことに注意してください。
878910
879=head2 How do I find out my hostname, domainname, or IP address?
911=head2 How do I read mail?
880X<hostname, domainname, IP address, host, domain, hostfqdn, inet_ntoa,
881gethostbyname, Socket, Net::Domain, Sys::Hostname>
882912
883(私のホスト名/ドイン名/IP アドレス見つけるには?)
913(メール読み出すには?)
884914
885=begin original
915CPAN にある Mail::Folder モジュール(MailFolder パッケージの一部です)や
916Mail::Internet モジュール(これも MailTools パッケージの一部です)が
917使えますが、モジュールを使うのはやりすぎかもしれません。
918以下にメールをソートする方法を示します。
886919
887(contributed by brian d foy)
920 #!/usr/bin/perl
921 # bysub1 - サブジェクトによる単純なソート
922 my(@msgs, @sub);
923 my $msgno = -1;
924 $/ = ''; # パラグラフ読み出し
925 while (<>) {
926 if (/^From/m) {
927 /^Subject:\s*(?:Re:\s*)*(.*)/mi;
928 $sub[++$msgno] = lc($1) || '';
929 }
930 $msgs[$msgno] .= $_;
931 }
932 for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) {
933 print $msgs[$i];
934 }
888935
889=end original
936あるいはもっと簡潔に
890937
891(brian d foy によって寄贈されました)
938 #!/usr/bin/perl -n00
939 # bysub2 - awki的な、サブジェクトによるソート
940 BEGIN { $msgno = -1 }
941 $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m;
942 $msg[$msgno] .= $_;
943 END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] }
892944
893=begin original
945=head2 How do I find out my hostname/domainname/IP address?
894946
895The L<Net::Domain> module, which is part of the Standard Library starting
947(私の ホスト名/ドメイン名/IPアドレス を見つけるには?)
896in Perl 5.7.3, can get you the fully qualified domain name (FQDN), the host
897name, or the domain name.
898948
899=end original
949多くのプログラムが C<`hostname`> プログラムを呼び出しています。
950これは便利なときもありますが、高い移植性があるというわけではありません。
951これは、便利さと移植性とのトレードオフの一例です。
900952
901Perl 5.7.3 から標準ライブラリの一部である L<Net::Domain> モジュールを使うと、
953Sys::Hostname モジュール(標準Perl配布キットの一部です)は
902完全修飾ドメイン名 (FQDN)、ホスト名、ドメイン名得られます
954gethostbyename()を使って(DNS動作していることを仮定しています)
955IPアドレスを取得できたあとで、ホスト名を返します。
903956
904 use Net::Domain qw(hostname hostfqdn hostdomain);
957 use Socket;
958 use Sys::Hostname;
959 my $host = hostname();
960 my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
905961
906 my $host = hostfqdn();
907
908962=begin original
909963
910The L<Sys::Hostname> module, part of the Standard Library, can also get the
964Probably the simplest way to learn your DNS domain name is to grok
911hostname:
965it out of /etc/resolv.conf, at least under Unix. Of course, this
966assumes several things about your resolv.conf configuration, including
967that it exists.
912968
913969=end original
914970
915標準ライブラリの一部である L<Sys::Hostname> モジュールでもホスト名を
971少なくとも UNIX は、おそらくなたの使っていDNS
916得られます。
972ドメイン名を知る最も単純な方法は
973/etc/resolev.conf を解析することでしょう。
974もちろん、これはファイルが存在していることを含め、
975resolv.confの設定に関して幾つかの仮定を行っています。
917976
918 use Sys::Hostname;
919
920 $host = hostname();
921
922977=begin original
923978
924The L<Sys::Hostname::Long> module takes a different approach and tries
979(We still need a good DNS domain name-learning method for non-Unix
925harder to return the fully qualified hostname:
980systems.)
926981
927982=end original
928983
929L<Sys::Hostname::Long> モジュールは異なる手法をとり、完全修飾ホスト名
984(私たちは未だに非 UNIX システムのための良い DNS ドメイン名所得手法を
930返すためにさらに多くのこを試みます:
985必要しています)
931986
932 use Sys::Hostname::Long 'hostname_long';
987=head2 How do I fetch a news article or the active newsgroups?
933988
934 my $hostname = hostname_long();
989(ニュースのアーティクルやアクティブなニュースグループを取得するには?)
935990
936991=begin original
937992
938To get the IP address, you can use the C<gethostbyname> built-in function
993Use the Net::NNTP or News::NNTPClient modules, both available from CPAN.
939to turn the name into a number. To turn that number into the dotted octet
994This can make tasks like fetching the newsgroup list as simple as
940form (a.b.c.d) that most people expect, use the C<inet_ntoa> function
941from the L<Socket> module, which also comes with perl.
942995
943996=end original
944997
945IP アドレスを得るには、名前ら数値に変換するために C<gethostbyname>
998Net::NNTP モジュールNews::NNTPClient モジュールのいずれかを使います。
946組み込み関数が使えます。
999これらは両方ともCPANから入手可能です。これらは以下のように
947数値を、ほとんど人が想定しているピオド付きの形 (a.b.c.d) に変換するには、
1000簡単にニュースグループのリストを取得するような作業ができます。
948標準配布されている L<Socket> モジュールの C<inet_ntoa> 関数を使います。
9491001
950 use Socket;
1002 perl -MNews::NNTPClient
1003 -e 'print News::NNTPClient->new->list("newsgroups")'
9511004
952 my $address = inet_ntoa(
1005=head2 How do I fetch/put an FTP file?
953 scalar gethostbyname( $host || 'localhost' )
954 );
9551006
956=head2 How do I fetch/put an (S)FTP file?
1007(FTPファイルをダウンロード/アップロードするには?)
9571008
958((S)FTP ファイルをダウンロード/アップロードするには?)
959
9601009=begin original
9611010
962L<Net::FTP>, and L<Net::SFTP> allow you to interact with FTP and SFTP (Secure
1011LWP::Simple (available from CPAN) can fetch but not put. Net::FTP (also
963FTP) servers.
1012available from CPAN) is more complex but can put as well as fetch.
9641013
9651014=end original
9661015
967L<Net::FTP> と L<Net::SFTP> で FTP および SFTP (Secure FTP)バと
1016LWP::Simple (CPANで入手可能)はダウンロドができますがアップロードはできません。
968相互作用きるうにな
1017Net::FTP(これもCPAN入手可能)はこれよりも複雑でが、
1018ダウンロードとアップロードの両方ができます。
9691019
9701020=head2 How can I do RPC in Perl?
9711021
972(Perl で RPC を行うには?)
1022(Perl で RPC を行うにはどうすればよいのですか?)
9731023
9741024=begin original
9751025
976Use one of the RPC modules( L<https://metacpan.org/search?q=RPC> ).
1026A DCE::RPC module is being developed (but is not yet available) and
1027will be released as part of the DCE-Perl package (available from
1028CPAN). The rpcgen suite, available from CPAN/authors/id/JAKE/, is
1029an RPC stub generator and includes an RPC::ONC module.
9771030
9781031=end original
9791032
980RFC モジュール ( L<https://metacpan.org/search?q=RPC> ) の一つを使いましょう
1033DCE::RPCが開発中です(ただし、まだ入手可能にはなっていません)
1034これは DCE-Perl パッケージ(CPAN から入手可能です)の一部として
1035リリースされるでしょう。
1036rpcgenスイートがCAPN/authors/id/JAKE/から入手可能です。
1037これはRPCスタブのジェネレーターであり、RPC::ONCモジュールを含んでいます。
9811038
9821039=head1 AUTHOR AND COPYRIGHT
9831040
984Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and
1041Copyright (c) 1997-1999 Tom Christiansen and Nathan Torkington.
985other authors as noted. All rights reserved.
1042All rights reserved.
9861043
987This documentation is free; you can redistribute it and/or modify it
1044When included as part of the Standard Version of Perl, or as part of
988under the same terms as Perl itself.
1045its complete documentation whether printed or otherwise, this work
1046may be distributed only under the terms of Perl's Artistic License.
1047Any distribution of this file or derivatives thereof I<outside>
1048of that package require that special arrangements be made with
1049copyright holder.
9891050
9901051Irrespective of its distribution, all code examples in this file
991are hereby placed into the public domain. You are permitted and
1052are hereby placed into the public domain. You are permitted and
9921053encouraged to use this code in your own programs for fun
993or for profit as you see fit. A simple comment in the code giving
1054or for profit as you see fit. A simple comment in the code giving
9941055credit would be courteous but is not required.
995
996=begin meta
997
998Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
999Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-5.14.1, 5.00150039)
1000Status: completed
1001
1002=end meta