masqmail-0.2

annotate src/smtpsend.c @ 5:3cafdebd1479

removed remaining reference to docs in Makefile
author meillo@marmaro.de
date Fri, 26 Sep 2008 22:15:26 +0200
parents
children 26e34ae9a3e3
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@0 35 void logwrite(int pri, const char *fmt, ...)
meillo@0 36 {
meillo@0 37 va_list args;
meillo@0 38 va_start(args, fmt);
meillo@0 39
meillo@0 40 vfprintf(stdout, fmt, args);
meillo@0 41
meillo@0 42 va_end(args);
meillo@0 43 }
meillo@0 44
meillo@0 45 void debugf(const char *fmt, ...)
meillo@0 46 {
meillo@0 47 va_list args;
meillo@0 48 va_start(args, fmt);
meillo@0 49
meillo@0 50 vfprintf(stdout, fmt, args);
meillo@0 51
meillo@0 52 va_end(args);
meillo@0 53 }
meillo@0 54
meillo@0 55 int
meillo@0 56 main(int argc, char *argv[])
meillo@0 57 {
meillo@0 58 gchar *helo_name = g_malloc(64);
meillo@0 59 gchar *server_name = g_strdup("localhost");
meillo@0 60 gint server_port = 25;
meillo@0 61 GList *resolve_list = g_list_append(NULL, resolve_byname);
meillo@0 62
meillo@0 63 gethostname(helo_name, 63);
meillo@0 64
meillo@0 65 conf.host_name = g_strdup(helo_name);
meillo@0 66
meillo@0 67 while(1){
meillo@0 68 int c;
meillo@0 69 c = getopt(argc, argv, "d:p:s:H:");
meillo@0 70 if(c == -1)
meillo@0 71 break;
meillo@0 72 switch(c){
meillo@0 73 case 'd':
meillo@0 74 conf.debug_level = atoi(optarg);
meillo@0 75 break;
meillo@0 76 case 'p':
meillo@0 77 server_port = atoi(optarg);
meillo@0 78 break;
meillo@0 79 case 's':
meillo@0 80 g_free(server_name);
meillo@0 81 server_name = g_strdup(optarg);
meillo@0 82 break;
meillo@0 83 case 'H':
meillo@0 84 g_free(helo_name);
meillo@0 85 helo_name = g_strdup(optarg);
meillo@0 86 break;
meillo@0 87 default:
meillo@0 88 break;
meillo@0 89 }
meillo@0 90 }
meillo@0 91
meillo@0 92 if (optind < argc){
meillo@0 93 gint ret;
meillo@0 94 message *msg = create_message();
meillo@0 95
meillo@0 96 while (optind < argc){
meillo@0 97 msg->rcpt_list =
meillo@0 98 g_list_append(msg->rcpt_list,
meillo@0 99 create_address_qualified(argv[optind++], TRUE, conf.host_name));
meillo@0 100 }
meillo@0 101
meillo@0 102 if((ret = accept_message(stdin, msg, ACC_NODOT_TERM|ACC_HEAD_FROM_RCPT)) == AERR_OK){
meillo@0 103 if((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok){
meillo@0 104 exit(EXIT_SUCCESS);
meillo@0 105 }
meillo@0 106 fprintf(stderr, "deliver failed: %d\n", ret);
meillo@0 107 }
meillo@0 108 fprintf(stderr, "accept failed: %d\n", ret);
meillo@0 109 exit(ret);
meillo@0 110 }else{
meillo@0 111 fprintf(stderr, "no recipients given.\n");
meillo@0 112 exit(-1);
meillo@0 113 }
meillo@0 114 }