/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Things to consider:
- When parsing phrase, should I ignore non-ascii, or replace with a
'?' character? Right now parsing fails.
- Are comments allowed in domain-literals?
- Need a way to mark the *end* of a group. Maybe add a field to _address,
int group_end;, so if you care, you can search for the end of
a group with address_is_group_end();
- Need a way to parse "<>", it's a valid SMTP address...
- Need a way to parse ",,,", it's a valid address-list, it just doesn't
have any addresses.
- The personal for ""Sam"" <sam@here> is "Sam", and for "'s@b'" <s@b>
is 's@b', should I strip those outside parentheses, or is that
too intrusive? Maybe an apps business if it wants to?
- Should we do best effort parsing, so parsing "sam@locahost, foo@"
gets one address, or just say it is or it isn't in RFC format?
Right now we're strict, we'll see how it goes.
- parse Received: field?
- test for memory leaks on malloc failure
- fix the realloc, try a struct _string { char* b, size_t sz };
The lexer finds consecutive sequences of characters, so it should
define:
struct parse822_token_t {
const char* b; // beginning of token
const char* e; // one past end of token
}
typedef struc parse822_token_t TOK;
Then I can have str_append_token(), and the lexer functions can
look like:
int parse822_atom(const char** p, const char* e, TOK* atom);
Just a quick though, I'll have to see how many functions that will
actually help.
- get example addresses from rfc2822, and from the perl code.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/sys/address.h>
#include <mailutils/parse822.h>
#ifdef EOK
# undef EOK
#endif
#define EOK 0
#define EPARSE ENOENT
/*
* Some convenience functions for dealing with dynamically re-sized
* strings.
*/
static int str_append_n(char** to, const char* from, size_t n)
{
size_t l = 0;
/* if not to, then silently discard data */
if(!to) {
return EOK;
}
if(*to) {
char* bigger;
l = strlen(*to);
bigger = realloc(*to, l + n + 1);
if(!bigger) {
return ENOMEM;
}
*to = bigger;
} else {
*to = malloc(n + 1);
}
strncpy(&to[0][l], from, n);
/* strncpy is lame, nul terminate our buffer */
to[0][l + n] = 0;
return EOK;
}
static int str_append(char** to, const char* from)
{
return str_append_n(to, from, strlen(fro
|