Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > 40c756a8011f8b53c82f133567c4dbff > files > 174

mhonarc-2.6.16-6.mga1.noarch.rpm

<html>
<head>
<title>MHonArc Reference -- Appendix: Application Programming Interface</title>
<link rel="stylesheet" type="text/css" href="docstyles.css">
<style>
.cb_head {
  font-family: monospace;
  padding-top: 1em;
  border-color: black;
  border-style: solid none none none;
  border-top-width: thin;
}
.cb_body {
  padding-left: 1em;
}
</style>
</head>
<body>

<!--X-NavButtons-Start-->
<table width="100%">
<tr valign="top">
<td align="left"><nobr><a href="app-utilsprg.html"><img src="prev.png"border=0 alt="[Prev]"></a>&nbsp;&nbsp;&nbsp;</nobr></td><td align="center" width="99%"><a href="mhonarc.html"><img src="up.png" border=0 alt="[TOC]"></a><a href="faq/faq.html"><img src="faq.png" border=0 alt="[FAQ]"></a><a href="app-bugs.html"><img src="bug.png" border=0 alt="[Bugs]"></a><a href="http://www.mhonarc.org/"><img src="home.png" border=0 alt="[Home]"></a></td><td align="right"><nobr>&nbsp;&nbsp;&nbsp;<a href="app-mimeconf.html"><img src="next.png" border=0 alt="[Next]"></a></nobr></td></tr></table>
<!--X-NavButtons-End-->
<hr>

<h1><a name="appendixA">Appendix: Application Programming Interface</a></h1>

<p>A simple API is available to allow for embedded usage
of MHonArc within other Perl programs.
</p>

<!--X-TOC-Start-->
<ul>
<li><a href="#init">Initialization</a>
<li><a href="#process_input">Processing Input</a>
<li><a href="#callback">Callbacks</a>
<ul>
<li><small><a href="#CBDbPreLoad">$mhonarc::CBDbPreLoad</a></small>
<li><small><a href="#CBDbPreSave">$mhonarc::CBDbPreSave</a></small>
<li><small><a href="#CBDbSave">$mhonarc::CBDbSave</a></small>
<li><small><a href="#CBMailFolderRead">$mhonarc::CBMailFolderRead</a></small>
<li><small><a href="#CBMessageConverted">$mhonarc::CBMessageConverted</a></small>
<li><small><a href="#CBMessageBodyRead">$mhonarc::CBMessageBodyRead</a></small>
<li><small><a href="#CBMessageHeadRead">$mhonarc::CBMessageHeadRead</a></small>
<li><small><a href="#CBRawMessageBodyRead">$mhonarc::CBRawMessageBodyRead</a></small>
<li><small><a href="#CBRcVarExpand">$mhonarc::CBRcVarExpand</a></small>
</ul>
<li><a href="#utilities">Utility Routines</a>
<ul>
<li><small><a href="#mhonarc::get_icon_url">mhonarc::get_icon_url</a></small>
<li><small><a href="#mhonarc::htmlize">mhonarc::htmlize</a></small>
<li><small><a href="#mhonarc::write_attachment">mhonarc::write_attachment</a></small>
<li><small><a href="#readmail::MAILhead_get_disposition">readmail::MAILhead_get_disposition</a></small>
</ul>
<li><a href="#notes">Notes</a>
</ul>
<!--X-TOC-End-->

<!-- ================================================================== -->
<hr>
<h2><a name="init">Initialization</a></h2>

<p>Before calling any MHonarc routines, you must initialize the MHonArc
library.  The following code snippet shows you how to initialize
MHonArc:
</p>
<pre class="code">
<i># Require MHonArc library</i>
<b>require 'mhamain.pl';</b>
<i># Initialize MHonArc</i>
<b>mhonarc::initialize();</b>
</pre>
<table class="note" width="100%">
<tr valign=top>
<td><strong>NOTE:</strong></td>
<td width="100%"><p>The <tt>mhonarc::initialize()</tt> routine should only be
called once within your program.
</p>
</td>
</tr>
</table>
<p> </p>
<table class="note" width="100%">
<tr valign=top>
<td><strong>NOTE:</strong></td>
<td width="100%"><p>If <tt>mhamain.pl</tt> is not in perl's library search path, you
will need to add the directory path to perl's search path before
calling <tt>require</tt>.
</p>
</td>
</tr>
</table>

