commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-88-g790527f


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-88-g790527f
Date: Fri, 17 Sep 2010 23:48:49 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=790527fab6a62624f6c7797bd54dca57c03ef020

The branch, master has been updated
       via  790527fab6a62624f6c7797bd54dca57c03ef020 (commit)
      from  274ca0bfebbb4881ee9a3a01a239b6659dd64705 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 790527fab6a62624f6c7797bd54dca57c03ef020
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Sep 18 02:40:56 2010 +0300

    smtp client: implement more functions.
    
    * include/mailutils/smtp.h (mu_smtp_mail_basic)
    (mu_smtp_rcpt_basic, mu_smtp_send_stream)
    (mu_smtp_rset, mu_smtp_quit): New prototypes.
    * include/mailutils/sys/smtp.h (MU_SMTP_RCPT)
    (MU_SMTP_MORE, MU_SMTP_DOT, MU_SMTP_QUIT, MU_SMTP_CLOS): New states.
    (_mu_smtp_xscript_level): New proto.
    * libmailutils/errors (MU_ERR_REPLY): New error code.
    * libproto/mailer/Makefile.am (libmu_mailer_la_SOURCES): Add new sources.
    * libproto/mailer/smtp_data.c: New file.
    * libproto/mailer/smtp_mail.c: New file.
    * libproto/mailer/smtp_quit.c: New file.
    * libproto/mailer/smtp_rcpt.c: New file.
    * libproto/mailer/smtp_rset.c: New file.
    * libproto/mailer/smtp_ehlo.c: Return MU_ERR_REPLY if the server replied
    with a code other than 2xx.
    * libproto/mailer/smtp_open.c: Likewise.
    * testsuite/smtpsend.c: Implement full sending cycle (excepting
    authorization).

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/smtp.h                     |    6 ++
 include/mailutils/sys/smtp.h                 |    7 ++-
 libmailutils/errors                          |    1 +
 libproto/mailer/Makefile.am                  |    5 ++
 libproto/mailer/smtp_data.c                  |   95 ++++++++++++++++++++++++++
 libproto/mailer/smtp_ehlo.c                  |    8 +--
 libproto/mailer/{smtp_open.c => smtp_mail.c} |   30 ++++++---
 libproto/mailer/smtp_open.c                  |   10 +--
 libproto/mailer/{smtp_open.c => smtp_quit.c} |   23 +++---
 libproto/mailer/{smtp_open.c => smtp_rcpt.c} |   29 ++++++---
 libproto/mailer/{smtp_open.c => smtp_rset.c} |   21 +++---
 testsuite/smtpsend.c                         |   94 +++++++++++++++++++++++--
 12 files changed, 269 insertions(+), 60 deletions(-)
 create mode 100644 libproto/mailer/smtp_data.c
 copy libproto/mailer/{smtp_open.c => smtp_mail.c} (65%)
 copy libproto/mailer/{smtp_open.c => smtp_quit.c} (74%)
 copy libproto/mailer/{smtp_open.c => smtp_rcpt.c} (64%)
 copy libproto/mailer/{smtp_open.c => smtp_rset.c} (76%)

diff --git a/include/mailutils/smtp.h b/include/mailutils/smtp.h
index 1f6812d..c34af0e 100644
--- a/include/mailutils/smtp.h
+++ b/include/mailutils/smtp.h
@@ -45,4 +45,10 @@ int mu_smtp_get_domain (mu_smtp_t smtp, const char **pdom);
 int mu_smtp_capa_test (mu_smtp_t smtp, const char *capa, const char **pret);
 int mu_smtp_starttls (mu_smtp_t smtp);
 
+int mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const char *args);
+int mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const char *args);
+int mu_smtp_send_stream (mu_smtp_t smtp, mu_stream_t str);
+int mu_smtp_rset (mu_smtp_t smtp);
+int mu_smtp_quit (mu_smtp_t smtp);
+
 #endif
diff --git a/include/mailutils/sys/smtp.h b/include/mailutils/sys/smtp.h
index 48fd5d8..c741076 100644
--- a/include/mailutils/sys/smtp.h
+++ b/include/mailutils/sys/smtp.h
@@ -36,6 +36,11 @@ enum mu_smtp_state
     MU_SMTP_INIT,
     MU_SMTP_EHLO,
     MU_SMTP_MAIL,
+    MU_SMTP_RCPT,
+    MU_SMTP_MORE,
+    MU_SMTP_DOT,
+    MU_SMTP_QUIT,
+    MU_SMTP_CLOS
   };
 
 struct _mu_smtp
