#-*- perl -*- # # Copyright (C) 2001 Ken'ichi Fukamachi # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # # $Id$ # $FML$ # package FML::Header; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; use Mail::Header; use FML::Log qw(Log LogWarn LogError); =head1 NAME FML::Header - header manipulators =head1 SYNOPSIS $header = use FML::Header \@header; $header->add('X-ML-Info', "mailing list name"); $header->delete('Return-Receipt-To'); $header->replace(field, value); =head1 DESCRIPTION C is an adapter for C class. C is the base class. =head1 METHODS Methods defined in C are available. For example, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C. =cut require Exporter; @ISA = qw(Mail::Header Exporter); # Descriptions: forward new() request to the base class # Arguments: $self $args # Side Effects: none # Return Value: none sub new { my ($self, $args) = @_; # an adapter for Mail::Header::new() $self->SUPER::new($args); } sub DESTROY {} sub AUTOLOAD { my ($self, $args) = @_; Log("Error: $AUTOLOAD is not defined"); } =head2 C return the C defind in the header's Content-Type field. =head2 C return the C defind in the header's Content-Type field. =cut # Descriptions: return the type defind in the header's Content-Type field. # Arguments: $self # Side Effects: extra spaces in the type to return is removed. # Return Value: none sub content_type { my ($header) = @_; my ($type) = split(/;/, $header->get('content-type')); if (defined $type) { $type =~ s/\s*//g; return $type; } undef; } # Descriptions: return boundary defined in Content-Type # Arguments: $self $args # Side Effects: none. # Return Value: none sub mime_boundary { my ($header) = @_; my $m = $header->get('content-type'); if ($m =~ /boundary=\"(.*)\"/) { return $1; } else { undef; } } ### ### FML specific functions ### =head1 FML SPECIFIC METHODS =head2 C add X-ML-Name: =head2 C add X-Mail-Count: =head2 C add X-ML-Count: =cut sub add_fml_ml_name { my ($header, $config, $args) = @_; $header->add('X-ML-Name', $config->{ x_ml_name }); } sub add_fml_traditional_article_id { my ($header, $config, $args) = @_; $header->add('X-Mail-Count', $args->{ id }); } sub add_fml_article_id { my ($header, $config, $args) = @_; $header->add('X-ML-Count', $args->{ id }); } =head2 C add X-MLServer: and List-Software: =head2 C add List-* sereies defined in RFC2369. =head2 C add X-Sequence. =cut sub add_software_info { my ($header, $config, $args) = @_; my $fml_version = $config->{ fml_version }; if ($fml_version) { $header->add('X-MLServer', $fml_version); $header->add('List-Software', $fml_version); } } sub add_rfc2369 { my ($header, $config, $args) = @_; # addresses my $post = $config->{ address_for_post }; my $command = $config->{ address_for_command }; my $maintainer = $config->{ maintainer }; # See RFC2369 for more details $header->add('List-Post', "") if $post; $header->add('List-Owner', "") if $maintainer; if ($command) { $header->add('List-Help', ""); $header->add('List-Subscribe', ""); $header->add('List-UnSubscribe', ""); } } sub add_x_sequence { my ($header, $config, $args) = @_; $header->add('X-Sequence', "$config->{ x_ml_name } $args->{ id }"); } =head2 C add subject tag e.g. [elena:00010]. The real function exists in C. =head2 C add or replace C. =cut sub rewrite_subject_tag { my ($header, $config, $args) = @_; my $pkg = "FML::Header::Subject"; eval qq{ require $pkg; $pkg->import();}; unless ($@) { $pkg->rewrite_subject_tag($header, $config, $args); } else { Log("Error: cannot load $pkg"); } } sub rewrite_reply_to { my ($header, $config, $args) = @_; my $reply_to = $header->get('reply-to'); unless (defined $reply_to) { $header->add('reply-to', $config->{ address_for_post }); } } =head2 C remove header fields defiend in C<$unsafe_header_fields>. =cut sub delete_unsafe_header_fields { my ($header, $config, $args) = @_; my (@fields) = split(/\s+/, $config->{ unsafe_header_fields }); for (@fields) { $header->delete($_);} } =head1 MISCELLANEOUS UTILITIES =head2 C remove subject tag like string in C<$string>. =cut sub remove_subject_tag_like_string { my ($str) = @_; $str =~ s/\W[-\w]+.\s*\d+\W//g; $str =~ s/\s+/ /g; $str =~ s/^\s*//g; $str; } =head1 SEE ALSO L =head1 AUTHOR Ken'ichi Fukamachi =head1 COPYRIGHT Copyright (C) 2001 Ken'ichi Fukamachi All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 HISTORY FML::Header appeared in fml5 mailing list driver package. See C for more details. =cut 1;