Commit a809b24b a809b24b395bf7ca2e3c76972557f6374e95584a by Alain Magloire

encoding.texi headers.texi mailbox.texi mailer.texi mime.texi

 	sfrom.c.texi url.texi

new files describing each facette of mailutils.
1 parent 8747a68b
1 @subsection RFC1522
2 @cindex RFC1522
3
4 @subsection Quoted Printable
5 @cindex Quoted Printable
6
7 @subsection Base64
8 @cindex Base64
9
1 So far we plan support for RFC822 and RFC1522;
2
3 @deftypefun int header_init (header_t *@var{hdr}, const char *@var{blurb}, size_t @var{len}, int @var{flag})
4 Initialize a @var{hdr} to a supported type. If @var{blurb} is not NULL, it is
5 parsed. @var{Flag} can be set to RFC8222 or RFC1522 so far onlyr rfc822 is
6 supported.
7 @end deftypefun
8 @deftypefun void header_destroy (header_t *@var{hdr})
9 The ressources allocate for @var{hdr} or freed.
10 @end deftypefun
11
12 @deftypefun int header_set_value (header_t @var{hdr}, const char *@var{fn}, const char *@var{fv}, size_t n, int @var{replace})
13 Set the field-name @var{fn} to field-value @var{fv} of size @var{n} in
14 @var{hdr}. If @var{replace} is non-zero the initial value is replace, if zero
15 it is append.
16 @end deftypefun
17
18 @deftypefun int header_get_value (header_t @var{hdr}, const char *fn, char *fv, size_t len, size_t *n)
19 Value of field-name @var{fn} is return in buffer @var{fv} of size @var{len}.
20 The number of bytes written is put in @var{n}.
21 @end deftypefun
22
23 @deftypefun int header_get_mvalue (header_t @var{hdr}, const char *fn, char **fv, size_t *n)
24 Value of field-name @var{fn} is return in allocated buffer @var{fn} from
25 @code{malloc(3)}. The number of bytes written is put in @var{n}.
26 @end deftypefun
27
28 @deftypefun int header_gvalue (const char *@var{blurb}, size_t @var{bl}, const char *@var{fn}, char *@var{fv}, size_t @var{len}, size_t *@var{n})
29 Field-name @var{fn} is extract form @var{blurb} of size @var{bl} and put in
30 buffer @var{fv} of size @var{len}.
31 The number of bytes written is put in @var{n}.
32 @end deftypefun
33
34 @deftypefun int header_gmvalue (const char *@var{blurb}, size_t @var{bl}, const char *@var{fn}, char **@var{fv}, size_t *@var{nv})
35 Field-name @var{fn} is extract form @var{blurb} of size @var{bl} and put in
36 @code{malloc(3)}ted buffer @var{fv}. The number of bytes written is put in
37 @var{n}.
38 @end deftypefun
39
40 @subsection Headers Macros
41 @cindex Headers Macros
42
43 @subsection Headers Parsed
44 @cindex Headers Parsed
45
46 Return a hash table, a dictionnary, ???
47
48 @subsection Headers Regex
49 @cindex Headers Regex
50
51 Using regular expression ?
1 Mail boxes come in different formats and may be on a remote hosts,
2 only accessible through a Mail Delivery Agent(MDA). Regardeless
3 of the format and the protocol use, some common actions are needed like
4 reading, saving, deleting, scaning ... Those actions are provided via a
5 unify API mailbox_t.
6
7 All functions of the mailbox_t API return 0 if succesfull or non-zero
8 otherwise.
9
10 Initializing and destroying a mailbox_t object.
11
12 @deftypefun int mailbox_init (mailbox_t *@var{mbx}, const char * @var{url}, int @var{id})
13 Based on the type of the @var{url}, @var{mbx} is initialize to a known type,
14 if @var{id} is not zero, it represents the id of the mailbox. The @var{id}
15 will be use instead of doing heuristic search on the @var{url}.
16 @end deftypefun
17
18 @deftypefun int mailbox_destroy (mailbox_t *@var{mbx})
19 All ressources allocated is release if the stream is not open,
20 @code{mailbox_close()} is call.
21 @end deftypefun
22
23 Opening and closing mailbox can be done any number of times. But be warn
24 on some cases like POP3, when opening, the lock can be persistent until
25 the stream is close as required by the RFC.
26
27 @deftypefun int mailbox_open (mailbox_t @var{mbx}, int @var{flag})
28 Open the mailbox box stream. This funtion will call @code{mailbox_scan()}.
29 @end deftypefun
30
31 @deftypefun int mailbox_close (mailbox_t @var{mbx})
32 Close the streams and release the locks.
33 @end deftypefun
34
35 Message can be mark for deletion but the action of removing them is only
36 taken when calling @code{mailbox_expunge()}.
37
38 @deftypefun int mailbox_delete (mailbox_t @var{mbx}, size_t @var{msgno})
39 Mark @var{msgno} for deletion.
40 @end deftypefun
41
42 @deftypefun int mailbox_undelete (mailbox_t @var{mbx}, size_t @var{msgno})
43 UnMark @var{msgno} for deletion.
44 @end deftypefun
45
46 @deftypefun int mailbox_is_deleted (mailbox_t @var{mbx}, size_t @var{msgno})
47 Return 1 if @var{msgno} is mark deleted.
48 @end deftypefun
49
50 @deftypefun int mailbox_expunge (mailbox_t @var{mbx})
51 All msgs marked for deletion will be remove and the mailbox updated.
52 @end deftypefun
53
54 Certain mailboxes allow to append new messages to the existing folder.
55
56 @deftypefun int mailbox_create_envelope (mailbox_t @var{mbx}, size_t *@var{msgno})
57 Create an envelope, @var{msgno} will contain a uniq number for this envelope.
58 @end deftypefun
59
60 @deftypefun int mailbox_set_header (mailbox_t @var{mbx}, size_t @var{msgno}, const char *@var{header}, size_t @var{len}, int @var{replace})
61 Fill the header of new envelope @var{msgno}. If @var{replace} is zero the
62 buffer @var{header} will be append, otherwise it will overwrite any
63 existing one.
64 @end deftypefun
65
66 @deftypefun int mailbox_set_body (mailbox_t @var{mbx}, size_t @var{msgno}, const char *@var{body}, size_t @var{len}, int @var{replace})
67 Fill the body of new envelope @var{msgno}. If @var{replace} is zero the buffer
68 @var{body} will be append, otherwise it will overwrite any existing one.
69 @end deftypefun
70
71 @deftypefun int mailbox_append (mailbox_t @var{mbx}, size_t @var{msgno})
72 @var{msgno} given from @code{mailbox_new_message()} will be append to
73 the mailbox.
74 @end deftypefun
75
76 @deftypefun int mailbox_destroy_envelope (mailbox_t @var{mbx}, size_t @var{msgno})
77 Ressources allocated to envelope @var{msgno} will be release. This function
78 should be call after @code{mailbox_append()}.
79 @end deftypefun
80
81 Reading the message body and header.
82
83 @deftypefun int mailbox_get_body (mailbox_t @var{mbx}, size_t @var{msgno}, off_t @var{off}, char *@var{buffer}, size_t @var{len}, size_t *@var{read})
84 Read the body of message @var{msgno} starting at offset @var{off} in
85 @var{buffer} of size @var{len}. The number of byte read is return in
86 @var{nread}.
87 @end deftypefun
88 @deftypefun int mailbox_get_mbody (mailbox_t @var{mbx}, size_t @var{msgno}, off_t @var{off}, char **@var{buffer}, size_t *@var{read})
89 A buffer allocate with @code{malloc()} is return containing the body of
90 message @var{msgno} starting at offset @var{off} in @var{buffer}.
91 The number of byte read is return in @var{nread}.
92 @end deftypefun
93
94 @deftypefun int mailbox_get_header (mailbox_t @var{mbx}, size_t @var{msgno}, off_t @var{off}, char *@var{buffer}, size_t @var{len}, size_t *@var{read})
95 Read the header of message @var{msgno} starting at offset @var{off} in
96 @var{buffer} of size @var{len}. The number of byte read is return in
97 @var{nread}.
98 @end deftypefun
99 @deftypefun int mailbox_get_mheader (mailbox_t @var{mbx}, size_t @var{msgno}, off_t @var{off}, char **@var{buffer}, size_t *@var{read})
100 A buffer allocate with @code{malloc()} is return containing the header of
101 message @var{msgno} starting at offset @var{off} in @var{buffer}.
102 The number of byte read is return in @var{nread}.
103 @end deftypefun
104
105 Most mailbox provides locking before changing there content. functions
106 will grab the lock before doing any destructive action. They are also
107 provide here for accesssing the folder outside the API in that case the
108 lock should be grab and unlock. There is also another level of internal
109 locking to provide synchronisation to the mailbox_t object.
110
111 @deftypefun int mailbox_lock (mailbox_t @var{mbx}, int @var{flag})
112 Grab the lock. In some case, i.e Unix mbox this may involve creating
113 a .lock file in the spool directory.
114 @end deftypefun
115
116 @deftypefun int mailbox_unlock (mailbox_t @var{mbx})
117 Release the lock.
118 @end deftypefun
119
120 Ownership and group. When creating certain mailbox, you can set the
121 owner/group.
122
123 @deftypefun int mailbox_set_owner (mailbox_t @var{mbx}, uid_t @var{uid})
124 Set the owner to @var{uid}. If the Mailbox was not @code{mailbox_open()}
125 the action is delayed until the stream is open.
126 @end deftypefun
127 @deftypefun int mailbox_set_group (mailbox_t @var{mbx}, gid_t @var{gid})
128 Set the group to @var{gid}. If the Mailbox was not @code{mailbox_open()}
129 the action is delayed until the stream is open.
130 @end deftypefun
131
132 Setting timeout and notifications.
133
134 @deftypefun int mailbox_set_timeout (mailbox_t @var{mbx}, size_t @var{millis})
135 Not Implemented.
136 @end deftypefun
137 @deftypefun int mailbox_get_timeout (mailbox_t @var{mbx}, size_t @var{millis})
138 Not Implemented.
139 @end deftypefun
140 @deftypefun int mailbox_set_refresh (mailbox_t @var{mbx}, size_t @var{millis})
141 Not Implemented.
142 @end deftypefun
143 @deftypefun int mailbox_get_refresh (mailbox_t @var{mbx}, size_t @var{millis})
144 Not Implemented.
145 @end deftypefun
146 @deftypefun int mailbox_set_notification (mailbox_t @var{mbx}, ...)
147 Not Implemented.
148 @end deftypefun
149
150
151 Instead of providing different functions to create a mailbox_t the
152 information is encoded in the form of a URL.
153
154 @table @samp
155 @item POP3 Post Office Protocol, Not Implemented.
156 pop://<user>;AUTH=<auth>@@<host>:<port>
157 @item IMAP, not implemented
158 imap://
159 @item QMAIL, not implemented
160 qmail://
161 @item Unix mbox
162 file://
163 @item MMDF, not implemented
164 mmdf://
165 @item SMail, not implemented
166 smail://
167 @end table
168
169 The URL will contain the necessary information to initialize @code{mailbox_t}
170 properly.
171
172
173 All mailbox implementations provide this minimum set of the API and more
174 if need be.
175
176 @subsection Unix Mbox
177 @cindex Unix Mbox
178
179 TODO: describe particularities and mail locking policy,
180 describe the flags use in _open(..);
181
182 @subsection POP3 Mbox
183 @cindex POP3 Mbox
184
185 TODO: describe timeout policies,
186 describe the flags use in _open(..),
187 describe Different authorisation supported.
188
189 @subsection IMAP Mbox
190 @cindex IMAP Mbox
191
192 Not implemented.
193
194 @subsection QMail Mbox
195 @cindex QMail Mbox
196
197 Not implemented.
198
199 @subsection MMDF Mbox
200 @cindex MMDF Mbox
201
202 Not implemented.
1
2 Mail Delivery is done here. Nothing is implemented and the API is still shaky.
3
4 @deftypefun int mailer_init (mailer_t *@var{mailer}, const char *@var{name}, int @var{flag})
5 Not Implemented.
6 @end deftypefun
7
8 @deftypefun int mailer_destroy (mailer_r *@var{mailer})
9 Not Implemented.
10 @end deftypefun
11
12 @deftypefun int mailer_user (mailer_t @var{mailer}, const char *@var{user})
13 Not Implemented.
14 @end deftypefun
15
16 @deftypefun int mailer_passwd (mailer_t @var{mailer}, const char *@var{passwd})
17 Not Implemented.
18 @end deftypefun
19
20 @deftypefun int mailer_open (mailer_t @var{mailer}, int @var{flag})
21 Not Implemented.
22 @end deftypefun
23
24 @deftypefun int mailer_close (mailer_t @var{mailer})
25 Not Implemented.
26 @end deftypefun
27
28 @deftypefun int mailer_set_body (mailer_t @var{mailer}, char *, size_t)
29 Not Implemented.
30 @end deftypefun
31
32 @deftypefun int mailer_set_header (mailer_t @var{mailer}, char *, size_t)
33 Not Implemented.
34 @end deftypefun
35
36 @deftypefun int mailer_set_timeout (mailer_t @var{mailer}, size_t)
37 Not Implemented.
38 @end deftypefun
39
40 @deftypefun int mailer_get_timeout (mailer_t @var{mailer}, size_t)
41 Not Implemented.
42 @end deftypefun
43
44 @deftypefun int mailer_send_envelope (mailer_t @var{mailer}, size_t)
45 Not Implemented.
46 @end deftypefun
47
48
49 @subsection Mailto
50 @cindex Mailto
51 The URL mailto: is supported.
52
53 TODO: example of mailto, and mailing lists,
54
55 @subsection SMTP
56 @cindex SMTP
57
58 TODO: todo
59
60 @subsection UUCP
61 @cindex UUCP
62
63 Yeurk ! It this to old ? Is it worth it ?
64
65 @subsection Sendmail
66 @cindex Sendmail
67
68 This is not a protocol, but someone may use it as the mailer, and
69 we provide the magic.
70
71 @subsection mailx
72 @cindex mailx
73
74 This is not a protocol, but someone may use it as the mailer, and
75 we provide the magic.
76
77 @subsection mail
78 @cindex mail
79
80 This is not a protocol, but someone may use it as the mailer, and
81 we provide the magic.
82
83 @subsection MPP
84 @cindex MPP
85
86 Mail Posting Protocol.
1 Mime stuff in the Body.
1 /* sfrom, Simple From */
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <mailutils.h>
6 #include <paths.h>
7
8 #ifndef _PATH_MAILDIR
9 #define _PATH_MAILDIR "/usr/spool/mail"
10 #endif
11
12 int main (int argc, char **argv)
13 @{
14 char buffer[1024];
15 char from[64];
16 char subject[64];
17 char *header;
18 mailbox_t mbox;
19 int status, id, msg_no;
20
21 if (argc == 2)
22 @{
23 mail = argv[1];
24 @}
25 else
26 @{
27 mail = getenv ("MAIL");
28 if (mail == NULL)
29 @{
30 char * user = getlogin ();
31 int len = strlen (_PATH_MAILDIR) + strlen (user) + 1;
32 mail = malloc (len);
33 if (mail == NULL)
34 @{
35 fprintf (stderr, "malloc failed\n");
36 exit (EXIT_FAILURE);
37 @}
38 snprintf (mail, len, "%s/%s", _PATH_MAILDIR, user);
39 @}
40 @}
41
42 status = mailbox_init (&mbox, mail, 0);
43 if (status != 0)
44 @{
45 fprintf (stderr, "mailbox_init(%s) failed\n", mail);
46 exit (EXIT_FAILURE);
47 @}
48
49 status = mailbox_open (mbox, MU_MB_ORDONLY);
50 if (status != 0)
51 @{
52 fprintf (stderr, "mailbox_open(%s), %s\n", mail);
53 exit (EXIT_FAILURE);
54 @}
55
56 mailbox_scan (mbox, &msg_total);
57
58 for (msgno = 0; msgno < msg_total; msgno++)
59 @{
60 if (mailbox_get_header (mbox, msgno, buffer,
61 sizeof (buffer), &size) != 0)
62 @{
63 fprintf (stderr, "header corrupted\n");
64 exit (EXIT_FAILURE);
65 @}
66 header_gvalue (buffer, size, MU_HDR_FROM, from, sizeof (from), NULL);
67 header_gvalue (buffer, size, MU_HDR_SUBJECT, subject,
68 sizeof (subject), NULL);
69 printf ("%s %s\n", from, subject);
70 @}
71
72 mailbox_close (mbox);
73 mailbox_destroy (&mbox);
74 return 0;
75 @}
1
2 See rfc2368, rfc2369, rfc2384
3