File: app-api.html

package info (click to toggle)
mhonarc 2.6.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,020 kB
  • sloc: perl: 280,086; makefile: 11
file content (1068 lines) | stat: -rw-r--r-- 33,884 bytes parent folder | download | duplicates (7)
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
<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>