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_xmit.c	2.1  2.1 3/18/91";
  10: #endif not lint
  11: 
  12: #include <stdio.h>
  13: #include <sys/types.h>
  14: #include <sys/file.h>
  15: #include <sys/wait.h>
  16: #include "popper.h"
  17: 
  18: /*
  19:  *  xmit:   POP XTND function to receive a message from
  20:  *          a client and send it in the mail
  21:  */
  22: 
  23: pop_xmit (p)
  24: POP     *   p;
  25: {
  26:     FILE                *   tmp;                    /*  File descriptor for
  27:                                                         temporary file */
  28:     char                    buffer[MAXLINELEN];     /*  Read buffer */
  29:     char                    temp_xmit[MAXDROPLEN];  /*  Name of the temporary
  30:                                                         filedrop */
  31:     union   wait            stat;
  32:     int                     id, pid;
  33: 
  34:     /*  Create a temporary file into which to copy the user's message */
  35:     (void)mktemp((char *)strcpy(temp_xmit,POP_TMPXMIT));
  36: #ifdef DEBUG
  37:     if(p->debug)
  38:         pop_log(p,POP_DEBUG,
  39:             "Creating temporary file for sending a mail message \"%s\"\n",
  40:                 temp_xmit);
  41: #endif DEBUG
  42:     if ((tmp = fopen(temp_xmit,"w+")) == NULL)
  43:         return (pop_msg(p,POP_FAILURE,
  44:             "Unable to create temporary message file \"%s\", errno = %d",
  45:                 temp_xmit,errno));
  46: 
  47:     /*  Tell the client to start sending the message */
  48:     pop_msg(p,POP_SUCCESS,"Start sending the message.");
  49: 
  50:     /*  Receive the message */
  51: #ifdef DEBUG
  52:     if(p->debug)pop_log(p,POP_DEBUG,"Receiving mail message");
  53: #endif DEBUG
  54:     while (fgets(buffer,MAXLINELEN,p->input)){
  55:         /*  Look for initial period */
  56: #ifdef DEBUG
  57:         if(p->debug)pop_log(p,POP_DEBUG,"Receiving: \"%s\"",buffer);
  58: #endif DEBUG
  59:         if (*buffer == '.') {
  60:             /*  Exit on end of message */
  61:             if (strcmp(buffer,".\r\n") == 0) break;
  62:         }
  63:         (void)fputs (buffer,tmp);
  64:     }
  65:     (void)fclose (tmp);
  66: 
  67: #ifdef DEBUG
  68:     if(p->debug)pop_log(p,POP_DEBUG,"Forking for \"%s\"",MAIL_COMMAND);
  69: #endif DEBUG
  70:     /*  Send the message */
  71:     switch (pid = fork()) {
  72:         case 0:
  73:             (void)fclose (p->input);
  74:             (void)fclose (p->output);
  75:             (void)close(0);
  76:             if (open(temp_xmit,O_RDONLY,0) < 0) (void)_exit(1);
  77:             (void)execl (MAIL_COMMAND,"send-mail","-t","-oem",NULLCP);
  78:             (void)_exit(1);
  79:         case -1:
  80: #ifdef DEBUG
  81:             if (!p->debug) (void)unlink (temp_xmit);
  82: #endif DEBUG
  83:             return (pop_msg(p,POP_FAILURE,
  84:                 "Unable to execute \"%s\"",MAIL_COMMAND));
  85:         default:
  86:             while((id = wait(&stat)) >=0 && id != pid);
  87:             if (!p->debug) (void)unlink (temp_xmit);
  88:             if (stat.w_retcode)
  89:                 return (pop_msg(p,POP_FAILURE,"Unable to send message"));
  90:             return (pop_msg (p,POP_SUCCESS,"Message sent successfully"));
  91:     }
  92: 
  93: }

Defined functions

pop_xmit defined in line 23; used 1 times

Defined variables

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