1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 1999-2021 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    any later version.
8 
9    GNU Mailutils is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    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 #include "mail.h"
18 
19 /*
20  * prev[ious] [message]
21  * -
22  */
23 
24 int
mail_previous(int argc,char ** argv)25 mail_previous (int argc, char **argv)
26 {
27   size_t n;
28   mu_message_t msg;
29 
30   if (argc < 2)
31     {
32       int rc = 1;
33 
34       n = get_cursor ();
35       if (n)
36         while (--n > 0)
37 	  {
38 	    if (util_isdeleted (n))
39 	      continue;
40 	    rc = util_get_message (mbox, n, &msg);
41 	    if (rc == 0)
42 	      break;
43 	  }
44 
45       if (rc)
46 	{
47 	  mu_error (_("No applicable message"));
48 	  return 1;
49 	}
50     }
51   else
52     {
53       msgset_t *list = NULL;
54       int rc = msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT, &list);
55       if (!rc)
56 	{
57 	  n = msgset_msgno (list);
58 	  msgset_free (list);
59 	  if (util_get_message (mbox, n, &msg))
60 	    return 1;
61 	}
62       else
63 	{
64 	  mu_error (_("No applicable message"));
65 	  return 1;
66 	}
67     }
68   set_cursor (n);
69   util_do_command ("print");
70   return 0;
71 }
72