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

Defined functions

pop_dropinfo defined in line 25; used 1 times

Defined variables

SccsId defined in line 9; never used
copyright defined in line 8; never used
Last modified: 1996-03-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3194
Valid CSS Valid XHTML 1.0 Strict