Message ID Question

Christopher Pryce <[email protected]> Mon, 24 Apr 2006 14:18:49 -0500
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
I transfer mail from a Pop mail server to my own mail directories  
with this script:

#!/usr/bin/perl

# transfers mail from a server to a file structure on the host computer
use strict;
use Mail::Box::Manager;

my $mgr = Mail::Box::Manager->new;
my $folder = $mgr->open(
     folder  =>'/Users/Chris/mailbox/cpryce',
     create  => 1,
     type    =>'maildir',
     access  => 'rw'
);
my $username = 'xxxx';
my $password = 'xxxx';

my $pop = $mgr->open( folder => '/',
                       type => 'pop3',
                       username => $username,
                       password => $password,
                       server_name => '10.1.0.8',
                       server_port => '110',
                       access=> 'rw'
                  );

foreach my $popmsg ( $pop->messages ) {
     my $mid = $popmsg->messageId;
     $mgr->copyMessage( $folder, $popmsg ) unless  $folder->find 
( $mid );
     $popmsg->delete();
}
$mgr->closeAllFolders;


After it is transfered, another script comes along and creates an XML  
listing. The problem is that certain incorrectly formed messages are  
missing the Message-Id: header field. So in the second script that  
builds the listing, if I do this:

my $mgr = Mail::Box::Manager->new();
my $folder = $mgr->open(
     folder  =>'/Users/Chris/mailbox/cpryce',
     extract => 1,
     access  => 'rw',
     type    => 'maildir',
     save_on_exit => 1
);

foreach my $msg ( sort{ $b->timestamp cmp $a->timestamp} $folder- 
 >messages ) {

     # create a message node.
     my $mNode = $doc->createElement('message');

     # add the message id as an attribute to this node.
     my $messageId = $msg->messageId();

     ### Mail::Message creates a default messageId if it is missing.
     ### How to get it to be saved back to this message.

     # ... more node creation.
}
$folder->close(write=>'ALWAYS');

The XML will be parsed for an HTML directory listing and the  
messageId attribute is destined for an HREF tag. The trouble is, how  
to figure out if the Message-Id: header field for this message is  
actually part of the message, or a default supplied. If it is a  
default, how do I save it back into the current message? Should I  
(can I) check for it as the message is being transfered from the POP3  
Server? Or can I force it to be written to the message when the XML  
index is created.

Christopher Pryce