Commit e7562048 e75620481f3cb5d2a77b6f3d75fdbea2902a0410 by Sean 'Shaleh' Perry

added examples dir and an example

1 parent 7a2b08e6
1 Fri Oct 1 01:00:00 1999 Sean 'Shaleh' Perry <shaleh@debian.org>
2
3 * added and examples directory and the first example, from.c
4
1 Fri Oct 1 03:17:28 1999 Jakob 'sparky' Kaivo <jkaivo@gnu.org> 5 Fri Oct 1 03:17:28 1999 Jakob 'sparky' Kaivo <jkaivo@gnu.org>
2 6
3 * libmailbox/*.[ch]: added cleanup patches from Shaleh while he works 7 * libmailbox/*.[ch]: added cleanup patches from Shaleh while he works
......
1 /**
2 * Code in the public domain, Sean 'Shaleh' Perry <shaleh@debian.org>, 1999
3 *
4 * Created as an example of using libmailbox
5 *
6 **/
7 #include <mailbox.h>
8 #include <paths.h>
9 #include <stdio.h>
10
11 int main(int argc, char *argv[]) {
12 mailbox *mail;
13 unsigned int i;
14 char *header, *from, *date;
15 char *user;
16 char mailpath[256];
17
18 user = getenv("USER");
19 if (user == NULL)
20 {
21 fprintf(stderr, "who am I?\n");
22 exit(-1);
23 }
24 snprintf (mailpath, 256, "%s/%s", _PATH_MAILDIR, user);
25 mail = mbox_open(mailpath);
26 if( mail == NULL ) {
27 perror("mbox_open: ");
28 exit(-1);
29 }
30 for(i = 0; i < mail->messages; ++i) {
31 header = mbox_get_header(mail, i);
32 if( header == NULL ) {
33 perror("mbox_get_header: ");
34 exit(-1);
35 }
36 from = mbox_header_line(mail, i, "From");
37 if (from == NULL)
38 {
39 perror("mbox_header_line: ");
40 exit(-1);
41 }
42 date = mbox_header_line(mail, i, "Date");
43 if (date == NULL)
44 {
45 perror("mbox_header_line: ");
46 exit(-1);
47 }
48 printf("%s %s\n", from, date);
49 free(header);
50 free(from);
51 free(date);
52 }
53 mbox_close(mail);
54 exit(0);
55 }