added examples dir and an example
Showing
2 changed files
with
59 additions
and
0 deletions
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 | ... | ... |
examples/from.c
0 → 100644
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 | } |
-
Please register or sign in to post a comment