]>
diplodocus.org Git - nmh/blob - uip/rmm.c
1 /* rmm.c -- remove a message(s)
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
11 #define RMM_SWITCHES \
12 X("unlink", 0, UNLINKSW) \
13 X("nounlink", 0, NUNLINKSW) \
14 X("rmmproc program", 0, RPROCSW) \
15 X("normmproc", 0, NRPRCSW) \
16 X("version", 0, VERSIONSW) \
17 X("help", 0, HELPSW) \
19 #define X(sw, minchars, id) id,
20 DEFINE_SWITCH_ENUM(RMM
);
23 #define X(sw, minchars, id) { sw, minchars, id },
24 DEFINE_SWITCH_ARRAY(RMM
, switches
);
29 main (int argc
, char **argv
)
31 int msgnum
, unlink_msgs
= 0;
32 char *cp
, *maildir
, *folder
= NULL
;
33 char buf
[BUFSIZ
], **argp
;
35 struct msgs_array msgs
= { 0, 0, NULL
};
38 if (nmh_init(argv
[0], 1)) { return 1; }
40 arguments
= getarguments (invo_name
, argc
, argv
, 1);
44 while ((cp
= *argp
++)) {
46 switch (smatch (++cp
, switches
)) {
48 ambigsw (cp
, switches
);
51 adios (NULL
, "-%s unknown\n", cp
);
54 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
56 print_help (buf
, switches
, 1);
59 print_version(invo_name
);
70 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
71 adios (NULL
, "missing argument to %s", argp
[-2]);
78 if (*cp
== '+' || *cp
== '@') {
80 adios (NULL
, "only one folder at a time!");
82 folder
= pluspath (cp
);
84 app_msgarg(&msgs
, cp
);
87 if (!context_find ("path"))
88 free (path ("./", TFOLDER
));
90 app_msgarg(&msgs
, "cur");
92 folder
= getfolder (1);
93 maildir
= m_maildir (folder
);
95 if (chdir (maildir
) == NOTOK
)
96 adios (maildir
, "unable to change directory to");
98 /* read folder and create message structure */
99 if (!(mp
= folder_read (folder
, 1)))
100 adios (NULL
, "unable to read folder %s", folder
);
102 /* check for empty folder */
104 adios (NULL
, "no messages in %s", folder
);
106 /* parse all the message ranges/sequences and set SELECTED */
107 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
108 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
110 seq_setprev (mp
); /* set the previous-sequence */
113 * As part of the new world locking order, folder_delmsgs() now updates
114 * the sequence and context for us. But since folder_delmsgs() doesn't
115 * have access to the folder name, change the context now.
118 context_replace (pfolder
, folder
);
120 /* "remove" the SELECTED messages */
121 folder_delmsgs (mp
, unlink_msgs
, 0);
123 folder_free (mp
); /* free folder structure */