File: pm-jadate5.rc

package info (click to toggle)
procmail-lib 1%3A2009.1202-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 2,372 kB
  • ctags: 541
  • sloc: perl: 294; makefile: 196; sh: 4
file content (227 lines) | stat: -rw-r--r-- 5,171 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# pm-jadate5.rc -- 'Fri Jun 19 18:51:56 1998' date parser from var INPUT
#
#   File id
#
#       Copyright (C) 1997-2010 Jari Aalto
#
#       This program is free software; you can redistribute it and/or
#       modify it under the terms of the GNU General Public License as
#       published by the Free Software Foundation; either version 2 of the
#       License, or (at your option) any later version
#
#       This program is distributed in the hope that it will be useful, but
#       WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#       General Public License for more details at
#       <http://www.gnu.org/copyleft/gpl.html>.
#
#   Description
#
#	This includerc parses date from variable INPUT which has string
#
#           "WeekDay Month dayNbr Year"
#
#       Example input
#
#           "Fri Jun 19 18:51:56 1998"      -- without comma
#           "Fri, Jun 19 18:51:56 1998"     -- with comma
#
#       Returned values
#
#	    YYYY    = 4 digits
#           YY      = 2 digits
#           MON     = 3 characters
#           MM      = 2 digits
#           DAY     = 3 characters
#           DD      = 2 digits
#           hh      = 2 digits      If available
#           mm	    = 2 digits	    If available
#           ss      = 2 digits      If available
#           TZ      = 5 characters  If available
#
#	Variable ERROR is set to "yes" if it couldn't recognize the INPUT
#	and couldn't parse the basic YYYY,YY,MM,DD variables.
#
#   Required settings
#
#	PMSRC must point to source directory of procmail code. This subroutine
#       will include pm-javar.rc from there.
#
#   Call arguments (variables to set before calling)
#
#           INPUT = string-to-parse
#
#       The INPUT can have anything after "Week, dayNbr Month Year", or
#       before it: you can pass a string like
#       "Fri Jun 19 18:51:56 1998 11:43:23 +0200".
#
#   Usage example
#
#	The first *Received* header will tell when the message was received
#	by your mailserver. We parse the date and avoid calling expensive
#       `date' command.
#
#	    PMSRC	    = $HOME/pm
#	    RC_DATE_WDMY    = $PMSRC/pm-jadate5.rc #Week-Day-Month-Year parser
#
#           # Get time from first header, it ends like this:
#
#           :0
#           *$ ()\/From .*
#           {
#               INPUT = $MATCH
#               #  Turn off the logging while executing this part
#
#               VERBOSE=off   INCLUDERC = $RC_DATE_WDMY   VERBOSE=on
#
#               :0
#               * ERROR ?? yes
#               {
#		   # Use some other way to get the time or shout loudly
#		}
#           }
#
#   Change Log (none)

# .................................................... &initialising ...


id    = "pm-jadate5.rc"
dummy = "
========================================================================
$id: init:
"

:0
* !  WSPC ?? ( )
{
    INCLUDERC = $PMSRC/pm-javar.rc
}

# ..................................................... &output-vars ...
# output variables

#	 Kill following variables

YYYY MM MON DD DAY hh mm ss TZ

#	Set to default

ERROR = "yes"		# set defualt value

# ........................................................... &do-it ...
#	Check that input is something like: Thu, 13 Nov 1997

dummy = "$id: Parse: Fri Jun 19 18:51:56 1998"
dummy = "$id: INPUT = $INPUT"		# show what we try to match

:0 D
*$ INPUT ?? ()\/[SMTWF]$a$a[,$WSPC]+$a$a$a$s$d+$s+.*
{
    INPUT = $MATCH

    :0
    * INPUT ?? ^\/...
    {
        DAY = $MATCH
    }

    :0
    *$ INPUT ?? ^...[,$WSPC]+\/...
    {
        MON = $MATCH
    }

        #	Move to the DD MON section

        :0
        *$ INPUT ?? ^...[,$WSPC]+...$s+\/.*
        {
            INPUT = $MATCH
        }

    # ........................................................ &date ...

    :0
    *$  INPUT ?? ^\/$d$d
    {
        DD = $MATCH
    }
    :0 E                        # else
    *$  INPUT ?? ^\/$d
    {
        DD = "0$MATCH"
    }


    # ........................................................ &time ...
    # Change INPUT

    in = $INPUT                     # just for logging purposes

        :0
        *$ INPUT ?? ^$d+$s+\/.*
        {
            INPUT = $MATCH
        }


    :0
    *$ INPUT ?? ^\/$d$d
    {
        hh = $MATCH
    }

    :0
    *$ INPUT ?? ^$d$d:\/$d$d
    {
        mm = $MATCH
    }


    :0
    *$ INPUT ?? ^$d$d:$d$d:\/$d$d
    {
        ss = $MATCH
    }

    :0
    *$ INPUT ?? ^$d$d:$d$d:$d$d$s+\/[-+]....
    {
        TZ = $MATCH
    }


    # ........................................................ &year ...

    :0
    *$ INPUT ?? ^$d+:$d+:$d+$s+\/....
    {
        YYYY = $MATCH
    }


    #	If this last recipe succeeds, then the whole string has been parsed.
    #
    :0
    * YYYY ?? ..\/..
    {
        YY    = $MATCH
        ERROR = "no"
    }


    #   Now reverse engineer to the numer, David Tamkin <dattier@miso.wwa.com>
    #   technically one should use $\monthnym but here it doesn't matter
    #   If user gave invalid input, will not match

    :0
    * $ mm2nbr ?? $MON\/..
    {
        MM = $MATCH
    }
}

dummy = "$id: end:"

# end of file pm-jadate.rc