<!-- ================================================================== -->
<hr>
<h2><a name="process_input">Processing Input</a></h2>

<p>To instruct MHonArc to process input, use the following
routine:
</p>
<pre class="code">
<i># Tell MHonArc to start processing</i>
<b>mhonarc::process_input();</b>
</pre>
<p>When <tt>mhonarc::process_input()</tt> is called with no
arguments, it parses <tt><!--
-->&#64;<!--
-->ARGV</tt> for command-line arguments.
If you pass a list of arguments into <tt>mhonarc::process_input()</tt>
then that list will be processed for the command-line arguments.
For example:
</p>
<pre class="code">
mhonarc::process_input(
    '-quiet',
    '-outdir', $archive_path,
    '-rcfile', $rcfile,
    $mailbox_filename
);
</pre>
<p>The return value of <tt>mhonarc::process_input()</tt> will be
the CPU time, in seconds, MHonArc used.  Example usage:
</p>
<pre class="code">
$cpu_time = mhonarc::process_input();
</pre>
<p>To determine what the status of the processing was, you
can query the <tt>$mhonarc::CODE</tt> variable.  The value
of this variable reflects what the exit status of MHonArc would
be if invoked from the shell.  I.e.  If <tt>$mhonarc::CODE</tt>
is equal to 0, then no errors occured during processing.  A
non-zero value indicates some error occured.  Example usage:
</p>
<pre class="code">
mhonarc::process_input(
    '-quiet',
    '-outdir', $archive_path,
    '-rcfile', $rcfile,
    $mailbox_filename
);
if ($mhonarc::CODE) {
    # error code here
}
</pre>
<table class="note" width="100%">
<tr valign=top>
<td><strong>NOTE:</strong></td>
<td width="100%"><p>If <tt>$mhonarc::CODE</tt> is equal to <tt>75</tt>, this
indicates that MHonArc was unable to obtain a lock on the archive.
This exit code is recognized by MTAs like <tt>sendmail</tt> to
requeue a message and try to deliver it again later.  This is
useful when MHonArc is invoked by a <tt>sendmail</tt> alias.
</p>
</td>
</tr>
</table>

<p>It is okay to call <tt>mhonarc::process_input()</tt> multiple times
within a single program.  This is useful if your program wants
to process multiple archives.
</p>

<!-- ================================================================== -->
<hr>
<h2><a name="callback">Callbacks</a></h2>

<p>Support is available for registering callbacks to be invoked
when MHonArc is processing input.  To register a callback, all
you need to do is set the appriopriate MHonArc
variable to a routine reference (hard or symbolic).  For example,
to set the callback when a message header is read, you can do
something like the following:
</p>
<pre class="code">
$mhonarc::CBMessageHeadRead = \&amp;my_callback_routine;
</pre>
<table class="note" width="100%">
<tr valign=top>
<td><strong>NOTE:</strong></td>
<td width="100%"><p>The
<a href="install.html#sitelib"><b><tt>mhasiteinit.pl</tt></b></a>
site initialization library can be used to register callbacks.
The advantages for using <tt>mhasiteinit.pl</tt> is that it is
executed each time MHonArc is executed, and you do not have
to create custom front-ends to MHonArc if all you want to
do is register callbacks.  See
<cite><a href="install.html">Installation</a></cite> and the
example <tt>mhasiteinit.pl</tt> provided in the <tt>examples/</tt>
directory of the MHonArc distribution for more
information about <tt>mhasiteinit.pl</tt>.
</p>
</td>
</tr>
</table>

<p>What follows is the type of callbacks supported by MHonArc:
</p>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBDbPreLoad">$mhonarc::CBDbPreLoad</a></h3>

<div class="cb_body">
<p>Invoked just before the
<a href="resources/dbfile.html">database file</a> is loaded.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
$do_load = &amp;$mhonarc::CBDbPreLoad($pathname);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$pathname</tt></dt>
<dd><p>Pathname to <a href="resources/dbfile.html">database file</a>
    that will be loaded.
    </p>
</dl>

<p><b>Return Value:</b></p>
    <p>If a true value, MHonArc will load the database denoted by
    <tt>$pathname</tt>.  If a false value, MHonArc will skip loading the
    database file.
    </p>