@@ -75,6 +80,6 @@ struct _mu_smtp
 
 int _mu_smtp_trace_enable (mu_smtp_t smtp);
 int _mu_smtp_trace_disable (mu_smtp_t smtp);
-
+int _mu_smtp_xscript_level (mu_smtp_t smtp, int xlev);
 
 #endif
diff --git a/libmailutils/errors b/libmailutils/errors
index eb87bb5..b0a56b1 100644
--- a/libmailutils/errors
+++ b/libmailutils/errors
@@ -63,6 +63,7 @@ MU_ERR_NOPASSWORD           _("User password is not supplied")
 MU_ERR_BADREPLY             _("Invalid reply from the remote host")
 
 MU_ERR_SEQ                  _("Bad command sequence")
+MU_ERR_REPLY                _("Erroneous reply received")
 
 MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions. Set 0600")
 MU_ERR_BAD_AUTH_SCHEME      _("Unsupported authentication scheme")
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 8cb5c1e..7d42111 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -31,12 +31,17 @@ libmu_mailer_la_SOURCES = \
  smtp_capa.c\
  smtp_carrier.c\
  smtp_create.c\
+ smtp_data.c\
  smtp_disconnect.c\
  smtp_domain.c\
  smtp_ehlo.c\
  smtp_io.c\
+ smtp_mail.c\
+ smtp_rcpt.c\
  smtp_open.c\
+ smtp_rset.c\
  smtp_starttls.c\
  smtp_trace.c\
+ smtp_quit.c\
  remote.c
 
diff --git a/libproto/mailer/smtp_data.c b/libproto/mailer/smtp_data.c
new file mode 100644
index 0000000..13847d9
--- /dev/null
+++ b/libproto/mailer/smtp_data.c
@@ -0,0 +1,95 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/list.h>
+#include <mailutils/smtp.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/smtp.h>
+
+static int
+_smtp_data_send (mu_smtp_t smtp, mu_stream_t stream)
+{
+  int status;
+  struct mu_buffer_query oldbuf;
+  int buffer_changed = 0;
+  
+  status = mu_smtp_write (smtp, "DATA\r\n");
+  MU_SMTP_CHECK_ERROR (smtp, status);
+  status = mu_smtp_response (smtp);
+  MU_SMTP_CHECK_ERROR (smtp, status);
+  
+  if (smtp->replcode[0] != '3')
+    return MU_ERR_REPLY;
+  
+  if (mu_smtp_trace_mask (smtp, MU_SMTP_TRACE_QRY, MU_XSCRIPT_PAYLOAD))
+    _mu_smtp_xscript_level (smtp, MU_XSCRIPT_PAYLOAD);
+
+  if (mu_stream_ioctl (smtp->carrier, MU_IOCTL_GET_TRANSPORT_BUFFER,
+                      &oldbuf) == 0)
+    {
+      struct mu_buffer_query newbuf;
+      newbuf.type = MU_TRANSPORT_OUTPUT;
+      newbuf.buftype = mu_buffer_full;
+      newbuf.bufsize = 64*1024;
+      buffer_changed = mu_stream_ioctl (smtp->carrier,
+                                       MU_IOCTL_SET_TRANSPORT_BUFFER,
+                                       &newbuf) == 0;
+    }
+
+  status = mu_stream_copy (smtp->carrier, stream, 0, NULL);
+  _mu_smtp_xscript_level (smtp, MU_XSCRIPT_NORMAL);
+  mu_stream_flush (smtp->carrier);
+  if (buffer_changed)
+    mu_stream_ioctl (smtp->carrier, MU_IOCTL_SET_TRANSPORT_BUFFER,
+                    &oldbuf);
+  
+  return status;
+}
+
+
+int
+mu_smtp_send_stream (mu_smtp_t smtp, mu_stream_t stream)
+{
+  int status;
+  mu_stream_t input;
+  
+  if (!smtp)
+    return EINVAL;
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
+    return MU_ERR_FAILURE;
+  if (smtp->state != MU_SMTP_MORE)
+    return MU_ERR_SEQ;
+
+  status = mu_filter_create (&input, stream, "CRLFDOT", MU_FILTER_ENCODE,
+                            MU_STREAM_READ);
+  if (status)
+    return status;
+  
+  status = _smtp_data_send (smtp, input);
+  mu_stream_destroy (&input);
+  if (status == 0)
+    smtp->state = MU_SMTP_DOT;
+  return status;
+}
diff --git a/libproto/mailer/smtp_ehlo.c b/libproto/mailer/smtp_ehlo.c
index 4bbdac5..ad255c7 100644
--- a/libproto/mailer/smtp_ehlo.c
+++ b/libproto/mailer/smtp_ehlo.c
@@ -81,7 +81,7 @@ mu_smtp_ehlo (mu_smtp_t smtp)
       mu_list_set_comparator (smtp->capa, capa_comp);
     }
   else if (smtp->replcode[0] == '4')
