/[mailutils]/mailutils/examples/mta.c
ViewVC logotype

Diff of /mailutils/examples/mta.c

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

revision 1.3 by gray, Mon Nov 18 17:07:10 2002 UTC revision 1.4 by gray, Wed Dec 4 23:18:12 2002 UTC
# Line 59  Line 59 
59  #include <netinet/in.h>  #include <netinet/in.h>
60  #include <mu_asprintf.h>  #include <mu_asprintf.h>
61  #include <mailutils/argcv.h>  #include <mailutils/argcv.h>
 #include <mailutils/argp.h>  
62  #include <mailutils/mailutils.h>  #include <mailutils/mailutils.h>
63    
64  FILE *diag = NULL;       /* diagnostic output */  FILE *diag = NULL;       /* diagnostic output */
# Line 71  int dot = 1;             /* Message is t Line 70  int dot = 1;             /* Message is t
70    
71  header_t header;  header_t header;
72  address_t recipients = NULL;  address_t recipients = NULL;
73    char *progname;
74    
75  int mta_stdin __P((int argc, char **argv));  int mta_stdin __P((int argc, char **argv));
76  int mta_smtp __P((int argc, char **argv));  int mta_smtp __P((int argc, char **argv));
# Line 82  main (int argc, char **argv) Line 82  main (int argc, char **argv)
82    int c, status;    int c, status;
83    char *domain;    char *domain;
84    
85      progname = strrchr (argv[0], '/');
86      if (!progname)
87        progname = argv[0];
88      
89    while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF)    while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF)
90      {      {
91        switch (c)        switch (c)
# Line 137  main (int argc, char **argv) Line 141  main (int argc, char **argv)
141            if (!diag)            if (!diag)
142              {              {
143                mu_error ("%s: can't open diagnostic output: %s",                mu_error ("%s: can't open diagnostic output: %s",
144                          program_invocation_short_name, name);                          progname, name);
145                return 1;                return 1;
146              }              }
147          }          }
# Line 153  main (int argc, char **argv) Line 157  main (int argc, char **argv)
157    if ((status = header_create (&header, NULL, 0, NULL)) != 0)    if ((status = header_create (&header, NULL, 0, NULL)) != 0)
158      {      {
159        mu_error ("%s: can't create header: %s",        mu_error ("%s: can't create header: %s",
160                  program_invocation_short_name, mu_errstring (status));                  progname, mu_errstring (status));
161        return 1;        return 1;
162      }      }
163    
# Line 191  make_tmp (FILE *input, const char *from, Line 195  make_tmp (FILE *input, const char *from,
195        
196    if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL)    if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL)
197      {      {
198        mu_error ("%s: unable to open temporary file",        mu_error ("%s: unable to open temporary file", progname);
                 program_invocation_short_name);  
199        exit (1);        exit (1);
200      }      }
201    
# Line 221  make_tmp (FILE *input, const char *from, Line 224  make_tmp (FILE *input, const char *from,
224                  }                  }
225                else                else
226                  {                  {
227                    mu_error ("%s: can't determine sender address",                    mu_error ("%s: can't determine sender address", progname);
                             program_invocation_short_name);  
228                    exit (1);                    exit (1);
229                  }                  }
230              }              }
# Line 236  make_tmp (FILE *input, const char *from, Line 238  make_tmp (FILE *input, const char *from,
238                
239        if (fputs (buf, fp) == EOF)        if (fputs (buf, fp) == EOF)
240          {          {
241            mu_error ("%s: temporary file write error",            mu_error ("%s: temporary file write error", progname);
                     program_invocation_short_name);  
242            fclose (fp);            fclose (fp);
243            exit (1);            exit (1);
244          }          }
# Line 297  mta_send (message_t msg) Line 298  mta_send (message_t msg)
298    if (c)    if (c)
299      {      {
300        mu_error ("%s: address_to_string failure: %s",        mu_error ("%s: address_to_string failure: %s",
301                  program_invocation_short_name, mu_errstring (c));                  progname, mu_errstring (c));
302        return 1;        return 1;
303      }      }
304    value = malloc (n + 1);    value = malloc (n + 1);
305    if (!value)    if (!value)
306      {      {
307        mu_error ("%s: not enough memory", program_invocation_short_name);        mu_error ("%s: not enough memory", progname);
308        return 1;        return 1;
309      }      }
310    
# Line 361  message_finalize (message_t msg, int war Line 362  message_finalize (message_t msg, int war
362          {          {
363            if (add_recipient (value))            if (add_recipient (value))
364              {              {
365                mu_error ("%s: bad address %s",                mu_error ("%s: bad address %s", progname, value);
                         program_invocation_short_name, value);  
366                return 1;                return 1;
367              }              }
368            free (value);            free (value);
# Line 372  message_finalize (message_t msg, int war Line 372  message_finalize (message_t msg, int war
372          {          {
373            if (add_recipient (value))            if (add_recipient (value))
374              {              {
375                mu_error ("%s: bad address %s",                mu_error ("%s: bad address %s", progname, value);
                         program_invocation_short_name, value);  
376                return 1;                return 1;
377              }              }
378            free (value);            free (value);
# Line 383  message_finalize (message_t msg, int war Line 382  message_finalize (message_t msg, int war
382          {          {
383            if (add_recipient (value))            if (add_recipient (value))
384              {              {
385                mu_error ("%s: bad address %s: %s",                mu_error ("%s: bad address %s: %s", progname, value);
                         program_invocation_short_name, value);  
386                return 1;                return 1;
387              }              }
388            free (value);            free (value);
# Line 401  message_finalize (message_t msg, int war Line 399  message_finalize (message_t msg, int war
399        if (c)        if (c)
400          {          {
401            mu_error ("%s: address_to_string failure: %s",            mu_error ("%s: address_to_string failure: %s",
402                      program_invocation_short_name, mu_errstring (c));                      progname, mu_errstring (c));
403            return 1;            return 1;
404          }          }
405        value = malloc (n + 1);        value = malloc (n + 1);
406        if (!value)        if (!value)
407          {          {
408            mu_error ("%s: not enough memory",            mu_error ("%s: not enough memory", progname);
                     program_invocation_short_name);  
409            return 1;            return 1;
410          }          }
411    
# Line 431  mta_stdin (int argc, char **argv) Line 428  mta_stdin (int argc, char **argv)
428      {      {
429        if (add_recipient (argv[c]))        if (add_recipient (argv[c]))
430          {          {
431            mu_error ("%s: bad address %s",            mu_error ("%s: bad address %s", progname, argv[c]);
                     program_invocation_short_name, argv[c]);  
432            return 1;            return 1;
433          }          }
434      }      }
# Line 441  mta_stdin (int argc, char **argv) Line 437  mta_stdin (int argc, char **argv)
437    if ((c = mailbox_create_default (&mbox, tempfile)) != 0)    if ((c = mailbox_create_default (&mbox, tempfile)) != 0)
438      {      {
439        mu_error ("%s: can't create mailbox %s: %s",        mu_error ("%s: can't create mailbox %s: %s",
440                  program_invocation_short_name, tempfile, mu_errstring (c));                  progname, tempfile, mu_errstring (c));
441        unlink (tempfile);        unlink (tempfile);
442        return 1;        return 1;
443      }      }
# Line 449  mta_stdin (int argc, char **argv) Line 445  mta_stdin (int argc, char **argv)
445    if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)    if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
446      {      {
447        mu_error ("%s: can't open mailbox %s: %s",        mu_error ("%s: can't open mailbox %s: %s",
448                  program_invocation_short_name, tempfile, mu_errstring (c));                  progname, tempfile, mu_errstring (c));
449        unlink (tempfile);        unlink (tempfile);
450        return 1;        return 1;
451      }      }
# Line 460  mta_stdin (int argc, char **argv) Line 456  mta_stdin (int argc, char **argv)
456    
457    if (!recipients)    if (!recipients)
458      {      {
459        mu_error ("%s: Recipient names must be specified",        mu_error ("%s: Recipient names must be specified", progname);
                 program_invocation_short_name);  
460        return 1;        return 1;
461      }      }
462    
# Line 654  smtp (int fd) Line 649  smtp (int fd)
649                if ((c = mailbox_create_default (&mbox, tempfile)) != 0)                if ((c = mailbox_create_default (&mbox, tempfile)) != 0)
650                  {                  {
651                    mu_error ("%s: can't create mailbox %s: %s",                    mu_error ("%s: can't create mailbox %s: %s",
652                              program_invocation_short_name,                              progname,
653                              tempfile, mu_errstring (c));                              tempfile, mu_errstring (c));
654                    unlink (tempfile);                    unlink (tempfile);
655                    exit (1);                    exit (1);
# Line 663  smtp (int fd) Line 658  smtp (int fd)
658                if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)                if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
659                  {                  {
660                    mu_error ("%s: can't open mailbox %s: %s",                    mu_error ("%s: can't open mailbox %s: %s",
661                              program_invocation_short_name,                              progname,
662                              tempfile, mu_errstring (c));                              tempfile, mu_errstring (c));
663                    unlink (tempfile);                    unlink (tempfile);
664                    exit (1);                    exit (1);
# Line 706  mta_smtp (int argc, char **argv) Line 701  mta_smtp (int argc, char **argv)
701    fd = socket (PF_INET, SOCK_STREAM, 0);    fd = socket (PF_INET, SOCK_STREAM, 0);
702    if (fd < 0)    if (fd < 0)
703      {      {
704        mu_error ("%s: socket: %s", program_invocation_short_name,        mu_error ("%s: socket: %s", progname, strerror (errno));
                 strerror (errno));  
705        return 1;        return 1;
706      }      }
707    
# Line 723  mta_smtp (int argc, char **argv) Line 717  mta_smtp (int argc, char **argv)
717        if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0)        if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0)
718          {          {
719            close (fd);            close (fd);
720            mu_error ("%s: bind: %s", program_invocation_short_name,            mu_error ("%s: bind: %s", progname, strerror(errno));
                     strerror(errno));  
721            return 1;            return 1;
722          }          }
723      }      }
# Line 738  mta_smtp (int argc, char **argv) Line 731  mta_smtp (int argc, char **argv)
731            if (++port >= 65535)            if (++port >= 65535)
732              {              {
733                mu_error ("%s: can't bind socket: all ports in use?",                mu_error ("%s: can't bind socket: all ports in use?",
734                          program_invocation_short_name);                          progname);
735                return 1;                return 1;
736              }              }
737            address.sin_port = htons (port);            address.sin_port = htons (port);
# Line 764  mta_smtp (int argc, char **argv) Line 757  mta_smtp (int argc, char **argv)
757          {          {
758            if (errno == EINTR)            if (errno == EINTR)
759              continue;              continue;
760            mu_error ("%s: select: %s", program_invocation_short_name,            mu_error ("%s: select: %s", progname, strerror (errno));
                     strerror (errno));  
761            return 1;            return 1;
762          }          }
763    
764        len = sizeof (his_addr);        len = sizeof (his_addr);
765        if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0)        if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0)
766          {          {
767            mu_error ("%s: accept: %s", program_invocation_short_name,            mu_error ("%s: accept: %s", progname, strerror (errno));
                     strerror (errno));  
768            return 1;            return 1;
769          }          }
770    

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