<p><b>Notes:</b></p>
<ul>
<li><p>This callback, along with
    <a href="#CBPreSave"><tt>$mhonarc::CBDbPreSave</tt></a> (in theory),
    can be used to provide a customized loading and saving of MHonArc
    archive information.
    </p>
</ul>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBDbPreSave">$mhonarc::CBDbPreSave</a></h3>

<div class="cb_body">
<p>Invoked before data is saved to the
<a href="resources/dbfile.html">database file</a>.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
$do_save = &amp;$mhonarc::CBDbPreSave($pathname, $tmp_pathname);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$pathname</tt></dt>
<dd><p>Pathname to database file that will be written to.
    </p>

<dt><tt>$tmp_pathname</tt></dt>
<dd><p>Pathname temporary file that data will be written to before
    replacing <tt>$pathname</tt>.  Data is written to a temporary
    file first to prevent any I/O, or other, errors leaving a corrupt
    database.  If the data is written successfully, MHonArc renames
    <tt>$tmp_pathname</tt> to <tt>$pathname</tt>.
    </p>
</dl>

<p><b>Return Value:</b></p>
    <p>If a true value, MHonArc will save the data to
    <tt>$pathname</tt>.  If a false value, MHonArc will skip writing
    the database file.
    </p>

<p><b>Notes:</b></p>
<ul>
<li><p>Generally, this function should always return a true value.  This
    can easily be done by having the following statement at the end of
    the callback: <code>return 1;</code>
    </p>
    <p>A possible scenario where a false value may be returned if for
    cases where a customized format is used to save the data and the
    <a href="#CBDbPreLoad"><tt>$mhonarc::CBDbPreLoad</tt></a> function
    is defined to provide a customized way to load database data.
    </p>
</ul>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBDbSave">$mhonarc::CBDbSave</a></h3>

<div class="cb_body">
<p>Invoked when data has been written to
<a href="resources/dbfile.html">database file</a>.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
&amp;$mhonarc::CBDbSave($db_fh);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$db_fh</tt></dt>
<dd><p>Open filehandle to database file.  This filehandle can be
    used to write custom information to the database file.
    </p>
    <p><b>Note:</b> Any data written to <tt>$db_fh</tt> must be legal
    Perl code.
    </p>
</dl>

<p><b>Return Value:</b></p>
    <p>N/A</p>

</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBMailFolderRead">$mhonarc::CBMailFolderRead</a></h3>

<div class="cb_body">
<p>The callback function after a mail folder has been processed.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
&amp;$mhonarc::CBMailFolderRead($filename);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$filename</tt></dt>
<dd><p>Filename of mail folder.  If <tt>$filename</tt> equals
    "<tt>-</tt>", then the folder represents standard input.
    </p>
    <p>To determine if the mail folder is a mailbox file or a
    directory, the following can be done:
    </p>
<pre class="code">
    if (-d $filename) {
	# MH-style directory
    } else {
	# UUCP-style mailbox file
    }
</pre>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>N/A.
    </p>

<p><b>Notes:</b></p>
<ul>
<li><p>This callback is not invoked for cases when a single message
    is added to archive from standard input.  To capture this
    event, use 
    <a href="#CBMessageConverted"><tt>$mhonarc::CBMessageConverted</tt></a>.
    </p>
</ul>

</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBMessageConverted">$mhonarc::CBMessageConverted</a></h3>

<div class="cb_body">
<p>The callback function after a mail message has been converted.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
&amp;$mhonarc::CBMessageConverted(
		   $fields_hash_ref, $mesg_info_hash_ref);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$fields_hash_ref</tt></dt>
<dd><p>Reference to hash containing parsed message header.  the
    structure of this hash is the same as described for
    the <a href="#CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</tt></a>
    callback.
    </p>

