File: pm-jamime.rc

package info (click to toggle)
procmail-lib 1%3A2002.01.02-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,216 kB
  • ctags: 365
  • sloc: perl: 213; makefile: 126; sh: 6
file content (249 lines) | stat: -rw-r--r-- 6,759 bytes parent folder | download
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# @(#) pm-jamime.rc -- subroutine to read mime boundary etc. variables
# @(#) $Id: pm-jamime.rc,v 2.1 2002/01/01 23:34:26 jaalto Exp $
#
#   File id
#
#       .Copyright (C)   1997-2002 Jari Aalto
#       .$Maintainer:    Jari Aalto <jari.aalto@poboxes.com> $
#       .$Created:       1997-12 $
#       .$Keywords:      procmail, subroutine, mime $
#
#       This code is free software in terms of GNU Gen. pub. Lic. v2 or later
#	Refer to http://www.gnu.org/copyleft/gpl.html
#
#   Documentation
#
#       This includerc reads MIME boundary string from the message
#	if it exists. The boudary string is typically found from
#	Content-Type header.
#
#	    Mime-Version: 1.0
#	    Content-Type: multipart/mixed; boundary=9i9nmIyA2yEADZbW
#
#	In addition it will define few other mime variables. See the
#	returned values. You use these variables later in your MIME
#	message processing.
#
#   Mime Notes
#
#       1998-07-28 Brett Glass <brett@lariat.org> reported in PM-L that
#       there was security exploit in long attachement filenames:
#       http://www.xray.mpe.mpg.de/mailing-lists/procmail/1998-07/msg00248.html
#
#       And here is the url to the matter:
#
#       http://www.sjmercury.com/business/microsoft/docs/security0728.htm
#
#
#       When you use this module to detect mime messages, you can check the
#       filename length with recipe:
#
#           #  Recipe after calling $RC_MIME, this module,
#
#           re       = ".........."     # regexp with 10 matches
#           too_long = "$re$re$re$re"   # allow 40 characters maximum
#
#           :0
#           *$ $SUPREME^0  MIME_H_ATTACHEMENT ?? $re
#           *$ $SUPREME^0  MIME_B_ATTACHEMENT ?? $re
#           {
#               dummy = "** Dangerously long mime attachement filename"
#               dummy = "** $MIME_H_ATTACHEMENT $MIME_B_ATTACHEMENT"
#
#               :0 :
#               /var/spool/mail/MimeDanger
#           }
#
#   Required settings
#
#	PMSRC must point to source directory of procmail code. This subroutine
#       will include
#
#       o   pm-javar.rc
#
#   Call arguments (variables to set before calling)
#
#	(none)
#
#   Return values
#
#	o   Variable MIME is set to "yes" or "no" if messages has mime version
#	    string
#	o   MIME_VER contains the mime version string from the header.
#	o   MIME_TYPE contains the Content-Type from the header.
#	o   MIME_CTE contains Content-Transfer-Encoding from the header.
#       o   MIME_H_QP is "yes" if Content-Transfer-Encoding: quoted-printable
#	    is in the header.
#	o   MIME_B_QP is "yes" if Content-Transfer-Encoding: quoted-printable
#	    is found from the body.
#       o   MIME_BOUNDARY contains the boundary string, which is used to
#	    differentiate mime sections in the body.
#	o   MIME_BOUNDARY_COUNT is the number of boundary strings found
#	    from the body. The value is 3 if there is two mime sections,
#	    and 4 if 3 etc. MIME_BOUNDARY_COUNT -1 = count of sections.
#	o   MIME_H_ATTACHEMENT, contains the filename if there was attachement
#	    filename in the header. Content-Disposition: attachment;
#	    filename="..."
#	o   MIME_B_ATTACHEMENT. `body' file attachement. Note however that
#	    this is the match of first string in the body. There may be
#	    several attachements. MIME_B_ATTACHEMENT_FILE_COUNT tells you
#	    how many filenames are in the body.
#
#   Usage example
#
#	INCLUDERC = $PMSRC/pm-jamime-tag.rc
#
#   Change Log (none)

