1 ##--------------------------------------------------------------------------##
3 ## $Id: MailUtil.pm,v 1.3 2002/09/13 07:24:18 ehood Exp $
6 ##--------------------------------------------------------------------------##
7 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ##--------------------------------------------------------------------------##
25 package MHArc
::MailUtil
;
34 ##--------------------------------------------------------------------------##
40 ##--------------------------------------------------------------------------##
47 my @date_fields = ( );
49 @date_fields = ( ['received',0],['delivery-date',0],['date',0] );
54 push(@date_fields, [ $_, $1 ]);
56 push(@date_fields, [ $_, 0 ]);
62 my($field_str, $unix_time, $df, $i);
63 foreach (@date_fields) {
65 if (defined($field_str = $fields->{$df}[$i])) {
66 print qq/Debug: $df: $field_str\n/ if $Debug;
67 if ($df eq 'received') {
68 my @ra = split(/;/, $field_str);
69 $field_str = pop(@ra);
71 @date = mhonarc
::parse_date
($field_str);
73 print qq/Debug: \@date=/, join('|',@date), qq/\n/ if $Debug;
74 $unix_time = mhonarc
::get_time_from_date
(@date[1..$#date]);
79 if (!defined($unix_time)) {
80 print qq/Debug: Unable to parse date, using current time\n/ if $Debug;
86 ##--------------------------------------------------------------------------##
92 MHArc::MailUtil - General mail-related utilities for mail archiving system.
100 This module contains a collection of mail-related utility routines.
104 The following module variables can be set to affect the behavior
105 of the utility routines:
111 If set to a true value, routines will print out debuging information.
117 By default, no routines are exported into the calling namespace.
118 Routines in this module can be imported by explicitly listing the
119 routines to import in the C<use> declaration:
121 use MHArc::MailUtil qw( extract_date );
123 The following routines are availale:
127 =item C<extract_date($fields, I<@date_fields>)>
129 Extract the date from message header fields represented by C<$fields>.
130 Any additional arguments are treated as message fields names (which
131 should be lowercase names) to examine to find the date. If no fields
132 names are specified, than the following fields are checked in order:
133 C<Received>, C<Delivery-Date>, and C<Date>.
135 The return value of this function is the date of the message in
136 Unix time format: the same as what is returned by Perl's
137 builtin C<time> function.
143 Functions in this module assume that the MHonArc libraries have
148 C<$Id: MailUtil.pm,v 1.3 2002/09/13 07:24:18 ehood Exp $>
152 Earl Hood, earl@earlhood.com
154 This module is part of the mharc archiving system and comes with
155 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
156 the GNU General Public License, which may be found in the mharc