<dt><tt>$mesg_info_hash_ref</tt></dt>
<dd><p>Reference to hash contain meta-information about the message
    converted.  The following lists the keys that exist in the hash
    and what their values represent:
    </p>
    <dl>
    <dt><tt>folder</tt></dt>
    <dd><p>The filename of the mail folder the message was read from.
	If the filename is "<tt>-</tt>", then the folder was read from
	standard input.
	For cases when only a single mail message
	is added to an archive from standard input, <tt>folder</tt> 
	will be undefined.
	</p>
	</dd>
    <dt><tt>file</tt></dt>
    <dd><p>The source filename of the message just converted.
	This key is <b>only</b> defined for MH-style mail folders
	(i.e. the mail folder is a directory).  For mailbox-type
	folders, this key is set to <tt>undef</tt>.
	For cases when only a single mail message
	is added to an archive from standard input, <tt>file</tt> 
	will equal "<tt>-</tt>".
	</p>
	</dd>
    </dl>
    <p>The following table summarizes what the values of
    the <tt>$mesg_info_hash_ref</tt> hash will be based upon the type
    of input:
    </p>

    <table border="1">
    <tr valign="baseline">
      <td><i>MH-style folder</i></td>
      <td><tt>$mesg_info_hash_ref-&gt;{'folder'} = </tt><i>directory-name</i><br>
	  <tt>$mesg_info_hash_ref-&gt;{'file'} = </tt><i>filename</i></td>
    </tr>
    <tr valign="baseline">
      <td><i>Mailbox-style folder</i></td>
      <td><tt>$mesg_info_hash_ref-&gt;{'folder'} = </tt><i>filename</i><br>
	  <tt>$mesg_info_hash_ref-&gt;{'file'} = undef</tt></td>
    </tr>
    <tr valign="baseline">
      <td><i>Single Message</i></td>
      <td><tt>$mesg_info_hash_ref-&gt;{'folder'} = undef</tt><br>
	  <tt>$mesg_info_hash_ref-&gt;{'file'} = "-"</tt></td>
    </tr>
      
    </table>

</dl>

<p><b>Return Value:</b></p>
    <p>N/A.
    </p>

</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBMessageBodyRead">$mhonarc::CBMessageBodyRead</a></h3>

<div class="cb_body">
<p>The callback function after a mail message body has been converted.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
$boolean = &amp;$mhonarc::CBMessageBodyRead(
		           $fields_hash_ref, $html_text_ref, $files_array_ref);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$fields_hash_ref</tt></dt>
<dd><p>reference to hash containing parsed message header.  the
    structure of this hash is the same as described for
    the <a href="#CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</tt></a>
    callback.
    </p>

<dt><tt>$html_text_ref</tt></dt>
<dd><p>Reference to string contain the HTML markup for the
    body.  Modifications to the referenced data will be
    reflected in the message page generated.  Therefore,
    care should be observed when doing any modification.
    </p>
    <p>If MHonArc was unable to convert the body of the
    message, the following expression will evaluate to
    true:
    </p>
    <pre class="code">$$html_text_ref eq ""</pre>
    <p>If this is the case, you could set the value
    of $$html_text_ref to something else to customize
    the warning text MHonArc uses in the message page
    written.
    </p>

<dt><tt>$files_array_ref</tt></dt>
<dd><p>Reference to array of derived files when the body
    was converted.  Each file is typically relative
    to <tt>$mhonarc::OUTDIR</tt>, unless it is a full pathname.
    the <tt>mhonarc::OSis_absolute_path($filename)</tt> can
    be used to determine if a file is an absolute
    pathname or not.  Note, it is possible that a
    file could designate a directory; this indicates
    that the directory, and all files in the directory,
    are derived.
    </p>
    <p>Modifications to the array will affect the list
    of derived files MHonArc stores for the message.
    You can add files to the array if your routine
    creates files, but you can also delete items if
    your routine removes files; <b>CAUTION</b>: the HTML markup
    typically contains links to derived files so removing
    files could cause broken links unless <tt>$html_text_ref</tt>
    is modified to reflect the file deletions.
    </p>
</dl>

<p><b>Return Value:</b></p>
    <p>The return value is used by MHonArc to determine if the
    message should be excluded from any further processing.
    If the return value evaluates to true, then MHonArc will
    continue processing of the message.  If the return value
    evaluates to false, the message will be excluded.
    </p>

<p><b>Notes:</b></p>
<ul>
<li><p>To distinquish between
    <a href="resources/single.html">SINGLE</a>
    operation mode and
    archive operation mode, you can check the <tt>$mhonarc::SINGLE</tt>
    variable.  For example:
    </p>
    <pre class="code">
if ($mhonarc::SINGLE) {
    # single message-based processing here
} else {
    # archive-based processing here
}
    </pre>

<li><p>The <tt>$mhonarc::CBMessageBodyRead</tt> routine can be used
    to trigger automatic virus scanning of attachments.
    </p>
