Changes propose by Sam Roberts, They look valid and interesting.
Showing
2 changed files
with
141 additions
and
2 deletions
doc/address.texi
0 → 100644
1 | @code{#include <mailutils/mailbox.h>} | ||
2 | @deftp {Data Type} address_t | ||
3 | The @code{address_t} object is used to hold information about a parsed | ||
4 | RFC822 address list, and is an opaque | ||
5 | data structure to the user. Functions are provided to retrieve information | ||
6 | about the address list. An address list is a sequence of addresses, each | ||
7 | of which has four components: an optional phrase describing the address, the | ||
8 | local-part of the address, the domain of the address, and an optional | ||
9 | comment field. | ||
10 | |||
11 | If the phrase is present it is probably the personal name | ||
12 | associated with the the address, if not, the comment may contain some | ||
13 | identifying information. | ||
14 | |||
15 | Since the address-list may contain multiple addresses, they are accessed | ||
16 | by a @strong{one-based index number}, @var{no}. | ||
17 | |||
18 | Comment: Why is this one-based? nobody | ||
19 | familiar with C would ever expect that! | ||
20 | |||
21 | The size of a particular component | ||
22 | may be queried by providing @code{0} for the @var{len} of the buffer, | ||
23 | in which case the buffer is optional and if @var{n} is provided | ||
24 | *@var{n} is assigned the length of the component string. | ||
25 | |||
26 | If @var{len} | ||
27 | is greater than @code{0} it is the length of the buffer @var{buf}, and | ||
28 | as much of the component as possible will be copied into the buffer. | ||
29 | |||
30 | Comments: | ||
31 | |||
32 | The API isn't complete, there are useful things you can't do. | ||
33 | |||
34 | There needs to be a way of accessing the local-part and the | ||
35 | domain of an email address seperately, the syntax of local-part is too complex | ||
36 | to expect somebody to parse it, in particular strchring for '@@' | ||
37 | will fail if there is an '@@' in the local-part, which is valid if | ||
38 | its quoted or escaped. | ||
39 | |||
40 | You can't create an address or an address list. | ||
41 | |||
42 | Creating one should apropriately quote unsafe characters in the local | ||
43 | part and phrase/personal name, not allow a comment (its deprecated), etc. | ||
44 | |||
45 | What about groups? They are easy to parse, but a pain from an api point | ||
46 | of view. _address, instead of being a pure linked list, could | ||
47 | be more tree-like, so each _address also contained and _address* group | ||
48 | member. If there was a group, then email would be the name of the group, | ||
49 | something like "my special group: ;", and group would be the (possibly | ||
50 | empty) list of addresses in the group, and each of those addresses | ||
51 | could in turn be a group, etc. | ||
52 | |||
53 | This data structure reflects the structure of an address ok, but doesn't | ||
54 | address (;-)) what happens if you had a program that just wanted to print | ||
55 | out all the recipients email addresses. The @var{no} could still be | ||
56 | a linear index into the tree, so those not wanting to know could not | ||
57 | know, and the group nodes could silently dissappear. | ||
58 | |||
59 | But what if you wanted to iterate the whole tree? | ||
60 | address_is_group(addr, no)? address_get_group_name(addr, no)? | ||
61 | address_get_group(addr, &addr)? | ||
62 | |||
63 | For creating, maybe the easy way is to splice an address list. | ||
64 | |||
65 | address_create(&addr, NULL) | ||
66 | |||
67 | address_insert(addr, -1, "Big John", "bluesman", "yahoo.com"); | ||
68 | |||
69 | // -1 is the end, anything else is position to be inserted at, for ex. | ||
70 | |||
71 | address_create(&group, NULL) | ||
72 | |||
73 | address_insert(group, -1, "Sam", "sroberts", "uniserve.com"); | ||
74 | |||
75 | address_insert(group, -1, "Joe @ \"home\"", "joe", "uniserve.com"); | ||
76 | |||
77 | address_insert_group(addr, group, "the uniserve boys"); | ||
78 | |||
79 | This would be: | ||
80 | @example | ||
81 | Big John <bluesman@@yahoo.com>, the uniserve boys: Sam | ||
82 | <sroberts@@uniserve.com>, "Joe @@ \"home\"" <joe@@uniserve.com> ; | ||
83 | @end example | ||
84 | |||
85 | This is just a sketch of what I think should be conceptually possible | ||
86 | in a complete address parser class. Basically the goals are to be | ||
87 | able to see the structure of an RFC822 address exactly (except for | ||
88 | comments... they get munged together if present, but what the hell, | ||
89 | they're comments!) and to build as complex an address as is | ||
90 | possible. Simple things should still be simple. | ||
91 | |||
92 | Two problems are domain literals, and non-ascii characters. I | ||
93 | think domain literals should be parsed from [127.0.0.1] into | ||
94 | the more commonly groked 127.0.0.1 when somebody does a get_domain() | ||
95 | on one, and that if somebody wants to provide one as a domain, they | ||
96 | can. | ||
97 | |||
98 | Non ascii chars are uglier, perhaps a warning? Perhaps a non-strict | ||
99 | switch that makes it an error, and otherwise if they want umlauts | ||
100 | and utf-8 in the strings, just allow it? The machinery to encode | ||
101 | and decode header fields according to the MIME spec doesn't really | ||
102 | belong here, it's a layer on top of rfc822. | ||
103 | |||
104 | @end deftp | ||
105 | |||
106 | @deftypefun int address_create (address_t *@var{addr}, const char *@var{string}) | ||
107 | This function allocates and initializes @var{addr} by parsing the | ||
108 | RFC822 address-list @var{string}. | ||
109 | |||
110 | The return value is @code{0} on success and a code number on error conditions: | ||
111 | @table @code | ||
112 | @item ENOMEM | ||
113 | Not enough memory to allocate resources. | ||
114 | @end table | ||
115 | @end deftypefun | ||
116 | |||
117 | @deftypefun void address_destroy (address_t *@var{addr}) | ||
118 | The @var{addr} is destroyed. | ||
119 | @end deftypefun | ||
120 | |||
121 | @deftypefun int address_get_email (address_t *@var{addr}, | ||
122 | size_t no, char* buf, size_t len, size_t* n) | ||
123 | Acesses the @var{no}th email address component. | ||
124 | |||
125 | The return value is @code{0} on success and a code number on error conditions: | ||
126 | @table @code | ||
127 | @item EINVAL | ||
128 | @var{addr} is NULL. | ||
129 | @end table | ||
130 | @end deftypefun | ||
131 |
... | @@ -110,6 +110,7 @@ This document was produced for version @value{VERSION} of @sc{gnu} | ... | @@ -110,6 +110,7 @@ This document was produced for version @value{VERSION} of @sc{gnu} |
110 | * Attribute:: Attribute. | 110 | * Attribute:: Attribute. |
111 | * Stream:: Stream API. | 111 | * Stream:: Stream API. |
112 | * Authenticator:: Authenticator. | 112 | * Authenticator:: Authenticator. |
113 | * Address:: Address. | ||
113 | * Locker:: Locker. | 114 | * Locker:: Locker. |
114 | * Encoding:: Encoding API. | 115 | * Encoding:: Encoding API. |
115 | * URL:: Unified Ressource Locator. | 116 | * URL:: Unified Ressource Locator. |
... | @@ -210,14 +211,21 @@ For example writing a simple @command{from} command that will list the | ... | @@ -210,14 +211,21 @@ For example writing a simple @command{from} command that will list the |
210 | 211 | ||
211 | @include stream.texi | 212 | @include stream.texi |
212 | 213 | ||
213 | @node Authenticator, Locker, Stream, Top | 214 | @node Authenticator, Address, Stream, Top |
214 | @comment node-name, next, previous, up | 215 | @comment node-name, next, previous, up |
215 | @chapter Authenticator | 216 | @chapter Authenticator |
216 | @cindex Authenticator | 217 | @cindex Authenticator |
217 | 218 | ||
218 | @include auth.texi | 219 | @include auth.texi |
219 | 220 | ||
220 | @node Locker , Encoding, Authenticator, Top | 221 | @node Address, Locker, Authenticator, Top |
222 | @comment node-name, next, previous, up | ||
223 | @chapter Address | ||
224 | @cindex Address | ||
225 | |||
226 | @include address.texi | ||
227 | |||
228 | @node Locker, Encoding, Address, Top | ||
221 | @comment node-name, next, previous, up | 229 | @comment node-name, next, previous, up |
222 | @chapter Locker | 230 | @chapter Locker |
223 | @cindex Locker | 231 | @cindex Locker | ... | ... |
-
Please register or sign in to post a comment