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