</ul>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBMessageHeadRead">$mhonarc::CBMessageHeadRead</a></h3>

<div class="cb_body">
<p>The callback function after a
mail message header is read and before any other processing is done.
Note, the function is called after any exclusion checks
(<a href="resources/checknoarchive.html">CHECKNOARCHIVE</a> and
<a href="resources/msgexcfilter.html">MSGEXCFILTER</a>)
are
performed by MHonArc.
</p>
<p><b>Synopsis:</b></p>
<pre class="code">
$boolean = &amp;$mhonarc::CBMessageHeadRead(
			    $fields_hash_ref, $raw_header_txt);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$fields_hash_ref</tt></dt>
<dd><p>Reference to hash containing parsed message header.  Keys
    are the lowercase field names and the values are references
    to array contain the values for each field.  If a field
    is only declared once in the header, the array will only
    contain one item.
    For example, to access the raw subject text,
    do the following:
    <code>$fields_hash_ref-&gt;{'subject'}[0];</code>
    </p>
    <p>The hash also contains special keys represented the values
    MHonArc has extracted when parsing the message header.
    The values of these keys are regular scalars and NOT
    array references.  The following summarizes the keys
    made available:
    </p>
    <dl>
    <dt><tt>x-mha-index</tt></dt>
	<dd>The assigned index given to the message by MHonArc.
	</dd>
    <dt><tt>x-mha-message-id</tt></dt>
	<dd>The message-id MHonArc extracted.  Note, if the
	message did not specified a message ID, MHonArc
	auto-generates one.
	</dd>
    <dt><tt>x-mha-from</tt></dt>
	<dd>Who MHonArc thinkgs the message is from.  This value
	is controled by the <a href="resources/fromfields.html">FROMFIELDS</a>
	resource.
	</dd>
    <dt><tt>x-mha-subject</tt></dt>
	<dd>The message subject that will be used by MHonArc.  The
	value may be different from the raw subject text of the message
	since <a href="resources/subjectstripcode.html">SUBJECTSTRIPCODE</a>
	code will have been applied.
	If no subject is defined, then the value is the empty string.
	</dd>
    <dt><tt>x-mha-content-type</tt></dt>
	<dd>The content-type of the message MHonArc will use for
	the message.
	</dd>
    </dl>
    <p>For example, to access the subject text that MHonArc will use,
    do the following:
    <code>$fields_hash_ref-&gt;{'x-mha-subject'};</code>
    </p>
    </dd>

<dt><tt>$raw_header_txt</tt></dt>
<dd><p>The raw header data of the message.  This data may be
    useful if pattern matches are desired against header
    data.
    </p>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>The return value is used by MHonArc to determine if the
    message should be excluded from any further processing.
    If the return value evaluates to true, then MHonArc will
    continue processing of the message.  If the return value
    evaluates to false, the message will be excluded.
    </p>

<p><b>Notes:</b></p>
<ul>
<li><p>To distinquish between
    <a href="resources/single.html">SINGLE</a>
    operation mode and
    archive operation mode, you can check the <tt>$mhonarc::SINGLE</tt>
    variable.  For example:
    </p>
    <pre class="code">
if ($mhonarc::SINGLE) {
    # single message-based processing here
} else {
    # archive-based processing here
}
    </pre>

<li><p>MHonArc resources exist that allow message exclusion
    capabilities:
    <a href="resources/checknoarchive.html">CHECKNOARCHIVE</a>,
    <a href="resources/expireage.html">EXPIREAGE</a>,
    <a href="resources/expiredate.html">EXPIREDATE</a>,
    and
    <a href="resources/msgexcfilter.html">MSGEXCFILTER</a>.
    If possible, use these resources to perform message exclusion filtering.
    </p>
</ul>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBRawMessageBodyRead">$mhonarc::CBRawMessageBodyRead</a></h3>

<div class="cb_body">
<p>Invoked with the raw message body data is read from input.  I.e.
The message body has not been converted.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
$boolean = &amp;$mhonarc::CBRawMessageBodyRead(
			  $fields_hash_ref, $body_data_ref);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$fields_hash_ref</tt></dt>
<dd><p>Reference to hash containing parsed message header.  The
    structure of this hash is the same as described for
    the <a href="#CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</tt></a>
    callback.
    </p>

