summaryrefslogtreecommitdiffstats
path: root/rfc822.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1998-08-25 22:33:07 +0000
committerThomas Roessler <roessler@does-not-exist.org>1998-08-25 22:33:07 +0000
commit986ab5e943db7aaed2aed98f8b74e4c26666fdd8 (patch)
tree58cfec1114686823dbdbf22cf2ca52f77eb1075d /rfc822.c
parent9044dd4d58af4b4d64a6e68b7b76c42d317e7ce5 (diff)
CVS branch clean-up.
Diffstat (limited to 'rfc822.c')
-rw-r--r--rfc822.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/rfc822.c b/rfc822.c
index 487bea10..2c990486 100644
--- a/rfc822.c
+++ b/rfc822.c
@@ -198,30 +198,28 @@ parse_mailboxdomain (const char *s, const char *nonspecial,
static const char *
parse_address (const char *s,
+ char *token, size_t *tokenlen, size_t tokenmax,
char *comment, size_t *commentlen, size_t commentmax,
ADDRESS *addr)
{
- char token[128];
- size_t tokenlen = 0;
-
s = parse_mailboxdomain (s, ".\"(\\",
- token, &tokenlen, sizeof (token) - 1,
+ token, tokenlen, tokenmax,
comment, commentlen, commentmax);
if (!s)
return NULL;
if (*s == '@')
{
- if (tokenlen < sizeof (token) - 1)
- token[tokenlen++] = '@';
+ if (*tokenlen < tokenmax)
+ token[(*tokenlen)++] = '@';
s = parse_mailboxdomain (s + 1, ".([]\\",
- token, &tokenlen, sizeof (token) - 1,
+ token, tokenlen, tokenmax,
comment, commentlen, commentmax);
if (!s)
return NULL;
}
- token[tokenlen] = 0;
+ token[*tokenlen] = 0;
addr->mailbox = safe_strdup (token);
if (*commentlen && !addr->personal)
@@ -238,27 +236,34 @@ parse_route_addr (const char *s,
char *comment, size_t *commentlen, size_t commentmax,
ADDRESS *addr)
{
+ char token[STRING];
+ size_t tokenlen = 0;
+
SKIPWS (s);
/* find the end of the route */
if (*s == '@')
{
- char token[128];
- size_t tokenlen = 0;
-
while (s && *s == '@')
- s = parse_mailboxdomain (s + 1, ".[](\\", token,
+ {
+ if (tokenlen < sizeof (token) - 1)
+ token[tokenlen++] = '@';
+ s = parse_mailboxdomain (s + 1, ".\\[](", token,
&tokenlen, sizeof (token) - 1,
comment, commentlen, commentmax);
+ }
if (!s || *s != ':')
{
RFC822Error = ERR_BAD_ROUTE;
return NULL; /* invalid route */
}
+
+ if (tokenlen < sizeof (token) - 1)
+ token[tokenlen++] = ':';
s++;
}
- if ((s = parse_address (s, comment, commentlen, commentmax, addr)) == NULL)
+ if ((s = parse_address (s, token, &tokenlen, sizeof (token) - 1, comment, commentlen, commentmax, addr)) == NULL)
return NULL;
if (*s != '>' || !addr->mailbox)
@@ -276,7 +281,10 @@ parse_addr_spec (const char *s,
char *comment, size_t *commentlen, size_t commentmax,
ADDRESS *addr)
{
- s = parse_address (s, comment, commentlen, commentmax, addr);
+ char token[STRING];
+ size_t tokenlen = 0;
+
+ s = parse_address (s, token, &tokenlen, sizeof (token) - 1, comment, commentlen, commentmax, addr);
if (s && *s && *s != ',' && *s != ';')
{
RFC822Error = ERR_BAD_ADDR_SPEC;
@@ -304,7 +312,7 @@ add_addrspec (ADDRESS **top, ADDRESS **last, const char *phrase,
ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
{
const char *begin, *ps;
- char comment[128], phrase[128];
+ char comment[STRING], phrase[STRING];
size_t phraselen = 0, commentlen = 0;
ADDRESS *cur, *last = NULL;
@@ -413,7 +421,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
if (phraselen)
{
if (cur->personal)
- free (cur->personal);
+ FREE (&cur->personal);
/* if we get something like "Michael R. Elkins" remove the quotes */
rfc822_dequote_comment (phrase);
cur->personal = safe_strdup (phrase);
@@ -475,10 +483,9 @@ void rfc822_qualify (ADDRESS *addr, const char *host)
for (; addr; addr = addr->next)
if (!addr->group && addr->mailbox && strchr (addr->mailbox, '@') == NULL)
{
- if (!(p = malloc (strlen (addr->mailbox) + strlen (host) + 2)))
- return;
+ p = safe_malloc (strlen (addr->mailbox) + strlen (host) + 2);
sprintf (p, "%s@%s", addr->mailbox, host);
- free (addr->mailbox);
+ safe_free ((void **) &addr->mailbox);
addr->mailbox = p;
}
}
@@ -492,7 +499,7 @@ rfc822_cat (char *buf, size_t buflen, const char *value, const char *specials)
size_t tmplen = sizeof (tmp) - 3;
*pc++ = '"';
- for (; *value && tmplen; value++)
+ for (; *value && tmplen > 1; value++)
{
if (*value == '\\' || *value == '"')
{
@@ -583,7 +590,10 @@ void rfc822_write_address_single (char *buf, size_t buflen, ADDRESS *addr)
goto done;
*pbuf++ = ' ';
buflen--;
+ }
+ if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
+ {
if (!buflen)
goto done;
*pbuf++ = '<';
@@ -599,7 +609,7 @@ void rfc822_write_address_single (char *buf, size_t buflen, ADDRESS *addr)
pbuf += len;
buflen -= len;
- if (addr->personal)
+ if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
{
if (!buflen)
goto done;
@@ -668,7 +678,10 @@ void rfc822_write_address (char *buf, size_t buflen, ADDRESS *addr)
len = strlen (pbuf);
pbuf += len;
buflen -= len;
- if (addr->next && !addr->group)
+
+ /* if there is another address, and its not a group mailbox name or
+ group terminator, add a comma to separate the addresses */
+ if (addr->next && addr->next->mailbox && !addr->group)
{
if (!buflen)
goto done;
@@ -745,12 +758,7 @@ int main (int argc, char **argv)
{
ADDRESS *list;
char buf[256];
- char *str = "aaaaaaaaaaaaaa <bbbbbbbbbbbbbbbb>, ccccccc <dddddddddddddddd>,\n\
- eeeeeeeeee <ffffffffffffffff>, ggggggggggg <hhhhhhhhhhhhhhhhhhh>,\n\
- iiiiiiiiiiiiiiii <jjjjjjjjjjjjjjjjjjjj>,\n\
- kkkkkkkkkkkkkk <lllllllllllllllll>,\n\
- mmmmmmmmmmmmm <nnnnnnnnnnnnnnnnnn>, ooooooooooo <pppppppppppppp>,\n\
- qqqqqqqqqqqqq <rrrrrrrrrrrrrrrr>\n";
+ char *str = "michael, Michael Elkins <me@cs.hmc.edu>, testing a really complex address: this example <@contains.a.source.route@with.multiple.hosts:address@example.com>;, lothar@of.the.hillpeople (lothar)";
list = rfc822_parse_adrlist (NULL, str);
buf[0] = 0;