From d8d5b71961da0655289c9a563598f9ceea0f7910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Groenvall?= Date: Wed, 2 Oct 1996 19:55:18 +0000 Subject: [PATCH] Add experimental UIDL support in popper. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@824 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/popper/Makefile.in | 4 +-- appl/popper/pop_dropinfo.c | 66 ++++++++++++++++++++++++++++++++++- appl/popper/pop_get_command.c | 3 ++ appl/popper/pop_uidl.c | 54 ++++++++++++++++++++++++++++ appl/popper/popper.h | 6 ++++ 5 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 appl/popper/pop_uidl.c diff --git a/appl/popper/Makefile.in b/appl/popper/Makefile.in index e0d5cd523..8dd125cb4 100644 --- a/appl/popper/Makefile.in +++ b/appl/popper/Makefile.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_msg.c pop_parse.c pop_pass.c pop_quit.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 \ pop_get_command.o pop_get_subcommand.o pop_init.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_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) diff --git a/appl/popper/pop_dropinfo.c b/appl/popper/pop_dropinfo.c index 27117e11b..4bcd32d0a 100644 --- a/appl/popper/pop_dropinfo.c +++ b/appl/popper/pop_dropinfo.c @@ -12,6 +12,44 @@ static char SccsId[] = "@(#)@(#)pop_dropinfo.c 2.1 2.1 3/18/91"; #include 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 * it for use by the other POP routines. @@ -26,7 +64,15 @@ pop_dropinfo(POP *p) register int msg_num; /* Current message counter */ 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 */ p->msg_count = 0; p->msgs_deleted = 0; @@ -81,11 +127,23 @@ pop_dropinfo(POP *p) mp->offset = ftell(p->drop) - nchar; mp->del_flag = FALSE; mp->retr_flag = FALSE; +#ifdef UIDL + mp->msg_id = 0; + msg_idp = &mp->msg_id; +#endif #ifdef DEBUG if(p->debug) pop_log(p,POP_DEBUG, "Msg %d being added to list", mp->number); #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; p->drop_size += nchar; mp->lines++; @@ -96,9 +154,15 @@ pop_dropinfo(POP *p) if(p->debug && msg_num > 0) { int i; 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, "Msg %d at offset %d is %d octets long and has %u lines.", mp->number,mp->offset,mp->length,mp->lines); +#endif } #endif /* DEBUG */ diff --git a/appl/popper/pop_get_command.c b/appl/popper/pop_get_command.c index 4de761f15..c32dcb846 100644 --- a/appl/popper/pop_get_command.c +++ b/appl/popper/pop_get_command.c @@ -34,6 +34,9 @@ static state_table states[] = { trans, "last", 0, 0, pop_last, {trans, trans}, trans, "xtnd", 1, 99, pop_xtnd, {trans, trans}, 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}, }; diff --git a/appl/popper/pop_uidl.c b/appl/popper/pop_uidl.c new file mode 100644 index 000000000..15bc03b57 --- /dev/null +++ b/appl/popper/pop_uidl.c @@ -0,0 +1,54 @@ +#include +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 */ diff --git a/appl/popper/popper.h b/appl/popper/popper.h index d9afdf97d..f4ad80a2f 100644 --- a/appl/popper/popper.h +++ b/appl/popper/popper.h @@ -209,6 +209,9 @@ typedef struct { /* Message information */ is marked for deletion */ int retr_flag; /* Flag indicating if message was retrieved */ +#ifdef UIDL + char *msg_id; +#endif } MsgInfoList; typedef struct { /* POP parameter block */ @@ -267,6 +270,9 @@ int pop_updt(POP *p); int pop_user(POP *p); int pop_xmit(POP *p); int pop_xtnd(POP *p); +#ifdef UIDL +int pop_uidl(POP *p); +#endif state_table *pop_get_command(POP *p, char *mp); void pop_lower(char *buf); xtnd_table *pop_get_subcommand(POP *p);