Blame view

mail/previous.c 1.59 KB
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2
   Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
3

4
   GNU Mailutils is free software; you can redistribute it and/or modify
5 6 7 8
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   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, write to the Free Software
Wojciech Polak authored
16
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
17 18 19 20 21 22 23 24 25 26 27

#include "mail.h"

/*
 * prev[ious] [message]
 * -
 */

int
mail_previous (int argc, char **argv)
{
28 29 30
  size_t n;
  message_t msg;

31 32
  if (argc < 2)
    {
33 34 35
      int rc = 1;
      for (n = cursor - 1; n > 0; n--)
	{
36 37
	  if (util_isdeleted (n))
	    continue;
38
	  rc = util_get_message (mbox, n, &msg);
39 40 41 42 43 44
	  if (rc == 0)
	    break;
	}

      if (rc)
	{
45
	  util_error (_("No applicable message"));
46 47
	  return 1;
	}
48
    }
49
  else
50
    {
51
      msgset_t *list = NULL;
52 53 54 55 56 57 58 59 60 61 62 63 64
      int rc = msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT, &list);
      if (!rc)
	{
	  n = list->msg_part[0];
	  msgset_free (list);
	  if (util_get_message (mbox, n, &msg))
	    return 1;
	}
      else
	{
	  util_error (_("No applicable message"));
	  return 1;
	}
65
    }
66
  cursor = n;
67
  util_do_command ("print");
68
  return 0;
69
}