]>
diplodocus.org Git - nmh/blob - uip/rmm.c
3 * rmm.c -- remove a message(s)
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 #define RMM_SWITCHES \
14 X("unlink", 0, UNLINKSW) \
15 X("nounlink", 0, NUNLINKSW) \
16 X("rmmproc program", 0, RPROCSW) \
17 X("normmproc", 0, NRPRCSW) \
18 X("version", 0, VERSIONSW) \
19 X("help", 0, HELPSW) \
21 #define X(sw, minchars, id) id,
22 DEFINE_SWITCH_ENUM(RMM
);
25 #define X(sw, minchars, id) { sw, minchars, id },
26 DEFINE_SWITCH_ARRAY(RMM
, switches
);
31 main (int argc
, char **argv
)
33 int msgnum
, unlink_msgs
= 0;
34 char *cp
, *maildir
, *folder
= NULL
;
35 char buf
[BUFSIZ
], **argp
;
37 struct msgs_array msgs
= { 0, 0, NULL
};
40 if (nmh_init(argv
[0], 1)) { return 1; }
42 arguments
= getarguments (invo_name
, argc
, argv
, 1);
46 while ((cp
= *argp
++)) {
48 switch (smatch (++cp
, switches
)) {
50 ambigsw (cp
, switches
);
53 adios (NULL
, "-%s unknown\n", cp
);
56 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
58 print_help (buf
, switches
, 1);
61 print_version(invo_name
);
72 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
73 adios (NULL
, "missing argument to %s", argp
[-2]);
80 if (*cp
== '+' || *cp
== '@') {
82 adios (NULL
, "only one folder at a time!");
84 folder
= pluspath (cp
);
86 app_msgarg(&msgs
, cp
);
89 if (!context_find ("path"))
90 free (path ("./", TFOLDER
));
92 app_msgarg(&msgs
, "cur");
94 folder
= getfolder (1);
95 maildir
= m_maildir (folder
);
97 if (chdir (maildir
) == NOTOK
)
98 adios (maildir
, "unable to change directory to");
100 /* read folder and create message structure */
101 if (!(mp
= folder_read (folder
, 1)))
102 adios (NULL
, "unable to read folder %s", folder
);
104 /* check for empty folder */
106 adios (NULL
, "no messages in %s", folder
);
108 /* parse all the message ranges/sequences and set SELECTED */
109 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
110 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
112 seq_setprev (mp
); /* set the previous-sequence */
115 * As part of the new world locking order, folder_delmsgs() now updates
116 * the sequence and context for us. But since folder_delmsgs() doesn't
117 * have access to the folder name, change the context now.
120 context_replace (pfolder
, folder
);
122 /* "remove" the SELECTED messages */
123 folder_delmsgs (mp
, unlink_msgs
, 0);
125 folder_free (mp
); /* free folder structure */