No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / appl / popper / pop_dele.c
blob842d2bfeefbbc477bae3cc8c3c00cc467e158a9e
1 /*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
7 #include <popper.h>
8 __RCSID("$Heimdal: pop_dele.c 6795 1999-08-12 11:37:55Z joda $"
9 "$NetBSD$");
11 /*
12 * dele: Delete a message from the POP maildrop
14 int
15 pop_dele (POP *p)
17 MsgInfoList * mp; /* Pointer to message info list */
18 int msg_num;
20 /* Convert the message number parameter to an integer */
21 msg_num = atoi(p->pop_parm[1]);
23 /* Is requested message out of range? */
24 if ((msg_num < 1) || (msg_num > p->msg_count))
25 return (pop_msg (p,POP_FAILURE,"Message %d does not exist.",msg_num));
27 /* Get a pointer to the message in the message list */
28 mp = &(p->mlp[msg_num-1]);
30 /* Is the message already flagged for deletion? */
31 if (mp->flags & DEL_FLAG)
32 return (pop_msg (p,POP_FAILURE,"Message %d has already been deleted.",
33 msg_num));
35 /* Flag the message for deletion */
36 mp->flags |= DEL_FLAG;
38 #ifdef DEBUG
39 if(p->debug)
40 pop_log(p, POP_DEBUG,
41 "Deleting message %u at offset %ld of length %ld\n",
42 mp->number, mp->offset, mp->length);
43 #endif /* DEBUG */
45 /* Update the messages_deleted and bytes_deleted counters */
46 p->msgs_deleted++;
47 p->bytes_deleted += mp->length;
49 /* Update the last-message-accessed number if it is lower than
50 the deleted message */
51 if (p->last_msg < msg_num) p->last_msg = msg_num;
53 return (pop_msg (p,POP_SUCCESS,"Message %d has been deleted.",msg_num));
56 #ifdef XDELE
57 /* delete a range of messages */
58 int
59 pop_xdele(POP *p)
61 MsgInfoList * mp; /* Pointer to message info list */
63 int msg_min, msg_max;
64 int i;
67 msg_min = atoi(p->pop_parm[1]);
68 if(p->parm_count == 1)
69 msg_max = msg_min;
70 else
71 msg_max = atoi(p->pop_parm[2]);
73 if (msg_min < 1)
74 return (pop_msg (p,POP_FAILURE,"Message %d does not exist.",msg_min));
75 if(msg_max > p->msg_count)
76 return (pop_msg (p,POP_FAILURE,"Message %d does not exist.",msg_max));
77 for(i = msg_min; i <= msg_max; i++) {
79 /* Get a pointer to the message in the message list */
80 mp = &(p->mlp[i - 1]);
82 /* Is the message already flagged for deletion? */
83 if (mp->flags & DEL_FLAG)
84 continue; /* no point in returning error */
85 /* Flag the message for deletion */
86 mp->flags |= DEL_FLAG;
88 #ifdef DEBUG
89 if(p->debug)
90 pop_log(p, POP_DEBUG,
91 "Deleting message %u at offset %ld of length %ld\n",
92 mp->number, mp->offset, mp->length);
93 #endif /* DEBUG */
95 /* Update the messages_deleted and bytes_deleted counters */
96 p->msgs_deleted++;
97 p->bytes_deleted += mp->length;
100 /* Update the last-message-accessed number if it is lower than
101 the deleted message */
102 if (p->last_msg < msg_max) p->last_msg = msg_max;
104 return (pop_msg (p,POP_SUCCESS,"Messages %d-%d has been deleted.",
105 msg_min, msg_max));
108 #endif /* XDELE */