masqmail-0.2

annotate src/smtpsend.c @ 189:bdd343cc4e19

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