Controlchan and MIME

Julien ÉLIE julien at trigofacile.com
Sat Jan 3 20:25:28 UTC 2009


Hi,

Can we use MIME::Parser in controlchan?
(and add it to the list of requirements in the man page and INSTALL)

It would be easier to decode control messages and extract
useful information (encodings and parts).
We could also remove the currently used parse_article() in order
to take benefit from MIME::Parser.


I have a working sample here:


use MIME::Parser;
use strict;

my $message=<<EOF;
[control article]
EOF

my $parser = new MIME::Parser;
my $entity = $parser->parse_data($message);
my $head = $entity->head;
my ($part, $part_head);

# Gives "ISO-8859-1" for instance.  We have to check
# whether it is defined -> if not (or if control.ctl
# compels the charset), we initialize it.
print $head->mime_attr('Content-Type.charset');

# Access Control: and From: headers -- for controlchan.
print $head->get('Control');
print $head->get('From');

if ($entity->parts > 0) {
  foreach $part ($entity->parts) {
    $part_head = $part->head;

    # We have here the type and the charset of the MIME part.
    print $part_head->mime_type;
    print $part_head->mime_attr('Content-Type.charset');

    # If the type is "application/news-groupinfo", we can
    # get the body.
    print $part->stringify_body;
  }
} else {
    print $entity->stringify_body;
}


Then, we go on treating the message as we are already doing,
using $part->stringify_body or $entity->stringify_body for the
contents of the body of the message.
(Adding "For your newsgroups file:" if not present in the first
case).
Note that we can handle QP and base64 control messages with that
because stringify_body does the conversion for us!



Is it OK to use the code I suggest here?

-- 
Julien ÉLIE

« Il vaut mieux un tapis persan volé qu'un tapis volant percé ! » (Astérix) 




More information about the inn-workers mailing list