-    return EAGAIN;
+    return MU_ERR_REPLY;
   else
     {
       status = mu_smtp_write (smtp, "HELO %s\r\n", smtp->domain);
@@ -89,10 +89,8 @@ mu_smtp_ehlo (mu_smtp_t smtp)
       status = mu_smtp_response (smtp);
       MU_SMTP_CHECK_ERROR (smtp, status);
       smtp->flags &= ~_MU_SMTP_ESMTP;
-      if (smtp->replcode[0] == '4')
-       return EAGAIN;
-      else if (smtp->replcode[0] != '2')
-       return MU_ERR_FAILURE;
+      if (smtp->replcode[0] != '2')
+       return MU_ERR_REPLY;
     }
   smtp->state = MU_SMTP_MAIL;
   return 0;
diff --git a/libproto/mailer/smtp_open.c b/libproto/mailer/smtp_mail.c
similarity index 65%
copy from libproto/mailer/smtp_open.c
copy to libproto/mailer/smtp_mail.c
index c843a1b..9099858 100644
--- a/libproto/mailer/smtp_open.c
+++ b/libproto/mailer/smtp_mail.c
@@ -20,30 +20,42 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
+#include <mailutils/mutil.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_open (mu_smtp_t smtp)
+mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const char *args)
 {
   int status;
   
   if (!smtp)
     return EINVAL;
-  if (smtp->state != MU_SMTP_INIT)
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
+    return MU_ERR_FAILURE;
+  if (smtp->state != MU_SMTP_MAIL)
     return MU_ERR_SEQ;
+  status = mu_smtp_write (smtp, "MAIL FROM:<%s>", email);
+  MU_SMTP_CHECK_ERROR (smtp, status);
+  if (args)
+    {
+      status = mu_smtp_write (smtp, " %s", args);
+      MU_SMTP_CHECK_ERROR (smtp, status);
+    }
+  status = mu_smtp_write (smtp, "\r\n");
+  MU_SMTP_CHECK_ERROR (smtp, status);
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (smtp->replcode[0] == '5')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  else if (smtp->replcode[0] == '4')
-    MU_SMTP_CHECK_ERROR (smtp, EAGAIN);
-  else if (smtp->replcode[0] != '2')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  smtp->state = MU_SMTP_EHLO;
+
+  if (smtp->replcode[0] != '2')
+    return MU_ERR_REPLY;
+
+  smtp->state = MU_SMTP_RCPT;
   return 0;
 }
 
+      
diff --git a/libproto/mailer/smtp_open.c b/libproto/mailer/smtp_open.c
index c843a1b..17235fd 100644
--- a/libproto/mailer/smtp_open.c
+++ b/libproto/mailer/smtp_open.c
@@ -37,12 +37,10 @@ mu_smtp_open (mu_smtp_t smtp)
     return MU_ERR_SEQ;
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (smtp->replcode[0] == '5')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  else if (smtp->replcode[0] == '4')
-    MU_SMTP_CHECK_ERROR (smtp, EAGAIN);
-  else if (smtp->replcode[0] != '2')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
+  if (smtp->replcode[0] != '2')
+    /* There's no use doing anything in this session, so we set the
+       _MU_SMTP_ERR flag. */
+    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_REPLY);
   smtp->state = MU_SMTP_EHLO;
   return 0;
 }
diff --git a/libproto/mailer/smtp_open.c b/libproto/mailer/smtp_quit.c
similarity index 74%
copy from libproto/mailer/smtp_open.c
copy to libproto/mailer/smtp_quit.c
index c843a1b..c87544e 100644
--- a/libproto/mailer/smtp_open.c
+++ b/libproto/mailer/smtp_quit.c
@@ -20,30 +20,29 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <mailutils/errno.h>
-#include <mailutils/cctype.h>
+#include <mailutils/filter.h>
 #include <mailutils/list.h>
 #include <mailutils/smtp.h>
