masqmail

annotate src/smtpsend.c @ 411:9b93c0a3bd8c

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