Commit a56b4522 a56b45227827ddd3fb2bb5ccfad755cf41f291fa by Alain Magloire

auth.texi

Authenticator.
1 parent 13e82e67
1 Mailboxes and Mailers provide a way to authenticate when the URL does not
2 contain enough information. The default action is to call function
3 @code{auth_authenticate} who will get the @emph{user} and @emph{passwd}
4 if not set, this function can be override by a custom method.
5
6 @section Helper Funtions
7 @deftypefun int auth_set_user (auth_t @var{auth}, const char *@var{user})
8 Set the @var{user} to field value.
9 @end deftypefun
10
11 @deftypefun int auth_set_passwd (auth_t @var{auth}, const char *@var{passwd})
12 Set the @var{passwd} to field value.
13 @end deftypefun
14
15 @deftypefun int auth_set_authenticate (auth_t @var{auth}, int *(authenticate)(auth_t, const char **user, const char **passwd)
16 Set Override the authentification function. If NULL authentication is
17 disabled. If *@var{user} and *@var{passwd} are not NULL, they should be
18 @code{free(3)} before setting new values.
19 @end deftypefun
20
21 To copy new email from an FTP server, lets suppose that we've register an
22 ftp mailbox type.
23
24 @example
25 #include <mailutils.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28
29 int main ()
30 @{
31 mailbox_t ftp;
32 mailbox_t local;
33 auth_t auth;
34 size_t i, count;
35
36 /* assume that ftp:// was register see @code{mailbox_add_type} */
37 if (mailbox_init (&local, "file:///home/thomasf/Mail/remote, 0) != 0
38 || mailbox_init (&ftp, "ftp://qnx.com/var/mail/thomasf, 0) != 0)
39 @{
40 fprintf (stderr, "Fail to init remote ftp mail\n");
41 exit (EXIT_FAILURE);
42 @}
43
44 mailbox_get_auth (ftp, &auth);
45 auth_set_user (auth, "thomasf");
46 auth_set_passwd (auth, "thomasf@@qnx.com");
47
48 if (mailbox_open (ftp, MU_MB_RDONLY) != 0
49 || mailbox_open (local, MU_MB_APPEND | MU_MB_CREAT) != 0)
50 @{
51 fprintf (stderr, "Fail to open remote ftp mail\n");
52 exit (EXIT_FAILURE);
53 @}
54
55 count = mailbox_count (ftp);
56 for (i = 1; i <= count; i++)
57 @{
58 mailbox_get_message (ftp, i, &message);
59 if (message_is_new (messsage))
60 @{
61 printf ("Appending message %d\n", i)
62 mailbox_append_message (local, message, 1);
63 @}
64 @}
65
66 mailbox_close (local);
67 mailbox_close (ftp);
68
69 return 0;
70 @}
71
72 @end example