- Adresscheck nach rfc822

This commit is contained in:
Enno Rehling 2004-08-22 09:41:47 +00:00
parent 8ab908dde9
commit db1a75f032
1 changed files with 42 additions and 17 deletions

View File

@ -135,27 +135,52 @@ locale_check(void)
return true; return true;
} }
static int
spc_email_isvalid(const char *address)
{
int count = 0;
const char *c, *domain;
static char *rfc822_specials = "()<>@,;:\\\"[]";
/* first we validate the name portion (name@domain) */
for (c = address; *c; c++) {
if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) ==
'\"')) {
while (*++c) {
if (*c == '\"') break;
if (*c == '\\' && (*++c == ' ')) continue;
if (*c <= ' ' || *c >= 127) return 0;
}
if (!*c++) return 0;
if (*c == '@') break;
if (*c != '.') return 0;
continue;
}
if (*c == '@') break;
if (*c <= ' ' || *c >= 127) return 0;
if (strchr(rfc822_specials, *c)) return 0;
}
if (c == address || *(c - 1) == '.') return 0;
/* next we validate the domain portion (name@domain) */
if (!*(domain = ++c)) return 0;
do {
if (*c == '.') {
if (c == domain || *(c - 1) == '.') return 0;
count++;
}
if (*c <= ' ' || *c >= 127) return 0;
if (strchr(rfc822_specials, *c)) return 0;
} while (*++c);
return (count >= 1);
}
int int
set_email(char** pemail, const char *newmail) set_email(char** pemail, const char *newmail)
{ {
int at = 0;
const char * s;
if (newmail && *newmail) { if (newmail && *newmail) {
for (s=newmail;*s;++s) { if (spc_email_isvalid(newmail)<=0) return -1;
switch(*s) {
case ':':
case '"':
case ' ':
return -1;
case '@':
if (at) return -1;
at = 1;
default:
break;
}
}
if (!at) return -1;
} }
if (*pemail) free(*pemail); if (*pemail) free(*pemail);
*pemail = 0; *pemail = 0;