Head.pm.html   [plain text]


<HTML>
<HEAD>
  <TITLE>MIME::Head</TITLE>
</HEAD>
<BODY 
       bgcolor="#FFFFFF" link="#CC3366" vlink="#993366" alink="#FF6666">
<FONT FACE="sans-serif" SIZE=-1><A HREF="http://www.zeegee.com" TARGET="_top"><IMG SRC="icons/zeegee.gif" ALT="ZeeGee Software" ALIGN="RIGHT" BORDER="0"></A><A NAME="__TOP__"><H1>MIME::Head</H1>
</A>
<P><B>This module is <FONT COLOR="#990000">BETA</FONT> code, which means that the interfaces are fairly stable BUT it has not been out in the community long enough to guarantee much testing. Use with caution! Please report any errors back to <A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A> as soon as you can.</B><UL>
<LI> <A HREF="#NAME">NAME</A>
<LI> <A HREF="#SYNOPSIS">SYNOPSIS</A>
<UL>
<LI> <A HREF="#Construction">Construction</A>
<LI> <A HREF="#Output">Output</A>
<LI> <A HREF="#Getting_field_contents">Getting field contents</A>
<LI> <A HREF="#Setting_field_contents">Setting field contents</A>
<LI> <A HREF="#Manipulating_field_contents">Manipulating field contents</A>
<LI> <A HREF="#Getting_high-level_MIME_information">Getting high-level MIME information</A>
</UL>
<LI> <A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI> <A HREF="#PUBLIC_INTERFACE">PUBLIC INTERFACE</A>
<UL>
<LI> <A HREF="#Creation_input_and_output">Creation, input, and output</A>
<LI> <A HREF="#Getting_setting_fields">Getting/setting fields</A>
<LI> <A HREF="#MIME-specific_methods">MIME-specific methods</A>
</UL>
<LI> <A HREF="#NOTES">NOTES</A>
<LI> <A HREF="#AUTHOR">AUTHOR</A>
<LI> <A HREF="#VERSION">VERSION</A>
</UL>
</A>

<P><HR>
<A NAME="NAME"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NAME</H2></A>


<P>MIME::Head - MIME message header (a subclass of Mail::Header)



<P><HR>
<A NAME="SYNOPSIS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SYNOPSIS</H2></A>


<P>Before reading further, you should see <A HREF="../MIME/Tools.pm.html">MIME::Tools</A> to make sure that 
you understand where this module fits into the grand scheme of things.
Go on, do it now.  I'll wait.


<P>Ready?  Ok...



<P><HR>
<A NAME="Construction"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Construction</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Create a new, empty header, and populate it manually:    
    $head = MIME::Head-&gt;new;
    $head-&gt;replace('content-type', 'text/plain; charset=US-ASCII');
    $head-&gt;replace('content-length', $len);
    
    ### Parse a new header from a filehandle:
    $head = MIME::Head-&gt;read(\*STDIN);
    
    ### Parse a new header from a file, or a readable pipe:
    $testhead = MIME::Head-&gt;from_file(&quot;/tmp/test.hdr&quot;);
    $a_b_head = MIME::Head-&gt;from_file(&quot;cat a.hdr b.hdr |&quot;);
</PRE></FONT>


<P><HR>
<A NAME="Output"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Output</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Output to filehandle:
    $head-&gt;print(\*STDOUT);  
    
    ### Output as string:
    print STDOUT $head-&gt;as_string;
    print STDOUT $head-&gt;stringify;
</PRE></FONT>


