Index: doc/Makefile.am =================================================================== RCS file: /cvs/mailutils/doc/Makefile.am,v retrieving revision 1.6 diff -u -r1.6 Makefile.am --- doc/Makefile.am 2001/04/23 03:56:31 1.6 +++ doc/Makefile.am 2001/05/05 16:21:53 @@ -23,3 +23,6 @@ url.texi \ version.texi +ex-address.texi: ../examples/addr.c + sed -es/{/@{/g -e s/}/@}/g < $< > $@ + Index: doc/address.texi =================================================================== RCS file: /cvs/mailutils/doc/address.texi,v retrieving revision 1.4 diff -u -r1.4 address.texi --- doc/address.texi 2001/04/15 01:49:51 1.4 +++ doc/address.texi 2001/05/05 16:21:54 @@ -1,9 +1,9 @@ address@hidden } address@hidden } -The internet address format is defined in RFC 822. RFC 822 is in the -process of being updated, and will soon be superceeded by a new RFC -that makes some corrections and clarifications. References to RFC 822 -here apply equally to the new RFC. +The internet address format is defined in RFC 822. RFC 822 has been +updated, and is now superceeded by RFC 2822, which +makes some corrections and clarifications. References to RFC 822 +here apply equally to RFC 2822. The RFC 822 format is more flexible than many people realize, here is a quick summary of the syntax this parser implements, see @@ -16,10 +16,15 @@ [display-name] "<" [route] addr-spec ">" mailbox-list = mailbox ["," mailbox-list] group = display-name ":" [mailbox-list] ";" -address = mailbox / group +address = mailbox / group / unix-mbox address-list = address ["," address-list] @end example +unix-mbox is a non-standard extention meant to deal with the common +practice of using user names as addresses in mail utilities. It allows +addresses such as "root" to be parsed correctly. These are NOT valid +internet email addresses, they must be qualified before use. + Several address functions have a set of common arguments with consistent semantics, these are described here to avoid repetition. @@ -133,7 +138,8 @@ @deftypefun int address_get_email (address_t address@hidden, size_t @var{no}, char* @var{buf}, size_t @var{len}, size_t* @var{n}) Acesses the email addr-spec extracted while -parsing the @var{no}th email address. +parsing the @var{no}th email address. This will be @code{0} +length for a unix-mbox. The return value is @code{0} on success and a code number on error conditions: @table @code @@ -157,7 +163,8 @@ @deftypefun int address_get_domain (address_t address@hidden, size_t @var{no}, char* @var{buf}, size_t @var{len}, size_t* @var{n}) Acesses the domain of an email addr-spec extracted while -parsing the @var{no}th email address. +parsing the @var{no}th email address. This will be @code{0} +length for a unix-mbox. The return value is @code{0} on success and a code number on error conditions: @table @code @@ -223,54 +230,6 @@ @section Example @example -#include -#include - -int -main(int argc, const char *argv[]) address@hidden - for(argc = 1; argv[argc]; argc++) - @{ - const char* str = argv[argc]; - address_t address = NULL; - - address_create(&address, str); - - printf("'%s' ->\n", str); - @{ - size_t no = 0; - size_t pcount; - - address_get_count(address, &pcount); - - printf(" pcount %d\n", pcount); - - for(no = 1; no <= pcount; no++) - @{ - char buf[BUFSIZ]; - - address_get_personal(address, no, buf, sizeof(buf), 0); - - printf(" personal '%s'\n", buf); - - address_get_local_part(address, no, buf, sizeof(buf), 0); - - printf(" local_part '%s'\n", buf); - - address_get_domain(address, no, buf, sizeof(buf), 0); - - printf(" domain '%s'\n", buf); - - address_get_email(address, no, buf, sizeof(buf), 0); - - printf(" email '%s'\n", buf); - @} - @} - - address_destroy(&address); - @} - - return 0; address@hidden address@hidden ex-address.texi @end example Index: examples/Addrs.good =================================================================== RCS file: /cvs/mailutils/examples/Addrs.good,v retrieving revision 1.1 diff -u -r1.1 Addrs.good --- examples/Addrs.good 2001/04/15 01:50:49 1.1 +++ examples/Addrs.good 2001/05/05 16:21:55 @@ -228,7 +228,7 @@ personal <'address@hidden'> local-part domain -"=?iso-8859-1?Q?Juan_Carlos_Marcos_Rodr=EDguez?=" => pcount 1 +"=?iso-8859-1?Q?Juan_Carlos_Marcos_Rodr=EDguez?=" => pcount 1 1 email personal <=?iso-8859-1?Q?Juan_Carlos_Marcos_Rodr=EDguez?=> local-part domain @@ -432,17 +432,17 @@ personal <=?US-ASCII?Q?gary=5Fc?=> local-part domain -=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier => pcount 1 +=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier => pcount 1 1 email personal <=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier> local-part <0> domain -=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier ,=> pcount 1 +=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier ,=> pcount 1 1 email personal <=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E?= Meunier> local-part <0> domain -=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E_Meunier?= => pcount 1 +=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E_Meunier?= => pcount 1 1 email personal <=?iso-8859-1?Q?Fr=E9d=E9ric_L_=2E_W_=2E_Meunier?=> local-part <0> domain @@ -554,14 +554,22 @@ 1 email local-part domain address@hidden, address@hidden, boot=> error ENOENT address@hidden, address@hidden, boot=> pcount 3 +1 email + local-part domain +2 email + local-part domain +3 email <> + local-part Paul Hoffman / IMC => pcount 1 1 email personal local-part domain -Sam=> error ENOENT +Sam=> pcount 1 +1 email <> + local-part Sam Roberts => pcount 1 1 email @@ -605,7 +613,9 @@ address@hidden@dikke.penguin.nl=> error ENOENT -root=> error ENOENT +root=> pcount 1 +1 email <> + local-part srr => error ENOENT Index: examples/addr.c =================================================================== RCS file: /cvs/mailutils/examples/addr.c,v retrieving revision 1.3 diff -u -r1.3 addr.c --- examples/addr.c 2001/04/15 01:49:51 1.3 +++ examples/addr.c 2001/05/05 16:21:55 @@ -78,11 +78,15 @@ address_get_local_part(address, no, buf, sizeof(buf), &got); - if(got) printf(" local-part <%s>", buf); + if(got) { + printf(" local-part <%s>", buf); - address_get_domain(address, no, buf, sizeof(buf), &got); + address_get_domain(address, no, buf, sizeof(buf), &got); - if(got) printf(" domain <%s>\n", buf); + if(got) printf(" domain <%s>", buf); + + printf("\n"); + } address_get_route(address, no, buf, sizeof(buf), &got); Index: include/mailutils/parse822.h =================================================================== RCS file: /cvs/mailutils/include/mailutils/parse822.h,v retrieving revision 1.3 diff -u -r1.3 parse822.h --- include/mailutils/parse822.h 2001/04/14 00:31:38 1.3 +++ include/mailutils/parse822.h 2001/05/05 16:21:56 @@ -78,6 +78,7 @@ extern int parse822_route_addr __P ((const char** p, const char* e, address_t* a)); extern int parse822_route __P ((const char** p, const char* e, char** route)); extern int parse822_addr_spec __P ((const char** p, const char* e, address_t* a)); +extern int parse822_unix_mbox __P ((const char** p, const char* e, address_t* a)); extern int parse822_local_part __P ((const char** p, const char* e, char** local_part)); extern int parse822_domain __P ((const char** p, const char* e, char** domain)); extern int parse822_sub_domain __P ((const char** p, const char* e, char** sub_domain)); Index: mailbox/parse822.c =================================================================== RCS file: /cvs/mailutils/mailbox/parse822.c,v retrieving revision 1.7 diff -u -r1.7 parse822.c --- mailbox/parse822.c 2001/04/16 21:05:51 1.7 +++ mailbox/parse822.c 2001/05/05 16:28:03 @@ -18,20 +18,9 @@ /* Things to consider: - - A group should create an address node for a group, accessable - with address_get_personal(). Perhaps an is_group() would be - useful? Test that a zero-length phrase is rejected! So these - are invalid: - : address@hidden ; - "" : ; - - When parsing phrase, should I ignore non-ascii, or replace with a '?' character? Right now parsing fails. - - Make domain optional in addr-spec, for parsing address lists - provided to local mail utilities, but NOT in the addr-spec of a - route-addr. - - Are comments allowed in domain-literals? - Need a way to mark the *end* of a group. Maybe add a field to _address, @@ -53,14 +42,12 @@ 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 field names and bodies? - parse dates? - parse Received: field? - test for memory leaks on malloc failure - fix the realloc, try a struct _string { char* b, size_t sz }; - - - get example mail from drums, and from the perl code. + - get example addresses from rfc2822, and from the perl code. */ #ifdef HAVE_CONFIG_H @@ -610,12 +597,15 @@ int parse822_address(const char** p, const char* e, address_t* a) { - /* address = mailbox / group */ + /* address = mailbox / group / unix-mbox */ int rc; - if((rc = parse822_mail_box(p, e, a)) == EPARSE) - rc = parse822_group(p, e, a); + if((rc = parse822_mail_box(p, e, a)) == EPARSE) { + if((rc = parse822_group(p, e, a)) == EPARSE) { + rc = parse822_unix_mbox(p, e, a); + } + } return rc; } @@ -690,7 +680,9 @@ int parse822_mail_box(const char** p, const char* e, address_t* a) { - /* mailbox = addr-spec [ "(" comment ")" ] / [phrase] route-addr + /* mailbox = + * addr-spec [ "(" comment ")" ] / + * [phrase] route-addr * * Note: we parse the ancient comment on the right since * it's such "common practice". :-( @@ -717,10 +709,6 @@ return rc; } - if(rc != EPARSE) { - *p = save; - return rc; - } /* -> phrase route-addr */ { @@ -731,18 +719,24 @@ if(rc != EPARSE && rc != EOK) { return rc; } + + if((rc = parse822_route_addr(p, e, a)) == EOK) { + /* add the phrase */ + (*a)->personal = phrase; - if((rc = parse822_route_addr(p, e, a))) { + return EOK; + } else if(rc != EPARSE) { + /* some internal error, fail out */ *p = save; str_free(&phrase); return rc; } + *p = save; - /* add the phrase */ - (*a)->personal = phrase; + return rc; } - return EOK; + return rc; } int parse822_route_addr(const char** p, const char* e, address_t* a) @@ -870,6 +864,29 @@ *p = save; str_free(&local_part); str_free(&domain); + } + return rc; +} + +int parse822_unix_mbox(const char** p, const char* e, address_t* a) +{ + /* unix-mbox = atom */ + + const char* save = *p; + char* mbox = 0; + int rc; + + parse822_skip_comments(p, e); + + rc = parse822_atom(p, e, &mbox); + + if(!rc) { + rc = fill_mb(a, 0, 0, mbox, 0); + } + + if(rc) { + *p = save; + str_free(&mbox); } return rc; }