[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic linking to a mhonarc archive



On August 10, 2002 at 19:23, Alan Burlison wrote:

> I'm trying to munge the subject and body of a message using the
> CBMessageBodyRead callback, to convert bugids into hrefs.  The callback
> looks like this:
> 
> sub msg_body_read
> {
>         my ($fields, $html, $files) = @_;
> 
>         # Convert any bugids in the subject to links.
>         $fields->{'x-mha-subject'} =~ s/\b([134]\d{6})\b/bugid($1)/ge;
> 
>         # Convert any bugids in thebody to links.
>         $$html =~ s/\b([134]\d{6})\b/bugid($1)/ge;
> }
> 
> This works fine for the body of the message - bugids are nicely converted
> into URLs, but in the case of the subject, although x-mha-subject is
> modified OK, it doesn't appear to be the subject that is _actually_ printed
> out in the mail header, as the resulting html is missing the link.  How do I
> munge the *real* subject line?

The "x-mha-..." fields are only copies of what MHonArc stores.
So changing the value has no permanent effect (should it?).

To get what you want you will need to use the
$mhonarc::CBMessageHeadRead callback since the message header is
"htmlized" right afterwords.

What you will need to do is the following:

* In CBMessageHeadRead:

  Change $fields->{'subject'} directly.  Remember, that the values
  of the $fields hash are array references (excluding the special
  x-mha-... values).  Something like the following should do:

    $fields->{'subject'}[0] =~ s/\b([134]\d{6})\b/bugid($1)/ge;

  To be cleaner, you may want to check that $fields->{'subject'} is
  defined in case a message comes in without a Subject.

  The x-mha- fields are not used when converting the message
  header to HTML, so you have to modify $fields directly.
  The x-mha- fields represent what MHonArc will store and use
  for other things.

* In CBMessageBodyRead:

  Now this part is ugly, which gives a good reason that modifying
  $fields->{'x-mha-subject'} in CBMessageHeadRead should changes the
  Subject used by MHonArc.  You will need to modifying an "internal"
  hash so your modified subject will be used for index page listing:

    $mhonarc::Subject{$fields->{'x-mha-index'}} =~
	s/\b([134]\d{6})\b/bugid($1)/ge;


I wonder if having a CBRawMessageHeadRead may be worth adding.
The callback would be called after a message header is parsed, but
before MHonArc extracts in data from it.  Of course, you would not
have the x-mha-... fields defined at this stage since it would
be before MHonArc processes the header.

--ewh

---------------------------------------------------------------------
To sign-off this list, send email to majordomo@mhonarc.org with the
message text UNSUBSCRIBE MHONARC-USERS


[Index of Archives]     [Bugtraq]     [Yosemite News]     [Mhonarc Home]