Re: piping message thru demime

Troy Piggins <[email protected]>
Newsgroups gmane.network.slrn.user
Message-ID <[email protected]>
* Christian Ebert <[email protected]> :
> * Troy Piggins on Friday, February 17, 2006 at 08:08:47 +1000:
> > Looks like I spoke too soon.  It worked on the test message I was
> > using, but running the macro on other signed messages it doesn't
> > work!?
> 
> Might be the seconde issue discussed on
> <http://scifi.squawk.com/demime.html>.

I thought of that, but the message doesn't have multipart/mixed in
it.

> > Both messages are by the same author.  I'll have to tinker
> > some more.
> 
> Save the message separately and run demime on it from the command
> line.

Did that, no error.  All ran ok.

> > The error message spreads text all over the screen so it's hard to
> > make out what the error is.
> 
> I guess the error is:
> 
> unexpected EOF while looking for matching `''
> 
> and 'echo' is the problem.
> 
> So, a rather clumsy way of doing this might be to save the
> article to a file and run demime on that file:

THought of that but haven't yet sorted out a method of doing it.

> (I replaced article_as_string with raw_article_as_string)
> 
> define demime ()
> {
>   variable demime_tmp, raw_art, fp, art_demime;
>   demime_tmp = "/tmp/slrn_demime."+ string (getpid () );
>   raw_art = raw_article_as_string ();
>   fp = fopen (demime_tmp, "w");
>   if (fp == NULL)
>     error (_function_name () +": could not open "+demime_tmp);
>   fputs (raw_art, fp);
>   fclose (fp);
>   fp = popen ("/usr/local/bin/demime - < "+demime_tmp, "r");
>   if (fp == NULL)
>     error (_function_name () +": demime pipe failed" );
>   art_demime = strjoin (fgetslines (fp), "");
>   pclose (fp);
>   if (art_demime != "") replace_article (art_demime);
>   else error (_function_name () +": failed");
>   system ("rm "+demime_tmp);
> }

Excellent - this worked on all the ones I've tested on so far.
Thanks.

I have actually changed this a little so that it runs every time I
open an article, and if the article is signed it runs demime, if not
it just opens it unaltered:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
define demime ()
{
  variable xcharset =
extract_displayed_article_header("Content-Type");
  if (string_match(xcharset,"\\Cmultipart/signed",1))
  {
    variable demime_tmp, raw_art, fp, art_demime;
    demime_tmp = "/tmp/slrn_demime."+ string (getpid () );
    raw_art = raw_article_as_string ();
    fp = fopen (demime_tmp, "w");
    if (fp == NULL)
      error (_function_name () +": could not open "+demime_tmp);
    fputs (raw_art, fp);
    fclose (fp);
    fp = popen ("/usr/local/bin/demime - < "+demime_tmp, "r");
    if (fp == NULL)
      error (_function_name () +": demime pipe failed" );
    art_demime = strjoin (fgetslines (fp), "");
    pclose (fp);
    if (art_demime != "") replace_article (art_demime);
    else error (_function_name () +": failed");
    system ("rm "+demime_tmp);
  }
}

() = register_hook ("read_article_hook", "demime");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

> I'm sure this can be done much better, I'm not good at this slang
> stuff.

Better at it than me ;-)

> If you are pulling from a local server you could also run demime
> on the 'original' article after detecting its location by
> disecting the Xref header.

Thanks again Christian.  You've been most helpful and I've learned a
lot about s-lang along the way which will surely help for any future
ideas for macros I have.

If you don't mind, I'd like to post this somewhere on a webpage -
obviously I'll give you full credit.  It's just that I am sure there
are others who would like this functionality.

Haven't you ever come across slrn not handling pgp signed messages
correctly?  eg this :

Message-ID: <[email protected]>

-- 
Troy Piggins
Ubuntu 5.10  pkgs : kernel 2.6.12-9-386, postfix 2.2.4, procmail 3.22
Compiled from src : slrn 0.9.8.1/rt (score_color patch), mutt 1.5.11i
                      vim 6.4


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.