# ............................................................ &code ...


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


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

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

MIME        = "no"           # set default value
MIME_H_QP   = "no"
MIME_B_QP   = "no"

MIME_VER
MIME_CTE
MIME_TYPE
MIME_BOUNDARY
MIME_BOUNDARY_COUNT

# ........................................................... &do-it ...
#   The WSPC ?? ( ) is there just double checking that we REALLY read
#   the pm-javar.rc. We must not set any MIME variables if that wasn't
#   read.

:0
* ^Mime-Version: *\/[0-9.]+
* WSPC ?? ( )
{
    MIME        = "yes"
    MIME_VER    = $MATCH

    :0
    * ^Content-Type: +\/.*
    {
	MIME_TYPE = $MATCH
    }

    :0
    *$ ^Content-Transfer-Encoding:$s+\/.*
    {
	MIME_CTE = $MATCH

	:0
	* MIME_CTE ?? quoted-printable
	{
	    MIME_H_QP = "yes"
	}
    }

    :0
    *$ B ?? ^Content-Transfer-Encoding:$s+quoted-printable
    {
        MIME_B_QP = "yes"
    }

    #	What is the MIME tag in this message?
    #
    #	Content-Type: multipart/mixed;
    #	    boundary="---- =_NextPart_000_01BD04D4.A5AC6B00"
    #
    #	Note that in the text, this string may not be excatly like this,
    #	Eg. in my messages there was "--" prepended to the tag.
    #

    :0
    * boundary *= *\"\/[^\";]+
    {
        MIME_BOUNDARY = $MATCH
    }

    #   Hm, the boundary string was not surrounded by double quotes.
    #   Search this kind of boundary string then:
    #
    #       Content-Type: multipart/mixed; boundary=9i9nmIyA2yEADZbW


    :0 E
    * boundary *= *\/[^\";]+
    {
        #   "    Don't mind this, a dummy double quote to help Emacs
        #        to end starting quote below. Otherwise syntax colour
        #        highlighting would go beserk.


        MIME_BOUNDARY = $MATCH
    }


    dummy = "$id: Do we have the boundary string?"

    :0
    *! MIME_BOUNDARY ?? ^^^^
    {
        #   Count how many mime sections there are in the message.
        #   MIME_BOUNDARY_COUNT -1 = count of mime sections.

        :0
        *$ B ?? 1^1  $\MIME_BOUNDARY
        { }

        MIME_BOUNDARY_COUNT = $=

    }

    #	Mime-Version: 1.0 (generated by tm-edit 7.106)
    #	Content-Type: application/octet-stream
    #	Content-Disposition: attachment; filename="file.txt"
    #	Content-Transfer-Encoding: 7bit
    #
    #	Note: the second regexp assumes "filename=file.txt"

    mimeAttachementRegexp1 = "filename$s*=$s*[\"']\/[^\"\']+"
    mimeAttachementRegexp2 = "filename$s*=$s*\/.*"

    :0
    *$                H ?? ^Content-Disposition:.*attachment$s*;$s*\/.*
    *$ $SUPREME^0 MATCH ??  $mimeAttachementRegexp1
    *$ $SUPREME^0 MATCH ??  $mimeAttachementRegexp2
    {
	MIME_H_ATTACHEMENT = $MATCH
    }

    :0 E
    *$                B ??  ^Content-Disposition:.*attachment$s*;$s*\/.*
    *$ $SUPREME^0 MATCH ??  $mimeAttachementRegexp1
    *$ $SUPREME^0 MATCH ??  $mimeAttachementRegexp2
    {
	MIME_B_ATTACHEMENT = $MATCH

        :0
        *$ B ?? 1^1  ^Content-Disposition:.*attachment.*filename
        { }

        MIME_B_ATTACHEMENT_FILE_COUNT = $=

    }

}

dummy = "$id: end:"

# pm-jamime-tag.rc ends here