1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* Copyright (c) 1989 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* Copyright (c) 1997 by Qualcomm Incorporated.
*/
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
#ifdef POPSCO
# define __SCO_WAIT3__
# include <fcntl.h>
#endif
#include <sys/wait.h>
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <popper.h>
/*
* xmit: POP XTND function to receive a message from
* a client and send it in the mail
*/
FILE *tmp; /* File descriptor for temporary file */
char temp_xmit[MAXDROPLEN]; /* Name of the temporary filedrop */
pop_xmit (p)
POP * p;
{
int tfn;
/* Create a temporary file into which to copy the user's message */
strncpy(temp_xmit, POP_TMPXMIT, sizeof(temp_xmit));
#ifdef DEBUG
if(p->debug)
pop_log(p,POP_DEBUG,
"Creating temporary file for sending a mail message \"%s\"",
temp_xmit);
#endif
if (((tfn=mkstemp(temp_xmit)) == -1) ||
((tmp=fdopen(tfn, "w+")) == NULL)) { /* failure, bail out */
return (pop_msg(p,POP_FAILURE,
"Unable to create temporary message file \"%s\", errno = %d",
temp_xmit, errno));
}
/* Receive the message */
#ifdef DEBUG
if(p->debug)pop_log(p,POP_DEBUG,"Receiving mail message");
#endif
p->xmitting = 1;
return(pop_msg(p,POP_SUCCESS,"Start sending message."));
}
pop_xmit_recv(p,buffer)
POP *p;
char *buffer;
{
/* Look for initial period */
#ifdef DEBUG
if(p->debug)pop_log(p,POP_DEBUG,"Receiving: \"%.1000s\"",buffer);
#endif
if (*buffer == '.') {
/* Exit on end of message */
if (strcmp(buffer,".\r\n") == 0) {
(void) fclose(tmp);
p->xmitting = 0;
pop_xmit_exec(p);
}
/* sendmail will not remove escaped .. */
else if (buffer[1] == '.') (void)fputs (&buffer[1], tmp);
else (void)fputs (buffer, tmp);
} else (void)fputs (buffer, tmp);
}
pop_xmit_exec(p)
POP *p;
{
#ifdef NeXT
union wait stat;
#else
int stat;
#endif
PID_T id, pid;
#ifdef DEBUG
if(p->debug)pop_log(p,POP_DEBUG,"Forking for \"%s\"",MAIL_COMMAND);
#endif
/* Send the message */
switch (pid = fork()) {
case 0:
/* Open the log file */
(void)closelog();
#ifdef SYSLOG42
(void)openlog(p->myname,0);
#else
(void)openlog(p->myname,LOG_PID,POP_FACILITY);
#endif
pop_log(p, POP_DEBUG,
"Pop transmit from \"%s\" on \"%s\"", p->user, p->client);
(void)fclose (p->input);
(void)fclose (p->output);
(void)close(0);
if (open(temp_xmit,O_RDONLY,0) < 0)
(void)_exit(1);
(void)execl (MAIL_COMMAND,"send-mail","-t","-i","-oem",NULLCP);
(void)_exit(1);
case -1:
if (!p->debug) (void)unlink (temp_xmit);
return (pop_msg(p,POP_FAILURE, "Unable to execute \"%s\" (%d)",
MAIL_COMMAND, errno));
default:
#ifdef NeXT
while((id = wait(&stat)) >=0 && id != pid);
#else
id = waitpid(pid, &stat, 0);
#endif
if (!p->debug) (void)unlink (temp_xmit);
#ifdef NeXT
if (!WIFEXITED (stat))
#else
if ((!WIFEXITED (stat)) || (WEXITSTATUS (stat) != 0))
#endif
return (pop_msg(p,POP_FAILURE,"Unable to send message"));
return (pop_msg (p,POP_SUCCESS,"Message sent successfully"));
}
}
pop_xmit_clean(p)
POP *p;
{
fclose(tmp);
if (!p->debug) (void)unlink (temp_xmit);
}
|