<P><HR>
<A NAME="Getting_field_contents"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Getting field contents</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Is this a reply?
    $is_reply = 1 if ($head-&gt;get('Subject') =~ /^Re: /);
    
    ### Get receipt information:
    print &quot;Last received from: &quot;, $head-&gt;get('Received', 0), &quot;\n&quot;;
    @all_received = $head-&gt;get('Received');
    
    ### Print the subject, or the empty string if none:
    print &quot;Subject: &quot;, $head-&gt;get('Subject',0), &quot;\n&quot;;
     
    ### Too many hops?  Count 'em and see!
    if ($head-&gt;count('Received') &gt; 5) { ...
    
    ### Test whether a given field exists
    warn &quot;missing subject!&quot; if (! $head-&gt;count('subject'));
</PRE></FONT>


<P><HR>
<A NAME="Setting_field_contents"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Setting field contents</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Declare this to be an HTML header:
    $head-&gt;replace('Content-type', 'text/html');
</PRE></FONT>


<P><HR>
<A NAME="Manipulating_field_contents"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Manipulating field contents</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Get rid of internal newlines in fields:
    $head-&gt;unfold;
    
    ### Decode any Q- or B-encoded-text in fields (DEPRECATED):
    $head-&gt;decode;
     
</PRE></FONT>


<P><HR>
<A NAME="Getting_high-level_MIME_information"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Getting high-level MIME information</H3></A>

<FONT SIZE=3 FACE="courier"><PRE>
    ### Get/set a given MIME attribute:
    unless ($charset = $head-&gt;mime_attr('content-type.charset')) {
        $head-&gt;mime_attr(&quot;content-type.charset&quot; =&gt; &quot;US-ASCII&quot;);
    }
</PRE></FONT>
<FONT SIZE=3 FACE="courier"><PRE>
    ### The content type (e.g., &quot;text/html&quot;):
    $mime_type     = $head-&gt;mime_type;
    
    ### The content transfer encoding (e.g., &quot;quoted-printable&quot;):
    $mime_encoding = $head-&gt;mime_encoding;
    
    ### The recommended name when extracted:
    $file_name     = $head-&gt;recommended_filename;
    
    ### The boundary text, for multipart messages:
    $boundary      = $head-&gt;multipart_boundary;
</PRE></FONT>


<P><HR>
<A NAME="DESCRIPTION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> DESCRIPTION</H2></A>


<P>A class for parsing in and manipulating RFC-822 message headers, with some 
methods geared towards standard (and not so standard) MIME fields as 
specified in RFC-1521, <I>Multipurpose Internet Mail Extensions</I>.



<P><HR>
<A NAME="PUBLIC_INTERFACE"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> PUBLIC INTERFACE</H2></A>



<P><HR>
<A NAME="Creation_input_and_output"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Creation, input, and output</H3></A>



<DL>
<P><DT><B><A NAME="item:new">new [ARG],[OPTIONS]</A></B></DT>
<DD>
<I>Class method, inherited.</I>
Creates a new header object.  Arguments are the same as those in the 
superclass.  

<P><DT><B><A NAME="item:from_file">from_file EXPR,OPTIONS</A></B></DT>
<DD>
<I>Class or instance method</I>.
For convenience, you can use this to parse a header object in from EXPR, 
which may actually be any expression that can be sent to open() so as to 
return a readable filehandle.  The &quot;file&quot; will be opened, read, and then 
closed:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Create a new header by parsing in a file:
    my $head = MIME::Head-&gt;from_file(&quot;/tmp/test.hdr&quot;);
</PRE></FONT>

<P>Since this method can function as either a class constructor <I>or</I> 
an instance initializer, the above is exactly equivalent to:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Create a new header by parsing in a file:
    my $head = MIME::Head-&gt;new-&gt;from_file(&quot;/tmp/test.hdr&quot;);
</PRE></FONT>

<P>On success, the object will be returned; on failure, the undefined value.


<P>The OPTIONS are the same as in new(), and are passed into new()
if this is invoked as a class method.


<P><B>Note:</B> This is really just a convenience front-end onto <CODE>read()</CODE>,
provided mostly for backwards-compatibility with MIME-parser 1.0.

<P><DT><B><A NAME="item:read">read FILEHANDLE</A></B></DT>
<DD>
<I>Instance (or class) method.</I> 
This initiallizes a header object by reading it in from a FILEHANDLE,
until the terminating blank line is encountered.  
A syntax error or end-of-stream will also halt processing.


<P>Supply this routine with a reference to a filehandle glob; e.g., <CODE>\*STDIN</CODE>:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Create a new header by parsing in STDIN:
    $head-&gt;read(\*STDIN);
</PRE></FONT>

<P>On success, the self object will be returned; on failure, a false value.


<P><B>Note:</B> in the MIME world, it is perfectly legal for a header to be
empty, consisting of nothing but the terminating blank line.  Thus,
we can't just use the formula that &quot;no tags equals error&quot;.


<P><B>Warning:</B> as of the time of this writing, Mail::Header::read did not flag
either syntax errors or unexpected end-of-file conditions (an EOF
before the terminating blank line).  MIME::ParserBase takes this
into account.

</DL>



<P><HR>
<A NAME="Getting_setting_fields"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Getting/setting fields</H3></A>


<P>The following are methods related to retrieving and modifying the header 
fields.  Some are inherited from Mail::Header, but I've kept the
documentation around for convenience.



<DL>
<P><DT><B><A NAME="item:add">add TAG,TEXT,[INDEX]</A></B></DT>
<DD>
<I>Instance method, inherited.</I>
Add a new occurence of the field named TAG, given by TEXT:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Add the trace information:    
    $head-&gt;add('Received', 
               'from eryq.pr.mcs.net by gonzo.net with smtp');
</PRE></FONT>

<P>Normally, the new occurence will be <I>appended</I> to the existing 
occurences.  However, if the optional INDEX argument is 0, then the 
new occurence will be <I>prepended</I>.  If you want to be <I>explicit</I> 
about appending, specify an INDEX of -1.


<P><B>Warning</B>: this method always adds new occurences; it doesn't overwrite
any existing occurences... so if you just want to <I>change</I> the value
of a field (creating it if necessary), then you probably <B>don't</B> want to use 
this method: consider using <CODE>replace()</CODE> instead.

<P><DT><B><A NAME="item:count">count TAG</A></B></DT>
<DD>
<I>Instance method, inherited.</I>
Returns the number of occurences of a field; in a boolean context, this
tells you whether a given field exists:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Was a &quot;Subject:&quot; field given?
    $subject_was_given = $head-&gt;count('subject');
</PRE></FONT>

<P>The TAG is treated in a case-insensitive manner.
This method returns some false value if the field doesn't exist,
and some true value if it does.

<P><DT><B><A NAME="item:decode">decode [FORCE]</A></B></DT>
<DD>
<I>Instance method, DEPRECATED.</I>
Go through all the header fields, looking for RFC-1522-style &quot;Q&quot;
(quoted-printable, sort of) or &quot;B&quot; (base64) encoding, and decode them
in-place.  Fellow Americans, you probably don't know what the hell I'm
talking about.  Europeans, Russians, et al, you probably do.  <CODE>:-)</CODE>. 


