Blame view

mail/set.c 1.76 KB
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2
   Copyright (C) 1999, 2001, 2007, 2010 Free Software Foundation, Inc.
3

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

9
   GNU Mailutils is distributed in the hope that it will be useful,
10 11 12 13 14
   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
15
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
16 17 18 19 20 21 22

#include "mail.h"

/*
 * se[t] [name[=[string]] ...] [name=number ...] [noname ...]
 */

23 24 25 26
/*
 * NOTE: ask is a synonym for asksub
 */

27 28 29
int
mail_set (int argc, char **argv)
{
30 31
  int flags = MOPTF_OVERWRITE | ((strcmp (argv[0], "setq") == 0) ? MOPTF_QUIET : 0);

32 33
  if (argc < 2)
    {
34
      mailvar_print (1);
35
      return 0;
36 37 38 39
    }
  else
    {
      int i = 0;
Sergey Poznyakoff authored
40

41 42
      for (i = 1; i < argc; i++)
	{
43 44 45 46 47
	  char *value = strchr (argv[i], '=');
	  if (value)
	    *value++ = 0;
	  
	  if (!strncmp ("no", argv[i], 2) && !value)
48
	    {
49 50
	      mailvar_set (&argv[i][2], NULL, mailvar_type_boolean,
			   flags | MOPTF_UNSET);
51
	    }
52
	  else if (value)
53
	    {
Sergey Poznyakoff authored
54 55 56
	      int nval;
	      char *p;
	      
57
	      nval = strtoul (value, &p, 0);
Sergey Poznyakoff authored
58
	      if (*p == 0)
59
		mailvar_set (argv[i], &nval, mailvar_type_number, flags);
Sergey Poznyakoff authored
60
	      else
61
		mailvar_set (argv[i], value, mailvar_type_string, flags);
62 63 64
	    }
	  else
	    {
65
	      int dummy = 1;
66
	      mailvar_set (argv[i], &dummy, mailvar_type_boolean, flags);
67 68 69 70
	    }
	}
      return 0;
    }
71 72
  return 1;
}