59 |
#include <netinet/in.h> |
#include <netinet/in.h> |
60 |
#include <mu_asprintf.h> |
#include <mu_asprintf.h> |
61 |
#include <mailutils/argcv.h> |
#include <mailutils/argcv.h> |
|
#include <mailutils/argp.h> |
|
62 |
#include <mailutils/mailutils.h> |
#include <mailutils/mailutils.h> |
63 |
|
|
64 |
FILE *diag = NULL; /* diagnostic output */ |
FILE *diag = NULL; /* diagnostic output */ |
70 |
|
|
71 |
header_t header; |
header_t header; |
72 |
address_t recipients = NULL; |
address_t recipients = NULL; |
73 |
|
char *progname; |
74 |
|
|
75 |
int mta_stdin __P((int argc, char **argv)); |
int mta_stdin __P((int argc, char **argv)); |
76 |
int mta_smtp __P((int argc, char **argv)); |
int mta_smtp __P((int argc, char **argv)); |
82 |
int c, status; |
int c, status; |
83 |
char *domain; |
char *domain; |
84 |
|
|
85 |
|
progname = strrchr (argv[0], '/'); |
86 |
|
if (!progname) |
87 |
|
progname = argv[0]; |
88 |
|
|
89 |
while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF) |
while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF) |
90 |
{ |
{ |
91 |
switch (c) |
switch (c) |
141 |
if (!diag) |
if (!diag) |
142 |
{ |
{ |
143 |
mu_error ("%s: can't open diagnostic output: %s", |
mu_error ("%s: can't open diagnostic output: %s", |
144 |
program_invocation_short_name, name); |
progname, name); |
145 |
return 1; |
return 1; |
146 |
} |
} |
147 |
} |
} |
157 |
if ((status = header_create (&header, NULL, 0, NULL)) != 0) |
if ((status = header_create (&header, NULL, 0, NULL)) != 0) |
158 |
{ |
{ |
159 |
mu_error ("%s: can't create header: %s", |
mu_error ("%s: can't create header: %s", |
160 |
program_invocation_short_name, mu_errstring (status)); |
progname, mu_errstring (status)); |
161 |
return 1; |
return 1; |
162 |
} |
} |
163 |
|
|
195 |
|
|
196 |
if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) |
if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) |
197 |
{ |
{ |
198 |
mu_error ("%s: unable to open temporary file", |
mu_error ("%s: unable to open temporary file", progname); |
|
program_invocation_short_name); |
|
199 |
exit (1); |
exit (1); |
200 |
} |
} |
201 |
|
|
224 |
} |
} |
225 |
else |
else |
226 |
{ |
{ |
227 |
mu_error ("%s: can't determine sender address", |
mu_error ("%s: can't determine sender address", progname); |
|
program_invocation_short_name); |
|
228 |
exit (1); |
exit (1); |
229 |
} |
} |
230 |
} |
} |
238 |
|
|
239 |
if (fputs (buf, fp) == EOF) |
if (fputs (buf, fp) == EOF) |
240 |
{ |
{ |
241 |
mu_error ("%s: temporary file write error", |
mu_error ("%s: temporary file write error", progname); |
|
program_invocation_short_name); |
|
242 |
fclose (fp); |
fclose (fp); |
243 |
exit (1); |
exit (1); |
244 |
} |
} |
298 |
if (c) |
if (c) |
299 |
{ |
{ |
300 |
mu_error ("%s: address_to_string failure: %s", |
mu_error ("%s: address_to_string failure: %s", |
301 |
program_invocation_short_name, mu_errstring (c)); |
progname, mu_errstring (c)); |
302 |
return 1; |
return 1; |
303 |
} |
} |
304 |
value = malloc (n + 1); |
value = malloc (n + 1); |
305 |
if (!value) |
if (!value) |
306 |
{ |
{ |
307 |
mu_error ("%s: not enough memory", program_invocation_short_name); |
mu_error ("%s: not enough memory", progname); |
308 |
return 1; |
return 1; |
309 |
} |
} |
310 |
|
|
362 |
{ |
{ |
363 |
if (add_recipient (value)) |
if (add_recipient (value)) |
364 |
{ |
{ |
365 |
mu_error ("%s: bad address %s", |
mu_error ("%s: bad address %s", progname, value); |
|
program_invocation_short_name, value); |
|
366 |
return 1; |
return 1; |
367 |
} |
} |
368 |
free (value); |
free (value); |
372 |
{ |
{ |
373 |
if (add_recipient (value)) |
if (add_recipient (value)) |
374 |
{ |
{ |
375 |
mu_error ("%s: bad address %s", |
mu_error ("%s: bad address %s", progname, value); |
|
program_invocation_short_name, value); |
|
376 |
return 1; |
return 1; |
377 |
} |
} |
378 |
free (value); |
free (value); |
382 |
{ |
{ |
383 |
if (add_recipient (value)) |
if (add_recipient (value)) |
384 |
{ |
{ |
385 |
mu_error ("%s: bad address %s: %s", |
mu_error ("%s: bad address %s: %s", progname, value); |
|
program_invocation_short_name, value); |
|
386 |
return 1; |
return 1; |
387 |
} |
} |
388 |
free (value); |
free (value); |
399 |
if (c) |
if (c) |
400 |
{ |
{ |
401 |
mu_error ("%s: address_to_string failure: %s", |
mu_error ("%s: address_to_string failure: %s", |
402 |
program_invocation_short_name, mu_errstring (c)); |
progname, mu_errstring (c)); |
403 |
return 1; |
return 1; |
404 |
} |
} |
405 |
value = malloc (n + 1); |
value = malloc (n + 1); |
406 |
if (!value) |
if (!value) |
407 |
{ |
{ |
408 |
mu_error ("%s: not enough memory", |
mu_error ("%s: not enough memory", progname); |
|
program_invocation_short_name); |
|
409 |
return 1; |
return 1; |
410 |
} |
} |
411 |
|
|
428 |
{ |
{ |
429 |
if (add_recipient (argv[c])) |
if (add_recipient (argv[c])) |
430 |
{ |
{ |
431 |
mu_error ("%s: bad address %s", |
mu_error ("%s: bad address %s", progname, argv[c]); |
|
program_invocation_short_name, argv[c]); |
|
432 |
return 1; |
return 1; |
433 |
} |
} |
434 |
} |
} |
437 |
if ((c = mailbox_create_default (&mbox, tempfile)) != 0) |
if ((c = mailbox_create_default (&mbox, tempfile)) != 0) |
438 |
{ |
{ |
439 |
mu_error ("%s: can't create mailbox %s: %s", |
mu_error ("%s: can't create mailbox %s: %s", |
440 |
program_invocation_short_name, tempfile, mu_errstring (c)); |
progname, tempfile, mu_errstring (c)); |
441 |
unlink (tempfile); |
unlink (tempfile); |
442 |
return 1; |
return 1; |
443 |
} |
} |
445 |
if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) |
if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) |
446 |
{ |
{ |
447 |
mu_error ("%s: can't open mailbox %s: %s", |
mu_error ("%s: can't open mailbox %s: %s", |
448 |
program_invocation_short_name, tempfile, mu_errstring (c)); |
progname, tempfile, mu_errstring (c)); |
449 |
unlink (tempfile); |
unlink (tempfile); |
450 |
return 1; |
return 1; |
451 |
} |
} |
456 |
|
|
457 |
if (!recipients) |
if (!recipients) |
458 |
{ |
{ |
459 |
mu_error ("%s: Recipient names must be specified", |
mu_error ("%s: Recipient names must be specified", progname); |
|
program_invocation_short_name); |
|
460 |
return 1; |
return 1; |
461 |
} |
} |
462 |
|
|
649 |
if ((c = mailbox_create_default (&mbox, tempfile)) != 0) |
if ((c = mailbox_create_default (&mbox, tempfile)) != 0) |
650 |
{ |
{ |
651 |
mu_error ("%s: can't create mailbox %s: %s", |
mu_error ("%s: can't create mailbox %s: %s", |
652 |
program_invocation_short_name, |
progname, |
653 |
tempfile, mu_errstring (c)); |
tempfile, mu_errstring (c)); |
654 |
unlink (tempfile); |
unlink (tempfile); |
655 |
exit (1); |
exit (1); |
658 |
if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) |
if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) |
659 |
{ |
{ |
660 |
mu_error ("%s: can't open mailbox %s: %s", |
mu_error ("%s: can't open mailbox %s: %s", |
661 |
program_invocation_short_name, |
progname, |
662 |
tempfile, mu_errstring (c)); |
tempfile, mu_errstring (c)); |
663 |
unlink (tempfile); |
unlink (tempfile); |
664 |
exit (1); |
exit (1); |
701 |
fd = socket (PF_INET, SOCK_STREAM, 0); |
fd = socket (PF_INET, SOCK_STREAM, 0); |
702 |
if (fd < 0) |
if (fd < 0) |
703 |
{ |
{ |
704 |
mu_error ("%s: socket: %s", program_invocation_short_name, |
mu_error ("%s: socket: %s", progname, strerror (errno)); |
|
strerror (errno)); |
|
705 |
return 1; |
return 1; |
706 |
} |
} |
707 |
|
|
717 |
if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0) |
if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0) |
718 |
{ |
{ |
719 |
close (fd); |
close (fd); |
720 |
mu_error ("%s: bind: %s", program_invocation_short_name, |
mu_error ("%s: bind: %s", progname, strerror(errno)); |
|
strerror(errno)); |
|
721 |
return 1; |
return 1; |
722 |
} |
} |
723 |
} |
} |
731 |
if (++port >= 65535) |
if (++port >= 65535) |
732 |
{ |
{ |
733 |
mu_error ("%s: can't bind socket: all ports in use?", |
mu_error ("%s: can't bind socket: all ports in use?", |
734 |
program_invocation_short_name); |
progname); |
735 |
return 1; |
return 1; |
736 |
} |
} |
737 |
address.sin_port = htons (port); |
address.sin_port = htons (port); |
757 |
{ |
{ |
758 |
if (errno == EINTR) |
if (errno == EINTR) |
759 |
continue; |
continue; |
760 |
mu_error ("%s: select: %s", program_invocation_short_name, |
mu_error ("%s: select: %s", progname, strerror (errno)); |
|
strerror (errno)); |
|
761 |
return 1; |
return 1; |
762 |
} |
} |
763 |
|
|
764 |
len = sizeof (his_addr); |
len = sizeof (his_addr); |
765 |
if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0) |
if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0) |
766 |
{ |
{ |
767 |
mu_error ("%s: accept: %s", program_invocation_short_name, |
mu_error ("%s: accept: %s", progname, strerror (errno)); |
|
strerror (errno)); |
|
768 |
return 1; |
return 1; |
769 |
} |
} |
770 |
|
|