<dt><tt>$body_data_ref</tt></dt>
<dd><p>Reference to string contain the raw data of the message
    body.  Modifications to the referenced data can be performed
    to change what data MHonArc will process.
    </p>

</dl>

<p><b>Return Value:</b></p>
    <p>The return value is used by MHonArc to determine if the
    message should be excluded from any further processing.
    If the return value evaluates to true, then MHonArc will
    continue processing of the message.  If the return value
    evaluates to false, the message will be excluded.
    </p>

</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="CBRcVarExpand">$mhonarc::CBRcVarExpand</a></h3>

<div class="cb_body">
<p>Invoked when a resource variable is to be expanded.  With this callback,
you can override and/or augment MHonArc's built-in resource variable
expansion support.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
($result, $do_expand_again, $can_clip) =
    &amp;$mhonarc::CBRcVarExpand($mha_index, $var_name, $arg_string);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$mha_index</tt></dt>
<dd><p>The MHonArc index key of the current message.
    </p>

<dt><tt>$var_name</tt></dt>
<dd><p>The variable name being expanded.
    For example, given the resource variable reference,
    "<tt>$VARIABLE$</tt>", <tt>$var_name</tt> would be equal to
    "<tt>VARIABLE</tt>".
    </p>

<dt><tt>$arg_string</tt></dt>
<dd><p>The argument string for the resource variable reference.
    For example, given the resource variable reference,
    "<tt>$VARIABLE(arg1)$</tt>", <tt>$arg_string</tt> would be equal to
    "<tt>arg1</tt>".
    </p>
    <p><b>Note:</b> MHonArc generally uses the character '<tt>;</tt>'
    to separate multiple arguments to a resource variable.  However,
    this is only convention, and if defining your own resource variable
    support via this callback, you can use whatever convention you like.
    </p>
</dl>

<p><b>Return Value:</b></p>
    <p>The return value is a list of values interpreted as follows:</p>
    <dl>
    <dt><tt>$result</tt></dt>
    <dd><p>The result (or replace text) for the variable.  If
	the result is equal to <tt>undef</tt>, MHonArc's built-in
	expansion code will be invoked to expand <tt>$var_name</tt>.
	If <tt>$result</tt> is defined, then MHonArc's built-in
	expansion will be skipped.
	</p>
	</dd>

    <dt><tt>$do_expand_again</tt></dt>
    <dd><p>If a true value, MHonArc will parse <tt>$result</tt> and
	expand any resource variables contained within.
	<b>Note:</b> <tt>$mhonarc::CBRcVarExpand</tt> will be
	called for each resource variable found.
	</p>
	</dd>

    <dt><tt>$can_clip</tt></dt>
    <dd><p>If a true value, clipping is allowed to be performed.
	Clipping is done if max length specification is specified
	in the resource variable reference.
	</dd>
    </dl>


<p><b>Notes:</b></p>
<ul>
<li><p>Use the <a href="resources/definevar.html">DEFINEVAR</a> resource
    whenever possible for defining custom resource variables.  The
    <tt>$mhonarc::CBRcVarExpand</tt> should only be used for cases
    where the sematics of <a href="resources/definevar.html">DEFINEVAR</a>
    are insufficient.
    </p>

<li><p>Colon variable modifiers, if specified in the resource
    variable reference, are applied by MHonArc after
    <tt>$mhonarc::CBRcVarExpand</tt> is invoked.
    </p>
</ul>
</div>

<!-- ================================================================== -->
<hr>
<h2><a name="utilities">Utility Routines</a></h2>

<p>The following are various utility routines available for use by
custom extensions and <a href="resources/mimefilters.html">filters</a>:
</p>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="mhonarc::get_icon_url">mhonarc::get_icon_url</a></h3>

<div class="cb_body">
<p>Retrieve icon URL for a give content-type as defined by the
<a href="resources/icons.html">ICONS</a> resource.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
$url = mhonarc::get_icon_url($content_type);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$content_type</tt></dt>
<dd><p>MIME content-type to retrieve icon for.
    </p>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>URL to icon.
    </p>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="mhonarc::htmlize">mhonarc::htmlize</a></h3>

<div class="cb_body">
<p>Convert HTML special characters into entity references.  The
following table shows with characters are converted:
</p>
<table border="1">
<tr>
  <th>Character</th><th>Entity Reference</th>
</tr>
<tr>
  <td>&lt;</td><td>&amp;lt;</td>
