1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<html>
<head>
<title>MHonArc v2.5 -- Appendix: Application Programming Interface
</title>
</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.gif"border=0 alt="[Prev]"></a> </nobr></td><td align="center" width="99%"><a href="mhonarc.html"><img src="up.gif" border=0 alt="[TOC]"></a><a href="faq/faq.html"><img src="faq.gif" border=0 alt="[FAQ]"></a><a href="app-bugs.html"><img src="bug.gif" border=0 alt="[Bugs]"></a><a href="http://www.mhonarc.org/"><img src="home.gif" border=0 alt="[Home]"></a></td><td align="right"><nobr> <a href="app-mimeconf.html"><img src="next.gif" 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="#CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</tt></a></small>
<li><small><a href="#CBMessageBodyRead"><tt>$mhonarc::CBMessageBodyRead</tt></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 = \&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><a name="CBMessageHeadRead"><tt>$mhonarc::CBMessageHeadRead</a></tt></h3>
<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 = &$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.
</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 FROMFIELDS resource.
</dd>
<dt><tt>x-mha-subject</tt></dt>
<dd>The message subject. 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>
</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>
<h3><a name="CBMessageBodyRead"><tt>$mhonarc::CBMessageBodyRead</a></tt></h3>
<p>The callback function after a mail message body has been read a converted.
</p>
<p><b>Synopsis:</b></p>
<pre>
&$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>
<!-- ================================================================== -->
<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.gif"border=0 alt="[Prev]"></a> </nobr></td><td align="center" width="99%"><a href="mhonarc.html"><img src="up.gif" border=0 alt="[TOC]"></a><a href="faq/faq.html"><img src="faq.gif" border=0 alt="[FAQ]"></a><a href="app-bugs.html"><img src="bug.gif" border=0 alt="[Bugs]"></a><a href="http://www.mhonarc.org/"><img src="home.gif" border=0 alt="[Home]"></a></td><td align="right"><nobr> <a href="app-mimeconf.html"><img src="next.gif" border=0 alt="[Next]"></a></nobr></td></tr></table>
<!--X-NavButtons-End-->
<hr>
<address>
01/11/24 03:22:00<br>
<img align="top" src="monicon.gif" alt="">
<a href="http://www.mhonarc.org/"
><strong>MHonArc</strong></a><br>
Copyright © 2001, <a href="http://www.earlhood.com/"
>Earl Hood</a>, <a href="mailto:mhonarc@mhonarc.org"
>mhonarc@mhonarc.org</a><br>
</address>
</body>
</html>
|