Added to the repository
Showing
3 changed files
with
113 additions
and
0 deletions
headers/posix/.cvsignore
0 → 100644
headers/posix/Makefile.am
0 → 100644
1 | ## Process this file with GNU Automake to create Makefile.in | ||
2 | |||
3 | ## Copyright (C) 2001, 2002 Free Software Foundation, Inc. | ||
4 | ## | ||
5 | ## GNU Mailutils is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License as | ||
7 | ## published by the Free Software Foundation; either version 2, or (at | ||
8 | ## your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, but | ||
11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | ## General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc. | ||
18 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | noinst_HEADERS = regex.h |
mailbox/munre.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with this library; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
17 | |||
18 | #if HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <errno.h> | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include <mailutils/error.h> | ||
26 | #include <mailutils/errno.h> | ||
27 | |||
28 | #include <regex.h> | ||
29 | |||
30 | static regex_t *re_prefix; | ||
31 | |||
32 | int | ||
33 | munre_set_regex (char *str, int caseflag, char **errp) | ||
34 | { | ||
35 | int rc; | ||
36 | int flags = REG_EXTENDED; | ||
37 | |||
38 | if (errp) | ||
39 | *errp = NULL; | ||
40 | |||
41 | if (!str) | ||
42 | str = "^re: *"; | ||
43 | if (re_prefix) | ||
44 | regfree (re_prefix); | ||
45 | else | ||
46 | { | ||
47 | re_prefix = malloc (sizeof (*re_prefix)); | ||
48 | if (!re_prefix) | ||
49 | return ENOMEM; | ||
50 | } | ||
51 | if (!caseflag) | ||
52 | flags |= REG_ICASE; | ||
53 | rc = regcomp (re_prefix, str, flags); | ||
54 | if (rc) | ||
55 | { | ||
56 | if (errp) | ||
57 | { | ||
58 | size_t s = regerror (rc, re_prefix, NULL, 0); | ||
59 | s++; | ||
60 | *errp = malloc (s); | ||
61 | if (*errp) | ||
62 | regerror (rc, re_prefix, *errp, s); | ||
63 | } | ||
64 | regfree (re_prefix); | ||
65 | free (re_prefix); | ||
66 | return MU_ERR_FAILURE; | ||
67 | } | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | int | ||
72 | munre_subject (const char *subject, const char **new_subject) | ||
73 | { | ||
74 | int rc; | ||
75 | regmatch_t rm; | ||
76 | |||
77 | if (!subject) | ||
78 | return EINVAL; | ||
79 | |||
80 | if (!re_prefix) | ||
81 | { | ||
82 | rc = munre_set_regex (NULL, 0, NULL); | ||
83 | if (rc) | ||
84 | return rc; | ||
85 | } | ||
86 | |||
87 | rc = regexec (re_prefix, subject, 1, &rm, 0); | ||
88 | if (rc == 0 && rm.rm_eo != -1 && new_subject) | ||
89 | *new_subject = subject + rm.rm_eo; | ||
90 | return rc; | ||
91 | } |
-
Please register or sign in to post a comment