author | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
commit | e3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff) | |
tree | 162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/libetpan/tests/readmsg-simple.c | |
parent | 2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff) | |
download | kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2 |
Initial revision
Diffstat (limited to 'kmicromail/libetpan/tests/readmsg-simple.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/tests/readmsg-simple.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/kmicromail/libetpan/tests/readmsg-simple.c b/kmicromail/libetpan/tests/readmsg-simple.c new file mode 100644 index 0000000..ea57d6d --- a/dev/null +++ b/kmicromail/libetpan/tests/readmsg-simple.c | |||
@@ -0,0 +1,133 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <string.h> | ||
3 | #include <stdlib.h> | ||
4 | |||
5 | #include <libetpan/libetpan.h> | ||
6 | |||
7 | #include "option-parser.h" | ||
8 | |||
9 | int main(int argc, char ** argv) | ||
10 | { | ||
11 | int r; | ||
12 | int driver; | ||
13 | char * server; | ||
14 | int port; | ||
15 | int connection_type; | ||
16 | char * user; | ||
17 | char * password; | ||
18 | int auth_type; | ||
19 | char * path; | ||
20 | char * cache_directory; | ||
21 | char * flags_directory; | ||
22 | struct mailstorage * storage; | ||
23 | int cached; | ||
24 | struct mailfolder * folder; | ||
25 | |||
26 | /* get options */ | ||
27 | |||
28 | r = parse_options(argc, argv, | ||
29 | &driver, &server, &port, &connection_type, | ||
30 | &user, &password, &auth_type, | ||
31 | &path, &cache_directory, &flags_directory); | ||
32 | |||
33 | cached = (cache_directory != NULL); | ||
34 | |||
35 | /* build the storage structure */ | ||
36 | |||
37 | storage = mailstorage_new(NULL); | ||
38 | if (storage == NULL) { | ||
39 | printf("error initializing storage\n"); | ||
40 | goto free_opt; | ||
41 | } | ||
42 | |||
43 | r = init_storage(storage, driver, server, port, connection_type, | ||
44 | user, password, auth_type, path, cache_directory, flags_directory); | ||
45 | if (r != MAIL_NO_ERROR) { | ||
46 | printf("error initializing storage\n"); | ||
47 | goto free_opt; | ||
48 | } | ||
49 | |||
50 | /* get the folder structure */ | ||
51 | |||
52 | folder = mailfolder_new(storage, path, NULL); | ||
53 | if (folder == NULL) { | ||
54 | printf("error initializing folder\n"); | ||
55 | goto free_storage; | ||
56 | } | ||
57 | |||
58 | r = mailfolder_connect(folder); | ||
59 | if (r != MAIL_NO_ERROR) { | ||
60 | printf("error initializing folder\n"); | ||
61 | goto free_folder; | ||
62 | } | ||
63 | |||
64 | while (optind < argc) { | ||
65 | mailmessage * msg; | ||
66 | uint32_t msg_num; | ||
67 | char * data; | ||
68 | size_t size; | ||
69 | |||
70 | msg_num = strtoul(argv[optind], NULL, 10); | ||
71 | |||
72 | r = mailsession_get_message(folder->fld_session, msg_num, &msg); | ||
73 | if (r != MAIL_NO_ERROR) { | ||
74 | printf("** message %i not found **\n", msg_num); | ||
75 | optind ++; | ||
76 | continue; | ||
77 | } | ||
78 | |||
79 | r = mailmessage_fetch(msg, &data, &size); | ||
80 | if (r != MAIL_NO_ERROR) { | ||
81 | printf("** message %i not found - %s **\n", msg_num, | ||
82 | maildriver_strerror(r)); | ||
83 | mailmessage_free(msg); | ||
84 | optind ++; | ||
85 | continue; | ||
86 | } | ||
87 | |||
88 | fwrite(data, 1, size, stdout); | ||
89 | |||
90 | mailmessage_fetch_result_free(msg, data); | ||
91 | |||
92 | mailmessage_free(msg); | ||
93 | |||
94 | optind ++; | ||
95 | } | ||
96 | |||
97 | mailfolder_free(folder); | ||
98 | mailstorage_free(storage); | ||
99 | |||
100 | if (server != NULL) | ||
101 | free(server); | ||
102 | if (user != NULL) | ||
103 | free(user); | ||
104 | if (password != NULL) | ||
105 | free(password); | ||
106 | if (path != NULL) | ||
107 | free(path); | ||
108 | if (cache_directory != NULL) | ||
109 | free(cache_directory); | ||
110 | if (flags_directory != NULL) | ||
111 | free(flags_directory); | ||
112 | |||
113 | return 0; | ||
114 | |||
115 | free_folder: | ||
116 | mailfolder_free(folder); | ||
117 | free_storage: | ||
118 | mailstorage_free(storage); | ||
119 | free_opt: | ||
120 | if (server != NULL) | ||
121 | free(server); | ||
122 | if (user != NULL) | ||
123 | free(user); | ||
124 | if (password != NULL) | ||
125 | free(password); | ||
126 | if (path != NULL) | ||
127 | free(path); | ||
128 | if (cache_directory != NULL) | ||
129 | free(cache_directory); | ||
130 | if (flags_directory != NULL) | ||
131 | free(flags_directory); | ||
132 | return -1; | ||
133 | } | ||