f42bd80b01abe12b36c1ff0d5ae4159d060d89a8
[mmh] / sbr / parse_msgs.c
1 #include <h/mh.h>
2 #include <h/utils.h>
3
4 int
5 parse_msgs(const struct msgs_array *msgs, char *folder, struct msgs_array *files)
6 {
7         int ret = 0;
8         char *msgnam;
9         struct msgs *f;
10         char *path;
11         size_t i;
12
13         if (folder) {
14                 path = toabsdir(folder);
15         } else {
16                 path = toabsdir(getcurfol());
17         }
18
19         path = mh_xstrdup(path);
20         path = add("/", path);
21
22         f = folder_read(path);
23
24         if (f == NULL) {
25                 return -1;
26         }
27
28         for (i = 0; i < msgs->size; i++) {
29                 if (*(msgs->msgs[i]) == '.' || *(msgs->msgs[i]) == '/') {
30                                 app_msgarg(files, msgs->msgs[i]);
31                                 continue;
32                 }
33
34                 if (!m_convert(f, msgs->msgs[i])) {
35                         ret++;
36                 }
37         }
38
39         for (i = f->lowsel; i <= f->hghsel; i++) {
40                 if (is_selected(f, i)) {
41                         msgnam = mh_xstrdup(path);
42                         msgnam = add(m_name(i), msgnam);
43                         app_msgarg(files, msgnam);
44                 }
45         }
46
47         folder_free(f);
48
49         return ret;
50 }