masqmail
view src/smtpsend.c @ 426:d48d3622b64f
Updated AUTHORS and THANKS files.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 30 May 2012 11:49:40 +0200 |
parents | fc1c6425c024 |
children |
line source
1 /*
2 ** MasqMail
3 ** Copyright (C) 1999 Oliver Kurth
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
20 #include <stdio.h>
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
26 #include <glib.h>
28 #include "masqmail.h"
29 #include "smtp_out.h"
31 masqmail_conf conf;
33 extern char *optarg;
34 extern int optind, opterr, optopt;
36 void
37 logwrite(int pri, const char *fmt, ...)
38 {
39 va_list args;
40 va_start(args, fmt);
42 vfprintf(stdout, fmt, args);
44 va_end(args);
45 }
47 void
48 debugf(const char *fmt, ...)
49 {
50 va_list args;
51 va_start(args, fmt);
53 vfprintf(stdout, fmt, args);
55 va_end(args);
56 }
58 int
59 main(int argc, char *argv[])
60 {
61 gchar *helo_name = g_malloc(64);
62 gchar *server_name = g_strdup("localhost");
63 gint server_port = 25;
64 GList *resolve_list = g_list_append(NULL, resolve_byname);
66 gethostname(helo_name, 63);
68 conf.host_name = g_strdup(helo_name);
70 while (1) {
71 int c;
72 c = getopt(argc, argv, "d:p:s:H:");
73 if (c == -1)
74 break;
75 switch (c) {
76 case 'd':
77 conf.debug_level = atoi(optarg);
78 break;
79 case 'p':
80 server_port = atoi(optarg);
81 break;
82 case 's':
83 g_free(server_name);
84 server_name = g_strdup(optarg);
85 break;
86 case 'H':
87 g_free(helo_name);
88 helo_name = g_strdup(optarg);
89 break;
90 default:
91 break;
92 }
93 }
95 if (optind < argc) {
96 gint ret;
97 message *msg = create_message();
99 while (optind < argc) {
100 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(argv[optind++], TRUE, conf.host_name));
101 }
103 if ((ret = accept_message(stdin, msg, ACC_DOT_IGNORE)) == AERR_OK) {
104 if ((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok) {
105 exit(0);
106 }
107 fprintf(stderr, "deliver failed: %d\n", ret);
108 }
109 fprintf(stderr, "accept failed: %d\n", ret);
110 exit(ret);
111 } else {
112 fprintf(stderr, "no recipients given.\n");
113 exit(-1);
114 }
115 }