Use new mh framework
Showing
2 changed files
with
13 additions
and
78 deletions
... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
21 | 21 | ||
22 | const char *argp_program_version = "rmm (" PACKAGE_STRING ")"; | 22 | const char *argp_program_version = "rmm (" PACKAGE_STRING ")"; |
23 | static char doc[] = "GNU MH rmm"; | 23 | static char doc[] = "GNU MH rmm"; |
24 | static char args_doc[] = ""; | 24 | static char args_doc[] = "[messages]"; |
25 | 25 | ||
26 | /* GNU options */ | 26 | /* GNU options */ |
27 | static struct argp_option options[] = { | 27 | static struct argp_option options[] = { |
... | @@ -45,56 +45,19 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -45,56 +45,19 @@ opt_handler (int key, char *arg, void *unused) |
45 | case 'f': | 45 | case 'f': |
46 | current_folder = arg; | 46 | current_folder = arg; |
47 | break; | 47 | break; |
48 | |||
48 | default: | 49 | default: |
49 | return 1; | 50 | return 1; |
50 | } | 51 | } |
51 | return 0; | 52 | return 0; |
52 | } | 53 | } |
53 | 54 | ||
54 | int | 55 | void |
55 | member (size_t num, size_t *msglist, size_t msgcnt) | 56 | rmm (mailbox_t mbox, message_t msg, size_t num, void *data) |
56 | { | 57 | { |
57 | size_t i; | 58 | attribute_t attr; |
58 | 59 | message_get_attribute (msg, &attr); | |
59 | for (i = 0; i < msgcnt; i++) | 60 | attribute_set_deleted (attr); |
60 | if (msglist[i] == num) | ||
61 | return 1; | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | int | ||
66 | rmm (mailbox_t mbox, size_t msgcnt, size_t *msglist) | ||
67 | { | ||
68 | size_t i, total = 0; | ||
69 | |||
70 | mailbox_messages_count (mbox, &total); | ||
71 | for (i = 1; i <= total; i++) | ||
72 | { | ||
73 | message_t msg; | ||
74 | size_t num; | ||
75 | int rc; | ||
76 | |||
77 | if ((rc = mailbox_get_message (mbox, i, &msg)) != 0) | ||
78 | { | ||
79 | mh_error ("can't get message %d: %s", i, mu_errstring (rc)); | ||
80 | return 1; | ||
81 | } | ||
82 | |||
83 | if ((rc = mh_message_number (msg, &num)) != 0) | ||
84 | { | ||
85 | mh_error ("can't get sequence number for message %d: %s", | ||
86 | i, mu_errstring (rc)); | ||
87 | return 1; | ||
88 | } | ||
89 | |||
90 | if (member (num, msglist, msgcnt)) | ||
91 | { | ||
92 | attribute_t attr; | ||
93 | message_get_attribute (msg, &attr); | ||
94 | attribute_set_deleted (attr); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return 0; | 61 | return 0; |
99 | } | 62 | } |
100 | 63 | ||
... | @@ -103,45 +66,17 @@ main (int argc, char **argv) | ... | @@ -103,45 +66,17 @@ main (int argc, char **argv) |
103 | { | 66 | { |
104 | int index = 0; | 67 | int index = 0; |
105 | mailbox_t mbox; | 68 | mailbox_t mbox; |
106 | size_t msgcnt = 0, *msglist = NULL; | 69 | mh_msgset_t msgset; |
107 | int status; | 70 | int status; |
108 | 71 | ||
109 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, | 72 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, |
110 | opt_handler, NULL, &index); | 73 | opt_handler, NULL, &index); |
111 | 74 | ||
112 | mbox = mh_open_folder (); | 75 | mbox = mh_open_folder (current_folder); |
113 | 76 | ||
114 | if (index < argc) | 77 | mh_msgset_parse (mbox, &msgset, argc - index, argv + index); |
115 | { | ||
116 | size_t i; | ||
117 | |||
118 | msgcnt = argc - index + 1; | ||
119 | msglist = calloc (argc - index + 1, sizeof(*msglist)); | ||
120 | for (i = 0; index < argc; index++, i++) | ||
121 | { | ||
122 | char *p = NULL; | ||
123 | msglist[i] = strtol (argv[index], &p, 0); | ||
124 | if (msglist[i] <= 0 || *p) | ||
125 | { | ||
126 | mh_error ("bad message list `%s'", argv[index]); | ||
127 | exit (1); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | if (current_message == 0) | ||
134 | { | ||
135 | mh_error ("no cur message"); | ||
136 | exit (1); | ||
137 | } | ||
138 | msglist = calloc (1, sizeof(*msglist)); | ||
139 | msglist[0] = current_message; | ||
140 | current_message = 0; | ||
141 | msgcnt = 1; | ||
142 | } | ||
143 | 78 | ||
144 | status = rmm (mbox, msgcnt, msglist); | 79 | status = mh_iterate (mbox, &msgset, rmm, NULL); |
145 | 80 | ||
146 | mailbox_expunge (mbox); | 81 | mailbox_expunge (mbox); |
147 | mailbox_close (mbox); | 82 | mailbox_close (mbox); | ... | ... |
... | @@ -137,7 +137,7 @@ main (int argc, char **argv) | ... | @@ -137,7 +137,7 @@ main (int argc, char **argv) |
137 | exit (1); | 137 | exit (1); |
138 | } | 138 | } |
139 | 139 | ||
140 | return scan (mh_open_folder ()); | 140 | return scan (mh_open_folder (current_folder)); |
141 | } | 141 | } |
142 | 142 | ||
143 | #ifdef HAVE_TERMCAP_H | 143 | #ifdef HAVE_TERMCAP_H | ... | ... |
-
Please register or sign in to post a comment