</tr>
<tr>
  <td>&gt;</td><td>&amp;gt;</td>
</tr>
<tr>
  <td>&amp;</td><td>&amp;amp;</td>
</tr>
<tr>
  <td>&quot;</td><td>&amp;quot;</td>
</tr>
</table>

<p><b>Synopsis:</b></p>
<pre class="code">
# Create an htmlized version of a string
$html_text = mhonarc::htmlize($text);

# Htmlize in-place
mhonarc::htmlize($text_ref);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$text</tt></dt>
<dd><p>Text to convert.  If a reference, conversion is done in-place,
    </p>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>The converted htmlized text.
    </p>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="mhonarc::write_attachment">mhonarc::write_attachment</a></h3>

<div class="cb_body">
<p>Saves data to a file with a specified content-type.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
require 'mhmimetypes.pl';

($filename, $url) =
    mhonarc::write_attachment($content_type, $data_ref, $options_hash_ref);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$content_type</tt></dt>
<dd><p>The content-type of the data.  The value should be a string
    in standard MIME content-type format.  Examples: <tt>images/jpeg</tt>,
    <tt>application/postscript</tt>.
    </p>
    </dd>

<dt><tt>$data_ref</tt></dt>
<dd><p>Scalar reference of data to write to disk.
    </p>
    </dd>

<dt><tt>$options_hash_ref</tt></dt>
<dd><p>Reference to hash containing options to routine.  All options
    are optional.  The following options are available:
    </p>
    <dl>
    <dt><tt>-dirpath</tt></dt>
	<dd>Pathname to directory to write file to.  If not specified,
	the value of <a href="resources/attachmentdir.html">ATTACHMENTDIR</a>
	or <a href="resources/outdir.html">OUTDIR</a> if ATTACHMENTDIR is
	not defined.
	</dd>
    <dt><tt>-filename</tt></dt>
	<dd>Name of file to write to.  If not specified, a random filename
	will be generated based on the value of <var>$content_type</var>.
	</dd>
    <dt><tt>-ext</tt></dt>
	<dd>Filename extension to use for file.
	If not specified, extension will be
	based on the value of <var>$content_type</var>.  The
	<tt>-filename</tt>, if specified, supercedes this option.
	</dd>
    <dt><tt>-url</tt></dt>
	<dd>Base URL.  If not specified the value of
	<a href="resources/attachmenturl.html">ATTACHMENTURL</a> is used.
	</dd>
    </dl>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>The return value is a list of values interpreted as follows:</p>
    <dl>
    <dt><tt>$filename</tt></dt>
    <dd><p>The name of the file <tt>$data_ref</tt> was written to.
	<tt>$filename</tt> may contain pathname components.  For
	<a href="resources/mimefilters.html">filters</a>, this value
	is suitable for use in the file return list.
	</p>
	</dd>
    <dt><tt>$url</tt></dt>
    <dd><p>The URL that links to <tt>$filename</tt>.  Calling code
	can use the URL within an HTML link.
	</p>
	</dd>
    </dl>

<p><b>Example:</b></p>
    <p>The following illustrates the typical way of specifying options
    to <tt>mhonarc::write_attachment</tt>:
    </p>
<pre class="code">
    ($filename, $urlfile) =
	mhonarc::write_attachment($ctype, $data, {
	  '-dirpath'  =&gt; $path,
	  '-filename' =&gt; $name,
	  '-ext'      =&gt; $ext,
	});
</pre>

<p><b>Notes:</b></p>
<ul>
<li><p>Care should practiced when using the <tt>-filename</tt> or
    <tt>-ext</tt> option since it could result in security vulnerabilities.
    When these options are not specified, <tt>mhonarc::write_attachment</tt>
    will created a safe random filename based upon the given content-type.
    </p>
</ul>
</div>

<!-- .................................................................. -->
<h3 class="cb_head"><a name="readmail::MAILhead_get_disposition">readmail::MAILhead_get_disposition</a></h3>

<div class="cb_body">
<p>Retrieve the content disposition of a message entity.
</p>

<p><b>Synopsis:</b></p>
<pre class="code">
require 'readmail.pl';

($disposition, $filename, $raw_filename, $html_name) =
    readmail::MAILhead_get_disposition($fields_hash_ref, $do_html);
</pre>

