~ubuntu-branches/debian/sid/postfix/sid

« back to all changes in this revision

Viewing changes to src/global/strip_addr.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (1.1.41)
  • Revision ID: package-import@ubuntu.com-20140211074430-91tdwgjriazawdz4
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
/* SYNOPSIS
7
7
/*      #include <strip_addr.h>
8
8
/*
9
 
/*      char    *strip_addr(address, extension, delimiter)
 
9
/*      char    *strip_addr(address, extension, delimiter_set)
10
10
/*      const char *address;
11
11
/*      char    **extension;
12
 
/*      int     delimiter;
 
12
/*      const char *delimiter_set;
13
13
/* DESCRIPTION
14
14
/*      strip_addr() takes an address and either returns a null
15
15
/*      pointer when the address contains no address extension,
25
25
/*      that had to be chopped off.
26
26
/*      The copy includes the recipient address delimiter.
27
27
/*      The caller is expected to pass the copy to myfree().
28
 
/* .IP delimiter
29
 
/*      Recipient address delimiter.
 
28
/* .IP delimiter_set
 
29
/*      Set of recipient address delimiter characters.
30
30
/* SEE ALSO
31
31
/*      split_addr(3) strip extension from localpart
32
32
/* LICENSE
56
56
 
57
57
/* strip_addr - strip extension from address */
58
58
 
59
 
char   *strip_addr(const char *full, char **extension, int delimiter)
 
59
char   *strip_addr(const char *full, char **extension, const char *delimiter_set)
60
60
{
61
61
    char   *ratsign;
62
62
    char   *extent;
66
66
    /*
67
67
     * A quick test to eliminate inputs without delimiter anywhere.
68
68
     */
69
 
    if (delimiter == 0 || strchr(full, delimiter) == 0) {
 
69
    if (*delimiter_set == 0 || full[strcspn(full, delimiter_set)] == 0) {
70
70
        stripped = saved_ext = 0;
71
71
    } else {
72
72
        stripped = mystrdup(full);
73
73
        if ((ratsign = strrchr(stripped, '@')) != 0)
74
74
            *ratsign = 0;
75
 
        if ((extent = split_addr(stripped, delimiter)) != 0) {
 
75
        if ((extent = split_addr(stripped, delimiter_set)) != 0) {
76
76
            extent -= 1;
77
77
            if (extension) {
78
 
                *extent = delimiter;
 
78
                *extent = full[strlen(stripped)];
79
79
                saved_ext = mystrdup(extent);
80
80
                *extent = 0;
81
81
            } else
105
105
{
106
106
    char   *extension;
107
107
    char   *stripped;
108
 
    int     delim = '-';
 
108
    char*  delim = "+-";
 
109
 
 
110
#define NO_DELIM        ""
109
111
 
110
112
    /*
111
113
     * Incredible. This function takes only three arguments, and the tests
112
114
     * already take more lines of code than the code being tested.
113
115
     */
114
 
    stripped = strip_addr("foo", (char **) 0, 0);
 
116
    stripped = strip_addr("foo", (char **) 0, NO_DELIM);
115
117
    if (stripped != 0)
116
118
        msg_panic("strip_addr botch 1");
117
119
 
118
 
    stripped = strip_addr("foo", &extension, 0);
 
120
    stripped = strip_addr("foo", &extension, NO_DELIM);
119
121
    if (stripped != 0)
120
122
        msg_panic("strip_addr botch 2");
121
123
    if (extension != 0)
131
133
    if (extension != 0)
132
134
        msg_panic("strip_addr botch 6");
133
135
 
134
 
    stripped = strip_addr("foo@bar", (char **) 0, 0);
 
136
    stripped = strip_addr("foo@bar", (char **) 0, NO_DELIM);
135
137
    if (stripped != 0)
136
138
        msg_panic("strip_addr botch 7");
137
139
 
138
 
    stripped = strip_addr("foo@bar", &extension, 0);
 
140
    stripped = strip_addr("foo@bar", &extension, NO_DELIM);
139
141
    if (stripped != 0)
140
142
        msg_panic("strip_addr botch 8");
141
143
    if (extension != 0)
151
153
    if (extension != 0)
152
154
        msg_panic("strip_addr botch 12");
153
155
 
154
 
    stripped = strip_addr("foo-ext", (char **) 0, 0);
 
156
    stripped = strip_addr("foo-ext", (char **) 0, NO_DELIM);
155
157
    if (stripped != 0)
156
158
        msg_panic("strip_addr botch 13");
157
159
 
158
 
    stripped = strip_addr("foo-ext", &extension, 0);
 
160
    stripped = strip_addr("foo-ext", &extension, NO_DELIM);
159
161
    if (stripped != 0)
160
162
        msg_panic("strip_addr botch 14");
161
163
    if (extension != 0)
178
180
    myfree(stripped);
179
181
    myfree(extension);
180
182
 
181
 
    stripped = strip_addr("foo-ext@bar", (char **) 0, 0);
 
183
    stripped = strip_addr("foo-ext@bar", (char **) 0, NO_DELIM);
182
184
    if (stripped != 0)
183
185
        msg_panic("strip_addr botch 19");
184
186
 
185
 
    stripped = strip_addr("foo-ext@bar", &extension, 0);
 
187
    stripped = strip_addr("foo-ext@bar", &extension, NO_DELIM);
186
188
    if (stripped != 0)
187
189
        msg_panic("strip_addr botch 20");
188
190
    if (extension != 0)
205
207
    myfree(stripped);
206
208
    myfree(extension);
207
209
 
 
210
    stripped = strip_addr("foo+ext@bar", &extension, delim);
 
211
    if (stripped == 0)
 
212
        msg_panic("strip_addr botch 25");
 
213
    if (extension == 0)
 
214
        msg_panic("strip_addr botch 26");
 
215
    msg_info("wanted:    foo+ext@bar -> %s %s", "foo@bar", "+ext");
 
216
    msg_info("strip_addr foo+ext@bar -> %s %s", stripped, extension);
 
217
    myfree(stripped);
 
218
    myfree(extension);
 
219
 
208
220
    return (0);
209
221
}
210
222