Add experimental UIDL support in popper.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@824 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -29,14 +29,14 @@ SOURCES = pop_dele.c pop_dropcopy.c pop_dropinfo.c \
|
|||||||
pop_last.c pop_list.c pop_log.c pop_lower.c \
|
pop_last.c pop_list.c pop_log.c pop_lower.c \
|
||||||
pop_msg.c pop_parse.c pop_pass.c pop_quit.c \
|
pop_msg.c pop_parse.c pop_pass.c pop_quit.c \
|
||||||
pop_rset.c pop_send.c pop_stat.c pop_updt.c \
|
pop_rset.c pop_send.c pop_stat.c pop_updt.c \
|
||||||
pop_user.c pop_xtnd.c pop_xmit.c popper.c
|
pop_user.c pop_xtnd.c pop_xmit.c pop_uidl.c popper.c
|
||||||
|
|
||||||
OBJECTS = pop_dele.o pop_dropcopy.o pop_dropinfo.o \
|
OBJECTS = pop_dele.o pop_dropcopy.o pop_dropinfo.o \
|
||||||
pop_get_command.o pop_get_subcommand.o pop_init.o \
|
pop_get_command.o pop_get_subcommand.o pop_init.o \
|
||||||
pop_last.o pop_list.o pop_log.o pop_lower.o \
|
pop_last.o pop_list.o pop_log.o pop_lower.o \
|
||||||
pop_msg.o pop_parse.o pop_pass.o pop_quit.o \
|
pop_msg.o pop_parse.o pop_pass.o pop_quit.o \
|
||||||
pop_rset.o pop_send.o pop_stat.o pop_updt.o \
|
pop_rset.o pop_send.o pop_stat.o pop_updt.o \
|
||||||
pop_user.o pop_xtnd.o pop_xmit.o popper.o
|
pop_user.o pop_xtnd.o pop_xmit.o pop_uidl.o popper.o
|
||||||
|
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
|
@@ -12,6 +12,44 @@ static char SccsId[] = "@(#)@(#)pop_dropinfo.c 2.1 2.1 3/18/91";
|
|||||||
#include <popper.h>
|
#include <popper.h>
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
#ifdef UIDL
|
||||||
|
|
||||||
|
/*
|
||||||
|
*Copy the string found after after : into a malloced buffer. Stop
|
||||||
|
* copying at end of string or end of line. End of line delimiter is
|
||||||
|
* not part the resulting copy of copy.
|
||||||
|
*/
|
||||||
|
static
|
||||||
|
char *
|
||||||
|
find_value_after_colon(char *p)
|
||||||
|
{
|
||||||
|
char *t, *tmp;
|
||||||
|
|
||||||
|
for (; *p != 0 && *p != ':'; p++) /* Find : */
|
||||||
|
;
|
||||||
|
|
||||||
|
if (*p == 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
p++; /* Skip over : */
|
||||||
|
|
||||||
|
for (t = p; *t != 0 && *t != '\n' && *t != '\r'; t++) /* Find end of str */
|
||||||
|
;
|
||||||
|
|
||||||
|
tmp = t = malloc(t - p + 1);
|
||||||
|
if (tmp == 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (; *p != 0 && *p != '\n' && *p != '\r'; p++, t++) /* Copy characters */
|
||||||
|
*t = *p;
|
||||||
|
*t = 0; /* Terminate string */
|
||||||
|
return tmp;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return "ErrorUIDL";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dropinfo: Extract information about the POP maildrop and store
|
* dropinfo: Extract information about the POP maildrop and store
|
||||||
* it for use by the other POP routines.
|
* it for use by the other POP routines.
|
||||||
@@ -26,7 +64,15 @@ pop_dropinfo(POP *p)
|
|||||||
register int msg_num; /* Current message
|
register int msg_num; /* Current message
|
||||||
counter */
|
counter */
|
||||||
int nchar; /* Bytes written/read */
|
int nchar; /* Bytes written/read */
|
||||||
|
#ifdef UIDL
|
||||||
|
/* msg_idp points to the current Message-Id to be filled in. The
|
||||||
|
* pointer is moved every time we find a From line and we fill in
|
||||||
|
* msg_id whenever we encounter the corresponding Message-Id or
|
||||||
|
* X-UIDL line. */
|
||||||
|
char *_sentinel = 0;
|
||||||
|
char **msg_idp = &_sentinel;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize maildrop status variables in the POP parameter block */
|
/* Initialize maildrop status variables in the POP parameter block */
|
||||||
p->msg_count = 0;
|
p->msg_count = 0;
|
||||||
p->msgs_deleted = 0;
|
p->msgs_deleted = 0;
|
||||||
@@ -81,11 +127,23 @@ pop_dropinfo(POP *p)
|
|||||||
mp->offset = ftell(p->drop) - nchar;
|
mp->offset = ftell(p->drop) - nchar;
|
||||||
mp->del_flag = FALSE;
|
mp->del_flag = FALSE;
|
||||||
mp->retr_flag = FALSE;
|
mp->retr_flag = FALSE;
|
||||||
|
#ifdef UIDL
|
||||||
|
mp->msg_id = 0;
|
||||||
|
msg_idp = &mp->msg_id;
|
||||||
|
#endif
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(p->debug)
|
if(p->debug)
|
||||||
pop_log(p,POP_DEBUG, "Msg %d being added to list", mp->number);
|
pop_log(p,POP_DEBUG, "Msg %d being added to list", mp->number);
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
}
|
}
|
||||||
|
#ifdef UIDL
|
||||||
|
else if (strncasecmp("Message-Id:",buffer, 11) == 0) {
|
||||||
|
if (mp->msg_id == 0)
|
||||||
|
*msg_idp = find_value_after_colon(buffer);
|
||||||
|
} else if (strncasecmp(buffer, "X-UIDL:", 7) == 0) {
|
||||||
|
*msg_idp = find_value_after_colon(buffer);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
mp->length += nchar;
|
mp->length += nchar;
|
||||||
p->drop_size += nchar;
|
p->drop_size += nchar;
|
||||||
mp->lines++;
|
mp->lines++;
|
||||||
@@ -96,9 +154,15 @@ pop_dropinfo(POP *p)
|
|||||||
if(p->debug && msg_num > 0) {
|
if(p->debug && msg_num > 0) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0, mp = p->mlp; i < p->msg_count; i++, mp++)
|
for (i = 0, mp = p->mlp; i < p->msg_count; i++, mp++)
|
||||||
|
#ifdef UIDL
|
||||||
|
pop_log(p,POP_DEBUG,
|
||||||
|
"Msg %d at offset %d is %d octets long and has %u lines and id %s.",
|
||||||
|
mp->number,mp->offset,mp->length,mp->lines, mp->msg_id);
|
||||||
|
#else
|
||||||
pop_log(p,POP_DEBUG,
|
pop_log(p,POP_DEBUG,
|
||||||
"Msg %d at offset %d is %d octets long and has %u lines.",
|
"Msg %d at offset %d is %d octets long and has %u lines.",
|
||||||
mp->number,mp->offset,mp->length,mp->lines);
|
mp->number,mp->offset,mp->length,mp->lines);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
@@ -34,6 +34,9 @@ static state_table states[] = {
|
|||||||
trans, "last", 0, 0, pop_last, {trans, trans},
|
trans, "last", 0, 0, pop_last, {trans, trans},
|
||||||
trans, "xtnd", 1, 99, pop_xtnd, {trans, trans},
|
trans, "xtnd", 1, 99, pop_xtnd, {trans, trans},
|
||||||
trans, "quit", 0, 0, pop_updt, {halt, halt},
|
trans, "quit", 0, 0, pop_updt, {halt, halt},
|
||||||
|
#ifdef UIDL
|
||||||
|
trans, "uidl", 0, 1, pop_uidl, {trans, trans},
|
||||||
|
#endif
|
||||||
(state) 0, NULL, 0, 0, NULL, {halt, halt},
|
(state) 0, NULL, 0, 0, NULL, {halt, halt},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
54
appl/popper/pop_uidl.c
Normal file
54
appl/popper/pop_uidl.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include <popper.h>
|
||||||
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
#ifdef UIDL
|
||||||
|
/*
|
||||||
|
* uidl: Uidl the contents of a POP maildrop
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
pop_uidl (POP *p)
|
||||||
|
{
|
||||||
|
MsgInfoList * mp; /* Pointer to message info list */
|
||||||
|
register int i;
|
||||||
|
register int msg_num;
|
||||||
|
|
||||||
|
/* Was a message number provided? */
|
||||||
|
if (p->parm_count > 0) {
|
||||||
|
msg_num = atoi(p->pop_parm[1]);
|
||||||
|
|
||||||
|
/* Is requested message out of range? */
|
||||||
|
if ((msg_num < 1) || (msg_num > p->msg_count))
|
||||||
|
return (pop_msg (p,POP_FAILURE,
|
||||||
|
"Message %d does not exist.",msg_num));
|
||||||
|
|
||||||
|
/* Get a pointer to the message in the message list */
|
||||||
|
mp = &p->mlp[msg_num-1];
|
||||||
|
|
||||||
|
/* Is the message already flagged for deletion? */
|
||||||
|
if (mp->del_flag)
|
||||||
|
return (pop_msg (p,POP_FAILURE,
|
||||||
|
"Message %d has been deleted.",msg_num));
|
||||||
|
|
||||||
|
/* Display message information */
|
||||||
|
return (pop_msg(p,POP_SUCCESS,"%u %s",msg_num,mp->msg_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display the entire list of messages */
|
||||||
|
pop_msg(p,POP_SUCCESS,
|
||||||
|
"%u messages (%u octets)",
|
||||||
|
p->msg_count-p->msgs_deleted,p->drop_size-p->bytes_deleted);
|
||||||
|
|
||||||
|
/* Loop through the message information list. Skip deleted messages */
|
||||||
|
for (i = p->msg_count, mp = p->mlp; i > 0; i--, mp++) {
|
||||||
|
if (!mp->del_flag)
|
||||||
|
(void)fprintf(p->output,"%u %s\r\n",mp->number,mp->msg_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "." signals the end of a multi-line transmission */
|
||||||
|
(void)fprintf(p->output,".\r\n");
|
||||||
|
(void)fflush(p->output);
|
||||||
|
|
||||||
|
return(POP_SUCCESS);
|
||||||
|
}
|
||||||
|
#endif /* UIDL */
|
@@ -209,6 +209,9 @@ typedef struct { /* Message information */
|
|||||||
is marked for deletion */
|
is marked for deletion */
|
||||||
int retr_flag; /* Flag indicating if message
|
int retr_flag; /* Flag indicating if message
|
||||||
was retrieved */
|
was retrieved */
|
||||||
|
#ifdef UIDL
|
||||||
|
char *msg_id;
|
||||||
|
#endif
|
||||||
} MsgInfoList;
|
} MsgInfoList;
|
||||||
|
|
||||||
typedef struct { /* POP parameter block */
|
typedef struct { /* POP parameter block */
|
||||||
@@ -267,6 +270,9 @@ int pop_updt(POP *p);
|
|||||||
int pop_user(POP *p);
|
int pop_user(POP *p);
|
||||||
int pop_xmit(POP *p);
|
int pop_xmit(POP *p);
|
||||||
int pop_xtnd(POP *p);
|
int pop_xtnd(POP *p);
|
||||||
|
#ifdef UIDL
|
||||||
|
int pop_uidl(POP *p);
|
||||||
|
#endif
|
||||||
state_table *pop_get_command(POP *p, char *mp);
|
state_table *pop_get_command(POP *p, char *mp);
|
||||||
void pop_lower(char *buf);
|
void pop_lower(char *buf);
|
||||||
xtnd_table *pop_get_subcommand(POP *p);
|
xtnd_table *pop_get_subcommand(POP *p);
|
||||||
|
Reference in New Issue
Block a user