perlfaq-5.0150042 >
5.10.1
との差分
perlfaq9 5.10.1 と 5.0150042 の差分
| 1 | 1 | |
| 2 | 2 | =encoding euc-jp |
| 3 | 3 | |
| 4 | 4 | =head1 NAME |
| 5 | 5 | |
| 6 | 6 | =begin original |
| 7 | 7 | |
| 8 | perlfaq9 - Networking | |
| 8 | perlfaq9 - Web, Email and Networking | |
| 9 | 9 | |
| 10 | 10 | =end original |
| 11 | 11 | |
| 12 | perlfaq9 - ネットワーク | |
| 12 | perlfaq9 - Web、メール、ネットワーク | |
| 13 | 13 | |
| 14 | 14 | =head1 DESCRIPTION |
| 15 | 15 | |
| 16 | 16 | =begin original |
| 17 | 17 | |
| 18 | This section deals with questions related to | |
| 18 | This section deals with questions related to running web sites, | |
| 19 | ||
| 19 | sending and receiving email as well as general networking. | |
| 20 | 20 | |
| 21 | 21 | =end original |
| 22 | 22 | |
| 23 | このセクションでは、 | |
| 23 | このセクションでは、web サイトの実行、メールの送受信、および一般的な | |
| 24 | 質問を扱っています。 | |
| 24 | ネットワークに関する質問を扱っています。 | |
| 25 | 25 | |
| 26 | =head2 | |
| 26 | =head2 Should I use a web framework? | |
| 27 | 27 | |
| 28 | ( | |
| 28 | (web フレームワークを使うべき?) | |
| 29 | 29 | |
| 30 | 30 | =begin original |
| 31 | 31 | |
| 32 | ||
| 32 | Yes. If you are building a web site with any level of interactivity | |
| 33 | (forms / users / databases), you | |
| 34 | will want to use a framework to make handling requests | |
| 35 | and responses easier. | |
| 33 | 36 | |
| 34 | 37 | =end original |
| 35 | 38 | |
| 36 | ||
| 39 | はい。 | |
| 40 | 何らかのレベルの相互作用(フォーム、ユーザー、データベース)を持つ web サイトを | |
| 41 | 構築しているなら、リクエストとレスポンスをより簡単に扱えるような | |
| 42 | フレームワークを使いたいでしょう。 | |
| 37 | 43 | |
| 38 | 44 | =begin original |
| 39 | 45 | |
| 40 | ||
| 46 | If there is no interactivity then you may still want | |
| 41 | ||
| 47 | to look at using something like L<Template Toolkit|https://metacpan.org/module/Template> | |
| 42 | ||
| 48 | or L<Plack::Middleware::TemplateToolkit> | |
| 43 | ||
| 49 | so maintenance of your HTML files (and other assets) is easier. | |
| 44 | 50 | |
| 45 | 51 | =end original |
| 46 | 52 | |
| 47 | T | |
| 53 | 相互作用がなくても、HTML ファイル(およびその他の資産)の管理をより | |
| 48 | ||
| 54 | 簡単にするために | |
| 49 | ||
| 55 | L<Template Toolkit|https://metacpan.org/module/Template> や | |
| 50 | ||
| 56 | L<Plack::Middleware::TemplateToolkit> のようなものを使いたいかもしれません。 | |
| 51 | あります。 | |
| 52 | 57 | |
| 53 | = | |
| 58 | =head2 Which web framework should I use? | |
| 59 | X<framework> X<CGI.pm> X<CGI> X<Catalyst> X<Dancer> | |
| 54 | 60 | |
| 55 | ||
| 61 | (どの web フレームワークを使うべき?) | |
| 56 | http://www.ietf.org/rfc/rfc3875 | |
| 57 | 62 | |
| 58 | =end original | |
| 59 | ||
| 60 | CGI 仕様は RFC に概要が述べられています: | |
| 61 | http://www.ietf.org/rfc/rfc3875 | |
| 62 | ||
| 63 | 63 | =begin original |
| 64 | 64 | |
| 65 | ||
| 65 | There is no simple answer to this question. Perl frameworks can run everything | |
| 66 | from basic file servers and small scale intranets to massive multinational | |
| 67 | multilingual websites that are the core to international businesses. | |
| 66 | 68 | |
| 67 | 69 | =end original |
| 68 | 70 | |
| 69 | ||
| 71 | この質問への単純な答えはありません。 | |
| 70 | ||
| 72 | Perl のフレームワークには、基本的なファイルサーバとスケールの小さい | |
| 73 | イントラネット用から国際ビジネスのコアとなる巨大国際多言語 web サイトまで | |
| 74 | あらゆるものがあります。 | |
| 71 | 75 | |
| 72 | 76 | =begin original |
| 73 | 77 | |
| 74 | ||
| 78 | Below is a list of a few frameworks with comments which might help you in | |
| 75 | ||
| 79 | making a decision, depending on your specific requirements. Start by reading | |
| 76 | o | |
| 80 | the docs, then ask questions on the relevant mailing list or IRC channel. | |
| 77 | 81 | |
| 78 | 82 | =end original |
| 79 | 83 | |
| 80 | ||
| 84 | 以下は、特定の要求に合わせて決定を行う助けとなるであろうコメント付きの | |
| 81 | ||
| 85 | いくつかのフレームワークの一覧です。 | |
| 82 | ||
| 86 | 文書を読むことから始めて、それから関連するメーリングリストや IRC | |
| 83 | ||
| 87 | チャンネルに質問してください。 | |
| 84 | 88 | |
| 85 | = | |
| 89 | =over 4 | |
| 86 | 90 | |
| 87 | ||
| 91 | =item L<Catalyst> | |
| 88 | specification) and HTTP response headers (defined in the HTTP | |
| 89 | specification, RFC2616) is intentional, but can sometimes be confusing. | |
| 90 | 92 | |
| 91 | =end original | |
| 92 | ||
| 93 | (CGI 仕様に定義されている) CGI レスポンスヘッダと、(RFC2616 の HTTP 仕様で | |
| 94 | 定義されている) HTTP レスポンスヘッダの類似性は意図的なものですが、 | |
| 95 | 時々混乱を引き起こします。 | |
| 96 | ||
| 97 | 93 | =begin original |
| 98 | 94 | |
| 99 | ||
| 95 | Strongly object-oriented and fully-featured with a long development history and | |
| 100 | ||
| 96 | a large community and addon ecosystem. It is excellent for large and complex | |
| 101 | ||
| 97 | applications, where you have full control over the server. | |
| 102 | simpler in various respects. The CGI specification allows any of the | |
| 103 | usual newline representations in the CGI response (it's the server's | |
| 104 | job to create an accurate HTTP response based on it). So "\n" written in | |
| 105 | text mode is technically correct, and recommended. NPH scripts are more | |
| 106 | tricky: they must put out a complete and accurate set of HTTP | |
| 107 | transaction response headers; the HTTP specification calls for records | |
| 108 | to be terminated with carriage-return and line-feed, i.e ASCII \015\012 | |
| 109 | written in binary mode. | |
| 110 | 98 | |
| 111 | 99 | =end original |
| 112 | 100 | |
| 113 | ||
| 101 | 長い開発の歴史と大きなコミュニティおよびアドオン生態系を持ち、 | |
| 114 | ||
| 102 | 強力にオブジェクト指向で完全な機能があります。 | |
| 115 | ||
| 103 | サーバに対する完全な制御がある場所での大きく複雑なアプリケーションには | |
| 116 | ||
| 104 | 素晴らしいものです。 | |
| 117 | "Parsed Header" スクリプトは色々な側面においてより単純です。 | |
| 118 | CGI 仕様は CGI レスポンスとして一般的な改行表現のどれを使ってもよいことに | |
| 119 | なっています(そこから正確な HTTP レスポンスを作成するのはサーバの仕事です)。 | |
| 120 | 従って "\n" をテキストモードで書くのは技術的に正しく、推奨されています。 | |
| 121 | NPH スクリプトではより微妙です: ここでは完全に正確な HTTP トランザクション | |
| 122 | レスポンスヘッダを出力しなければなりません; HTTP 仕様はレコードが復帰と | |
| 123 | 改行(つまりバイナリモードで ASCII コードの \015\012 が書かれる)で | |
| 124 | 終端されていることを要求します。 | |
| 125 | 105 | |
| 106 | =item L<Dancer> | |
| 107 | ||
| 126 | 108 | =begin original |
| 127 | 109 | |
| 128 | ||
| 110 | Young and free of legacy weight, providing a lightweight and easy to learn API. | |
| 129 | system | |
| 111 | Has a growing addon ecosystem. It is best used for smaller projects and | |
| 130 | ||
| 112 | very easy to learn for beginners. | |
| 131 | 113 | |
| 132 | 114 | =end original |
| 133 | 115 | |
| 134 | ||
| 116 | 新しくレガシーな重みから解放されていて、軽量で学習しやすい API を提供します。 | |
| 135 | ||
| 117 | アドオン生態系は大きくなりつつあります。 | |
| 136 | ||
| 118 | より小さいプロジェクトに最適で初心者が学習するのはとても簡単です。 | |
| 137 | 119 | |
| 138 | = | |
| 120 | =item L<Mojolicious> | |
| 139 | 121 | |
| 140 | (私の CGI スクリプトはコマンドラインでは動くのだけど、ブラウザ上では動きません (500 Server Error になります)) | |
| 141 | ||
| 142 | 122 | =begin original |
| 143 | 123 | |
| 144 | ||
| 124 | Fairly young with a focus on HTML5 and real-time web technologies such as | |
| 145 | ||
| 125 | WebSockets. | |
| 146 | 126 | |
| 147 | 127 | =end original |
| 148 | 128 | |
| 149 | ||
| 129 | 比較的若く、HTML5 と WebSockets のようなリアルタイム web 技術に焦点を | |
| 150 | ||
| 130 | 当てています。 | |
| 151 | 131 | |
| 152 | ||
| 132 | =item L<Web::Simple> | |
| 153 | 133 | |
| 154 | 134 | =begin original |
| 155 | 135 | |
| 156 | ||
| 136 | Currently experimental, strongly object-oriented, built for speed and intended | |
| 157 | ||
| 137 | as a toolkit for building micro web apps, custom frameworks or for tieing | |
| 158 | ||
| 138 | together existing Plack-compatible web applications with one central dispatcher. | |
| 159 | post it on comp.infosystems.www.authoring.cgi (if it's something to do | |
| 160 | with HTTP or the CGI protocols). Questions that appear to be Perl | |
| 161 | questions but are really CGI ones that are posted to comp.lang.perl.misc | |
| 162 | are not so well received. | |
| 163 | 139 | |
| 164 | 140 | =end original |
| 165 | 141 | |
| 166 | ||
| 142 | 現在の所実験的で、強力にオブジェクト指向で、速度重視で構築されており、 | |
| 167 | ||
| 143 | ごく小さい web アプリやカスタムフレームワークを構築したり、 | |
| 168 | ||
| 144 | 既存の Plack 互換の web アプリケーションを一つの中央ディスパッチャと | |
| 169 | ||
| 145 | 結びつけることを意図しています。 | |
| 170 | Perl に関する質問のように見えていても、実は CGI に関するものだというものが | |
| 171 | comp.lang.perl.misc に投稿されることがありますが、回答はついていません。 | |
| 172 | 146 | |
| 147 | =back | |
| 148 | ||
| 173 | 149 | =begin original |
| 174 | 150 | |
| 175 | ||
| 151 | All of these interact with or use L<Plack> which is worth understanding | |
| 176 | liste | |
| 152 | the basics of when building a website in Perl (there is a lot of useful | |
| 153 | L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>). | |
| 177 | 154 | |
| 178 | 155 | =end original |
| 179 | 156 | |
| 180 | ||
| 157 | これら全ては L<Plack> を使うか相互作用しており、Perl で web サイトを | |
| 181 | ||
| 158 | 構築するときは基本を理解する価値があります (多くの有用な | |
| 159 | L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware> が | |
| 160 | あります)。 | |
| 182 | 161 | |
| 183 | ||
| 162 | =head2 What is Plack and PSGI? | |
| 184 | 163 | |
| 185 | ||
| 164 | (Plack と PSGI って何?) | |
| 186 | 165 | |
| 187 | (CGI プログラムから、もっとまともなエラーメッセージを得るには?) | |
| 188 | ||
| 189 | 166 | =begin original |
| 190 | 167 | |
| 191 | ||
| 168 | L<PSGI> is the Perl Web Server Gateway Interface Specification, it is | |
| 192 | ||
| 169 | a standard that many Perl web frameworks use, you should not need to | |
| 193 | ||
| 170 | understand it to build a web site, the part you might want to use is L<Plack>. | |
| 194 | server error log. | |
| 195 | 171 | |
| 196 | 172 | =end original |
| 197 | 173 | |
| 198 | ||
| 174 | L<PSGI> は Perl Web Server Gateway Interface Specification です; これは多くの | |
| 199 | ||
| 175 | Perl web フレームワークが使う標準で、web サイトを構築するためにこれを | |
| 200 | ||
| 176 | 理解する必要はないはずです; 使いたい部分は L<Plack> でしょう。 | |
| 201 | 安全なものに置き換えます。 | |
| 202 | その出力は、サーバーの通常のエラーログに送られます。 | |
| 203 | 177 | |
| 204 | use CGI::Carp; | |
| 205 | warn "This is a complaint"; | |
| 206 | die "But this one is serious"; | |
| 207 | ||
| 208 | 178 | =begin original |
| 209 | 179 | |
| 210 | ||
| 180 | L<Plack> is a set of tools for using the PSGI stack. It contains | |
| 211 | ||
| 181 | L<middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware> | |
| 182 | components, a reference server and utilities for Web application frameworks. | |
| 183 | Plack is like Ruby's Rack or Python's Paste for WSGI. | |
| 212 | 184 | |
| 213 | 185 | =end original |
| 214 | 186 | |
| 215 | ||
| 187 | L<Plack> は PSGI スタックを使うためのツールの集合です。 | |
| 216 | リ | |
| 188 | これには Web アプリケーションフレームワークのための | |
| 217 | ||
| 189 | L<ミドルウェア|https://metacpan.org/search?q=plack%3A%3Amiddleware> 要素、 | |
| 190 | リファレンスサーバ、ユーティリティを含みます。 | |
| 191 | Plack は Ruby の Rack や Python の WSGI のための Paste に似ています。 | |
| 218 | 192 | |
| 219 | BEGIN { | |
| 220 | use CGI::Carp qw(carpout); | |
| 221 | open(LOG, ">>/var/local/cgi-logs/mycgi-log") | |
| 222 | or die "Unable to append to mycgi-log: $!\n"; | |
| 223 | carpout(*LOG); | |
| 224 | } | |
| 225 | ||
| 226 | 193 | =begin original |
| 227 | 194 | |
| 228 | You c | |
| 195 | You could build a web site using L<Plack> and your own code, | |
| 229 | ||
| 196 | but for anything other than a very basic web site, using a web framework | |
| 197 | (that uses L<Plack>) is a better option. | |
| 230 | 198 | |
| 231 | 199 | =end original |
| 232 | 200 | |
| 233 | ||
| 201 | L<Plack> と独自のコードを使って web サイトを構築することもできますが、 | |
| 234 | ||
| 202 | とても基本的な web サイト以外のものなら、(L<Plack> を使った) web | |
| 235 | ||
| 203 | フレームワークを使うのがよりよい選択肢です。 | |
| 236 | 204 | |
| 237 | use CGI::Carp qw(fatalsToBrowser); | |
| 238 | die "Bad error here"; | |
| 239 | ||
| 240 | =begin original | |
| 241 | ||
| 242 | Even if the error happens before you get the HTTP header out, the module | |
| 243 | will try to take care of this to avoid the dreaded server 500 errors. | |
| 244 | Normal warnings still go out to the server error log (or wherever | |
| 245 | you've sent them with C<carpout>) with the application name and date | |
| 246 | stamp prepended. | |
| 247 | ||
| 248 | =end original | |
| 249 | ||
| 250 | あなたが HTTP ヘッダーを受け取るよりも前にエラーが起こったとしても、 | |
| 251 | モジュールはサーバーの 500 エラーを避けるためにそのエラーを取り扱おうと | |
| 252 | するでしょう。 | |
| 253 | 通常の警告はサーバーのエラーログ(もしくはあなたが C<carpout> で指定した場所)に | |
| 254 | アプリケーションの名前と日付を伴って送られます。 | |
| 255 | ||
| 256 | 205 | =head2 How do I remove HTML from a string? |
| 257 | 206 | |
| 258 | 207 | (ある文字列から HTML を取り除くには?) |
| 259 | 208 | |
| 260 | 209 | =begin original |
| 261 | 210 | |
| 262 | ||
| 211 | Use L<HTML::Strip>, or L<HTML::FormatText> which not only removes HTML | |
| 263 | ||
| 212 | but also attempts to do a little simple formatting of the resulting | |
| 264 | ||
| 213 | plain text. | |
| 265 | attempts to do a little simple formatting of the resulting plain text. | |
| 266 | 214 | |
| 267 | 215 | =end original |
| 268 | 216 | |
| 269 | ||
| 217 | L<HTML::Strip> を使うか、HTML を取り除くだけでなく結果のプレーンテキストを | |
| 270 | ||
| 218 | 少し単純な形式にしようとする L<HTML::FormatText> を使ってください。 | |
| 271 | もう一つのまず正しい方法は、HTML::FormatText を使って HTML を | |
| 272 | 取り除くだけでなく、結果のプレーンテキストを簡単に整形することです。 | |
| 273 | 219 | |
| 274 | =begin original | |
| 275 | ||
| 276 | Many folks attempt a simple-minded regular expression approach, like | |
| 277 | C<< s/<.*?>//g >>, but that fails in many cases because the tags | |
| 278 | may continue over line breaks, they may contain quoted angle-brackets, | |
| 279 | or HTML comment may be present. Plus, folks forget to convert | |
| 280 | entities--like C<<> for example. | |
| 281 | ||
| 282 | =end original | |
| 283 | ||
| 284 | 多くの人が、C<< s/<.*?>//g >> のような単純な(simple-minded)正規表現を | |
| 285 | 使ったアプローチを行おうとするのですが、これは多くの場合 | |
| 286 | 失敗していまいます。 | |
| 287 | なぜなら、タグは行をまたがって継続する可能性があり、 | |
| 288 | クォートされたアングルブラケットを含む可能性があり、 | |
| 289 | HTML のコメントがあるかもしれないからです。 | |
| 290 | さらに、人々は C<<> のようなエンティティを変換することを忘れてしまうのです。 | |
| 291 | ||
| 292 | =begin original | |
| 293 | ||
| 294 | Here's one "simple-minded" approach, that works for most files: | |
| 295 | ||
| 296 | =end original | |
| 297 | ||
| 298 | 以下の例は「単純な」アプローチで、ほとんどのファイルに対しては | |
| 299 | うまくいきます: | |
| 300 | ||
| 301 | #!/usr/bin/perl -p0777 | |
| 302 | s/<(?:[^>'"]*|(['"]).*?\1)*>//gs | |
| 303 | ||
| 304 | =begin original | |
| 305 | ||
| 306 | If you want a more complete solution, see the 3-stage striphtml | |
| 307 | program in | |
| 308 | http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz | |
| 309 | . | |
| 310 | ||
| 311 | =end original | |
| 312 | ||
| 313 | もし、より完璧な解決策を求めているのなら、 | |
| 314 | http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz | |
| 315 | にある 3-stage striphtml プログラムを参照してみてください。 | |
| 316 | ||
| 317 | =begin original | |
| 318 | ||
| 319 | Here are some tricky cases that you should think about when picking | |
| 320 | a solution: | |
| 321 | ||
| 322 | =end original | |
| 323 | ||
| 324 | 以下に挙げたのは、あなたが自分でやろうとしたときに | |
| 325 | 考慮すべきであろうトリッキーな例です: | |
| 326 | ||
| 327 | <IMG SRC = "foo.gif" ALT = "A > B"> | |
| 328 | ||
| 329 | <IMG SRC = "foo.gif" | |
| 330 | ALT = "A > B"> | |
| 331 | ||
| 332 | <!-- <A comment> --> | |
| 333 | ||
| 334 | <script>if (a<b && a>c)</script> | |
| 335 | ||
| 336 | <# Just data #> | |
| 337 | ||
| 338 | <![INCLUDE CDATA [ >>>>>>>>>>>> ]]> | |
| 339 | ||
| 340 | =begin original | |
| 341 | ||
| 342 | If HTML comments include other tags, those solutions would also break | |
| 343 | on text like this: | |
| 344 | ||
| 345 | =end original | |
| 346 | ||
| 347 | 以下のテキストのように HTML のコメントが他のタグを含んでいた場合には、 | |
| 348 | せっかくの対応策もダメにしてしまうかもしれません: | |
| 349 | ||
| 350 | <!-- This section commented out. | |
| 351 | <B>You can't see me!</B> | |
| 352 | --> | |
| 353 | ||
| 354 | 220 | =head2 How do I extract URLs? |
| 355 | 221 | |
| 356 | 222 | (URL の展開を行うには?) |
| 357 | 223 | |
| 358 | 224 | =begin original |
| 359 | 225 | |
| 360 | ||
| 226 | L<HTML::SimpleLinkExtor> will extract URLs from HTML, it handles anchors, | |
| 361 | ||
| 227 | images, objects, frames, and many other tags that can contain a URL. | |
| 362 | f | |
| 228 | If you need anything more complex, you can create your own subclass of | |
| 363 | ||
| 229 | L<HTML::LinkExtor> or L<HTML::Parser>. You might even use | |
| 364 | ||
| 230 | L<HTML::SimpleLinkExtor> as an example for something specifically | |
| 365 | C<HTML::SimpleLinkExtor> as an example for something specifically | |
| 366 | 231 | suited to your needs. |
| 367 | 232 | |
| 368 | 233 | =end original |
| 369 | 234 | |
| 370 | ||
| 235 | L<HTML::SimpleLinkExtor> は HTML から URL を抽出します; これはアンカー、 | |
| 371 | 多くのタグを | |
| 236 | イメージ、オブジェクト、フレームおよび URL を含んでいるその他の多くのタグを | |
| 372 | ||
| 237 | 扱います。 | |
| 373 | ||
| 238 | より複雑なものが必要なら、独自の L<HTML::LinkExtor> や L<HTML::Parser> の | |
| 374 | ||
| 239 | サブクラスを作ることができます。 | |
| 375 | ||
| 240 | 何か特別な用途に合わせるための例として L<HTML::SimpleLinkExtor> を使うことも | |
| 376 | ||
| 241 | できます。 | |
| 377 | 242 | |
| 378 | 243 | =begin original |
| 379 | 244 | |
| 380 | You can use URI::Find to extract URLs from an arbitrary text document. | |
| 245 | You can use L<URI::Find> to extract URLs from an arbitrary text document. | |
| 381 | 246 | |
| 382 | 247 | =end original |
| 383 | 248 | |
| 384 | 任意のテキスト文書から URL を抽出するためには、URI::Find が使えます。 | |
| 249 | 任意のテキスト文書から URL を抽出するためには、L<URI::Find> が使えます。 | |
| 385 | 250 | |
| 386 | =begin original | |
| 387 | ||
| 388 | Less complete solutions involving regular expressions can save | |
| 389 | you a lot of processing time if you know that the input is simple. One | |
| 390 | solution from Tom Christiansen runs 100 times faster than most | |
| 391 | module based approaches but only extracts URLs from anchors where the first | |
| 392 | attribute is HREF and there are no other attributes. | |
| 393 | ||
| 394 | =end original | |
| 395 | ||
| 396 | もし入力が単純であることが分かっているなら、正規表現を使ったより不完全な | |
| 397 | 解法によって多くの処理時間を節約できます。 | |
| 398 | Tom Christiansen による一つの解法は、モジュールを使った手法よりも 100 倍 | |
| 399 | 速いですが、最初の属性が HREF で、その他の属性がないアンカーの URL のみを | |
| 400 | 抽出します。 | |
| 401 | ||
| 402 | #!/usr/bin/perl -n00 | |
| 403 | # qxurl - tchrist@perl.com | |
| 404 | print "$2\n" while m{ | |
| 405 | < \s* | |
| 406 | A \s+ HREF \s* = \s* (["']) (.*?) \1 | |
| 407 | \s* > | |
| 408 | }gsix; | |
| 409 | ||
| 410 | =head2 How do I download a file from the user's machine? How do I open a file on another machine? | |
| 411 | ||
| 412 | (ユーザーのマシンからファイルをダウンロードするには? 別のマシンにあるファイルをオープンするには?) | |
| 413 | ||
| 414 | =begin original | |
| 415 | ||
| 416 | In this case, download means to use the file upload feature of HTML | |
| 417 | forms. You allow the web surfer to specify a file to send to your web | |
| 418 | server. To you it looks like a download, and to the user it looks | |
| 419 | like an upload. No matter what you call it, you do it with what's | |
| 420 | known as B<multipart/form-data> encoding. The CGI.pm module (which | |
| 421 | comes with Perl as part of the Standard Library) supports this in the | |
| 422 | start_multipart_form() method, which isn't the same as the startform() | |
| 423 | method. | |
| 424 | ||
| 425 | =end original | |
| 426 | ||
| 427 | この場合、ダウンロードというのは HTML フォームのファイルアップロード機能を | |
| 428 | 使うということを意味します。 | |
| 429 | Web サーファーに、Web サーバーに送るファイルを指定できるようにします。 | |
| 430 | あなたにとってダウンロードに見えるものは、ユーザーにとってはアップロードに | |
| 431 | 見えます。 | |
| 432 | 何と呼ぶかには関わらず、B<multipart/form-data> | |
| 433 | エンコーディングとして知られているものを使うことができるでしょう。 | |
| 434 | CGI.pm モジュール(標準ライブラリになっています)はこれを start_multipart_form() | |
| 435 | という starform() メソッドとは異なるメソッドでサポートしています。 | |
| 436 | ||
| 437 | =begin original | |
| 438 | ||
| 439 | See the section in the CGI.pm documentation on file uploads for code | |
| 440 | examples and details. | |
| 441 | ||
| 442 | =end original | |
| 443 | ||
| 444 | コードのサンプルと詳細については、CGI.pm の文書のファイルアップロードの | |
| 445 | 章を参照してください。 | |
| 446 | ||
| 447 | =head2 How do I make an HTML pop-up menu with Perl? | |
| 448 | ||
| 449 | (Perl で HTML のポップアップメニューを作るには?) | |
| 450 | ||
| 451 | =begin original | |
| 452 | ||
| 453 | (contributed by brian d foy) | |
| 454 | ||
| 455 | =end original | |
| 456 | ||
| 457 | (brian d foy によって寄贈されました) | |
| 458 | ||
| 459 | =begin original | |
| 460 | ||
| 461 | The CGI.pm module (which comes with Perl) has functions to create | |
| 462 | the HTML form widgets. See the CGI.pm documentation for more | |
| 463 | examples. | |
| 464 | ||
| 465 | =end original | |
| 466 | ||
| 467 | CGI.pm モジュール(標準配布です)には HTML フォームウィジェットを作るための | |
| 468 | 関数があります。 | |
| 469 | 更なる例については CGI.pm の文書を参照してください。 | |
| 470 | ||
| 471 | use CGI qw/:standard/; | |
| 472 | print header, | |
| 473 | start_html('Favorite Animals'), | |
| 474 | ||
| 475 | start_form, | |
| 476 | "What's your favorite animal? ", | |
| 477 | popup_menu( | |
| 478 | -name => 'animal', | |
| 479 | -values => [ qw( Llama Alpaca Camel Ram ) ] | |
| 480 | ), | |
| 481 | submit, | |
| 482 | ||
| 483 | end_form, | |
| 484 | end_html; | |
| 485 | ||
| 486 | 251 | =head2 How do I fetch an HTML file? |
| 487 | 252 | |
| 488 | 253 | (HTML ファイルをフェッチするには?) |
| 489 | 254 | |
| 490 | 255 | =begin original |
| 491 | 256 | |
| 492 | 257 | (contributed by brian d foy) |
| 493 | 258 | |
| 494 | 259 | =end original |
| 495 | 260 | |
| 496 | 261 | (brian d foy によって寄贈されました) |
| 497 | 262 | |
| 498 | 263 | =begin original |
| 499 | 264 | |
| 500 | Use the libwww-perl distribution. The | |
| 265 | Use the libwww-perl distribution. The L<LWP::Simple> module can fetch web | |
| 501 | 266 | resources and give their content back to you as a string: |
| 502 | 267 | |
| 503 | 268 | =end original |
| 504 | 269 | |
| 505 | 270 | libwww-perl ディストリビューションを使ってください。 |
| 506 | ||
| 271 | L<LWP::Simple> はウェブ上のリソースをフェッチして、その内容を文字列として | |
| 507 | 272 | 返します: |
| 508 | 273 | |
| 509 | ||
| 274 | use LWP::Simple qw(get); | |
| 510 | 275 | |
| 511 | ||
| 276 | my $html = get( "http://www.example.com/index.html" ); | |
| 512 | 277 | |
| 513 | 278 | =begin original |
| 514 | 279 | |
| 515 | 280 | It can also store the resource directly in a file: |
| 516 | 281 | |
| 517 | 282 | =end original |
| 518 | 283 | |
| 519 | 284 | リソースを直接ファイルに保存することもできます: |
| 520 | 285 | |
| 521 | ||
| 286 | use LWP::Simple qw(getstore); | |
| 522 | 287 | |
| 523 | ||
| 288 | getstore( "http://www.example.com/index.html", "foo.html" ); | |
| 524 | 289 | |
| 525 | 290 | =begin original |
| 526 | 291 | |
| 527 | 292 | If you need to do something more complicated, you can use |
| 528 | ||
| 293 | L<LWP::UserAgent> module to create your own user-agent (e.g. browser) | |
| 529 | 294 | to get the job done. If you want to simulate an interactive web |
| 530 | browser, you can use the | |
| 295 | browser, you can use the L<WWW::Mechanize> module. | |
| 531 | 296 | |
| 532 | 297 | =end original |
| 533 | 298 | |
| 534 | 299 | もっと複雑なことをする必要がある場合は、仕事を行うための独自の |
| 535 | 300 | ユーザーエージェント(例えばブラウザ)を作るために |
| 536 | ||
| 301 | L<LWP::UserAgent> モジュールを使えます。 | |
| 537 | 302 | 対話的なウェブブラウザをシミュレートしたい場合は、 |
| 538 | ||
| 303 | L<WWW::Mechanize> モジュールが使えます。 | |
| 539 | 304 | |
| 540 | 305 | =head2 How do I automate an HTML form submission? |
| 541 | 306 | |
| 542 | 307 | (HTML フォームの処理を自動化するには?) |
| 543 | 308 | |
| 544 | 309 | =begin original |
| 545 | 310 | |
| 546 | 311 | If you are doing something complex, such as moving through many pages |
| 547 | and forms or a web site, you can use | |
| 312 | and forms or a web site, you can use L<WWW::Mechanize>. See its | |
| 548 | 313 | documentation for all the details. |
| 549 | 314 | |
| 550 | 315 | =end original |
| 551 | 316 | |
| 552 | 317 | もし、複数のページとフォームや web サイトを移動するような、複雑なことを |
| 553 | しようとしているなら、 | |
| 318 | しようとしているなら、L<WWW::Mechanize> が使えます。 | |
| 554 | 319 | 全ての詳細についてはこれのドキュメントを参照してください。 |
| 555 | 320 | |
| 556 | 321 | =begin original |
| 557 | 322 | |
| 558 | 323 | If you're submitting values using the GET method, create a URL and encode |
| 559 | 324 | the form using the C<query_form> method: |
| 560 | 325 | |
| 561 | 326 | =end original |
| 562 | 327 | |
| 563 | 328 | GET メソッドを使って値を処理しているのであれば、URL を作って、 |
| 564 | 329 | さらに C<query_form> メソッドを使ってフォームをエンコードします: |
| 565 | 330 | |
| 566 | ||
| 331 | use LWP::Simple; | |
| 567 | ||
| 332 | use URI::URL; | |
| 568 | 333 | |
| 569 | ||
| 334 | my $url = url('L<http://www.perl.com/cgi-bin/cpan_mod')>; | |
| 570 | ||
| 335 | $url->query_form(module => 'DB_File', readme => 1); | |
| 571 | ||
| 336 | $content = get($url); | |
| 572 | 337 | |
| 573 | 338 | =begin original |
| 574 | 339 | |
| 575 | 340 | If you're using the POST method, create your own user agent and encode |
| 576 | 341 | the content appropriately. |
| 577 | 342 | |
| 578 | 343 | =end original |
| 579 | 344 | |
| 580 | 345 | POST メソッドを使っているのであれば、自分用のエージェントを作成して |
| 581 | 346 | コンテンツを適切にエンコードしてやります。 |
| 582 | 347 | |
| 583 | ||
| 348 | use HTTP::Request::Common qw(POST); | |
| 584 | ||
| 349 | use LWP::UserAgent; | |
| 585 | 350 | |
| 586 | ||
| 351 | my $ua = LWP::UserAgent->new(); | |
| 587 | ||
| 352 | my $req = POST 'L<http://www.perl.com/cgi-bin/cpan_mod'>, | |
| 588 | ||
| 353 | [ module => 'DB_File', readme => 1 ]; | |
| 589 | ||
| 354 | my $content = $ua->request($req)->as_string; | |
| 590 | 355 | |
| 591 | 356 | =head2 How do I decode or create those %-encodings on the web? |
| 592 | X<URI> X< | |
| 357 | X<URI> X<URI::Escape> X<RFC 2396> | |
| 593 | 358 | |
| 594 | 359 | (web上で %-encodings をデコードしたり生成したりするには?) |
| 595 | 360 | |
| 596 | 361 | =begin original |
| 597 | 362 | |
| 598 | ||
| 363 | Most of the time you should not need to do this as | |
| 364 | your web framework, or if you are making a request, | |
| 365 | the L<LWP> or other module would handle it for you. | |
| 599 | 366 | |
| 600 | 367 | =end original |
| 601 | 368 | |
| 602 | ||
| 369 | ほとんどの場合、web フレームワークでこれを行う必要はないはずです; | |
| 370 | リクエストを作ったときには、L<LWP> やその他のモジュールが代わりにこれらを | |
| 371 | 扱います。 | |
| 603 | 372 | |
| 604 | 373 | =begin original |
| 605 | 374 | |
| 606 | T | |
| 375 | To encode a string yourself, use the L<URI::Escape> module. The C<uri_escape> | |
| 607 | ||
| 376 | function returns the escaped string: | |
| 608 | with the hexadecimal representation of the character's number from | |
| 609 | the US-ASCII table. For instance, a colon, C<:>, becomes C<%3A>. | |
| 610 | 377 | |
| 611 | 378 | =end original |
| 612 | 379 | |
| 613 | ||
| 380 | 自分で文字列をエンコードするには、L<URI::Escape> モジュールを使ってください。 | |
| 614 | URI として予約されている文字を扱います。 | |
| 615 | この符号化は予約文字を、その文字の番号の 16 進表現に | |
| 616 | US-ASCII テーブルを使って置き換えます。 | |
| 617 | 例えば、コロン (C<:>) は C<%3A> になります。 | |
| 618 | ||
| 619 | =begin original | |
| 620 | ||
| 621 | In CGI scripts, you don't have to worry about decoding URIs if you are | |
| 622 | using C<CGI.pm>. You shouldn't have to process the URI yourself, | |
| 623 | either on the way in or the way out. | |
| 624 | ||
| 625 | =end original | |
| 626 | ||
| 627 | CGI スクリプトでは、C<CGI.pm> を使っているなら URL のデコードについて | |
| 628 | 気にする必要はありません。 | |
| 629 | エンコードにしてもデコードにしても、URI を自分で処理する必要はないはずです。 | |
| 630 | ||
| 631 | =begin original | |
| 632 | ||
| 633 | If you have to encode a string yourself, remember that you should | |
| 634 | never try to encode an already-composed URI. You need to escape the | |
| 635 | components separately then put them together. To encode a string, you | |
| 636 | can use the the C<URI::Escape> module. The C<uri_escape> function | |
| 637 | returns the escaped string: | |
| 638 | ||
| 639 | =end original | |
| 640 | ||
| 641 | もし文字列を自分でエンコードする必要があるなら、 | |
| 642 | 決してすでに構成された URI をエンコードするべきではないことを | |
| 643 | 忘れないでください。 | |
| 644 | 要素を別々にエスケープして、それから全てを合わせます。 | |
| 645 | 文字列をエンコードするには、C<URI::Escape> モジュールが使えます。 | |
| 646 | 381 | C<uri_escape> 関数はエスケープされた文字列を返します: |
| 647 | 382 | |
| 648 | ||
| 383 | my $original = "Colon : Hash # Percent %"; | |
| 649 | 384 | |
| 650 | ||
| 385 | my $escaped = uri_escape( $original ); | |
| 651 | 386 | |
| 652 | ||
| 387 | print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25' | |
| 653 | 388 | |
| 654 | 389 | =begin original |
| 655 | 390 | |
| 656 | 391 | To decode the string, use the C<uri_unescape> function: |
| 657 | 392 | |
| 658 | 393 | =end original |
| 659 | 394 | |
| 660 | 395 | 文字列をデコードするには、C<uri_unescape> 関数を使います: |
| 661 | 396 | |
| 662 | ||
| 397 | my $unescaped = uri_unescape( $escaped ); | |
| 663 | 398 | |
| 664 | ||
| 399 | print $unescaped; # back to original | |
| 665 | 400 | |
| 666 | 401 | =begin original |
| 667 | 402 | |
| 668 | ||
| 403 | Remember not to encode a full URI, you need to escape each | |
| 669 | ||
| 404 | component separately and then join them together. | |
| 670 | is one way to do it: | |
| 671 | 405 | |
| 672 | 406 | =end original |
| 673 | 407 | |
| 674 | ||
| 408 | URI 全体をエンコードするのではなく、それぞれの要素を別々にエスケープして | |
| 675 | ||
| 409 | それから互いに結合する必要があることを忘れないでください。 | |
| 676 | 410 | |
| 677 | # encode | |
| 678 | $string =~ s/([^^A-Za-z0-9\-_.!~*'()])/ sprintf "%%%0x", ord $1 /eg; | |
| 679 | ||
| 680 | #decode | |
| 681 | $string =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg; | |
| 682 | ||
| 683 | 411 | =head2 How do I redirect to another page? |
| 684 | 412 | |
| 685 | 413 | (別のページにリダイレクトするには?) |
| 686 | 414 | |
| 687 | 415 | =begin original |
| 688 | 416 | |
| 689 | ||
| 417 | Most Perl Web Frameworks will have a mechanism for doing this, | |
| 690 | s | |
| 418 | using the L<Catalyst> framework it would be: | |
| 691 | responses which are defined in the CGI specification for a Parsed Headers | |
| 692 | script. The other kind (an absolute URLpath) is resolved internally to | |
| 693 | the server without any HTTP redirection. The CGI specifications do not | |
| 694 | allow relative URLs in either case. | |
| 695 | 419 | |
| 696 | 420 | =end original |
| 697 | 421 | |
| 698 | ||
| 422 | ほとんどの Perl Web フレームワークはこれを行う機構があります; L<Catalyst> | |
| 699 | ||
| 423 | フレームワークを使っているなら以下のようになります: | |
| 700 | CGI "Location:" レスポンスのうちの一つです。 | |
| 701 | その他の種類 (絶対 URL パス) は HTTP リダイレクトなしにサーバによって | |
| 702 | 内部的に解決されます。 | |
| 703 | CGI 仕様ではどちらの場合でも相対 URL は認められていません。 | |
| 704 | 424 | |
| 705 | ||
| 425 | $c->res->redirect($url); | |
| 426 | $c->detach(); | |
| 706 | 427 | |
| 707 | Use of CGI.pm is strongly recommended. This example shows redirection | |
| 708 | with a complete URL. This redirection is handled by the web browser. | |
| 709 | ||
| 710 | =end original | |
| 711 | ||
| 712 | CGI.pm を使うことを強くお勧めします。 | |
| 713 | この例では完全な URL へのリダイレクトを行います。 | |
| 714 | このリダイレクトは web ブラウザによって扱われます。 | |
| 715 | ||
| 716 | use CGI qw/:standard/; | |
| 717 | ||
| 718 | my $url = 'http://www.cpan.org/'; | |
| 719 | print redirect($url); | |
| 720 | ||
| 721 | 428 | =begin original |
| 722 | 429 | |
| 723 | ||
| 430 | If you are using Plack (which most frameworks do), then | |
| 724 | ||
| 431 | L<Plack::Middleware::Rewrite> is worth looking at if you | |
| 432 | are migrating from Apache or have URL's you want to always | |
| 433 | redirect. | |
| 725 | 434 | |
| 726 | 435 | =end original |
| 727 | 436 | |
| 728 | ||
| 437 | (ほとんどのフレームワークが使っている) Plack を使っていて、 | |
| 729 | ||
| 438 | Apache からの移動や常にリダイレクトしたい URL があるなら、 | |
| 439 | L<Plack::Middleware::Rewrite> は見る価値があるでしょう。 | |
| 730 | 440 | |
| 731 | my $url = '/CPAN/index.html'; | |
| 732 | print redirect($url); | |
| 733 | ||
| 734 | =begin original | |
| 735 | ||
| 736 | But if coded directly, it could be as follows (the final "\n" is | |
| 737 | shown separately, for clarity), using either a complete URL or | |
| 738 | an absolute URLpath. | |
| 739 | ||
| 740 | =end original | |
| 741 | ||
| 742 | しかし、直接コーディングするなら、完全な URL か絶対 URLpath を使って、 | |
| 743 | 以下のようになります(最後の "\n" は明確化するために分けて表示しています)。 | |
| 744 | ||
| 745 | print "Location: $url\n"; # CGI response header | |
| 746 | print "\n"; # end of headers | |
| 747 | ||
| 748 | 441 | =head2 How do I put a password on my web pages? |
| 749 | 442 | |
| 750 | 443 | (私の web ぺージでパスワードを入力するには?) |
| 751 | 444 | |
| 752 | 445 | =begin original |
| 753 | 446 | |
| 754 | ||
| 447 | See if the web framework you are using has an | |
| 755 | ||
| 448 | authentication system and if that fits your needs. | |
| 756 | of web servers--apache does it differently from iPlanet which does | |
| 757 | it differently from IIS. Check your web server documentation for | |
| 758 | the details for your particular server. | |
| 759 | 449 | |
| 760 | 450 | =end original |
| 761 | 451 | |
| 762 | ||
| 452 | 使っている web フレームワークが認証システムを持っているか、そしてそれが | |
| 763 | ||
| 453 | 目的に合致しているかを調べてください。 | |
| 764 | web サーバの種類によって設定は異なります -- apache は iPlanet とは異なり、 | |
| 765 | また IIS とも異なります。 | |
| 766 | 特定のサーバーに関する詳細については、そのサーバーのドキュメントを | |
| 767 | チェックしてください。 | |
| 768 | 454 | |
| 769 | =head2 How do I edit my .htpasswd and .htgroup files with Perl? | |
| 770 | ||
| 771 | (Perl を使って .htpasswd や .htgroup といったファイルを編集するには?) | |
| 772 | ||
| 773 | 455 | =begin original |
| 774 | 456 | |
| 775 | ||
| 457 | Alternativly look at L<Plack::Middleware::Auth::Basic>, | |
| 776 | ||
| 458 | or one of the other L<Plack authentication|https://metacpan.org/search?q=plack+auth> | |
| 777 | ||
| 459 | options. | |
| 778 | a DBI compatible driver. HTTPD::UserAdmin supports files used by the | |
| 779 | "Basic" and "Digest" authentication schemes. Here's an example: | |
| 780 | 460 | |
| 781 | 461 | =end original |
| 782 | 462 | |
| 783 | ||
| 463 | あるいは、L<Plack::Middleware::Auth::Basic> またはその他の | |
| 784 | ||
| 464 | L<Plack 認証|https://metacpan.org/search?q=plack+auth> オプションの一つを | |
| 785 | ||
| 465 | 見てください。 | |
| 786 | データベースはテキスト、dbm、Berkeley DB、あるいは DBI 互換ドライバのある | |
| 787 | どんなデータベースでもかまいません。 | |
| 788 | HTTPD::UserAdmin は "Basic" および "Digest" 認証スキームで | |
| 789 | 使われるファイルをサポートします。 | |
| 790 | 以下に例を挙げます: | |
| 791 | 466 | |
| 792 | ||
| 467 | =head2 How do I make sure users can't enter values into a form that causes my CGI script to do bad things? | |
| 793 | HTTPD::UserAdmin | |
| 794 | ->new(DB => "/foo/.htpasswd") | |
| 795 | ->add($username => $password); | |
| 796 | 468 | |
| 797 | =head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things? | |
| 798 | ||
| 799 | 469 | (私の CGI スクリプトに悪影響をもたらすようなものを、ユーザーがフォームに入力できないようにするには?) |
| 800 | 470 | |
| 801 | 471 | =begin original |
| 802 | 472 | |
| 803 | See the security references listed in the CGI Meta FAQ | |
| 804 | ||
| 805 | =end original | |
| 806 | ||
| 807 | CGI Meta FAQ に挙げられているセキュリティに関する参考資料を参照してください。 | |
| 808 | ||
| 809 | http://www.perl.org/CGI_MetaFAQ.html | |
| 810 | ||
| 811 | =head2 How do I parse a mail header? | |
| 812 | ||
| 813 | (メールのヘッダーを解析するには?) | |
| 814 | ||
| 815 | =begin original | |
| 816 | ||
| 817 | For a quick-and-dirty solution, try this solution derived | |
| 818 | from L<perlfunc/split>: | |
| 819 | ||
| 820 | =end original | |
| 821 | ||
| 822 | 拙速な解決策なら、L<perlfunc/split> から派生した | |
| 823 | 以下のやり方を試してみてください。 | |
| 824 | ||
| 825 | $/ = ''; | |
| 826 | $header = <MSG>; | |
| 827 | $header =~ s/\n\s+/ /g; # merge continuation lines | |
| 828 | %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header ); | |
| 829 | ||
| 830 | =begin original | |
| 831 | ||
| 832 | That solution doesn't do well if, for example, you're trying to | |
| 833 | maintain all the Received lines. A more complete approach is to use | |
| 834 | the Mail::Header module from CPAN (part of the MailTools package). | |
| 835 | ||
| 836 | =end original | |
| 837 | ||
| 838 | このやり方は、たとえば受信した行すべてを保守しようとするときには | |
| 839 | うまくありません。 | |
| 840 | より完璧なアプローチはCPANにあるMail::Header モジュールを | |
| 841 | 使うというものです(このモジュールは MailTools パッケージの一部です)。 | |
| 842 | ||
| 843 | =head2 How do I decode a CGI form? | |
| 844 | ||
| 845 | (CGI フォームをデコードするには?) | |
| 846 | ||
| 847 | =begin original | |
| 848 | ||
| 849 | 473 | (contributed by brian d foy) |
| 850 | 474 | |
| 851 | 475 | =end original |
| 852 | 476 | |
| 853 | 477 | (brian d foy によって寄贈されました) |
| 854 | 478 | |
| 855 | 479 | =begin original |
| 856 | 480 | |
| 857 | ||
| 481 | You can't prevent people from sending your script bad data. Even if | |
| 858 | ||
| 482 | you add some client-side checks, people may disable them or bypass | |
| 859 | ||
| 483 | them completely. For instance, someone might use a module such as | |
| 860 | ||
| 484 | L<LWP> to submit to your web site. If you want to prevent data that | |
| 861 | ||
| 485 | try to use SQL injection or other sorts of attacks (and you should | |
| 862 | you | |
| 486 | want to), you have to not trust any data that enter your program. | |
| 863 | 487 | |
| 864 | 488 | =end original |
| 865 | 489 | |
| 866 | ||
| 490 | 人々がスクリプトに悪いデータを送るのを防ぐことは出来ません。 | |
| 867 | ||
| 491 | 例えクライアント側でチェックをしたとしても、それを無効にしたり | |
| 868 | ||
| 492 | 完全に回避したりできます。 | |
| 869 | ||
| 493 | 例えば、L<LWP> のようなモジュールを使って web サイトに | |
| 870 | ||
| 494 | 投稿するかもしれません。 | |
| 871 | ||
| 495 | SQL インジェクションや同様の種類の攻撃を行うようなデータを防ぎたいのなら | |
| 496 | (そしておそらくそうしたいでしょう)、プログラムに入力される | |
| 497 | どんなデータも信用しないようにする必要があります。 | |
| 872 | 498 | |
| 873 | 499 | =begin original |
| 874 | 500 | |
| 875 | ||
| 501 | The L<perlsec> documentation has general advice about data security. | |
| 876 | ||
| 502 | If you are using the L<DBI> module, use placeholder to fill in data. | |
| 877 | ||
| 503 | If you are running external programs with C<system> or C<exec>, use | |
| 504 | the list forms. There are many other precautions that you should take, | |
| 505 | too many to list here, and most of them fall under the category of not | |
| 506 | using any data that you don't intend to use. Trust no one. | |
| 878 | 507 | |
| 879 | 508 | =end original |
| 880 | 509 | |
| 881 | ||
| 510 | L<perlsec> 文書にはデータセキュリティに関する一般的な助言があります。 | |
| 882 | ||
| 511 | L<DBI> モジュールを使っているなら、データを埋めるのにプレースホルダを | |
| 512 | 使ってください。 | |
| 513 | C<system> や C<exec> で外部プログラムを実行しているなら、リスト形式を | |
| 514 | 使ってください。 | |
| 515 | その他、ここに書ききれないほどの注意するべき多くの事前注意があり、 | |
| 516 | そのほとんどは、使おうとしていないデータは使わないという分野に当てはまります。 | |
| 517 | 誰も信用しないでください。 | |
| 883 | 518 | |
| 884 | ||
| 519 | =head2 How do I parse a mail header? | |
| 885 | 520 | |
| 886 | ||
| 521 | (メールのヘッダーを解析するには?) | |
| 887 | 522 | |
| 888 | my @items = param( 'item' ); # multiple values, same field name | |
| 889 | ||
| 890 | 523 | =begin original |
| 891 | 524 | |
| 892 | ||
| 525 | Use the L<Email::MIME> module. It's well-tested and supports all the | |
| 526 | craziness that you'll see in the real world (comment-folding whitespace, | |
| 527 | encodings, comments, etc.). | |
| 893 | 528 | |
| 894 | 529 | =end original |
| 895 | 530 | |
| 896 | ||
| 531 | L<Email::MIME> モジュールを使ってください。 | |
| 532 | これはよくテストされていて、現実世界で見ることになるあらゆる狂気 | |
| 533 | (コメント畳み込み空白、エンコーディング、コメントなど)に対応しています。 | |
| 897 | 534 | |
| 898 | ||
| 535 | use Email::MIME; | |
| 899 | 536 | |
| 900 | ||
| 537 | my $message = Email::MIME->new($rfc2822); | |
| 538 | my $subject = $message->header('Subject'); | |
| 539 | my $from = $message->header('From'); | |
| 901 | 540 | |
| 902 | my $total = $cgi->param( 'price' ) + $cgi->param( 'shipping' ); | |
| 903 | ||
| 904 | my @items = $cgi->param( 'item' ); | |
| 905 | ||
| 906 | 541 | =begin original |
| 907 | 542 | |
| 908 | ||
| 543 | If you've already got some other kind of email object, consider passing | |
| 909 | ||
| 544 | it to L<Email::Abstract> and then using its cast method to get an | |
| 910 | ||
| 545 | L<Email::MIME> object: | |
| 911 | 546 | |
| 912 | 547 | =end original |
| 913 | 548 | |
| 914 | ||
| 549 | 既に何らかの他の種類のメールオブジェクトがあるなら、それを | |
| 915 | ||
| 550 | L<Email::Abstract> に渡して、それから L<Email::MIME> オブジェクトを | |
| 551 | 得るために cast メソッドを使うことを考慮してください: | |
| 916 | 552 | |
| 917 | ||
| 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'); | |
| 918 | 556 | |
| 919 | Many people try to write their own decoder (or copy one from | |
| 920 | another program) and then run into one of the many "gotchas" | |
| 921 | of the task. It's much easier and less hassle to use CGI.pm. | |
| 922 | ||
| 923 | =end original | |
| 924 | ||
| 925 | 多くの人々が自分用のデコーダを書こうとします (あるいは他のプログラムから | |
| 926 | コピーしようとします); そしてこの作業の多くの「コツ」の一つに出くわすことに | |
| 927 | なります。 | |
| 928 | CGI.pm を使うことはより簡単で、面倒事も少なくなります。 | |
| 929 | ||
| 930 | 557 | =head2 How do I check a valid mail address? |
| 931 | 558 | |
| 932 | 559 | (メールアドレスが正しいかチェックするには?) |
| 933 | 560 | |
| 934 | 561 | =begin original |
| 935 | 562 | |
| 936 | 563 | (partly contributed by Aaron Sherman) |
| 937 | 564 | |
| 938 | 565 | =end original |
| 939 | 566 | |
| 940 | 567 | (一部は Aaron Sherman によって寄贈されました) |
| 941 | 568 | |
| 942 | 569 | =begin original |
| 943 | 570 | |
| 944 | This isn't as simple a question as it sounds. | |
| 571 | This isn't as simple a question as it sounds. There are two parts: | |
| 945 | 572 | |
| 946 | 573 | =end original |
| 947 | 574 | |
| 948 | 575 | これは見た目ほど単純な質問ではありません。 |
| 949 | 576 | これは二つの部分からなります: |
| 950 | 577 | |
| 951 | 578 | =begin original |
| 952 | 579 | |
| 953 | 580 | a) How do I verify that an email address is correctly formatted? |
| 954 | 581 | |
| 955 | 582 | =end original |
| 956 | 583 | |
| 957 | 584 | a) メールアドレスが正しい形式かを検証するには? |
| 958 | 585 | |
| 959 | 586 | =begin original |
| 960 | 587 | |
| 961 | 588 | b) How do I verify that an email address targets a valid recipient? |
| 962 | 589 | |
| 963 | 590 | =end original |
| 964 | 591 | |
| 965 | 592 | b) メールアドレスが正当な受信者を対象としているかを検証するには? |
| 966 | 593 | |
| 967 | 594 | =begin original |
| 968 | 595 | |
| 969 | 596 | Without sending mail to the address and seeing whether there's a human |
| 970 | 597 | on the other end to answer you, you cannot fully answer part I<b>, but |
| 971 | ||
| 598 | the L<Email::Valid> module will do both part I<a> and part I<b> as far | |
| 972 | ||
| 599 | as you can in real-time. | |
| 973 | 600 | |
| 974 | 601 | =end original |
| 975 | 602 | |
| 976 | 603 | そのアドレスにメールを送ってそれが届いたかどうかを確認しなければ |
| 977 | 604 | 完全にパート I<b> に答えられませんが、C<Email::Valid> か |
| 978 | 605 | C<RFC::RFC822::Address> のモジュールは、リアルタイムでできる限りの |
| 979 | 606 | ことに対してパート I<a> とパート I<b> の両方を行います。 |
| 980 | 607 | |
| 981 | 608 | =begin original |
| 982 | 609 | |
| 983 | If you want to just check part I<a> to see that the address is valid | |
| 984 | according to the mail header standard with a simple regular expression, | |
| 985 | you can have problems, because there are deliverable addresses that | |
| 986 | aren't RFC-2822 (the latest mail header standard) compliant, and | |
| 987 | addresses that aren't deliverable which, are compliant. However, the | |
| 988 | following will match valid RFC-2822 addresses that do not have comments, | |
| 989 | folding whitespace, or any other obsolete or non-essential elements. | |
| 990 | This I<just> matches the address itself: | |
| 991 | ||
| 992 | =end original | |
| 993 | ||
| 994 | もしあなたが単純な正規表現でアドレスがメールヘッダ標準に従っているかを | |
| 995 | 見ることでパート I<a> をチェックしたいなら、問題を抱えることになります; | |
| 996 | なぜなら、RFC-2822 (最新のメールヘッダ標準) に準拠してないけれども | |
| 997 | 配達可能なアドレスが存在し、標準に準拠しているけれども配達不能なアドレスも | |
| 998 | 存在するからです。 | |
| 999 | しかし以下のコードは、コメント、折り畳みの空白、あるいはその他の時代遅れに | |
| 1000 | なっていたり本質的でない要素を含んでいない、有効な RFC-2822 アドレスに | |
| 1001 | マッチングします。 | |
| 1002 | これは I<単に> アドレス自身にマッチングします: | |
| 1003 | ||
| 1004 | my $atom = qr{[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+}; | |
| 1005 | my $dot_atom = qr{$atom(?:\.$atom)*}; | |
| 1006 | my $quoted = qr{"(?:\\[^\r\n]|[^\\"])*"}; | |
| 1007 | my $local = qr{(?:$dot_atom|$quoted)}; | |
| 1008 | my $quotedpair = qr{\\[\x00-\x09\x0B-\x0c\x0e-\x7e]}; | |
| 1009 | my $domain_lit = qr{\[(?:$quotedpair|[\x21-\x5a\x5e-\x7e])*\]}; | |
| 1010 | my $domain = qr{(?:$dot_atom|$domain_lit)}; | |
| 1011 | my $addr_spec = qr{$local\@$domain}; | |
| 1012 | ||
| 1013 | =begin original | |
| 1014 | ||
| 1015 | Just match an address against C</^${addr_spec}$/> to see if it follows | |
| 1016 | the RFC2822 specification. However, because it is impossible to be | |
| 1017 | sure that such a correctly formed address is actually the correct way | |
| 1018 | to reach a particular person or even has a mailbox associated with it, | |
| 1019 | you must be very careful about how you use this. | |
| 1020 | ||
| 1021 | =end original | |
| 1022 | ||
| 1023 | もしアドレスが RFC 2822 仕様に準拠しているかどうかを見たいなら、単に | |
| 1024 | C</^${addr_spec}$/> とマッチングさせてください。 | |
| 1025 | しかし、このような正しい形式のアドレスが実際に特定の個人に届く | |
| 1026 | 正しい方法なのか、あるいはその個人に関連付けられたメールボックスに | |
| 1027 | 届くのかさえも明確にすることは不可能なので、これをどう使うかについては | |
| 1028 | とても慎重になる必要があります。 | |
| 1029 | ||
| 1030 | =begin original | |
| 1031 | ||
| 1032 | 610 | Our best advice for verifying a person's mail address is to have them |
| 1033 | 611 | enter their address twice, just as you normally do to change a |
| 1034 | 612 | password. This usually weeds out typos. If both versions match, send |
| 1035 | 613 | mail to that address with a personal message. If you get the message |
| 1036 | 614 | back and they've followed your directions, you can be reasonably |
| 1037 | 615 | assured that it's real. |
| 1038 | 616 | |
| 1039 | 617 | =end original |
| 1040 | 618 | |
| 1041 | 619 | 私たちができる最善のアドバイスは、個人のメールアドレスをチェックするのに |
| 1042 | 620 | パスワードを変更するときと同じようにユーザーにアドレスを |
| 1043 | 621 | 二回入力させるというものです。 |
| 1044 | 622 | これによって通常は打ち間違いを防ぐことができます。 |
| 1045 | 623 | 二回の入力がマッチしたなら、個人的な内容のメッセージをメールとして |
| 1046 | 624 | そのアドレスへ送ります。 |
| 1047 | 625 | もしメッセージが返ってきて、それがあなたの指示に従っているなら、 |
| 1048 | 626 | それが実際のものであると十分に仮定できます。 |
| 1049 | 627 | |
| 1050 | 628 | =begin original |
| 1051 | 629 | |
| 1052 | 630 | A related strategy that's less open to forgery is to give them a PIN |
| 1053 | (personal ID number). | |
| 631 | (personal ID number). Record the address and PIN (best that it be a | |
| 1054 | random one) for later processing. In the mail you send, a | |
| 632 | random one) for later processing. In the mail you send, include a link to | |
| 1055 | ||
| 633 | your site with the PIN included. If the mail bounces, you know it's not | |
| 1056 | ||
| 634 | valid. If they don't click on the link, either they forged the address or | |
| 1057 | ||
| 635 | (assuming they got the message) following through wasn't important so you | |
| 1058 | ||
| 636 | don't need to worry about it. | |
| 1059 | 637 | |
| 1060 | 638 | =end original |
| 1061 | 639 | |
| 1062 | より偽造のやりにくい別のやり方に、チェックに対象者に対して PIN | |
| 640 | より偽造のやりにくい別のやり方に、チェックに対象者に対して PIN (Personal ID | |
| 1063 | ||
| 641 | Number) を与えるというものがあります。 | |
| 1064 | 642 | 後の処理のためにアドレスと PIN (ランダムであることが望ましい)を |
| 1065 | 643 | 記録しておくのです。 |
| 1066 | あなたがメールを送るときに、 | |
| 644 | あなたがメールを送るときに、PIN が含まれたあなたのサイトへのリンクを | |
| 1067 | ||
| 645 | 含めてください。 | |
| 1068 | ||
| 646 | メールがバウンスしたなら、不正であることが分かります。 | |
| 1069 | ||
| 647 | リンクがクリックされなければ、アドレスが偽造されたか、(メッセージが | |
| 1070 | ||
| 648 | 届いたとして) 最後まで行うことが重要ではなかったのでそれについて | |
| 1071 | ||
| 649 | 気にする必要はないと言うことです。 | |
| 1072 | 各桁に対して足し算や引き算を行うなどして | |
| 1073 | PIN を変形したものを含めて返すように依頼するという方法です。 | |
| 1074 | 650 | |
| 1075 | 651 | =head2 How do I decode a MIME/BASE64 string? |
| 1076 | 652 | |
| 1077 | 653 | (MIME/BASE64 文字列のデコードを行うには?) |
| 1078 | 654 | |
| 1079 | 655 | =begin original |
| 1080 | 656 | |
| 1081 | The MIME | |
| 657 | The L<MIME::Base64> package handles this as well as the MIME/QP encoding. | |
| 1082 | ||
| 658 | Decoding base 64 becomes as simple as: | |
| 1083 | 659 | |
| 1084 | 660 | =end original |
| 1085 | 661 | |
| 1086 | MIME | |
| 662 | L<MIME::Base64> パッケージはこの問題と、 | |
| 1087 | 663 | MIME/QP エンコーディングを取り扱います。 |
| 1088 | 664 | BASE64 のデコードは以下のように単純です: |
| 1089 | 665 | |
| 1090 | ||
| 666 | use MIME::Base64; | |
| 1091 | ||
| 667 | my $decoded = decode_base64($encoded); | |
| 1092 | 668 | |
| 1093 | 669 | =begin original |
| 1094 | 670 | |
| 1095 | The MIME | |
| 671 | The L<Email::MIME> module can decode base 64-encoded email message parts | |
| 1096 | ||
| 672 | transparently so the developer doesn't need to worry about it. | |
| 1097 | messages. | |
| 1098 | 673 | |
| 1099 | 674 | =end original |
| 1100 | 675 | |
| 1101 | MIME | |
| 676 | L<Email::MIME> モジュールは BASE64 でエンコードされたメールのメッセージ部分を | |
| 1102 | ||
| 677 | 透過的にデコードできるので、開発者はそれについて気にする必要はありません。 | |
| 1103 | 678 | |
| 1104 | = | |
| 679 | =head2 How do I find the user's mail address? | |
| 1105 | 680 | |
| 1106 | ||
| 681 | (あるユーザーのメールアドレスを知るには?) | |
| 1107 | a more direct approach is to use the unpack() function's "u" | |
| 1108 | format after minor transliterations: | |
| 1109 | 682 | |
| 1110 | =end original | |
| 1111 | ||
| 1112 | もしデコードしたい文字列が短い(84 文字以下)の場合、より直接的なやり方は、 | |
| 1113 | ちょっとした変換をした後で unpack() 関数の "u" フォーマットを | |
| 1114 | 使うというものです: | |
| 1115 | ||
| 1116 | tr#A-Za-z0-9+/##cd; # remove non-base64 chars | |
| 1117 | tr#A-Za-z0-9+/# -_#; # convert to uuencoded format | |
| 1118 | $len = pack("c", 32 + 0.75*length); # compute length byte | |
| 1119 | print unpack("u", $len . $_); # uudecode and print | |
| 1120 | ||
| 1121 | =head2 How do I return the user's mail address? | |
| 1122 | ||
| 1123 | (ユーザーのメールアドレスを返すには?) | |
| 1124 | ||
| 1125 | 683 | =begin original |
| 1126 | 684 | |
| 1127 | ||
| 685 | Ask them for it. There are so many email providers available that it's | |
| 1128 | ||
| 686 | unlikely the local system has any idea how to determine a user's email address. | |
| 1129 | you can probably try using something like this: | |
| 1130 | 687 | |
| 1131 | 688 | =end original |
| 1132 | 689 | |
| 1133 | ||
| 690 | その人に聞いてください。 | |
| 1134 | ||
| 691 | 多くのメールプロバイダが利用可能なので、ローカルシステムがユーザーの | |
| 1135 | ||
| 692 | メールアドレスを決定する方法はまずありません。 | |
| 1136 | 693 | |
| 1137 | use Sys::Hostname; | |
| 1138 | $address = sprintf('%s@%s', scalar getpwuid($<), hostname); | |
| 1139 | ||
| 1140 | 694 | =begin original |
| 1141 | 695 | |
| 1142 | ||
| 696 | The exception is for organization-specific email (e.g. foo@yourcompany.com) | |
| 1143 | ||
| 697 | where policy can be codified in your program. In that case, you could look at | |
| 1144 | ||
| 698 | $ENV{USER}, $ENV{LOGNAME}, and getpwuid($<) in scalar context, like so: | |
| 1145 | on which Perl runs are so forthcoming with this information as is Unix. | |
| 1146 | 699 | |
| 1147 | 700 | =end original |
| 1148 | 701 | |
| 1149 | ||
| 702 | 例外は、組織に固有のメール (例えば foo@yourcompany.com) で、ポリシーを | |
| 1150 | ||
| 703 | プログラムにコード化できる場合です。 | |
| 1151 | ||
| 704 | この場合、以下のように | |
| 1152 | ||
| 705 | $ENV{USER}, $ENV{LOGNAME} およびスカラコンテキストで and getpwuid($<) を | |
| 1153 | こ | |
| 706 | 見ることができます: | |
| 1154 | 707 | |
| 708 | my $user_name = getpwuid($<) | |
| 709 | ||
| 1155 | 710 | =begin original |
| 1156 | 711 | |
| 1157 | ||
| 712 | But you still cannot make assumptions about whether this is correct, unless | |
| 1158 | ||
| 713 | your policy says it is. You really are best off asking the user. | |
| 1159 | It makes a more intelligent guess than the code above, using information | |
| 1160 | given when the module was installed, but it could still be incorrect. | |
| 1161 | Again, the best way is often just to ask the user. | |
| 1162 | 714 | |
| 1163 | 715 | =end original |
| 1164 | 716 | |
| 1165 | ||
| 717 | しかし、ポリシーがそうなっていない限り、これが正しいかどうかに関して | |
| 1166 | ||
| 718 | 仮定することはやはりできません。 | |
| 1167 | ||
| 719 | 本当に最良なのはユーザーに聞くことです。 | |
| 1168 | これは上で例示したやり方よりも賢く、モジュールがインストールされたときの | |
| 1169 | 情報を使いますが、それでも正しくない可能性があります。 | |
| 1170 | くり返しますが、最善の方法はユーザーに尋ねること、というのがほとんどです。 | |
| 1171 | 720 | |
| 1172 | =head2 How do I send mail? | |
| 721 | =head2 How do I send email? | |
| 1173 | 722 | |
| 1174 | 723 | (メールを送るには?) |
| 1175 | 724 | |
| 1176 | 725 | =begin original |
| 1177 | 726 | |
| 1178 | Use the | |
| 727 | Use the L<Email::MIME> and L<Email::Sender::Simple> modules, like so: | |
| 1179 | 728 | |
| 1180 | 729 | =end original |
| 1181 | 730 | |
| 1182 | ||
| 731 | 以下のように、L<Email::MIME> と L<Email::Sender::Simple> モジュールを | |
| 732 | 使ってください: | |
| 1183 | 733 | |
| 1184 | ||
| 734 | # first, create your message | |
| 1185 | ||
| 735 | my $message = Email::MIME->create( | |
| 1186 | ||
| 736 | header_str => [ | |
| 1187 | ||
| 737 | From => 'you@example.com', | |
| 1188 | ||
| 738 | To => 'friend@example.com', | |
| 1189 | ||
| 739 | Subject => 'Happy birthday!', | |
| 740 | ], | |
| 741 | attributes => { | |
| 742 | encoding => 'quoted-printable', | |
| 743 | charset => 'utf-8', | |
| 744 | }, | |
| 745 | body_str => "Happy birthday to you!\n", | |
| 746 | ); | |
| 1190 | 747 | |
| 1191 | ||
| 748 | use Email::Sender::Simple qw(sendmail); | |
| 1192 | ||
| 749 | sendmail($message); | |
| 1193 | EOF | |
| 1194 | close(SENDMAIL) or warn "sendmail didn't close nicely"; | |
| 1195 | 750 | |
| 1196 | 751 | =begin original |
| 1197 | 752 | |
| 1198 | ||
| 753 | By default, L<Email::Sender::Simple> will try `sendmail` first, if it exists | |
| 1199 | ||
| 754 | in your $PATH. This generally isn't the case. If there's a remote mail | |
| 1200 | ||
| 755 | server you use to send mail, consider investigating one of the Transport | |
| 1201 | ||
| 756 | classes. At time of writing, the available transports include: | |
| 1202 | be immediately delivered, so leave it out if you want immediate | |
| 1203 | delivery. | |
| 1204 | 757 | |
| 1205 | 758 | =end original |
| 1206 | 759 | |
| 1207 | ||
| 760 | デフォルトでは、L<Email::Sender::Simple> は、$PATH にあれば `sendmail` を | |
| 1208 | ||
| 761 | 最初に試します。 | |
| 1209 | ||
| 762 | これは一般的に間違いです。 | |
| 1210 | ||
| 763 | メールを送るのに使うリモートのメールサーバがある場合、 | |
| 1211 | ||
| 764 | Transport クラスの一つを調査することを考慮してください。 | |
| 1212 | ||
| 765 | これを書いている時点では、利用可能な転送層は以下のようなものです: | |
| 1213 | 意味します。 | |
| 1214 | ですから、すぐに配送させたいのであればこのオプションを取り除いてください。 | |
| 1215 | 766 | |
| 1216 | = | |
| 767 | =over 4 | |
| 1217 | 768 | |
| 1218 | ||
| 769 | =item L<Email::Sender::Transport::Sendmail> | |
| 1219 | called mailx) directly or simply opening up port 25 have having an | |
| 1220 | intimate conversation between just you and the remote SMTP daemon, | |
| 1221 | probably sendmail. | |
| 1222 | 770 | |
| 1223 | =end original | |
| 1224 | ||
| 1225 | あるいは、直接 mail (mailx と呼ばれることもあります)を呼びだしたり、 | |
| 1226 | 単純に 25 番ポートを使ってリモートの SMTP デーモン(多分 sendmail でしょう) | |
| 1227 | との間で詳細な通信を行うといったあまり便利でない方法もあります。 | |
| 1228 | ||
| 1229 | 771 | =begin original |
| 1230 | 772 | |
| 1231 | ||
| 773 | This is the default. If you can use the L<mail(1)> or L<mailx(1)> | |
| 774 | program to send mail from the machine where your code runs, you should | |
| 775 | be able to use this. | |
| 1232 | 776 | |
| 1233 | 777 | =end original |
| 1234 | 778 | |
| 1235 | ||
| 779 | これはデフォルトです。 | |
| 780 | コードを実行しているマシンからメールを送るのに L<mail(1)> や L<mailx(1)> が | |
| 781 | 使えるなら、これが使えるはずです。 | |
| 1236 | 782 | |
| 1237 | ||
| 783 | =item L<Email::Sender::Transport::SMTP> | |
| 1238 | 784 | |
| 1239 | $mailer = Mail::Mailer->new(); | |
| 1240 | $mailer->open({ From => $from_address, | |
| 1241 | To => $to_address, | |
| 1242 | Subject => $subject, | |
| 1243 | }) | |
| 1244 | or die "Can't open: $!\n"; | |
| 1245 | print $mailer $body; | |
| 1246 | $mailer->close(); | |
| 1247 | ||
| 1248 | 785 | =begin original |
| 1249 | 786 | |
| 1250 | Th | |
| 787 | This transport contacts a remote SMTP server over TCP. It optionally | |
| 1251 | ||
| 788 | uses SSL and can authenticate to the server via SASL. | |
| 1252 | are many reasons to use a mail transport agent like sendmail. These | |
| 1253 | include queuing, MX records, and security. | |
| 1254 | 789 | |
| 1255 | 790 | =end original |
| 1256 | 791 | |
| 1257 | ||
| 792 | この転送層は TCP を使ってリモート SMTP サーバに接続します。 | |
| 1258 | ||
| 793 | オプションとして SSL を使って、SASL 経由でサーバに認証できます。 | |
| 1259 | 生の SMTP コマンドを無視します。 | |
| 1260 | sendmail のような mail transport agent を使う理由はたくさんあります。 | |
| 1261 | その中にはキューイングも含まれますし、MX レコードやセキュリティと | |
| 1262 | いったものが含まれます。 | |
| 1263 | 794 | |
| 1264 | = | |
| 795 | =item L<Email::Sender::Transport::SMTP::TLS> | |
| 1265 | 796 | |
| 1266 | (メールメッセージに添付するためにどうやって MIME を使えばいいですか?) | |
| 1267 | ||
| 1268 | 797 | =begin original |
| 1269 | 798 | |
| 1270 | This | |
| 799 | This is like the SMTP transport, but uses TLS security. You can | |
| 1271 | ||
| 800 | authenticate with this module as well, using any mechanisms your server | |
| 801 | supports after STARTTLS. | |
| 1272 | 802 | |
| 1273 | 803 | =end original |
| 1274 | 804 | |
| 1275 | こ | |
| 805 | これは SMTP 転送と似ていますが、TLS セキュリティを使います。 | |
| 1276 | ||
| 806 | このモジュールも、STARTTLS の後サーバが対応している任意の機構を使って | |
| 807 | 認証できます。 | |
| 1277 | 808 | |
| 1278 | ||
| 809 | =back | |
| 1279 | 810 | |
| 1280 | ### Create a new multipart message: | |
| 1281 | $msg = MIME::Lite->new( | |
| 1282 | From =>'me@myhost.com', | |
| 1283 | To =>'you@yourhost.com', | |
| 1284 | Cc =>'some@other.com, some@more.com', | |
| 1285 | Subject =>'A message with 2 parts...', | |
| 1286 | Type =>'multipart/mixed' | |
| 1287 | ); | |
| 1288 | ||
| 1289 | ### Add parts (each "attach" has same arguments as "new"): | |
| 1290 | $msg->attach(Type =>'TEXT', | |
| 1291 | Data =>"Here's the GIF file you wanted" | |
| 1292 | ); | |
| 1293 | $msg->attach(Type =>'image/gif', | |
| 1294 | Path =>'aaa000123.gif', | |
| 1295 | Filename =>'logo.gif' | |
| 1296 | ); | |
| 1297 | ||
| 1298 | $text = $msg->as_string; | |
| 1299 | ||
| 1300 | 811 | =begin original |
| 1301 | 812 | |
| 1302 | ||
| 813 | Telling L<Email::Sender::Simple> to use your transport is straightforward. | |
| 1303 | 814 | |
| 1304 | 815 | =end original |
| 1305 | 816 | |
| 1306 | ||
| 817 | 使用する転送層を L<Email::Sender::Simple> に教えるのは簡単です: | |
| 1307 | 818 | |
| 1308 | ||
| 819 | sendmail( | |
| 820 | $message, | |
| 821 | { | |
| 822 | transport => $email_sender_transport_object, | |
| 823 | } | |
| 824 | ); | |
| 1309 | 825 | |
| 826 | =head2 How do I use MIME to make an attachment to a mail message? | |
| 827 | ||
| 828 | (メールメッセージに添付するためにどうやって MIME を使えばいいですか?) | |
| 829 | ||
| 1310 | 830 | =begin original |
| 1311 | 831 | |
| 1312 | ||
| 832 | L<Email::MIME> directly supports multipart messages. L<Email::MIME> | |
| 1313 | ||
| 833 | objects themselves are parts and can be attached to other L<Email::MIME> | |
| 834 | objects. Consult the L<Email::MIME> documentation for more information, | |
| 835 | including all of the supported methods and examples of their use. | |
| 1314 | 836 | |
| 1315 | 837 | =end original |
| 1316 | 838 | |
| 1317 | ||
| 839 | L<Email::MIME> は直接マルチパートメッセージに対応しています。 | |
| 1318 | L< | |
| 840 | L<Email::MIME> 自身はパートで、その他の L<Email::MIME> オブジェクトに | |
| 841 | 添付できます。 | |
| 842 | 対応している全てのメソッドとその使い方の例を含む、さらなる情報については | |
| 843 | L<Email::MIME> 文書を参照してください。 | |
| 1319 | 844 | |
| 1320 | =head2 How do I read mail? | |
| 845 | =head2 How do I read email? | |
| 1321 | 846 | |
| 1322 | 847 | (メールを読み出すには?) |
| 1323 | 848 | |
| 1324 | 849 | =begin original |
| 1325 | 850 | |
| 1326 | ||
| 851 | Use the L<Email::Folder> module, like so: | |
| 1327 | MailFolder package) or the Mail::Internet module from CPAN (part | |
| 1328 | of the MailTools package), often a module is overkill. Here's a | |
| 1329 | mail sorter. | |
| 1330 | 852 | |
| 1331 | 853 | =end original |
| 1332 | 854 | |
| 1333 | ||
| 855 | 以下のように、L<Email::Folder> モジュールを使ってください: | |
| 1334 | Mail::Internet モジュール(これも MailTools パッケージの一部です)が | |
| 1335 | 使えますが、モジュールを使うのはやりすぎかもしれません。 | |
| 1336 | 以下にメールをソートする方法を示します。 | |
| 1337 | 856 | |
| 1338 | ||
| 857 | use Email::Folder; | |
| 1339 | 858 | |
| 1340 | ||
| 859 | my $folder = Email::Folder->new('/path/to/email/folder'); | |
| 1341 | ||
| 860 | while(my $message = $folder->next_message) { | |
| 1342 | ||
| 861 | # next_message returns Email::Simple objects, but we want | |
| 1343 | ||
| 862 | # Email::MIME objects as they're more robust | |
| 1344 | ||
| 863 | my $mime = Email::MIME->new($message->as_string); | |
| 1345 | ||
| 864 | } | |
| 1346 | $sub[++$msgno] = lc($1) || ''; | |
| 1347 | } | |
| 1348 | $msgs[$msgno] .= $_; | |
| 1349 | } | |
| 1350 | for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) { | |
| 1351 | print $msgs[$i]; | |
| 1352 | } | |
| 1353 | 865 | |
| 1354 | 866 | =begin original |
| 1355 | 867 | |
| 1356 | ||
| 868 | There are different classes in the L<Email::Folder> namespace for | |
| 869 | supporting various mailbox types. Note that these modules are generally | |
| 870 | rather limited and only support B<reading> rather than writing. | |
| 1357 | 871 | |
| 1358 | 872 | =end original |
| 1359 | 873 | |
| 1360 | ||
| 874 | 様々なメールボックスの種類に対応するための異なったクラスが | |
| 875 | L<Email::Folder> 名前空間にあります。 | |
| 876 | これらのモジュールは一般的に B<読み込み> にのみ対応していて書き込みには | |
| 877 | 対応していないことに注意してください。 | |
| 1361 | 878 | |
| 1362 | #!/usr/bin/perl -n00 | |
| 1363 | # bysub2 - awkish sort-by-subject | |
| 1364 | BEGIN { $msgno = -1 } | |
| 1365 | $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m; | |
| 1366 | $msg[$msgno] .= $_; | |
| 1367 | END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] } | |
| 1368 | ||
| 1369 | 879 | =head2 How do I find out my hostname, domainname, or IP address? |
| 1370 | 880 | X<hostname, domainname, IP address, host, domain, hostfqdn, inet_ntoa, |
| 1371 | 881 | gethostbyname, Socket, Net::Domain, Sys::Hostname> |
| 1372 | 882 | |
| 1373 | 883 | (私のホスト名/ドメイン名/IP アドレスを見つけるには?) |
| 1374 | 884 | |
| 1375 | 885 | =begin original |
| 1376 | 886 | |
| 1377 | 887 | (contributed by brian d foy) |
| 1378 | 888 | |
| 1379 | 889 | =end original |
| 1380 | 890 | |
| 1381 | 891 | (brian d foy によって寄贈されました) |
| 1382 | 892 | |
| 1383 | 893 | =begin original |
| 1384 | 894 | |
| 1385 | The Net::Domain module, which is part of the | |
| 895 | The L<Net::Domain> module, which is part of the Standard Library starting | |
| 1386 | in | |
| 896 | in Perl 5.7.3, can get you the fully qualified domain name (FQDN), the host | |
| 1387 | 897 | name, or the domain name. |
| 1388 | 898 | |
| 1389 | 899 | =end original |
| 1390 | 900 | |
| 1391 | ||
| 901 | Perl 5.7.3 から標準ライブラリの一部である L<Net::Domain> モジュールを使うと、 | |
| 1392 | 902 | 完全修飾ドメイン名 (FQDN)、ホスト名、ドメイン名が得られます。 |
| 1393 | 903 | |
| 1394 | ||
| 904 | use Net::Domain qw(hostname hostfqdn hostdomain); | |
| 1395 | 905 | |
| 1396 | ||
| 906 | my $host = hostfqdn(); | |
| 1397 | 907 | |
| 1398 | 908 | =begin original |
| 1399 | 909 | |
| 1400 | The | |
| 910 | The L<Sys::Hostname> module, part of the Standard Library, can also get the | |
| 1401 | ||
| 911 | hostname: | |
| 1402 | 912 | |
| 1403 | 913 | =end original |
| 1404 | 914 | |
| 1405 | ||
| 915 | 標準ライブラリの一部である L<Sys::Hostname> モジュールでもホスト名を | |
| 1406 | ||
| 916 | 得られます。 | |
| 1407 | 917 | |
| 1408 | ||
| 918 | use Sys::Hostname; | |
| 1409 | 919 | |
| 1410 | ||
| 920 | $host = hostname(); | |
| 1411 | 921 | |
| 1412 | 922 | =begin original |
| 1413 | 923 | |
| 1414 | T | |
| 924 | The L<Sys::Hostname::Long> module takes a different approach and tries | |
| 1415 | ||
| 925 | harder to return the fully qualified hostname: | |
| 1416 | form (a.b.c.d) that most people expect, use the C<inet_ntoa> function | |
| 1417 | from the <Socket> module, which also comes with perl. | |
| 1418 | 926 | |
| 1419 | 927 | =end original |
| 1420 | 928 | |
| 1421 | ||
| 929 | L<Sys::Hostname::Long> モジュールは異なる手法をとり、完全修飾ホスト名を | |
| 1422 | ||
| 930 | 返すためにさらに多くのことを試みます: | |
| 1423 | 数値を、ほとんどの人が想定しているピリオド付きの形 (a.b.c.d) に変換するには、 | |
| 1424 | 標準配布されている C<Socket> モジュールの C<inet_ntoa> 関数を使います。 | |
| 1425 | 931 | |
| 1426 | ||
| 932 | use Sys::Hostname::Long 'hostname_long'; | |
| 1427 | 933 | |
| 1428 | ||
| 934 | my $hostname = hostname_long(); | |
| 1429 | scalar gethostbyname( $host || 'localhost' ) | |
| 1430 | ); | |
| 1431 | 935 | |
| 1432 | =head2 How do I fetch a news article or the active newsgroups? | |
| 1433 | ||
| 1434 | (ニュースの記事やアクティブなニュースグループを取得するには?) | |
| 1435 | ||
| 1436 | 936 | =begin original |
| 1437 | 937 | |
| 1438 | ||
| 938 | To get the IP address, you can use the C<gethostbyname> built-in function | |
| 1439 | ||
| 939 | to turn the name into a number. To turn that number into the dotted octet | |
| 940 | form (a.b.c.d) that most people expect, use the C<inet_ntoa> function | |
| 941 | from the L<Socket> module, which also comes with perl. | |
| 1440 | 942 | |
| 1441 | 943 | =end original |
| 1442 | 944 | |
| 1443 | ||
| 945 | IP アドレスを得るには、名前から数値に変換するために C<gethostbyname> | |
| 1444 | ||
| 946 | 組み込み関数が使えます。 | |
| 1445 | ||
| 947 | 数値を、ほとんどの人が想定しているピリオド付きの形 (a.b.c.d) に変換するには、 | |
| 1446 | ||
| 948 | 標準配布されている L<Socket> モジュールの C<inet_ntoa> 関数を使います。 | |
| 1447 | 949 | |
| 1448 | ||
| 950 | use Socket; | |
| 1449 | -e 'print News::NNTPClient->new->list("newsgroups")' | |
| 1450 | 951 | |
| 1451 | ||
| 952 | my $address = inet_ntoa( | |
| 953 | scalar gethostbyname( $host || 'localhost' ) | |
| 954 | ); | |
| 1452 | 955 | |
| 1453 | (FTP | |
| 956 | =head2 How do I fetch/put an (S)FTP file? | |
| 1454 | 957 | |
| 958 | ((S)FTP ファイルをダウンロード/アップロードするには?) | |
| 959 | ||
| 1455 | 960 | =begin original |
| 1456 | 961 | |
| 1457 | L | |
| 962 | L<Net::FTP>, and L<Net::SFTP> allow you to interact with FTP and SFTP (Secure | |
| 1458 | ||
| 963 | FTP) servers. | |
| 1459 | 964 | |
| 1460 | 965 | =end original |
| 1461 | 966 | |
| 1462 | L | |
| 967 | L<Net::FTP> と L<Net::SFTP> で FTP および SFTP (Secure FTP) サーバと | |
| 1463 | ||
| 968 | 相互作用できるようになります。 | |
| 1464 | Net::FTP(これも CPAN で入手可能)はこれよりも複雑ですが、 | |
| 1465 | ダウンロードとアップロードの両方ができます。 | |
| 1466 | 969 | |
| 1467 | 970 | =head2 How can I do RPC in Perl? |
| 1468 | 971 | |
| 1469 | 972 | (Perl で RPC を行うには?) |
| 1470 | 973 | |
| 1471 | 974 | =begin original |
| 1472 | 975 | |
| 1473 | ||
| 976 | Use one of the RPC modules( L<https://metacpan.org/search?q=RPC> ). | |
| 1474 | 977 | |
| 1475 | 978 | =end original |
| 1476 | 979 | |
| 1477 | ( | |
| 980 | RFC モジュール ( L<https://metacpan.org/search?q=RPC> ) の一つを使いましょう。 | |
| 1478 | 981 | |
| 1479 | =begin original | |
| 1480 | ||
| 1481 | Use one of the RPC modules you can find on CPAN ( | |
| 1482 | http://search.cpan.org/search?query=RPC&mode=all ). | |
| 1483 | ||
| 1484 | =end original | |
| 1485 | ||
| 1486 | CPAN ( http://search.cpan.org/search?query=RPC&mode=all ) で見付かる | |
| 1487 | RFC モジュールの一つを使いましょう。 | |
| 1488 | ||
| 1489 | =head1 REVISION | |
| 1490 | ||
| 1491 | Revision: $Revision$ | |
| 1492 | ||
| 1493 | Date: $Date$ | |
| 1494 | ||
| 1495 | See L<perlfaq> for source control details and availability. | |
| 1496 | ||
| 1497 | 982 | =head1 AUTHOR AND COPYRIGHT |
| 1498 | 983 | |
| 1499 | Copyright (c) 1997-200 | |
| 984 | Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and | |
| 1500 | 985 | other authors as noted. All rights reserved. |
| 1501 | 986 | |
| 1502 | 987 | This documentation is free; you can redistribute it and/or modify it |
| 1503 | 988 | under the same terms as Perl itself. |
| 1504 | 989 | |
| 1505 | 990 | Irrespective of its distribution, all code examples in this file |
| 1506 | are hereby placed into the public domain. | |
| 991 | are hereby placed into the public domain. You are permitted and | |
| 1507 | 992 | encouraged to use this code in your own programs for fun |
| 1508 | or for profit as you see fit. | |
| 993 | or for profit as you see fit. A simple comment in the code giving | |
| 1509 | 994 | credit would be courteous but is not required. |
| 1510 | 995 | |
| 1511 | 996 | =begin meta |
| 1512 | 997 | |
| 1513 | 998 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
| 1514 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) | |
| 999 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-5.14.1, 5.00150039) | |
| 1000 | Status: completed | |
| 1515 | 1001 | |
| 1516 | 1002 | =end meta |