/[mailutils]/mailutils/examples/msg-send.c
ViewVC logotype

Diff of /mailutils/examples/msg-send.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by sroberts, Fri May 10 13:02:33 2002 UTC revision 1.4 by gray, Thu Aug 29 14:43:13 2002 UTC
# Line 1  Line 1 
1    /* GNU mailutils - a suite of utilities for electronic mail
2       Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3    
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, or (at your option)
7       any later version.
8    
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.
13    
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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17    
18  #include <sys/types.h>  #include <sys/types.h>
19  #include <sys/stat.h>  #include <sys/stat.h>
20    
# Line 16  Line 33 
33  #include <mailutils/registrar.h>  #include <mailutils/registrar.h>
34  #include <mailutils/stream.h>  #include <mailutils/stream.h>
35    
36  #define C(X) {int e; if((e = X) != 0) { \  #define C(X) do {\
37    fprintf(stderr, "%s failed: %s\n", #X, mu_errstring(e)); \    int e;\
38    exit(1); } }    if((e = X) != 0) { \
39           fprintf(stderr, "%s failed: %s\n", #X, mu_errstring(e)); \
40           exit(1);\
41      }\
42    } while (0)
43    
44  const char USAGE[] =  const char USAGE[] =
45    "usage: mailer [-hd] [-m mailer] [-f from] [to]..."  "usage: mailer [-hd] [-m mailer] [-f from] [to]..."
46    ;   ;
47  const char HELP[] =  const char HELP[] =
48    "  -h    print this helpful message\n"  "  -h    print this helpful message\n"
49    "  -m    a mailer URL (default is \"sendmail:\")\n"  "  -m    a mailer URL (default is \"sendmail:\")\n"
50    "  -f    the envelope from address (default is from user environment)\n"  "  -f    the envelope from address (default is from user environment)\n"
51    "  to    a list of envelope to addresses (default is from message)\n"  "  to    a list of envelope to addresses (default is from message)\n"
52    "\n"  "\n"
53    "An RFC2822 formatted message is read from stdin and delivered using\n"  "An RFC2822 formatted message is read from stdin and delivered using\n"
54    "the mailer.\n"  "the mailer.\n"
55    ;   ;
56    
57  int  int
58  main (int argc, char *argv[])  main (int argc, char *argv[])
59  {  {
60    int       opt;    int opt;
61    int       optdebug  = 0;    int optdebug = 0;
62    char*     optmailer = "sendmail:";    char *optmailer = "sendmail:";
63    char*     optfrom   = 0;    char *optfrom = 0;
64    
65    stream_t  in     = 0;    stream_t in = 0;
66    message_t msg    = 0;    message_t msg = 0;
67    mailer_t  mailer = 0;    mailer_t mailer = 0;
68    address_t from   = 0;    address_t from = 0;
69    address_t to     = 0;    address_t to = 0;
70    
71    while((opt = getopt(argc, argv, "hdm:f:")) != -1)    while ((opt = getopt (argc, argv, "hdm:f:")) != -1)
   {  
     switch(opt)  
72      {      {
73        case 'h':        switch (opt)
74          printf("%s\n%s", USAGE, HELP);          {
75          return 0;          case 'h':
76        case 'd':            printf ("%s\n%s", USAGE, HELP);
77          optdebug++;            return 0;
78          break;            
79        case 'm':          case 'd':
80          optmailer = optarg;            optdebug++;
81          break;            break;
82        case 'f':            
83          optfrom = optarg;          case 'm':
84          break;            optmailer = optarg;
85        default:            break;
86          fprintf(stderr, "%s\n", USAGE);            
87          break;          case 'f':
88              optfrom = optarg;
89              break;
90    
91            default:
92              fprintf (stderr, "%s\n", USAGE);
93              exit (1);
94            }
95      }      }
   }  
96    
97    /* Register mailers. */    /* Register mailers. */
98    {    {
99      list_t bookie;      list_t bookie;
100      registrar_get_list (&bookie);      registrar_get_list (&bookie);
101      C( list_append (bookie, smtp_record) )      list_append (bookie, smtp_record);
102      C( list_append (bookie, sendmail_record) )      list_append (bookie, sendmail_record);
   }  
   
   if(optfrom)  
   {  
     C( address_create(&from, optfrom) )  
   }  
   
   if(argv[optind])  
   {  
     char** av = argv + optind;  
   
     C( address_createv(&to, (const char**) av, -1) )  
103    }    }
104    
105    C( stdio_stream_create(&in, stdin, 0) )    if (optfrom)
106        {
107    C( stream_open(in) )        C (address_create (&from, optfrom));
108        }
109    
110    C( message_create (&msg, NULL) )    if (argv[optind])
111        {
112          char **av = argv + optind;
113    
114    C( message_set_stream(msg, in, NULL) )        C (address_createv (&to, (const char **) av, -1));
115        }
116    
117    C( mailer_create(&mailer, optmailer) )    C (stdio_stream_create (&in, stdin, 0));
118      C (stream_open (in));
119      C (message_create (&msg, NULL));
120      C (message_set_stream (msg, in, NULL));
121      C (mailer_create (&mailer, optmailer));
122    
123    if(optdebug)    if (optdebug)
124    {      {
125      mu_debug_t debug;        mu_debug_t debug;
126      mailer_get_debug (mailer, &debug);        mailer_get_debug (mailer, &debug);
127      mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);        mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
128    }      }
129    
130    C( mailer_open(mailer, 0) )    C (mailer_open (mailer, 0));
131    
132    C( mailer_send_message(mailer, msg, from, to) )    C (mailer_send_message (mailer, msg, from, to));
133    
134    return 0;    return 0;
135  }  }
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26