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