<P><B>This method has been deprecated.</B>
See <A HREF="../MIME/Parser.pm.html#item:decode_headers">decode_headers</A> for the full reasons.
If you absolutely must use it and don't like the warning, then
provide a FORCE:

<FONT SIZE=3 FACE="courier"><PRE>
   &quot;I_NEED_TO_FIX_THIS&quot;
          Just shut up and do it.  Not recommended.
          Provided only for those who need to keep old scripts functioning.
</PRE></FONT>
<FONT SIZE=3 FACE="courier"><PRE>
   &quot;I_KNOW_WHAT_I_AM_DOING&quot;
          Just shut up and do it.  Not recommended.
          Provided for those who REALLY know what they are doing.
</PRE></FONT>

<P><B>What this method does.</B>
For an example, let's consider a valid email header you might get:

<FONT SIZE=3 FACE="courier"><PRE>
    From: =?US-ASCII?Q?Keith_Moore?= &lt;moore@cs.utk.edu&gt;
    To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= &lt;keld@dkuug.dk&gt;
    CC: =?ISO-8859-1?Q?Andr=E9_?= Pirard &lt;PIRARD@vm1.ulg.ac.be&gt;
    Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
     =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
     =?US-ASCII?Q?.._cool!?=
</PRE></FONT>

<P>That basically decodes to (sorry, I can only approximate the
Latin characters with 7 bit sequences /o and 'e):

<FONT SIZE=3 FACE="courier"><PRE>
    From: Keith Moore &lt;moore@cs.utk.edu&gt;
    To: Keld J/orn Simonsen &lt;keld@dkuug.dk&gt;
    CC: Andr'e  Pirard &lt;PIRARD@vm1.ulg.ac.be&gt;
    Subject: If you can read this you understand the example... cool!
</PRE></FONT>

<P><B>Note:</B> currently, the decodings are done without regard to the
character set: thus, the Q-encoding <CODE>=F8</CODE> is simply translated to the
octet (hexadecimal <CODE>F8</CODE>), period.  For piece-by-piece decoding
of a given field, you want the array context of 
<CODE>MIME::Word::decode_mimewords()</CODE>.


<P><B>Warning:</B> the CRLF+SPACE separator that splits up long encoded words 
into shorter sequences (see the Subject: example above) gets lost
when the field is unfolded, and so decoding after unfolding causes
a spurious space to be left in the field.  
<I>THEREFORE: if you're going to decode, do so BEFORE unfolding!</I>


<P>This method returns the self object.


<P><I>Thanks to Kent Boortz for providing the idea, and the baseline 
RFC-1522-decoding code.</I>

<P><DT><B><A NAME="item:delete">delete TAG,[INDEX]</A></B></DT>
<DD>
<I>Instance method, inherited.</I>
Delete all occurences of the field named TAG.

<FONT SIZE=3 FACE="courier"><PRE>
    ### Remove some MIME information:
    $head-&gt;delete('MIME-Version');
    $head-&gt;delete('Content-type');
</PRE></FONT>
<P><DT><B><A NAME="item:get">get TAG,[INDEX]</A></B></DT>
<DD>
<I>Instance method, inherited.</I>  
Get the contents of field TAG.


<P>If a <B>numeric INDEX</B> is given, returns the occurence at that index, 
or undef if not present:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Print the first and last 'Received:' entries (explicitly):
    print &quot;First, or most recent: &quot;, $head-&gt;get('received', 0), &quot;\n&quot;;
    print &quot;Last, or least recent: &quot;, $head-&gt;get('received',-1), &quot;\n&quot;; 
</PRE></FONT>

<P>If <B>no INDEX</B> is given, but invoked in a <B>scalar</B> context, then
INDEX simply defaults to 0:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Get the first 'Received:' entry (implicitly):
    my $most_recent = $head-&gt;get('received');
</PRE></FONT>

<P>If <B>no INDEX</B> is given, and invoked in an <B>array</B> context, then
<I>all</I> occurences of the field are returned:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Get all 'Received:' entries:
    my @all_received = $head-&gt;get('received');
</PRE></FONT>
<P><DT><B><A NAME="item:get_all">get_all FIELD</A></B></DT>
<DD>
<I>Instance method.</I>
Returns the list of <I>all</I> occurences of the field, or the 
empty list if the field is not present:

<FONT SIZE=3 FACE="courier"><PRE>
    ### How did it get here?
    @history = $head-&gt;get_all('Received');
</PRE></FONT>

<P><B>Note:</B> I had originally experimented with having <CODE>get()</CODE> return all 
occurences when invoked in an array context... but that causes a lot of 
accidents when you get careless and do stuff like this:

<FONT SIZE=3 FACE="courier"><PRE>
    print &quot;\u$field: &quot;, $head-&gt;get($field), &quot;\n&quot;;
</PRE></FONT>

<P>It also made the intuitive behaviour unclear if the INDEX argument 
was given in an array context.  So I opted for an explicit approach
to asking for all occurences.

<P><DT><B><A NAME="item:print">print [OUTSTREAM]</A></B></DT>
<DD>
<I>Instance method, override.</I>
Print the header out to the given OUTSTREAM, or the currently-selected
filehandle if none.  The OUTSTREAM may be a filehandle, or any object
that responds to a print() message.


<P>The override actually lets you print to any object that responds to
a print() method.  This is vital for outputting MIME entities to scalars.


<P>Also, it defaults to the <I>currently-selected</I> filehandle if none is given
(not STDOUT!), so <I>please</I> supply a filehandle to prevent confusion.

<P><DT><B><A NAME="item:stringify">stringify</A></B></DT>
<DD>
<I>Instance method.</I>
Return the header as a string.  You can also invoke it as <CODE>as_string</CODE>.

<P><DT><B><A NAME="item:unfold">unfold [FIELD]</A></B></DT>
<DD>
<I>Instance method, inherited.</I>
Unfold (remove newlines in) the text of all occurences of the given FIELD.  
If the FIELD is omitted, <I>all</I> fields are unfolded.
Returns the &quot;self&quot; object.

</DL>



<P><HR>
<A NAME="MIME-specific_methods"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> MIME-specific methods</H3></A>


<P>All of the following methods extract information from the following fields:

<FONT SIZE=3 FACE="courier"><PRE>
    Content-type
    Content-transfer-encoding
    Content-disposition
</PRE></FONT>

<P>Be aware that they do not just return the raw contents of those fields,
and in some cases they will fill in sensible (I hope) default values.
Use <CODE>get()</CODE> or <CODE>mime_attr()</CODE> if you need to grab and process the 
raw field text.


<P><B>Note:</B> some of these methods are provided both as a convenience and
for backwards-compatibility only, while others (like
recommended_filename()) <I>really do have to be in MIME::Head to work
properly,</I> since they look for their value in more than one field.
However, if you know that a value is restricted to a single
field, you should really use the Mail::Field interface to get it.



<DL>
<P><DT><B><A NAME="item:mime_attr">mime_attr ATTR,[VALUE]</A></B></DT>
<DD>
A quick-and-easy interface to set/get the attributes in structured 
MIME fields:

<FONT SIZE=3 FACE="courier"><PRE>
    $head-&gt;mime_attr(&quot;content-type&quot;         =&gt; &quot;text/html&quot;);
    $head-&gt;mime_attr(&quot;content-type.charset&quot; =&gt; &quot;US-ASCII&quot;);
    $head-&gt;mime_attr(&quot;content-type.name&quot;    =&gt; &quot;homepage.html&quot;);
</PRE></FONT>

<P>This would cause the final output to look something like this:

<FONT SIZE=3 FACE="courier"><PRE>
    Content-type: text/html; charset=US-ASCII; name=&quot;homepage.html&quot;
</PRE></FONT>

<P>Note that the special empty sub-field tag indicates the anonymous 
first sub-field.


<P><B>Giving VALUE as undefined</B> will cause the contents of the named subfield 
to be deleted:

<FONT SIZE=3 FACE="courier"><PRE>
    $head-&gt;mime_attr(&quot;content-type.charset&quot; =&gt; undef);
</PRE></FONT>

<P><B>Supplying no VALUE argument</B> just returns the attribute's value,
or undefined if it isn't there:

<FONT SIZE=3 FACE="courier"><PRE>
    $type = $head-&gt;mime_attr(&quot;content-type&quot;);      ### text/html
    $name = $head-&gt;mime_attr(&quot;content-type.name&quot;); ### homepage.html
</PRE></FONT>

<P>In all cases, the new/current value is returned.

<P><DT><B><A NAME="item:mime_encoding">mime_encoding</A></B></DT>
<DD>
<I>Instance method.</I>
Try <I>real hard</I> to determine the content transfer encoding
(e.g., <CODE>&quot;base64&quot;</CODE>, <CODE>&quot;binary&quot;</CODE>), which is returned in all-lowercase.


<P>If no encoding could be found, the default of <CODE>&quot;7bit&quot;</CODE> is returned.  
I quote from RFC-1521 section 5:

<FONT SIZE=3 FACE="courier"><PRE>
    This is the default value -- that is, &quot;Content-Transfer-Encoding: 7BIT&quot; 
    is assumed if the Content-Transfer-Encoding header field is not present.
</PRE></FONT>
<P><DT><B><A NAME="item:mime_type">mime_type [DEFAULT]</A></B></DT>
<DD>
<I>Instance method.</I>
Try <CODE>real hard</CODE> to determine the content type (e.g., <CODE>&quot;text/plain&quot;</CODE>,
<CODE>&quot;image/gif&quot;</CODE>, <CODE>&quot;x-weird-type&quot;</CODE>, which is returned in all-lowercase.  
&quot;Real hard&quot; means that if no content type could be found, the default 
(usually <CODE>&quot;text/plain&quot;</CODE>) is returned.  From RFC-1521 section 7.1:

<FONT SIZE=3 FACE="courier"><PRE>
    The default Content-Type for Internet mail is 
    &quot;text/plain; charset=us-ascii&quot;.
</PRE></FONT>

<P>Unless this is a part of a &quot;multipart/digest&quot;, in which case 
&quot;message/rfc822&quot; is the default.  Note that you can also <I>set</I> the 
default, but you shouldn't: normally only the MIME parser uses this 
feature.

<P><DT><B><A NAME="item:multipart_boundary">multipart_boundary</A></B></DT>
<DD>
<I>Instance method.</I>
If this is a header for a multipart message, return the 
&quot;encapsulation boundary&quot; used to separate the parts.  The boundary
is returned exactly as given in the <CODE>Content-type:</CODE> field; that
is, the leading double-hyphen (<CODE>--</CODE>) is <I>not</I> prepended.


<P>Well, <I>almost</I> exactly... this passage from RFC-1521 dictates
that we remove any trailing spaces:

<FONT SIZE=3 FACE="courier"><PRE>
   If a boundary appears to end with white space, the white space 
   must be presumed to have been added by a gateway, and must be deleted.
</PRE></FONT>

<P>Returns undef (<B>not</B> the empty string) if either the message is not
multipart, if there is no specified boundary, or if the boundary is
illegal (e.g., if it is empty after all trailing whitespace has been
removed).

<P><DT><B><A NAME="item:recommended_filename">recommended_filename</A></B></DT>
<DD>
<I>Instance method.</I>
Return the recommended external filename.  This is used when
extracting the data from the MIME stream.


<P>Returns undef if no filename could be suggested.

</DL>



<P><HR>
<A NAME="NOTES"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NOTES</H2></A>



<DL>
<P><DT><B><A NAME="item:Why_have_separate_objects_for_the_entity_head_and_body">Why have separate objects for the entity, head, and body?</A></B></DT>
<DD>
See the documentation for the MIME-tools distribution
for the rationale behind this decision.

<P><DT><B><A NAME="item:Why_assume_that_MIME_headers_are_email_headers">Why assume that MIME headers are email headers?</A></B></DT>
<DD>
I quote from Achim Bohnet, who gave feedback on v.1.9 (I think
he's using the word &quot;header&quot; where I would use &quot;field&quot;; e.g.,
to refer to &quot;Subject:&quot;, &quot;Content-type:&quot;, etc.):

<FONT SIZE=3 FACE="courier"><PRE>
    There is also IMHO no requirement [for] MIME::Heads to look 
    like [email] headers; so to speak, the MIME::Head [simply stores] 
    the attributes of a complex object, e.g.:
</PRE></FONT>
<FONT SIZE=3 FACE="courier"><PRE>
        new MIME::Head type =&gt; &quot;text/plain&quot;,
                       charset =&gt; ...,
                       disposition =&gt; ..., ... ;
</PRE></FONT>

<P>I agree in principle, but (alas and dammit) RFC-1521 says otherwise.
RFC-1521 [MIME] headers are a syntactic subset of RFC-822 [email] headers.
Perhaps a better name for these modules would be RFC1521:: instead of
MIME::, but we're a little beyond that stage now.


<P>In my mind's eye, I see an abstract class, call it MIME::Attrs, which does
what Achim suggests... so you could say:

<FONT SIZE=3 FACE="courier"><PRE>
     my $attrs = new MIME::Attrs type =&gt; &quot;text/plain&quot;,
				 charset =&gt; ...,
                                 disposition =&gt; ..., ... ;
</PRE></FONT>

<P>We could even make it a superclass of MIME::Head: that way, MIME::Head
would have to implement its interface, <I>and</I> allow itself to be
initiallized from a MIME::Attrs object.


<P>However, when you read RFC-1521, you begin to see how much MIME information
is organized by its presence in particular fields.  I imagine that we'd
begin to mirror the structure of RFC-1521 fields and subfields to such 
a degree that this might not give us a tremendous gain over just
having MIME::Head.

<P><DT><B><A NAME="item:Why_all_this_occurence_and_index_jazz_Isn_t_every_field_unique">Why all this &quot;occurence&quot; and &quot;index&quot; jazz?  Isn't every field unique?</A></B></DT>
<DD>
Aaaaaaaaaahh....no.


<P>Looking at a typical mail message header, it is sooooooo tempting to just
store the fields as a hash of strings, one string per hash entry.  
Unfortunately, there's the little matter of the <CODE>Received:</CODE> field, 
which (unlike <CODE>From:</CODE>, <CODE>To:</CODE>, etc.) will often have multiple 
occurences; e.g.:

<FONT SIZE=3 FACE="courier"><PRE>
    Received: from gsfc.nasa.gov by eryq.pr.mcs.net  with smtp
        (Linux Smail3.1.28.1 #5) id m0tStZ7-0007X4C; 
	 Thu, 21 Dec 95 16:34 CST
    Received: from rhine.gsfc.nasa.gov by gsfc.nasa.gov 
	 (5.65/Ultrix3.0-C) id AA13596; 
	 Thu, 21 Dec 95 17:20:38 -0500
    Received: (from eryq@localhost) by rhine.gsfc.nasa.gov 
	 (8.6.12/8.6.12) id RAA28069; 
	 Thu, 21 Dec 1995 17:27:54 -0500
    Date: Thu, 21 Dec 1995 17:27:54 -0500
    From: Eryq &lt;eryq@rhine.gsfc.nasa.gov&gt;
    Message-Id: &lt;199512212227.RAA28069@rhine.gsfc.nasa.gov&gt;
    To: eryq@eryq.pr.mcs.net
    Subject: Stuff and things
</PRE></FONT>

<P>The <CODE>Received:</CODE> field is used for tracing message routes, and although
it's not generally used for anything other than human debugging, I
didn't want to inconvenience anyone who actually wanted to get at that
information.  


<P>I also didn't want to make this a special case; after all, who
knows what other fields could have multiple occurences in the
future?  So, clearly, multiple entries had to somehow be stored
multiple times... and the different occurences had to be retrievable.

</DL>



<P><HR>
<A NAME="AUTHOR"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> AUTHOR</H2></A>


<P>Eryq (<I><FILE><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></FILE></I>), ZeeGee Software Inc (<I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I>).


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


<P>The more-comprehensive filename extraction is courtesy of 
Lee E. Brotzman, Advanced Data Solutions.



<P><HR>
<A NAME="VERSION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> VERSION</H2></A>


<P>$Revision: 1.1 $ $Date: 2004/04/09 17:04:45 $

<P><HR>
<ADDRESS><FONT SIZE=-1>
Generated Wed Jan 17 01:58:21 2001 by cvu_pod2html
</FONT></ADDRESS>
</FONT></BODY>
</HTML>