📄 ch06.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->
<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<TITLE>Without a title - Title</TITLE>
</HEAD>
<BODY BACKGROUND="r2harch.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/r2harch.gif" TEXT="#000000" BGCOLOR="#FFFFFF">
<H2 ALIGN="CENTER"><A HREF="ch05.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch05.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37"
ALIGN="BOTTOM" BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42"
HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><A HREF="ch07.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch07.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif"
WIDTH="45" HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><FONT COLOR="#0000AA"><BR>
<BR>
6</FONT><BR>
<A NAME="Heading1"></A><FONT COLOR="#000077">MIME Documents<BR>
</FONT>
<HR>
</H2>
<UL>
<LI><A HREF="#Heading1">MIME Documents</A>
<UL>
<LI><A HREF="#Heading2">MIME, WWW, and CGI</A>
<UL>
<LI><A HREF="#Heading3">The MIME-Version Header Field</A>
<LI><A HREF="#Heading4">The Content-Type Header Field</A>
<LI><A HREF="#Heading5">The Content-Transfer-Encoding Header Field</A>
<LI><A HREF="#Heading6">Additional Header Fields</A>
</UL>
<LI><A HREF="#Heading7">How MIME Data Is Encoded</A>
<UL>
<LI><A HREF="#Heading8">B Base64 Encoding</A>
<LI><A HREF="#Heading9">Q Quoted-Printable Encoding</A>
</UL>
<LI><A HREF="#Heading10">Encoding and Decoding MIME with libwww</A>
<UL>
<LI><A HREF="#Heading11">Using MIME::Base64</A>
</UL>
<LI><A HREF="#Heading12">Listing 7.1. E-mail with Base64 encoded</A>
<LI><A HREF="#Heading13">MIME attachment</A>
<LI><A HREF="#Heading15">Using MIME::QuotedPrint</A>
</UL>
</UL>
<P>
<HR>
</P>
<UL>
<LI>MIME, WWW, and CGI
<P>
<LI>How MIME Data Is Encoded
<P>
<LI>Encoding and Decoding MIME with libwww
</UL>
<P>MIME is an acronym for Multipurpose Internet Mail Extensions. In the previous
chapter, we talked about how message headers in MIME format were used in an HTTP
request. Despite its misleading name, MIME is used to define the structure and content
of many different types of Internet messages other than just mail. MIME is a protocol
that allows transmission of non-text files such as graphics, audio, video, and program
files. Elements other than text, such as graphics and audio, are encoded in the message
as ASCII text. The MIME message can then be easily transmitted via e-mail or other
text-based protocols. The non-text elements in the message are then unencoded at
the other end after the MIME message is downloaded.
<H3 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">MIME, WWW, and CGI</FONT></H3>
<P>In this chapter, we will look at how MIME messages and encoding schemes relate
to the WWW and CGI. The MIME standard is introduced in RFC1341 and later completely
defined in RFC 1521. RFC 1521 replaces the older RFC 1341 completely. A full discussion
of the MIME standard is not necessary, but may be found at the following URL:</P>
<PRE><FONT COLOR="#0066FF">http://www.freesoft.org/Connected/RFC/1521/index.html
</FONT></PRE>
<P>MIME provides three mechanisms which allow non-textual data to be specified and
encoded into text documents that can be transferred over text e-mail gateways:
<UL>
<LI>The MIME-Version Header Field
<P>
<LI>The Content-Type Header Field
<P>
<LI>The Content-Transfer-Encoding Header Field
</UL>
<P>In addition to these three main mechanisms, two optional header fields may be
defined to add a unique ID and a description of the body of the message:
<UL>
<LI>The Content-ID Header Field
<P>
<LI>The Content-Description Header Fields.
</UL>
<P>In this chapter, we will look at the preceding header fields and their significance
to programming to the Web. In the "How MIME Data Is Encoded" section, we
will look at how the Perl5 MIME:: module can be used to encode data, which can be
used in MIME messages. We will then look at a multipart MIME message generated by
Netscape Mail, and see how these mechanisms are used in a real-world situation.
<H4 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">The MIME-Version
Header Field</FONT></H4>
<P>The MIME-Version header field uses a version number to declare a message to be
conformant with this specification and allows mail processing agents to distinguish
between such messages and those generated by older or non-conformant software, which
is presumed to lack such a field.
<H4 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">The Content-Type
Header Field</FONT></H4>
<P>The Content-Type header field is used to specify the "type" and "subtype"
of data in the body of a message and to fully specify the encoding of the data. There
are seven main Content-Types, each with a growing number of subtypes. MIME has been
carefully designed as an extensible mechanism, and it is expected that the set of
content-type/subtype pairs and their associated parameters will grow significantly
with time. Here are the seven main Content-Types along with currently defined subtypes.
<B><TT>Text</TT></B> A text Content-Type value can be used to represent textual information
in a number of character sets and formatted text description languages in a standardized
manner:</P>
<PRE><FONT COLOR="#0066FF">text/html html htm
text/plain txt pl
text/richtext rtx
text/tab-separated-values tsv
text/x-setext etx
</FONT></PRE>
<P><B><TT>Multipart</TT></B> A multipart Content-Type value can be used to combine
several body parts, possibly of differing types of data, into a single message. <B><TT>Multipart/Alternative</TT></B>
This signifies multiple content-types with the same (or similar) information. <B><TT>Multipart/Digest</TT></B>
This signifies a series of included mail messages. Messages are of type message/RFC822
unless an explicit content-type is specified for each part. <B><TT>Multipart/Mixed</TT></B>
This signifies data with multiple content-types. <B><TT>Multipart/Parallel</TT></B>
This is similar to multipart/mixed data in parallel. <B><TT>Application</TT></B>
An application Content-Type value can be used to transmit application data or binary
data, and hence, among other uses, to implement an electronic mail file transfer
service:</P>
<PRE><FONT COLOR="#0066FF">application/octet-stream bin
application/oda oda
application/pdf pdf
application/postscript ai eps ps
application/rtf rtf
application/x-mif mif
application/x-maker fm
application/x-csh csh
application/x-dvi dvi
application/x-hdf hdf
application/x-latex latex
application/x-netcdf nc cdf
application/x-sh sh
application/x-tcl tcl
application/x-tex tex
application/x-texinfo texinfo texi
application/x-troff t tr roff
application/x-troff-man man
application/x-troff-me me
application/x-troff-ms ms
application/x-wais-source src
application/zip zip
application/x-bcpio bcpio
application/x-cpio cpio
application/x-gtar gtar
application/x-shar shar
application/x-sv4cpio sv4cpio
application/x-sv4crc sv4crc
application/x-tar tar
application/x-ustar ustar
</FONT></PRE>
<P><B><TT>Message</TT></B> A message Content-Type value can be used for encapsulating
another message in the document. <B><TT>Message/RFC822</TT></B> This signifies an
included (MIME) mail message. <B><TT>Message/News</TT></B> This signifies an included
(MIME) USENET news message. <B><TT>Message/Partial</TT></B> This signifies that the
content is a single part of a message split into multiple mail messages. <B><TT>Image</TT></B>
This is an image Content-Type value for transmitting still image (picture) data:</P>
<PRE><FONT COLOR="#0066FF">image/gif gif
image/ief ief
image/jpeg jpeg jpg jpe
image/tiff tiff tif
image/x-cmu-raster ras
image/x-portable-anymap pnm
image/x-portable-bitmap pbm
image/x-portable-graymap pgm
image/x-portable-pixmap ppm
image/x-rgb rgb
image/x-xbitmap xbm
image/x-xpixmap xpm
image/x-xwindowdump xwd
</FONT></PRE>
<P><B><TT>Audio</TT></B> This is an audio Content-Type value for transmitting audio
or voice data:</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -