1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* Copyright (c) 1989 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ifndef lint
static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
/* based on @(#)pop_dropinfo.c 2.1 3/18/91 */
#endif
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#else
#include <string.h>
#endif
#include <sys/stat.h>
#include <sys/file.h>
#include "popper.h"
/*
* dropinfo: Extract information about the POP maildrop and store
* it for use by the other POP routines.
*/
pop_dropinfo(p)
POP * p;
{
char buffer[BUFSIZ]; /* Read buffer */
MsgInfoList * mp; /* Pointer to message
info list */
register int msg_num; /* Current message
counter */
int nchar; /* Bytes written/read */
int end; /* eom */
/* Initialize maildrop status variables in the POP parameter block */
p->msg_count = 0;
p->msgs_deleted = 0;
p->last_msg = 0;
p->bytes_deleted = 0;
p->drop_size = 0;
end = 1;
/* Allocate memory for message information structures */
p->msg_count = ALLOC_MSGS;
p->mlp = (MsgInfoList *)calloc((unsigned)p->msg_count,sizeof(MsgInfoList));
if (p->mlp == NULL){
(void)fclose (p->drop);
p->msg_count = 0;
return pop_msg (p,POP_FAILURE,
"Can't build message list for '%s': Out of memory", p->user);
}
rewind (p->drop);
/* Scan the file, loading the message information list with
information about each message */
for (msg_num = p->drop_size = 0, mp = p->mlp - 1;
fgets(buffer,MAXMSGLINELEN,p->drop);) {
nchar = strlen(buffer);
#ifdef MMDF
if((strncmp(buffer,"\001\001\001\001",4) == 0) && (end == 0)) {
end = 1;
continue;
}
if (is_msg_boundary(buffer)) {
end = 0;
#else
if (strncmp(buffer,"From ",5) == 0) {
#endif
if (++msg_num > p->msg_count) {
p->mlp=(MsgInfoList *) realloc(p->mlp,
(p->msg_count+=ALLOC_MSGS)*sizeof(MsgInfoList));
if (p->mlp == NULL){
(void)fclose (p->drop);
p->msg_count = 0;
return pop_msg (p,POP_FAILURE,
"Can't build message list for '%s': Out of memory",
p->user);
}
mp = p->mlp + msg_num - 2;
}
#ifdef DEBUG
if(p->debug)
pop_log(p,POP_DEBUG,
"Msg %d at offset %d is %d octets long and has %u lines.",
mp->number,mp->offset,mp->length,mp->lines);
#endif
++mp;
mp->number = msg_num;
mp->length = 0;
mp->lines = 0;
mp->offset = ftell(p->drop) - nchar;
mp->del_flag = FALSE;
mp->retr_flag = FALSE;
#ifdef DEBUG
if(p->debug)
pop_log(p,POP_DEBUG, "Msg %d being added to list", mp->number);
#endif
}
mp->length += nchar;
p->drop_size += nchar;
mp->lines++;
}
p->msg_count = msg_num;
#ifdef DEBUG
if(p->debug && msg_num > 0) {
register i;
for (i = 0, mp = p->mlp; i < p->msg_count; i++, mp++)
pop_log(p,POP_DEBUG,
"Msg %d at offset %d is %d octets long and has %u lines.",
mp->number,mp->offset,mp->length,mp->lines);
}
#endif
return(POP_SUCCESS);
}
|