Refactoring Some Chicken Star Soup

Saturday, September 28th, 2002 at 12:00 am | 347 views | trackback url
foreach (@body) {
        chomp $_;
        next if /^#/;
        $line =~ s,<template>,
<template>,m;
        if (m{(<template>)}) {
                push @unwrap, undef;
                $line = '<template>';
                next;
        }
        if (m{(</template>)}) {
                push @unwrap, $line;
                $line = undef;
                push @unwrap, "
</template>;";
                last;
        }
        if (@unwrap) {
                if ( m/^ [^s=]+ s+ 
                        =           # an '=' sign, er.
                        s* /x      # optional whitespace
                                or
                        m/^ [.*]$/x   
                )
                {
                        $line =~ s/^#/
#/m;
                        $line .= "
";
                        push @unwrap, $line;
                        $line = $_;
                } else {
                        $line .= $_;
                }
        }
}
push @unwrap, " ";

This simple little bit of code I hacked up takes the body of an email message, strips off everything outside the opening <template> tag and after the closing </template> tag, and passes it to Config::General for tokenizing.

The magic part of this is where it “unwraps” lines that would wrap in the user’s MUA, such as url=http://www.foo.com/, where the value of ‘url’ is too long to fit on one line of the user’s MUA, and wraps down to the next line.

I’m nearly done with this one, just a few more “junk input” regression tests to go before release time.

pilot-link 0.11.5

    Nearly complete, a few more tests on Irix and BSD before a new one. snprintf() and getopt_long() are proving problematic with AC_LIBOBJ and friends on Irix 6.4.

    Many thanks to tridge for lending me the shell on the Irix box, and for giving me some ideas to look into, and to jpr for doing a bunch of legwork.

Last Modified: Saturday, September 28th, 2002 @ 00:00

Leave a Reply

You must be logged in to post a comment.

Bad Behavior has blocked 92 access attempts in the last 7 days.