File: pm-jadate.rc

package info (click to toggle)
procmail-lib 1%3A2009.1202-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,384 kB
  • sloc: perl: 294; makefile: 177; sh: 4
file content (146 lines) | stat: -rw-r--r-- 3,789 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
# pm-jadate.rc -- Read date from the message hdrs: From_, Receved:
#
#   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 recipe will scan several headers to find the date string.
#       When suitable header is found and the parsing has succeeded, the
#       return variables are set. The Date values reflects the arrive time
#       of the message; not the sending time. If nothing works, a shell call
#       `date' is used as a last resort.
#
#	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
#
#   Required settings
#
#	PMSRC must point to source directory of procmail code. This subroutine
#       will include
#
#       o   pm-javar.rc
#       o   pm-jadate1.rc
#       o   pm-jadate3.rc
#       o   pm-jadate4.rc
#
#   Call arguments (variables to set before calling)
#
#       (none)
#
#   Usage example
#
#           INCLUDERC = $PMSRC/pm-jadate.rc
#           #   now we have all date variables that we need
#           #
#           $TODAY    = $YYYY-$MM-$DD
#
#   Change Log (none)

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


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

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

# ..................................................... &output-vars ...
# output variables, these actually come from the another subroutine,
# but let's mention them here too
#
# DATE YYYY MM MON DD DAY hh mm ss

ERROR = "yes"

# ........................................................... &do-it ...

#   Try MDA From_ header first
#   From foo@bar.com  Tue Nov 18 12:43:56 1997

fromRegexp = "...$s+...$s+$d+$s+$d$d:.*"

dummy = "$id: From_ date test"

:0
*$ ^From$s+$NSPC+\/$s+$fromRegexp
{
    dummy = "$id: Standard From_ header matched"
    INPUT       = $MATCH
    INCLUDERC   = $PMSRC/pm-jadate3.rc # Date parser
}

# Get time from first header, which is in some systems is
# Received: ... ; Thu, 13 Nov 1997 11:43:50 +0200

dummy = "$id: Received date test"

:0
*$ ! YYYY ?? $d
*$   ^Received:.*;$s+\/...,$s+$d+$s+...$s$d$d$d$d.*
{
    dummy       = "$id: First Received header matched"
    INPUT       = $MATCH
    INCLUDERC   = $PMSRC/pm-jadate1.rc # Date parser
}

#   Emacs Gnus add X-From-line to the message
#   Emacs Rmail adds Mail-from line to the message
#   This is same as From_

dummy = "$id: MUA date test"

:0
*$ ! YYYY ?? $d
*$   ^(X-From-Line|Mail-from):$s+$NSPC+\/$s+$fromRegexp
{
    dummy       = "$id: Other possible From_ header matched"
    INPUT       = $MATCH
    INCLUDERC   = $PMSRC/pm-jadate3.rc # Date parser
}


#   Still no luck, I should add more tests to the above but I don't
#   know what. Call sh 'date' as a last resort
#

dummy = "$id: sh date test"

:0
*$ ! YYYY ?? $d
{
    dummy       = "$id: Last chance, calling sh date "
    INCLUDERC   = $PMSRC/pm-jadate4.rc
}

dummy = "$id: end:"

# end of file pm-jadate.rc