Commit 43853ce8 43853ce85b785d36b44b6850ceac7136c54f54f0 by Sergey Poznyakoff

mh: implement rmmproc.

* include/mailutils/sys/amd.h (_amd_data) <delete_msg>: New method.
* libmailutils/base/amd.c (amd_expunge): If delete_msg is defined,
use it.
* libproto/mh/mbox.c (_mh_msg_delete): New method.
(_mailbox_mh_init): Set delete_msg if "rmmproc" component is
defined.

* mh/tests/movemsg: New file.
* mh/tests/Makefile.am (EXTRA_DIST): Add movemsg.
* mh/tests/rmm.at: Test rmmproc effects.
* mh/tests/rmf.at (MH_KEYWORDS): Fix copy-n-paste error.

* doc/texinfo/mu-mh.texi: Document rmmproc.
* mh/TODO: Update.
1 parent 764ebfd7
......@@ -427,7 +427,12 @@ Mailutils @command{rmm} does not delete any messages. Standard
non-existent one.
@item
The @code{rmmproc} profile component is not used.
The @command{rmm} utility will unlink messages, if the @code{rmmproc}
profile component has empty value, e.g.:
@example
rmmproc:
@end example
@end enumerate
@item sortm
......
......@@ -82,7 +82,8 @@ struct _amd_data
int (*message_uid) (mu_message_t msg, size_t *puid);
size_t (*next_uid) (struct _amd_data *mhd);
int (*remove) (struct _amd_data *);
int (*delete_msg) (struct _amd_data *, struct _amd_message *);
/* List of messages: */
size_t msg_count; /* number of messages in the list */
size_t msg_max; /* maximum message buffer capacity */
......
......@@ -1166,37 +1166,46 @@ amd_expunge (mu_mailbox_t mailbox)
if (mhm->attr_flags & MU_ATTRIBUTE_DELETED)
{
int rc;
char *old_name;
char *new_name;
rc = amd->cur_msg_file_name (mhm, &old_name);
if (rc)
return rc;
rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
&new_name);
if (rc)
if (amd->delete_msg)
{
free (old_name);
return rc;
}
if (new_name)
{
/* FIXME: It may be a good idea to have a capability flag
in struct _amd_data indicating that no actual removal
is needed (e.g. for traditional MH). It will allow to
bypass lots of no-op code here. */
if (strcmp (old_name, new_name))
/* Rename original message */
rename (old_name, new_name);
rc = amd->delete_msg (amd, mhm);
if (rc)
return rc;
}
else
/* Unlink original file */
unlink (old_name);
free (old_name);
free (new_name);
{
char *old_name;
char *new_name;
rc = amd->cur_msg_file_name (mhm, &old_name);
if (rc)
return rc;
rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
&new_name);
if (rc)
{
free (old_name);
return rc;
}
if (new_name)
{
/* FIXME: It may be a good idea to have a capability flag
in struct _amd_data indicating that no actual removal
is needed (e.g. for traditional MH). It will allow to
bypass lots of no-op code here. */
if (strcmp (old_name, new_name))
/* Rename original message */
rename (old_name, new_name);
}
else
/* Unlink original file */
unlink (old_name);
free (old_name);
free (new_name);
}
_amd_message_delete (amd, mhm);
updated = 1;
/* Do not increase i! */
......
......@@ -351,6 +351,38 @@ _mh_msg_init (struct _amd_data *amd, struct _amd_message *amm)
return 0;
}
static int
_mh_msg_delete (struct _amd_data *amd, struct _amd_message *amm)
{
int rc, status;
char *name;
char *argv[3];
/* FIXME: Cache this value */
const char *proc = mu_mhprop_get_value (mu_mh_profile, "rmmproc", NULL);
if (!proc)
return ENOSYS;
rc = amd->cur_msg_file_name (amm, &name);
if (rc)
return rc;
if (proc[0] == 0)
{
rc = unlink (name);
if (rc)
rc = errno;
}
else
{
argv[0] = (char*) proc;
argv[1] = name;
argv[2] = NULL;
rc = mu_spawnvp (proc, argv, &status);
}
free (name);
return rc;
}
static int
mh_remove (struct _amd_data *amd)
......@@ -442,6 +474,10 @@ _mailbox_mh_init (mu_mailbox_t mailbox)
mailbox->_get_property = mh_get_property;
mailbox->_translate = mh_translate;
if (mu_mhprop_get_value (mu_mh_profile, "rmmproc", NULL))
amd->delete_msg = _mh_msg_delete;
return 0;
}
......
......@@ -24,8 +24,8 @@ State Nice Utility Comments
* -20 forw --inplace
* -20 send --alias,--filter,--format,--forward,--mime,
--width
* -20 refile --link copies messages; rmmproc ignored.
* -20 rmm rmproc:
* -20 refile --link copies messages
+ -20 rmm
+ -15 folder(s)
+ -15 mhn
+ -10 rmf
......
......@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4
EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 mhed movemsg
DISTCLEANFILES = atconfig $(check_SCRIPTS)
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
......
......@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
m4_pushdef([MH_KEYWORDS],[rmm])
m4_pushdef([MH_KEYWORDS],[rmf])
MH_CHECK([rmf +folder],[rmf00 rmf+folder],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
......
......@@ -47,5 +47,36 @@ test: 2 3 5
cur: 1
])
MH_CHECK([rmm rmmproc],[rmm02 rmmproc],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "rmmproc: $abs_top_srcdir/mh/tests/movemsg" >> $MH
rmm 1 4 || exit $?
find Mail/inbox -name '[[0-9]]' | sort
find Mail/removed -name '[[0-9]]' | sort
],
[0],
[Mail/inbox/2
Mail/inbox/3
Mail/inbox/5
Mail/removed/1
Mail/removed/4
])
MH_CHECK([rmm -- null rmmproc],[rmm03 null-rmmproc],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "rmmproc:" >> $MH
rmm 1 4 || exit $?
find Mail/inbox -name '[[0-9]]' | sort
test -f Mail/inbox/,1 || echo OK
test -f Mail/inbox/,4 || echo OK
],
[0],
[Mail/inbox/2
Mail/inbox/3
Mail/inbox/5
OK
OK
])
m4_popdef[MH_KEYWORDS])
# End of rmm.at
......