Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / doc / MHonArc / app-api.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<html>
<head>
<title>MHonArc v2.5 -- Appendix: Application Programming Interface
</title>
<style>
.cb_head {
font-family: monospace;
border-color: black;
border-style: solid none none none;
border-top-width: thin;
}
.cb_body {
padding-left: 1em;
}
</style>
</head>
<!--
<BODY background="ssbg75.jpg"
text="#000000" link="#0000ee" vlink="#551a8b" alink="ff0000">
-->
<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>This appendix describes the simple API available to allow the
embedding 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="#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="#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>
<i># Require MHonArc library</i>
<b>require 'mhamain.pl';</b>
<i># Initialize MHonArc</i>
<b>mhonarc::initialize();</b>
</pre>
<table border=0 cellpadding=4>
<tr valign=top>
<td><strong>NOTE</strong></td>
<td><p>The <tt>mhonarc::initialize()</tt> routine should only be
called once within your program.
</p>
</td>
</tr>
</table>
<table border=0 cellpadding=4>
<tr valign=top>
<td><strong>NOTE</strong></td>
<td><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>
<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>@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>
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>
$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>
mhonarc::process_input(
'-quiet',
'-outdir', $archive_path,
'-rcfile', $rcfile,
$mailbox_filename
);
if ($mhonarc::CODE) {
# error code here
}
</pre>
<table border=0 cellpadding=4>
<tr valign=top>
<td><strong>NOTE</strong></td>
<td><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>
$mhonarc::CBMessageHeadRead = \&amp;my_callback_routine;
</pre>
<table border=0 cellpadding=4>
<tr valign=top>
<td><strong>NOTE</strong></td>
<td><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>
$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>
$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>
&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="CBMessageBodyRead">$mhonarc::CBMessageBodyRead</a></h3>
<div class="cb_body">
<p>The callback function after a mail message body has been read a converted.
</p>
<p><b>Synopsis:</b></p>
<pre>
&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>
$$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>N/A</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>
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>
$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>
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>
&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>N/A</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>
($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="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>.
</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: 2002/05/02 01:34:30 $ <br>
<img align="top" src="monicon.png" alt="">
<a href="http://www.mhonarc.org/"
><strong>MHonArc</strong></a><br>
Copyright &#169; 2001, <a href="http://www.earlhood.com/"
>Earl Hood</a>, <a href="mailto:mhonarc@mhonarc.org"
>mhonarc@mhonarc.org</a><br>
</address>
</body>
</html>