mhonarc-users

Re: call mhonarc from script

1999-10-12 22:07:09
On October 12, 1999 at 19:27, zheng wang wrote:

Is it possible to get some example scripts that call mhonarc? I am trying
to automatically convert the mail from petidomo into html file.

Will you being calling MHonArc within Perl programs?  Is so, you
can invoke MHonArc directly without using system().  For example,
look at the source code for "mhonarc":

MAIN: {
    unshift(@INC, 'lib');       # Should I leave this line in?

    require 'mhamain.pl' || die qq/ERROR: Unable to require "mhamain.pl"\n/;
    mhonarc::initialize();
    mhonarc::process_input() ? exit(0) : exit($mhonarc::CODE);
}

In sum, to call MHonArc with Perl programs, you do the following
to initialize the MHonArc library:

    require 'mhamain.pl';
    mhonarc::initialize();

Note, you may need set @INC properly if mhamain.pl is not in perl's
default search path.

Once that is done, you can invoke mhonarc::process_input() to
process data.  You can pass arguments to mhonarc::process_input()
as you would pass arguments on the command-line.  For example:

    mhonarc::process_input(
                '-add',
                '-rcfile', '/path/to/resource/file.mrc',
                '/path/to/mail/folder');

The difference is that the arguments are passed as a Perl list.
This is actually more secure than using system() since no shell
interpretation is done (unless of cource you invoke system with
a list argument).

mhonarc::process_input() will return a true value if everything went
ok.  Else, it returns a false value, and exit code can be
retrieved with $mhonarc::CODE;

This embedded Perl approach allows to call MHonArc on multiple
archives (*in sequence*) without the overhead of forking off a
process each time.

For more complex examples of the MHonArc API, see the various mha-*
utility programs.

Someday I will get around to documenting the API.

        --ewh

<Prev in Thread] Current Thread [Next in Thread>