masqmail-0.2

diff src/smtpsend.c @ 0:08114f7dcc23

this is masqmail-0.2.21 from oliver kurth
author meillo@marmaro.de
date Fri, 26 Sep 2008 17:05:23 +0200
parents
children 26e34ae9a3e3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/smtpsend.c	Fri Sep 26 17:05:23 2008 +0200
     1.3 @@ -0,0 +1,114 @@
     1.4 +/*  MasqMail
     1.5 +    Copyright (C) 1999 Oliver Kurth
     1.6 +
     1.7 +    This program is free software; you can redistribute it and/or modify
     1.8 +    it under the terms of the GNU General Public License as published by
     1.9 +    the Free Software Foundation; either version 2 of the License, or
    1.10 +    (at your option) any later version.
    1.11 +
    1.12 +    This program is distributed in the hope that it will be useful,
    1.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 +    GNU General Public License for more details.
    1.16 +
    1.17 +    You should have received a copy of the GNU General Public License
    1.18 +    along with this program; if not, write to the Free Software
    1.19 +    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1.20 +*/
    1.21 +
    1.22 +#include <stdio.h>
    1.23 +#include <errno.h>
    1.24 +#include <stdlib.h>
    1.25 +#include <string.h>
    1.26 +#include <unistd.h>
    1.27 +
    1.28 +#include <glib.h>
    1.29 +
    1.30 +#include "masqmail.h"
    1.31 +#include "smtp_out.h"
    1.32 +
    1.33 +masqmail_conf conf;
    1.34 +
    1.35 +extern char *optarg;
    1.36 +extern int optind, opterr, optopt;
    1.37 +
    1.38 +void logwrite(int pri, const char *fmt, ...)
    1.39 +{
    1.40 +  va_list args;
    1.41 +  va_start(args, fmt);
    1.42 +
    1.43 +  vfprintf(stdout, fmt, args);
    1.44 +
    1.45 +  va_end(args);
    1.46 +}
    1.47 +
    1.48 +void debugf(const char *fmt, ...)
    1.49 +{
    1.50 +  va_list args;
    1.51 +  va_start(args, fmt);
    1.52 +
    1.53 +  vfprintf(stdout, fmt, args);
    1.54 +
    1.55 +  va_end(args);
    1.56 +}
    1.57 +
    1.58 +int
    1.59 +main(int argc, char *argv[])
    1.60 +{
    1.61 +  gchar *helo_name = g_malloc(64);
    1.62 +  gchar *server_name = g_strdup("localhost");
    1.63 +  gint server_port = 25;
    1.64 +  GList *resolve_list = g_list_append(NULL, resolve_byname);
    1.65 +
    1.66 +  gethostname(helo_name, 63);
    1.67 +
    1.68 +  conf.host_name = g_strdup(helo_name);
    1.69 +
    1.70 +  while(1){
    1.71 +    int c;
    1.72 +    c = getopt(argc, argv, "d:p:s:H:");
    1.73 +    if(c == -1)
    1.74 +      break;
    1.75 +    switch(c){
    1.76 +    case 'd':
    1.77 +      conf.debug_level = atoi(optarg);
    1.78 +      break;
    1.79 +    case 'p':
    1.80 +      server_port = atoi(optarg);
    1.81 +      break;
    1.82 +    case 's':
    1.83 +      g_free(server_name);
    1.84 +      server_name = g_strdup(optarg);
    1.85 +      break;
    1.86 +    case 'H':
    1.87 +      g_free(helo_name);
    1.88 +      helo_name = g_strdup(optarg);
    1.89 +      break;
    1.90 +    default:
    1.91 +      break;
    1.92 +    }
    1.93 +  }
    1.94 +
    1.95 +  if (optind < argc){
    1.96 +    gint ret;
    1.97 +    message *msg = create_message();
    1.98 +
    1.99 +    while (optind < argc){
   1.100 +      msg->rcpt_list =
   1.101 +	g_list_append(msg->rcpt_list,
   1.102 +		      create_address_qualified(argv[optind++], TRUE, conf.host_name));
   1.103 +    }
   1.104 +    
   1.105 +    if((ret = accept_message(stdin, msg, ACC_NODOT_TERM|ACC_HEAD_FROM_RCPT)) == AERR_OK){
   1.106 +      if((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok){
   1.107 +	exit(EXIT_SUCCESS);
   1.108 +      }
   1.109 +      fprintf(stderr, "deliver failed: %d\n", ret);
   1.110 +    }
   1.111 +    fprintf(stderr, "accept failed: %d\n", ret);
   1.112 +    exit(ret);
   1.113 +  }else{
   1.114 +    fprintf(stderr, "no recipients given.\n");
   1.115 +    exit(-1);
   1.116 +  }
   1.117 +}