Blame view

mh/rmm.c 2.03 KB
Wojciech Polak authored
1
/* GNU Mailutils -- a suite of utilities for electronic mail
Sergey Poznyakoff authored
2
   Copyright (C) 2002, 2005, 2007-2012, 2014-2017 Free Software
3
   Foundation, Inc.
4

Wojciech Polak authored
5
   GNU Mailutils is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8 9
   any later version.

Wojciech Polak authored
10
   GNU Mailutils is distributed in the hope that it will be useful,
11 12 13 14 15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
16
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
17 18 19 20 21

/* MH rmm command */

#include <mh.h>

22
static char prog_doc[] = N_("Remove messages");
23
static char args_doc[] = N_("[MSGLIST]");
24

25 26
static int
rmm (size_t num, mu_message_t msg, void *data)
27
{
28 29
  mu_attribute_t attr;
  mu_message_get_attribute (msg, &attr);
30
  mu_attribute_set_deleted (attr);
31
  return 0;
32 33
}

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
struct seq_closure
{
  mu_msgset_t rmset;
  int rmflag;
};

static int
rmseq (const char *name, const char *value, void *data)
{
  struct seq_closure *s = data;
  mu_mailbox_t mbox;

  mu_msgset_sget_mailbox (s->rmset, &mbox);
  mh_seq_delete (mbox, name, s->rmset, s->rmflag);
  return 0;
}

51 52 53
int
main (int argc, char **argv)
{
54
  mu_mailbox_t mbox;
55
  mu_msgset_t msgset;
56
  int status;
57 58
  struct seq_closure clos;
  
59 60
  mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
	     args_doc, prog_doc, NULL);
61

62
  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
63

64
  mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
65

66
  status = mu_msgset_foreach_message (msgset, rmm, NULL);
67 68 69 70 71 72
  
  clos.rmset = msgset;
  clos.rmflag = 0;
  mh_global_sequences_iterate (mbox, rmseq, &clos);
  clos.rmflag = SEQ_PRIVATE;
  mh_private_sequences_iterate (mbox, rmseq, &clos);
73

74 75 76
  mu_mailbox_expunge (mbox);
  mu_mailbox_close (mbox);
  mu_mailbox_destroy (&mbox);
77
  mh_global_save_state ();
78 79 80
  return status;
}