+#include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_open (mu_smtp_t smtp)
+mu_smtp_quit (mu_smtp_t smtp)
 {
   int status;
   
   if (!smtp)
     return EINVAL;
-  if (smtp->state != MU_SMTP_INIT)
-    return MU_ERR_SEQ;
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
+    return MU_ERR_FAILURE;
+  status = mu_smtp_write (smtp, "QUIT\r\n");
+  MU_SMTP_CHECK_ERROR (smtp, status);
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (smtp->replcode[0] == '5')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  else if (smtp->replcode[0] == '4')
-    MU_SMTP_CHECK_ERROR (smtp, EAGAIN);
-  else if (smtp->replcode[0] != '2')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  smtp->state = MU_SMTP_EHLO;
+  if (smtp->replcode[0] != '2')
+    return MU_ERR_REPLY;
+  smtp->state = MU_SMTP_CLOS;
   return 0;
 }
-
diff --git a/libproto/mailer/smtp_open.c b/libproto/mailer/smtp_rcpt.c
similarity index 64%
copy from libproto/mailer/smtp_open.c
copy to libproto/mailer/smtp_rcpt.c
index c843a1b..dd5d357 100644
--- a/libproto/mailer/smtp_open.c
+++ b/libproto/mailer/smtp_rcpt.c
@@ -20,30 +20,41 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
+#include <mailutils/mutil.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_open (mu_smtp_t smtp)
+mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const char *args)
 {
   int status;
   
   if (!smtp)
     return EINVAL;
-  if (smtp->state != MU_SMTP_INIT)
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
+    return MU_ERR_FAILURE;
+  if (smtp->state != MU_SMTP_RCPT && smtp->state != MU_SMTP_MORE)
     return MU_ERR_SEQ;
+  status = mu_smtp_write (smtp, "RCPT TO:<%s>", email);
+  MU_SMTP_CHECK_ERROR (smtp, status);
+  if (args)
+    {
+      status = mu_smtp_write (smtp, " %s", args);
+      MU_SMTP_CHECK_ERROR (smtp, status);
+    }
+  status = mu_smtp_write (smtp, "\r\n");
+  MU_SMTP_CHECK_ERROR (smtp, status);
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (smtp->replcode[0] == '5')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  else if (smtp->replcode[0] == '4')
-    MU_SMTP_CHECK_ERROR (smtp, EAGAIN);
-  else if (smtp->replcode[0] != '2')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  smtp->state = MU_SMTP_EHLO;
+
+  if (smtp->replcode[0] != '2')
+    return MU_ERR_REPLY;
+  smtp->state = MU_SMTP_MORE;
   return 0;
 }
 
+      
diff --git a/libproto/mailer/smtp_open.c b/libproto/mailer/smtp_rset.c
similarity index 76%
copy from libproto/mailer/smtp_open.c
copy to libproto/mailer/smtp_rset.c
index c843a1b..7a0a2e0 100644
--- a/libproto/mailer/smtp_open.c
+++ b/libproto/mailer/smtp_rset.c
@@ -20,30 +20,29 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <mailutils/errno.h>
-#include <mailutils/cctype.h>
+#include <mailutils/filter.h>
 #include <mailutils/list.h>
 #include <mailutils/smtp.h>
+#include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_open (mu_smtp_t smtp)
+mu_smtp_rset (mu_smtp_t smtp)
 {
   int status;
   
   if (!smtp)
     return EINVAL;
-  if (smtp->state != MU_SMTP_INIT)
-    return MU_ERR_SEQ;
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
+    return MU_ERR_FAILURE;
+  status = mu_smtp_write (smtp, "RSET\r\n");
+  MU_SMTP_CHECK_ERROR (smtp, status);
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (smtp->replcode[0] == '5')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
-  else if (smtp->replcode[0] == '4')
-    MU_SMTP_CHECK_ERROR (smtp, EAGAIN);
-  else if (smtp->replcode[0] != '2')
-    MU_SMTP_CHECK_ERROR (smtp, MU_ERR_FAILURE);
+  if (smtp->replcode[0] != '2')
+    return MU_ERR_REPLY;
   smtp->state = MU_SMTP_EHLO;
   return 0;
 }
-
diff --git a/testsuite/smtpsend.c b/testsuite/smtpsend.c
index 869f35d..cfa4958 100644
--- a/testsuite/smtpsend.c
+++ b/testsuite/smtpsend.c
@@ -23,16 +23,44 @@
 #include <mailutils/mailutils.h>
 #include <mailutils/smtp.h>
 
