2 ** Copyright 2000 Double Precision, Inc.
3 ** See COPYING for distribution information.
18 #define strcasecmp stricmp
24 #define strncasecmp strnicmp
29 static char *skipblob(char *p
, char **save_blob_ptr
)
38 if (*q
== '[' || *q
== ']')
40 else if (strchr("0123456789", *q
) == NULL
)
47 while (isspace((int)(unsigned char)*p
))
52 if (save_blob_ptr
&& *save_blob_ptr
&& !isalldigits
)
55 *(*save_blob_ptr
)++=*orig_p
++;
64 static char *skipblobs(char *p
, char **save_blob_ptr
)
71 q
=skipblob(p
, save_blob_ptr
);
76 /* Remove artifacts from the subject header */
78 static void stripsubj(char *s
, int *hasrefwd
, char *save_blob_buf
)
86 if (!isspace((int)(unsigned char)*p
))
91 while (p
[1] && isspace((int)(unsigned char)p
[1]))
104 ** (2) Remove all trailing text of the subject that matches
105 ** the subj-trailer ABNF, repeat until no more matches are
108 ** subj-trailer = "(fwd)" / WSP
115 if ( isspace((int)(unsigned char)p
[-1]))
120 if (p
-s
>= 5 && strncasecmp(p
-5, "(FWD)", 5) == 0)
123 *hasrefwd
|= CORESUBJ_FWD
;
135 int flag
=CORESUBJ_FWD
;
139 ** (3) Remove all prefix text of the subject
140 ** that matches the subj-leader ABNF.
142 ** subj-leader = (*subj-blob subj-refwd) / WSP
144 ** subj-blob = "[" *BLOBCHAR "]" *WSP
146 ** subj-refwd = ("re" / ("fw" ["d"])) *WSP [subj-blob] ":"
148 ** BLOBCHAR = %x01-5a / %x5c / %x5e-7f
149 ** ; any CHAR except '[' and ']'
152 if (isspace((int)(unsigned char)*p
))
158 q
=skipblobs(p
, NULL
);
160 if (strncasecmp(q
, "RE", 2) == 0)
165 else if (strncasecmp(q
, "FWD", 3) == 0)
169 else if (strncasecmp(q
, "FW", 2) == 0)
177 orig_blob_ptr
=save_blob_buf
;
179 q
=skipblob(q
, &save_blob_buf
);
187 save_blob_buf
=orig_blob_ptr
;
192 ** (4) If there is prefix text of the subject
193 ** that matches the subj-blob ABNF, and
194 ** removing that prefix leaves a non-empty
195 ** subj-base, then remove the prefix text.
197 ** subj-base = NONWSP *([*WSP] NONWSP)
198 ** ; can be a subj-blob
201 orig_blob_ptr
=save_blob_buf
;
203 q
=skipblob(p
, &save_blob_buf
);
210 save_blob_buf
=orig_blob_ptr
;
216 ** (6) If the resulting text begins with the
217 ** subj-fwd-hdr ABNF and ends with the subj-fwd-trl
218 ** ABNF, remove the subj-fwd-hdr and subj-fwd-trl and
219 ** repeat from step (2).
221 ** subj-fwd-hdr = "[fwd:"
223 ** subj-fwd-trl = "]"
226 if (strncasecmp(p
, "[FWD:", 5) == 0)
233 *hasrefwd
|= CORESUBJ_FWD
;
235 for (q
=s
; (*q
++=*p
++) != 0; )
245 while ( (*q
++ = *p
++) != 0)
251 char *rfc822_coresubj(const char *s
, int *hasrefwd
)
253 char *q
=strdup(s
), *r
;
263 if ((*r
& 0x80) == 0) /* Just US-ASCII casing, thanks */
265 if (*r
>= 'a' && *r
<= 'z')
268 stripsubj(q
, hasrefwd
, 0);
272 char *rfc822_coresubj_nouc(const char *s
, int *hasrefwd
)
283 stripsubj(q
, hasrefwd
, 0);
287 char *rfc822_coresubj_keepblobs(const char *s
)
289 char *q
=strdup(s
), *r
;
301 stripsubj(q
, &dummy
, r
);