[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dropping messages?



On October 2, 2002 at 18:55, Chad Kouse wrote:

> I'm attaching my resource file...

There is not much to it, just a MIMEFILTERS setting.  It looks okay.

> I run the script like this $htmlmsg = `/usr/bin/mhonarc -single
> -rcfile=/etc/mimefilters /tmp/mk_tmp001.msg`;
---------^
The '=' should be a space.

> see anything wrong ?

I tend to avoid using the backtick operator in Perl, except for very
trivial things (I'm wondering if it could be a source of your "hangs").
Main reasons are performance and security.  I'd use something like
the following:

  my $htmlmsg = "";
  my @cmd = (
    '/usr/bin/mhonarc',
    '-single',
    '-rcfile', '/etc/mimefilters',
    '/tmp/mk_tmp001.msg'
  );

  local(*MHONARC);
  my $child_pid = open(MHONARC, '|-');
  if ($child_pid) {   # parent
    local $_;
    while (<MHONARC>) {
      $htmlmsg .= $_;
    }
    if (!close(MHONARC)) {
      die qq/ERROR: Non-zero exit from "@cmd": $?\n/);
    }

  } else {      # child
    exec(@cmd) || die qq/ERROR: Cannot exec "@cmd": $!\n/;
  }

The above avoids having the overhead of a calling a shell process and
avoids any messing shell meta-character problems.  The above could
be encapsulated into a general routine for capturing the output of
a program.

Now, to be be even more efficient, you could avoid execing mhonarc and
call it via its API.  For what you are doing, you will need the
IO::String module:

  use IO::String;
  require 'mhamain.pl';
  mhonarc::initialize();

  my $html_msg = IO::String->new;
  my @mha_args = ('-quiet',
		  '-single',
		  '-rcfile', '/etc/mimefilters',
		  '-stdout', $html_msg,
		  '/tmp/mk_tmp001.msg');

  if (mhonarc::process_input(@mha_args)) {
    die qq/ERROR: mhonarc returned non-zero status: $mhonarc::CODE\n/;
  }

  print ${$html_msg->string_ref};

MHonArc secretly supports the ability of passing a reference to a
file handle to the -stdout option in order to support embedded usage.

--ewh

---------------------------------------------------------------------
To sign-off this list, send email to majordomo@mhonarc.org with the
message text UNSUBSCRIBE MHONARC-USERS


[Index of Archives]     [Bugtraq]     [Yosemite News]     [Mhonarc Home]