Blame view

mh/rmm.c 2.18 KB
Wojciech Polak authored
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2 3
   Copyright (C) 2002, 2005, 2007, 2008, 2009, 2010 Free Software
   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 23
static char doc[] = N_("GNU MH rmm")"\v"
N_("Use -help to obtain the list of traditional MH options.");
24
static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
25 26 27

/* GNU options */
static struct argp_option options[] = {
28
  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
Sergey Poznyakoff authored
29
   N_("specify folder to operate upon")},
30 31 32 33 34
  { 0 }
};

/* Traditional MH options */
struct mh_option mh_option[] = {
35
  { NULL }
36 37
};

38 39
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
40 41 42
{
  switch (key)
    {
43
    case ARG_FOLDER: 
44
      mh_set_current_folder (arg);
45
      break;
46
      
47
    default:
48
      return ARGP_ERR_UNKNOWN;
49 50 51 52
    }
  return 0;
}

53
void
54
rmm (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data)
55
{
56 57
  mu_attribute_t attr;
  mu_message_get_attribute (msg, &attr);
58
  mu_attribute_set_deleted (attr);
59 60 61 62 63 64
}

int
main (int argc, char **argv)
{
  int index = 0;
65
  mu_mailbox_t mbox;
66
  mh_msgset_t msgset;
67
  int status;
Wojciech Polak authored
68 69

  /* Native Language Support */
Sergey Poznyakoff authored
70
  MU_APP_INIT_NLS ();
Wojciech Polak authored
71

72
  mh_argp_init ();
73
  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
74 75
		 opt_handler, NULL, &index);

76
  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
77

78
  mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
79

80
  status = mh_iterate (mbox, &msgset, rmm, NULL);
81

82 83 84
  mu_mailbox_expunge (mbox);
  mu_mailbox_close (mbox);
  mu_mailbox_destroy (&mbox);
85
  mh_global_save_state ();
86 87 88
  return status;
}