# 2.11BSD#431 - /usr/src/libexec/popper/pop_send.c

##### Functions

    pop_send          X
    pop_sendline      X

       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: #ifndef lint
       8: static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
       9: static char SccsId[] = "@(#)@(#)pop_send.c	2.1  2.1 3/18/91";
      10: #endif not lint
      11:
      12: #include <stdio.h>
      13: #include <sys/types.h>
      14: #include <strings.h>
      15: #include "popper.h"
      16:
      17: /*
      18:  *  send:   Send the header and a specified number of lines
      19:  *          from a mail message to a POP client.
      20:  */
      21:
      22: pop_send(p)
      23: POP     *   p;
      24: {
      25:     MsgInfoList         *   mp;         /*  Pointer to message info list */
      26:     register int            msg_num;
      27:     register int            msg_lines;
      28:     char                    buffer[MAXMSGLINELEN];
      29:
      30:     /*  Convert the first parameter into an integer */
      31:     msg_num = atoi(p->pop_parm[1]);
      32:
      33:     /*  Is requested message out of range? */
      34:     if ((msg_num < 1) || (msg_num > p->msg_count))
      35:         return (pop_msg (p,POP_FAILURE,"Message %u does not exist.",msg_num));
      36:
      37:     /*  Get a pointer to the message in the message list */
      38:     mp = &p->mlp[msg_num-1];
      39:
      40:     /*  Is the message flagged for deletion? */
      41:     if (mp->del_flag)
      42:         return (pop_msg (p,POP_FAILURE,
      43:             "Message %u has been deleted.",msg_num));
      44:
      45:     /*  If this is a TOP command, get the number of lines to send */
      46:     if (strcmp(p->pop_command,"top") == 0) {
      47:         /*  Convert the second parameter into an integer */
      48:         msg_lines = atoi(p->pop_parm[2]);
      49:     }
      50:     else {
      51:         /*  Assume that a RETR (retrieve) command was issued */
      52:         msg_lines = -1;
      53:         /*  Flag the message as retreived */
      54:         mp->retr_flag = TRUE;
      55:     }
      56:
      57:     /*  Display the number of bytes in the message */
      58:     pop_msg(p,POP_SUCCESS,"%ld octets",mp->length);
      59:
      60:     /*  Position to the start of the message */
      61:     (void)fseek(p->drop,mp->offset,0);
      62:
      63:     /*  Skip the first line (the sendmail "From" line) */
      64:     (void)fgets (buffer,MAXMSGLINELEN,p->drop);
      65:
      66:     /*  Send the header of the message followed by a blank line */
      67:     while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
      68:         pop_sendline (p,buffer);
      69:         /*  A single newline (blank line) signals the
      70:             end of the header.  sendline() converts this to a NULL,
      71:             so that's what we look for. */
      72:         if (*buffer == 0) break;
      73:     }
      74:     /*  Send the message body */
      75:     while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
      76:         /*  Look for the start of the next message */
      77:         if (strncmp(buffer,"From ",5) == 0) break;
      78:         /*  Decrement the lines sent (for a TOP command) */
      79:         if (msg_lines >= 0 && msg_lines-- == 0) break;
      80:         pop_sendline(p,buffer);
      81:     }
      82:     /*  "." signals the end of a multi-line transmission */
      83:     (void)fputs(".\r\n",p->output);
      84:     (void)fflush(p->output);
      85:
      86:     return(POP_SUCCESS);
      87: }
      88:
      89: /*
      90:  *  sendline:   Send a line of a multi-line response to a client.
      91:  */
      92: pop_sendline(p,buffer)
      93: POP         *   p;
      94: char        *   buffer;
      95: {
      96:     char        *   bp;
      97:
      98:     /*  Byte stuff lines that begin with the temirnation octet */
      99:     if (*buffer == POP_TERMINATE) (void)fputc(POP_TERMINATE,p->output);
     100:
     101:     /*  Look for a <NL> in the buffer */
     102:     if (bp = index(buffer,NEWLINE)) *bp = 0;
     103:
     104:     /*  Send the line to the client */
     105:     (void)fputs(buffer,p->output);
     106:
     107: #ifdef DEBUG
     108:     if(p->debug)pop_log(p,POP_DEBUG,"Sending line \"%s\"",buffer);
     109: #endif DEBUG
     110:
     111:     /*  Put a <CR><NL> if a newline was removed from the buffer */
     112:     if (bp) (void)fputs ("\r\n",p->output);
     113: }

#### Defined functions

pop_send defined in line 22; used 1 times

- in /usr/src/libexec/popper/popper.h line 165

pop_sendline defined in line 92; used 2 times

- in line 68, 80

#### Defined variables

SccsId defined in line 9; never used
copyright defined in line 8; never used

Last modified: 1992-06-25 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1193 |