2 ##--------------------------------------------------------------------------##
4 ## $Id: extract-mesg-date,v 1.4 2002/09/15 03:33:08 ehood Exp $
6 ## See POD below or run program with -man option.
7 ##--------------------------------------------------------------------------##
8 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
10 ## This program is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; either version 2 of the License, or
13 ## (at your option) any later version.
15 ## This program is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with this program; if not, write to the Free Software
22 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ##--------------------------------------------------------------------------##
26 package MHArc
::extract_mesg_date
;
28 ##--------------------------------------------------------------------------##
30 BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); }
31 my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; }
32 use lib
"$Dir/../lib"; # Add relative lib to search path
34 ##--------------------------------------------------------------------------##
37 my $config = MHArc
::Config
->load("$Dir/../lib/config.sh");
39 ##--------------------------------------------------------------------------##
43 use MHArc
::Util
qw( usage );
44 use MHArc
::MailUtil
qw( extract_date );
50 my $time_fmt = '%Y-%m';
54 mhonarc
::initialize
();
55 mhonarc
::open_archive
(
59 ) || die qq/ERROR: Unable to load MHonArc library\n/;
60 mhonarc
::close_archive
();
62 # Grap command-line options
64 my $clstatus = GetOptions
(
66 "datefields=s" => \
$opt_dfs,
67 "fmt=s" => \
$time_fmt,
72 usage
(0) unless $clstatus;
77 $MHArc::MailUtil
::Debug
= 1;
81 if (defined($opt_dfs)) {
82 @date_fields = split(/:/, $opt_dfs);
83 } elsif (defined($config->{'MSG_DATE_FIELDS'})) {
84 @date_fields = split(/:/, $config->{'MSG_DATE_FIELDS'});
86 print "date_fields=@date_fields\n" if $debug;
87 my($fields, $header) = readmail
::MAILread_file_header
(\
*STDIN
);
88 print mhonarc
::time2str
(
89 $time_fmt, extract_date
($fields, @date_fields), 1);
93 ##--------------------------------------------------------------------------##
98 extract-mesg-date - Retrieve date of a mail message
102 extract-mesg-date [options]
106 This program extracts the date of a mail message read in from
107 standard input. The date of the message is determined by
108 examining the following mail header fields in order:
109 C<Received>, C<Delivery-Date>, C<Date>. The fields checked
110 can be changed with the C<-datefields> option. If no date
111 is found, than current local time is used.
113 The date of the message will be echoed to standard output.
114 The format of the date is controled by the C<-fmt> option.
116 This program is provided as part of mharc to provide the ability to
117 to determine the dates of messages during filtering.
118 Example shell command usage:
120 mesg_date=`cat message | extract-mesg-date`
122 Example useage within a procmail recipe:
125 MESGDATE_=| extract-mesg-date -fmt '%Y-%m'
128 $MBOXROOT/.listsadmin/$MESGDATE_
134 =item C<-datefields> I<date-fields-list>
136 Specifies the message header fields to examine in determining the
137 date of the message. Field names are separated by a colon.
140 -datefields x-archive-date:received:date
142 tells that C<X-Archive-Date>, C<Received>, and C<Date> should
147 Print out debugging information.
149 B<WARNING: DO NOT USE THIS OPTION WITHIN PROCMAILRC RULES.>
151 =item C<-fmt> I<time-fmt-string>
153 The time format to use. The format string syntax is the same as
154 defined by C<strftime>.
156 If C<-fmt> is not specified, than "C<%Y-%m>" is used.
160 Print out help message.
164 Print out the manpage.
170 This program uses functions within MHonArc's library. Therefore,
171 MHonArc must be installed on your system and the MHonArc libraries
172 located within Perl's include path.
176 $Id: extract-mesg-date,v 1.4 2002/09/15 03:33:08 ehood Exp $
180 Earl Hood, earl@earlhood.com
182 This program is part of the mharc archiving system and comes with
183 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
184 the GNU General Public License, which may be found in the mharc