Removed the space between function names and the opening parenthesis.
[mmh] / uip / rmm.c
1 /*
2 ** rmm.c -- remove a message(s)
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <h/utils.h>
11
12 static struct swit switches[] = {
13 #define UNLINKSW  0
14         { "unlink", 0 },
15 #define NUNLINKSW  1
16         { "nounlink", 0 },
17 #define VERSIONSW  2
18         { "version", 0 },
19 #define HELPSW  3
20         { "help", 0 },
21         { NULL, 0 }
22 };
23
24
25 int
26 main(int argc, char **argv)
27 {
28         int msgnum, unlink_msgs = 0;
29         char *cp, *maildir, *folder = NULL;
30         char buf[BUFSIZ], **argp;
31         char **arguments;
32         struct msgs_array msgs = { 0, 0, NULL };
33         struct msgs *mp;
34
35 #ifdef LOCALE
36         setlocale(LC_ALL, "");
37 #endif
38         invo_name = r1bindex(argv[0], '/');
39
40         /* read user profile/context */
41         context_read();
42
43         arguments = getarguments(invo_name, argc, argv, 1);
44         argp = arguments;
45
46         /* parse arguments */
47         while ((cp = *argp++)) {
48                 if (*cp == '-') {
49                         switch (smatch(++cp, switches)) {
50                         case AMBIGSW:
51                                 ambigsw(cp, switches);
52                                 done(1);
53                         case UNKWNSW:
54                                 adios(NULL, "-%s unknown\n", cp);
55
56                         case HELPSW:
57                                 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
58                                 print_help(buf, switches, 1);
59                                 done(1);
60                         case VERSIONSW:
61                                 print_version(invo_name);
62                                 done(1);
63
64                         case UNLINKSW:
65                                 unlink_msgs++;
66                                 continue;
67                         case NUNLINKSW:
68                                 unlink_msgs = 0;
69                                 continue;
70                         }
71                 }
72                 if (*cp == '+' || *cp == '@') {
73                         if (folder)
74                                 adios(NULL, "only one folder at a time!");
75                         else
76                                 folder = pluspath(cp);
77                 } else
78                         app_msgarg(&msgs, cp);
79         }
80
81         if (!context_find("path"))
82                 free(path("./", TFOLDER));
83         if (!msgs.size)
84                 app_msgarg(&msgs, "cur");
85         if (!folder)
86                 folder = getfolder(1);
87         maildir = m_maildir(folder);
88
89         if (chdir(maildir) == NOTOK)
90                 adios(maildir, "unable to change directory to");
91
92         /* read folder and create message structure */
93         if (!(mp = folder_read(folder)))
94                 adios(NULL, "unable to read folder %s", folder);
95
96         /* check for empty folder */
97         if (mp->nummsg == 0)
98                 adios(NULL, "no messages in %s", folder);
99
100         /* parse all the message ranges/sequences and set SELECTED */
101         for (msgnum = 0; msgnum < msgs.size; msgnum++)
102                 if (!m_convert(mp, msgs.msgs[msgnum]))
103                         done(1);
104         seq_setprev(mp);  /* set the previous-sequence */
105
106         /*
107         ** This is hackish.  If we are using a external rmmproc,
108         ** then we need to update the current folder in the
109         ** context so the external rmmproc will remove files
110         ** from the correct directory.  This should be moved to
111         ** folder_delmsgs().
112         */
113         if (rmmproc) {
114                 context_replace(pfolder, folder);
115                 context_save();
116                 fflush(stdout);
117         }
118
119         /* "remove" the SELECTED messages */
120         folder_delmsgs(mp, unlink_msgs, 0);
121
122         seq_save(mp);  /* synchronize message sequences  */
123         context_replace(pfolder, folder);  /* update current folder   */
124         context_save();  /* save the context file   */
125         folder_free(mp);  /* free folder structure   */
126         done(0);
127         return 1;
128 }