+static char usage_text[] =
+"usage: %s hostname [port=N] [trace=N] [tls=N] [from=STRING] [rcpt=STRING]\n"
+"                   [domain=STRING] input=FILE raw=N\n";
+
+static void
+usage ()
+{
+  fprintf (stderr, usage_text, mu_program_name);
+  exit (1);
+}
+
+static int
+send_rcpt_command (void *item, void *data)
+{
+  char *email = item;
+  mu_smtp_t smtp = data;
+
+  MU_ASSERT (mu_smtp_rcpt_basic (smtp, email, NULL));
+  return 0;
+}
+  
 int
 main (int argc, char **argv)
 {
   int i;
   char *host;
+  char *domain = NULL;
+  char *infile = NULL;
   int port = 25;
   int trace = 0;
   int tls = 0;
+  int raw = 1;
+  int flags = 0;
   mu_stream_t stream;
   mu_smtp_t smtp;
+  mu_stream_t instr;
+  char *from = NULL;
+  mu_list_t rcpt_list = NULL;
   
   mu_set_program_name (argv[0]);
 #ifdef WITH_TLS
@@ -40,10 +68,7 @@ main (int argc, char **argv)
 #endif  
   
   if (argc < 2)
-    {
-      fprintf (stderr, "usage: %s hostname [port=N] [trace=N] [tls=N]\n", 
argv[0]);
-      return 1;
-    }
+    usage ();
 
   for (i = 1; i < argc; i++)
     {
@@ -60,16 +85,36 @@ main (int argc, char **argv)
        trace = atoi (argv[i] + 6);
       else if (strncmp (argv[i], "tls=", 4) == 0)
        tls = atoi (argv[i] + 4);
+      else if (strncmp (argv[i], "domain=", 7) == 0)
+       domain = argv[i] + 7;
+      else if (strncmp (argv[i], "infile=", 7) == 0)
+       infile = argv[i] + 7;
+      else if (strncmp (argv[i], "raw=", 4) == 0)
+       raw = atoi (argv[i] + 4);
+      else if (strncmp (argv[i], "rcpt=", 5) == 0)
+       {
+         if (!rcpt_list)
+           MU_ASSERT (mu_list_create (&rcpt_list));
+         MU_ASSERT (mu_list_append (rcpt_list, argv[i] + 5));
+       }
+      else if (strncmp (argv[i], "from=", 5) == 0)
+       from = argv[i] + 5;
       else
        host = argv[i];
     }
 
   if (!host)
+    usage ();
+
+  if (!raw)
+    flags = MU_STREAM_SEEK;
+  if (infile)
     {
-      fprintf (stderr, "usage: %s hostname [port=N] [trace=N]\n", argv[0]);
-      return 1;
+      MU_ASSERT (mu_file_stream_create (&instr, infile, MU_STREAM_READ|flags));
+      MU_ASSERT (mu_stream_open (instr));
     }
-
+  else
+    MU_ASSERT (mu_stdio_stream_create (&instr, MU_STDIN_FD, flags));
   
   MU_ASSERT (mu_smtp_create (&smtp));
 
@@ -81,6 +126,24 @@ main (int argc, char **argv)
   
   if (trace)
     mu_smtp_trace (smtp, MU_SMTP_TRACE_SET);
+  if (domain)
+    mu_smtp_set_domain (smtp, domain);
+  if (!from)
+    {
+      from = getenv ("USER");
+      if (!from)
+       {
+         mu_error ("cannot determine sender name");
+         exit (1);
+       }
+    }
+
+  if (raw && !rcpt_list)
+    {
+      mu_error ("no recipients");
+      exit (1);
+    }
+  
   MU_ASSERT (mu_smtp_open (smtp));
   MU_ASSERT (mu_smtp_ehlo (smtp));
 
@@ -89,7 +152,24 @@ main (int argc, char **argv)
       MU_ASSERT (mu_smtp_starttls (smtp));
       MU_ASSERT (mu_smtp_ehlo (smtp));
     }
+
+  if (raw)
+    {
+      /* Raw sending mode: send from the stream directly */
+      MU_ASSERT (mu_smtp_mail_basic (smtp, from, NULL));
+      mu_list_do (rcpt_list, send_rcpt_command, smtp);
+      MU_ASSERT (mu_smtp_send_stream (smtp, instr));
+      MU_ASSERT (mu_smtp_quit (smtp));
+    }
+  else
+    {
+      /* Message (standard) sending mode: send a MU message. */
+      //FIXME;
+    }
+  
   
   mu_smtp_destroy (&smtp);
+  mu_stream_close (instr);
+  mu_stream_destroy (&instr);
   return 0;
 }


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]