qoo eiji <[email protected]> writes:
> Okay, I wrote this script because I've been trying to find a way to
> search my attachments in Thunderbird.
Thanks for your contribution! You are a brave person.
> #!/bin/perl
> ...
> $OUTPUTENCODING = "UTF-8";
For any script that you write, always use
use strict;
use warnings;
This will help you finding typing mistakes and other sources of
hard-to-find errors.
It is always worth the trouble to investigate the miscellaneous CPAN
modules that may help you. There are several modules that can parse
mail messages, saving you a lot of energy.
> $STATE = "INIT";
In general, uppercase names are 'reserved' for Perl. You're free to
use them but one day Perl may change its mind.
Also, using 'use strict' will force you to declare all variables.
> s/[\n\r]*$//g;
This can better be written as
s/[\n\r]+$//;
The 'g' modifier is useless since the pattern is anchored to the end
of the string.
> for (keys %MAIL_ATTACHMENTS) {
> $fn = $MAIL_ATTACHMENTS{$_};
You may consider using the form:
while ( my($key,$value) = each(%MAIL_ATTACHMENTS) ) {
> if (/$partbody_boundary/) {
The variable may contain characters that have a special meaning when
used inside a pattern.
You can use either:
$partbody_boundary = quotemeta($partbody_boundary);
if ( /$partbody_boundary/ )
or
if ( /\Q$partbody_boundary\E/ )
This will 'quote' the potential special characters so they only match
themselves.
-- Johan