Commit a351cb7c a351cb7c03611bcf1beea59b54375694a29f9047 by Sergey Poznyakoff

Source for rmm program.

1 parent 2bc860b3
Showing 1 changed file with 153 additions and 0 deletions
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 /* MH rmm command */
19
20 #include <mh.h>
21
22 const char *argp_program_version = "rmm (" PACKAGE_STRING ")";
23 static char doc[] = "GNU MH rmm";
24 static char args_doc[] = "";
25
26 /* GNU options */
27 static struct argp_option options[] = {
28 {"folder", 'f', "FOLDER", 0, "Specify folder to operate upon"},
29 { "\nUse -help switch to obtain the list of traditional MH options. ", 0, 0, OPTION_DOC, "" },
30
31 { 0 }
32 };
33
34 /* Traditional MH options */
35 struct mh_option mh_option[] = {
36 { 0 }
37 };
38
39 static int
40 opt_handler (int key, char *arg, void *unused)
41 {
42 switch (key)
43 {
44 case '+':
45 case 'f':
46 current_folder = arg;
47 break;
48 default:
49 return 1;
50 }
51 return 0;
52 }
53
54 int
55 member (size_t num, size_t *msglist, size_t msgcnt)
56 {
57 size_t i;
58
59 for (i = 0; i < msgcnt; i++)
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;
99 }
100
101 int
102 main (int argc, char **argv)
103 {
104 int index = 0;
105 mailbox_t mbox;
106 size_t msgcnt = 0, *msglist = NULL;
107 int status;
108
109 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
110 opt_handler, NULL, &index);
111
112 mbox = mh_open_folder ();
113
114 if (index < argc)
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
144 status = rmm (mbox, msgcnt, msglist);
145
146 mailbox_expunge (mbox);
147 mailbox_close (mbox);
148 mailbox_destroy (&mbox);
149 return status;
150 }
151
152
153