<p><b>Arguments:</b></p>
<dl>
<dt><tt>$fields_hash_ref</tt></dt>
<dd><p>reference to hash containing parsed message header.  the
    structure of this hash is the same as described for
    the <a href="#CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</tt></a>
    callback.
    </p>
    </dd>

<dt><tt>$do_html</tt></dt>
<dd><p>Generate an HTMLized version of filename designated in
    <tt>$fields_hash_ref</tt> for informational use within HTML markup.
    </p>
    </dd>
</dl>

<p><b>Return Value:</b></p>
    <p>The return value is a list of values interpreted as follows:</p>
    <dl>
    <dt><tt>$disposition</tt></dt>
    <dd><p>The disposition of the entity.  Generally, the value
	is either not defined, "<tt>attachment</tt>", or
	"<tt>inline</tt>".
	</p>
	</dd>
    <dt><tt>$filename</tt></dt>
    <dd><p>Filename of entity as defined in <tt>$fields_hash_ref</tt>,
	but translated for safe usage.  Any leading pathname component
	is removed and any unsafe characters are translated to
	underscores.
	</p>
	</dd>
    <dt><tt>$raw_filename</tt></dt>
    <dd><p>Raw filename of entity as defined in <tt>$fields_hash_ref</tt>.
	This is only provided for informative uses and should not
	be used for creating files.  Use <tt>$filename</tt> instead.
	</p>
	</dd>
    <dt><tt>$html_name</tt></dt>
    <dd><p>Raw filename of entity converted to HTML.  This return value
	is only provided if the <tt>$do_html</tt> argument is a true value.
	<tt>$html_name</tt> can be used for informative purposes in
	generated HTML by
	<a href="resources/mimefilters.html">filters</a>.
	</p>
	<table class="note" width="100%">
	<tr valign="baseline">
	<td><strong>NOTE:</strong></td>
	<td width="100%"><p>It is recommended that <tt>$html_name</tt>
	be used instead of HTMLizing <tt>$raw_filename</tt> directly since
	<tt>readmail::MAILhead_get_disposition</tt> does non-ASCII
	decoding and uses the
	<a href="resources/charsetconverters.html">CHARSETCONVERTERS</a>
	resource.
	</p>
	</td>
	</tr>
	</table>
	</p>
	</dd>
    </dl>
</div>

<!-- ================================================================== -->
<hr>
<h2><a name="notes">Notes</a></h2>

<ul>

<li><p>This API documention is not complete.  To get
    a better idea of what you may be able to do, have a look at the
    source code for the commands provided in the MHonArc distribution:
    <tt>mhonarc</tt>, <tt>mha-dbedit</tt>,
    <tt>mha-dbrecover</tt>, and <tt>mha-decode</tt>.  You may also
    want to look at the source of <tt>mhamain.pl</tt> and the
    various default <a href="resources/mimefilters.html">filters</a>.
    </p>

<li><p>Only a single archive can be processed at any given time.
    </p>

</ul>

<hr>
<!--X-NavButtons-Start-->
<table width="100%">
<tr valign="top">
<td align="left"><nobr><a href="app-utilsprg.html"><img src="prev.png"border=0 alt="[Prev]"></a>&nbsp;&nbsp;&nbsp;</nobr></td><td align="center" width="99%"><a href="mhonarc.html"><img src="up.png" border=0 alt="[TOC]"></a><a href="faq/faq.html"><img src="faq.png" border=0 alt="[FAQ]"></a><a href="app-bugs.html"><img src="bug.png" border=0 alt="[Bugs]"></a><a href="http://www.mhonarc.org/"><img src="home.png" border=0 alt="[Home]"></a></td><td align="right"><nobr>&nbsp;&nbsp;&nbsp;<a href="app-mimeconf.html"><img src="next.png" border=0 alt="[Next]"></a></nobr></td></tr></table>
<!--X-NavButtons-End-->

<hr>
<address>
$Date: 2005/07/08 02:04:05 $ <br>
<img align="top" src="monicon.png" alt="">
<a href="http://www.mhonarc.org/"
><strong>MHonArc</strong></a><br>
Copyright &#169; 2001,2005 <a href="http://www.earlhood.com/"
>Earl Hood</a>, <a href="mailto:mhonarc&#37;40mhonarc.org"
>mhonarc<!--
-->&#64;<!--
-->mhonarc.org</a><br>
</address>

</body>
</html>