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-97-g7b5902b


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-97-g7b5902b
Date: Mon, 20 Sep 2010 14:10:13 +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=7b5902b4ffd7acf44934dcdd1d09e70abe26efc3

The branch, master has been updated
       via  7b5902b4ffd7acf44934dcdd1d09e70abe26efc3 (commit)
       via  c382e9d0b7b893cb5eb7d6a91bdbd21c1987f934 (commit)
       via  30a7e0becb1e72ad3b01ef7a85cea650e6134ee3 (commit)
      from  76163154c740039046a2e0ae4b4aa423707c5473 (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 7b5902b4ffd7acf44934dcdd1d09e70abe26efc3
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Sep 20 15:40:34 2010 +0300

    Improve smtp sending functions.
    
    * include/mailutils/smtp.h (mu_smtp_write): Mark as printf-like.
    (mu_smtp_mail_basic, mu_smtp_rcpt_basic): Take variable number
    of arguments.  Mark as printf-like.
    (mu_smtp_data): New prototype.
    * include/mailutils/sys/smtp.h (_MU_SMTP_SAVEBUF): New flag.
    (_mu_smtp) <savebuf>: New member.
    (_mu_smtp_data_begin, _mu_smtp_data_end): New protos.
    * libproto/mailer/smtp_send.c: New file.
    * libproto/mailer/smtp_data.c (_mu_smtp_data_begin)
    (_mu_smtp_data_end, mu_smtp_data): New functions.
    
    * libproto/mailer/Makefile.am (libmu_mailer_la_SOURCES): Add smtp_send.c.
    * libproto/mailer/smtp_ehlo.c (mu_smtp_ehlo): Switch to MU_SMTP_EHLO
    only if in MU_SMTP_MAIL state.
    * libproto/mailer/smtp_mail.c (mu_smtp_mail_basic): Take variable number
    of arguments.
    * libproto/mailer/smtp_param.c (mu_smtp_get_param): Add missing typecast.
    * libproto/mailer/smtp_rcpt.c (mu_smtp_rcpt_basic): Take variable number
    of arguments.
    * libproto/mailer/smtp_send.c (_smtp_data_send): Use _mu_smtp_data_begin and
    _mu_smtp_data_end.
    * testsuite/smtpsend.c: Emulate sending from a MU message.

commit c382e9d0b7b893cb5eb7d6a91bdbd21c1987f934
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Sep 20 15:33:57 2010 +0300

    Stream improvements.
    
    * include/mailutils/stream.h (mu_stream_printf): Mark as printf-like.
    * include/mailutils/sys/stream.h (_MU_STR_EVENT_CLOSE): New event.
    (_mu_stream) <event_cb_data>: New member.
    * libmailutils/stream.c (mu_stream_seek): Avoid unnecessary seeks
    in mu_buffer_none mode.  Complements 906499db.
    (mu_stream_close): Mark _MU_STR_EVENT_CLOSE event.

commit 30a7e0becb1e72ad3b01ef7a85cea650e6134ee3
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Sep 20 15:30:27 2010 +0300

    Bugfix in message_stream.c
    
    * libmailutils/message_stream.c (scan_stream): Change signature.  All
    uses updated.
    Correct the calculation of body_start.
    (mu_message_stream_create): Return the stream.

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

Summary of changes:
 include/mailutils/smtp.h                     |   10 ++-
 include/mailutils/stream.h                   |    3 +-
 include/mailutils/sys/smtp.h                 |    5 +
 include/mailutils/sys/stream.h               |    2 +
 libmailutils/message_stream.c                |    9 +-
 libmailutils/stream.c                        |   11 ++-
 libproto/mailer/Makefile.am                  |    1 +
 libproto/mailer/smtp_data.c                  |   68 ++++++++++-----
 libproto/mailer/smtp_ehlo.c                  |    3 +-
 libproto/mailer/smtp_mail.c                  |   13 ++-
 libproto/mailer/smtp_param.c                 |    3 +-
 libproto/mailer/smtp_rcpt.c                  |   14 ++-
 libproto/mailer/{smtp_quit.c => smtp_send.c} |   38 ++++++--
 testsuite/smtpsend.c                         |  118 +++++++++++++++++++++-----
 14 files changed, 219 insertions(+), 79 deletions(-)
 copy libproto/mailer/{smtp_quit.c => smtp_send.c} (64%)

diff --git a/include/mailutils/smtp.h b/include/mailutils/smtp.h
index 5b64c7f..0d692ff 100644
--- a/include/mailutils/smtp.h
+++ b/include/mailutils/smtp.h
@@ -43,7 +43,7 @@ int mu_smtp_get_carrier (mu_smtp_t smtp, mu_stream_t 
*pcarrier);
 
 int mu_smtp_open (mu_smtp_t);
 int mu_smtp_response (mu_smtp_t smtp);
-int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...);
+int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...) MU_PRINTFLIKE(2,3);
 
 #define MU_SMTP_TRACE_CLR 0
 #define MU_SMTP_TRACE_SET 1
@@ -58,8 +58,12 @@ int mu_smtp_get_param (mu_smtp_t smtp, int code, const char 
**param);
 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_mail_basic (mu_smtp_t smtp, const char *email,
+                       const char *fmt, ...) MU_PRINTFLIKE(3,4);
+int mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email,
+                       const char *fmt, ...) MU_PRINTFLIKE(3,4);
+
+int mu_smtp_data (mu_smtp_t smtp, mu_stream_t *pstream);
 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);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index cfd9bef..810d3a9 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -140,7 +140,8 @@ int mu_stream_set_flags (mu_stream_t stream, int fl);
 int mu_stream_clr_flags (mu_stream_t stream, int fl);
 
 int mu_stream_vprintf (mu_stream_t str, const char *fmt, va_list ap);
-int mu_stream_printf (mu_stream_t stream, const char *fmt, ...);
+int mu_stream_printf (mu_stream_t stream, const char *fmt, ...)
+                      MU_PRINTFLIKE(2,3);
 
 int mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
                    mu_off_t *pcsz);
diff --git a/include/mailutils/sys/smtp.h b/include/mailutils/sys/smtp.h
index 884c921..0afe1e5 100644
--- a/include/mailutils/sys/smtp.h
+++ b/include/mailutils/sys/smtp.h
@@ -21,6 +21,7 @@
 # include <sys/socket.h>
 # include <mailutils/types.h>
 # include <mailutils/smtp.h>
+# include <mailutils/stream.h>
 
 # define _MU_SMTP_ESMTP   0x01 /* Connection supports ESMTP */
 # define _MU_SMTP_TRACE   0x02 /* Session trace required/enabled */
@@ -29,6 +30,7 @@
 # define _MU_SMTP_TLS     0x10 /* TLS initiated */ 
 # define _MU_SMTP_AUTH    0x20 /* Authorization passed */
 # define _MU_SMTP_CLNPASS 0x40 /* Password has been de-obfuscated */
+# define _MU_SMTP_SAVEBUF 0x80 /* Buffering state saved */
 
 #define MU_SMTP_XSCRIPT_MASK(n) (0x100<<(n))
 
@@ -69,6 +71,7 @@ struct _mu_smtp
   size_t flsize;
   
   mu_list_t mlrepl;
+  struct mu_buffer_query savebuf;
 };
 
 #define MU_SMTP_FSET(p,f) ((p)->flags |= (f))
@@ -91,5 +94,7 @@ int _mu_smtp_trace_disable (mu_smtp_t smtp);
 int _mu_smtp_xscript_level (mu_smtp_t smtp, int xlev);
 int _mu_smtp_gsasl_auth (mu_smtp_t smtp);
 int _mu_smtp_mech_impl (mu_smtp_t smtp, mu_list_t list);
+int _mu_smtp_data_begin (mu_smtp_t smtp);
+int _mu_smtp_data_end (mu_smtp_t smtp);
 
 #endif
diff --git a/include/mailutils/sys/stream.h b/include/mailutils/sys/stream.h
index 4e4fc51..938b9d5 100644
--- a/include/mailutils/sys/stream.h
+++ b/include/mailutils/sys/stream.h
@@ -28,6 +28,7 @@
 #define _MU_STR_EVENT_CLRFLAG   1
 #define _MU_STR_EVENT_FILLBUF   2
 #define _MU_STR_EVENT_FLUSHBUF  3
+#define _MU_STR_EVENT_CLOSE     4
 
 #define _MU_STR_EVMASK(n) (1<<(n))
 
@@ -63,6 +64,7 @@ struct _mu_stream
 
   void (*event_cb) (struct _mu_stream *, int code, unsigned long, void *);
   int  event_mask;
+  void *event_cb_data;
   
   const char *(*error_string) (struct _mu_stream *, int);
   
diff --git a/libmailutils/message_stream.c b/libmailutils/message_stream.c
index cfcd2dd..63476b9 100644
--- a/libmailutils/message_stream.c
+++ b/libmailutils/message_stream.c
@@ -133,7 +133,7 @@ _message_size (mu_stream_t stream, mu_off_t *psize)
 }
   
 static int
-scan_stream (mu_stream_t stream)
+scan_stream (struct _mu_message_stream *str)
 {
   char *from = NULL;
   char *env_from = NULL;
@@ -143,7 +143,7 @@ scan_stream (mu_stream_t stream)
   size_t bufsize = 0;
   size_t len;
   mu_off_t body_start, body_end;
-  struct _mu_message_stream *str = (struct _mu_message_stream *) stream;
+  mu_stream_t stream = str->transport;
 
   if (str->envelope)
     {
@@ -205,8 +205,6 @@ scan_stream (mu_stream_t stream)
   rc = mu_stream_seek (stream, 0, MU_SEEK_CUR, &body_start);
   if (rc)
     return rc;
-  else
-    body_start++;
   mu_stream_size (stream, &body_end);
   
   if (!env_from)
@@ -281,7 +279,7 @@ _message_open (mu_stream_t stream)
     }
   free (buffer);
 
-  return scan_stream (s->transport);
+  return scan_stream (s);
 }
 
 static int
@@ -355,6 +353,7 @@ mu_message_stream_create (mu_stream_t *stream, mu_stream_t 
src, int flags)
   s->stream.size = _message_size;
   s->stream.seek = _message_seek;
   s->stream.error_string = _message_error_string;
+  *stream = (mu_stream_t)s;
   return 0;  
 }
 
diff --git a/libmailutils/stream.c b/libmailutils/stream.c
index d8a92a3..8d725fe 100644
--- a/libmailutils/stream.c
+++ b/libmailutils/stream.c
@@ -375,10 +375,11 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int 
whence,
       return mu_stream_seterr (stream, EINVAL, 1);
     }
 
-  if ((stream->buftype == mu_buffer_none && offset != stream->offset)
-      || stream->level == 0
-      || offset < stream->offset
-      || offset > stream->offset + stream->level)
+  if (stream->buftype == mu_buffer_none ?
+      (offset != stream->offset)
+       : (stream->level == 0
+         || offset < stream->offset
+         || offset > stream->offset + stream->level))
     {
       if ((rc = _stream_flush_buffer (stream, 1)))
        return rc;
@@ -945,10 +946,12 @@ mu_stream_close (mu_stream_t stream)
     
   if (!stream)
     return EINVAL;
+  
   mu_stream_flush (stream);
   /* Do close the stream only if it is not used by anyone else */
   if (stream->ref_count > 1)
     return 0;
+  _stream_event (stream, _MU_STR_EVENT_CLOSE, 0, NULL);
   if (stream->close)
     rc = stream->close (stream);
   return rc;
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 9654f90..fbbb481 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -48,6 +48,7 @@ libmu_mailer_la_SOURCES = \
  smtp_param.c\
  smtp_rcpt.c\
  smtp_rset.c\
+ smtp_send.c\
  smtp_starttls.c\
  smtp_trace.c\
  smtp_quit.c\
diff --git a/libproto/mailer/smtp_data.c b/libproto/mailer/smtp_data.c
index 13847d9..d9f558f 100644
--- a/libproto/mailer/smtp_data.c
+++ b/libproto/mailer/smtp_data.c
@@ -22,18 +22,18 @@
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/errno.h>
+#include <mailutils/diag.h>
 #include <mailutils/filter.h>
 #include <mailutils/list.h>
 #include <mailutils/smtp.h>
 #include <mailutils/stream.h>
+#include <mailutils/sys/stream.h>
 #include <mailutils/sys/smtp.h>
 
-static int
-_smtp_data_send (mu_smtp_t smtp, mu_stream_t stream)
+int
+_mu_smtp_data_begin (mu_smtp_t smtp)
 {
   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);
@@ -47,34 +47,51 @@ _smtp_data_send (mu_smtp_t smtp, mu_stream_t stream)
     _mu_smtp_xscript_level (smtp, MU_XSCRIPT_PAYLOAD);
 
   if (mu_stream_ioctl (smtp->carrier, MU_IOCTL_GET_TRANSPORT_BUFFER,
-                      &oldbuf) == 0)
+                      &smtp->savebuf) == 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;
+      if (mu_stream_ioctl (smtp->carrier, MU_IOCTL_SET_TRANSPORT_BUFFER,
+                          &newbuf) == 0)
+       MU_SMTP_FSET (smtp, _MU_SMTP_SAVEBUF);
     }
+  return 0;
+}
 
-  status = mu_stream_copy (smtp->carrier, stream, 0, NULL);
+int
+_mu_smtp_data_end (mu_smtp_t smtp)
+{
+  int status = 0;
+  /* code is always _MU_STR_EVENT_CLOSE */
+  if (MU_SMTP_FISSET (smtp, _MU_SMTP_SAVEBUF))
+    {
+      status = mu_stream_ioctl (smtp->carrier, MU_IOCTL_SET_TRANSPORT_BUFFER,
+                               &smtp->savebuf);
+      if (status)
+       mu_diag_output (MU_DIAG_NOTICE,
+                       "failed to restore buffer state on SMTP carrier: %s",
+                       mu_strerror (status));
+    }
   _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;
 }
 
+static void
+_smtp_event_cb (struct _mu_stream *str, int code,
+               unsigned long lval, void *pval)
+{
+  mu_smtp_t smtp = str->event_cb_data;
+  _mu_smtp_data_end (smtp);
+}
 
 int
-mu_smtp_send_stream (mu_smtp_t smtp, mu_stream_t stream)
+mu_smtp_data (mu_smtp_t smtp, mu_stream_t *pstream)
 {
   int status;
   mu_stream_t input;
-  
+
   if (!smtp)
     return EINVAL;
   if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
@@ -82,14 +99,17 @@ mu_smtp_send_stream (mu_smtp_t smtp, mu_stream_t stream)
   if (smtp->state != MU_SMTP_MORE)
     return MU_ERR_SEQ;
 
-  status = mu_filter_create (&input, stream, "CRLFDOT", MU_FILTER_ENCODE,
-                            MU_STREAM_READ);
+  status = _mu_smtp_data_begin (smtp);
   if (status)
     return status;
-  
-  status = _smtp_data_send (smtp, input);
-  mu_stream_destroy (&input);
-  if (status == 0)
-    smtp->state = MU_SMTP_DOT;
-  return status;
+
+  status = mu_filter_create (&input, smtp->carrier, "CRLFDOT",
+                            MU_FILTER_ENCODE, MU_STREAM_WRITE);
+  if (status)
+    return status;
+  input->event_cb = _smtp_event_cb;
+  input->event_cb_data = smtp;
+  input->event_mask = _MU_STR_EVMASK (_MU_STR_EVENT_CLOSE);
+  *pstream = input;
+  return 0;
 }
diff --git a/libproto/mailer/smtp_ehlo.c b/libproto/mailer/smtp_ehlo.c
index 3a693c7..1a7caf5 100644
--- a/libproto/mailer/smtp_ehlo.c
+++ b/libproto/mailer/smtp_ehlo.c
@@ -94,6 +94,7 @@ mu_smtp_ehlo (mu_smtp_t smtp)
       if (smtp->replcode[0] != '2')
        return MU_ERR_REPLY;
     }
-  smtp->state = MU_SMTP_MAIL;
+  if (smtp->state == MU_SMTP_EHLO)
+    smtp->state = MU_SMTP_MAIL;
   return 0;
 }
diff --git a/libproto/mailer/smtp_mail.c b/libproto/mailer/smtp_mail.c
index 9099858..c3b02de 100644
--- a/libproto/mailer/smtp_mail.c
+++ b/libproto/mailer/smtp_mail.c
@@ -19,6 +19,7 @@
 #endif
 
 #include <errno.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/errno.h>
@@ -26,10 +27,11 @@
 #include <mailutils/list.h>
 #include <mailutils/mutil.h>
 #include <mailutils/smtp.h>
+#include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const char *args)
+mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const char *fmt, ...)
 {
   int status;
   
@@ -41,9 +43,14 @@ mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const 
char *args)
     return MU_ERR_SEQ;
   status = mu_smtp_write (smtp, "MAIL FROM:<%s>", email);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (args)
+  if (fmt)
     {
-      status = mu_smtp_write (smtp, " %s", args);
+      va_list ap;
+
+      status = mu_smtp_write (smtp, " ");
+      va_start (ap, fmt);
+      status = mu_stream_vprintf (smtp->carrier, fmt, ap);
+      va_end (ap);
       MU_SMTP_CHECK_ERROR (smtp, status);
     }
   status = mu_smtp_write (smtp, "\r\n");
diff --git a/libproto/mailer/smtp_param.c b/libproto/mailer/smtp_param.c
index 5017c1d..21fa74b 100644
--- a/libproto/mailer/smtp_param.c
+++ b/libproto/mailer/smtp_param.c
@@ -24,6 +24,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
+#include <mailutils/secret.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
@@ -69,7 +70,7 @@ mu_smtp_get_param (mu_smtp_t smtp, int pcode, const char 
**pparam)
   if (pcode == MU_SMTP_PARAM_PASSWORD && smtp->secret &&
       !MU_SMTP_FISSET (smtp, _MU_SMTP_CLNPASS))
     {
-      smtp->param[pcode] = mu_secret_password (smtp->secret);
+      smtp->param[pcode] = (char*) mu_secret_password (smtp->secret);
       MU_SMTP_FSET (smtp, _MU_SMTP_CLNPASS);
     }
   
diff --git a/libproto/mailer/smtp_rcpt.c b/libproto/mailer/smtp_rcpt.c
index dd5d357..30962fe 100644
--- a/libproto/mailer/smtp_rcpt.c
+++ b/libproto/mailer/smtp_rcpt.c
@@ -26,10 +26,11 @@
 #include <mailutils/list.h>
 #include <mailutils/mutil.h>
 #include <mailutils/smtp.h>
+#include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const char *args)
+mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const char *fmt, ...)
 {
   int status;
   
@@ -41,9 +42,14 @@ mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const 
char *args)
     return MU_ERR_SEQ;
   status = mu_smtp_write (smtp, "RCPT TO:<%s>", email);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (args)
+  if (fmt)
     {
-      status = mu_smtp_write (smtp, " %s", args);
+      va_list ap;
+
+      status = mu_smtp_write (smtp, " ");
+      va_start (ap, fmt);
+      status = mu_stream_vprintf (smtp->carrier, fmt, ap);
+      va_end (ap);
       MU_SMTP_CHECK_ERROR (smtp, status);
     }
   status = mu_smtp_write (smtp, "\r\n");
@@ -56,5 +62,3 @@ mu_smtp_rcpt_basic (mu_smtp_t smtp, const char *email, const 
char *args)
   smtp->state = MU_SMTP_MORE;
   return 0;
 }
-
-      
diff --git a/libproto/mailer/smtp_quit.c b/libproto/mailer/smtp_send.c
similarity index 64%
copy from libproto/mailer/smtp_quit.c
copy to libproto/mailer/smtp_send.c
index c87544e..104fa12 100644
--- a/libproto/mailer/smtp_quit.c
+++ b/libproto/mailer/smtp_send.c
@@ -28,21 +28,41 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
+static int
+_smtp_data_send (mu_smtp_t smtp, mu_stream_t stream)
+{
+  int status = _mu_smtp_data_begin (smtp);
+
+  if (status)
+    return status;
+
+  status = mu_stream_copy (smtp->carrier, stream, 0, NULL);
+  _mu_smtp_data_end (smtp);
+  return status;
+}
+
+
 int
-mu_smtp_quit (mu_smtp_t smtp)
+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;
-  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] != '2')
-    return MU_ERR_REPLY;
-  smtp->state = MU_SMTP_CLOS;
-  return 0;
+  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/testsuite/smtpsend.c b/testsuite/smtpsend.c
index f3e345a..92c8445 100644
--- a/testsuite/smtpsend.c
+++ b/testsuite/smtpsend.c
@@ -20,6 +20,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <mailutils/cctype.h>
 #include <mailutils/mailutils.h>
 #include <mailutils/smtp.h>
 
@@ -27,7 +28,8 @@ static char usage_text[] =
 "usage: %s hostname [port=N] [trace=N] [tls=N] [from=STRING] [rcpt=STRING]\n"
 "                   [domain=STRING] [user=STRING] [pass=STRING]\n"
 "                   [service=STRING] [realm=STRING] [host=STRING]\n"
-"                   [auth=method[,...]] [url=STRING] [input=FILE] [raw=N]\n";
+"                   [auth=method[,...]] [url=STRING] [input=FILE] [raw=N]\n"
+"                   [skiphdr=name[,...]]\n";
 
 static void
 usage ()
@@ -45,12 +47,40 @@ send_rcpt_command (void *item, void *data)
   MU_ASSERT (mu_smtp_rcpt_basic (smtp, email, NULL));
   return 0;
 }
+
+static void
+update_list (mu_list_t *plist, const char *arg)
+{
+  int mc, j;
+  char **mv;
+  mu_list_t list = *plist;
   
+  if (!list)
+    {
+      MU_ASSERT (mu_list_create (&list));
+      *plist = list;
+    }
+
+  MU_ASSERT (mu_argcv_get_np (arg, strlen (arg),
+                             ",", NULL,
+                             0,
+                             &mc, &mv, NULL));
+  for (j = 0; j < mc; j++)
+    MU_ASSERT (mu_list_append (list, mv[j]));
+  free (mv);
+}
+
+static int
+headercmp (const void *item, const void *data)
+{
+  return mu_c_strcasecmp (item, data);
+}
+
 int
 main (int argc, char **argv)
 {
   int i;
-  char *host;
+  char *host = NULL;
   char *infile = NULL;
   int port = 25;
   int tls = 0;
@@ -62,6 +92,7 @@ main (int argc, char **argv)
   char *from = NULL;
   mu_list_t rcpt_list = NULL;
   mu_list_t meth_list = NULL;
+  mu_list_t skiphdr_list = NULL;
   
   mu_set_program_name (argv[0]);
 #ifdef WITH_TLS
@@ -85,8 +116,17 @@ main (int argc, char **argv)
            }
        }
       else if (strncmp (argv[i], "trace=", 6) == 0)
-       mu_smtp_trace (smtp, atoi (argv[i] + 6) ?
-                      MU_SMTP_TRACE_SET : MU_SMTP_TRACE_CLR);
+       {
+         char *arg = argv[i] + 6;
+
+         if (mu_isdigit (arg[0]))
+           mu_smtp_trace (smtp, atoi (argv[i] + 6) ?
+                          MU_SMTP_TRACE_SET : MU_SMTP_TRACE_CLR);
+         else if (strcmp (arg, "secure") == 0)
+           mu_smtp_trace_mask (smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_SECURE);
+         else if (strcmp (arg, "payload") == 0)
+           mu_smtp_trace_mask (smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_PAYLOAD);
+       }
       else if (strncmp (argv[i], "tls=", 4) == 0)
        tls = atoi (argv[i] + 4);
       else if (strncmp (argv[i], "domain=", 7) == 0)
@@ -110,8 +150,8 @@ main (int argc, char **argv)
       else if (strncmp (argv[i], "url=", 4) == 0)
        MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_URL,
                                      argv[i] + 4));
-      else if (strncmp (argv[i], "infile=", 7) == 0)
-       infile = argv[i] + 7;
+      else if (strncmp (argv[i], "input=", 6) == 0)
+       infile = argv[i] + 6;
       else if (strncmp (argv[i], "raw=", 4) == 0)
        raw = atoi (argv[i] + 4);
       else if (strncmp (argv[i], "rcpt=", 5) == 0)
@@ -123,20 +163,17 @@ main (int argc, char **argv)
       else if (strncmp (argv[i], "from=", 5) == 0)
        from = argv[i] + 5;
       else if (strncmp (argv[i], "auth=", 5) == 0)
+       update_list (&meth_list, argv[i] + 5);
+      else if (strncmp (argv[i], "skiphdr=", 8) == 0)
        {
-         int mc, j;
-         char **mv;
-         
-         if (!meth_list)
-           MU_ASSERT (mu_list_create (&meth_list));
-
-         MU_ASSERT (mu_argcv_get_np (argv[i] + 5, strlen (argv[i] + 5),
-                                     ",", NULL,
-                                     0,
-                                     &mc, &mv, NULL));
-         for (j = 0; j < mc; j++)
-           MU_ASSERT (mu_list_append (meth_list, mv[j]));
-         free (mv);
+         update_list (&skiphdr_list, argv[i] + 8);
+         raw = 0;
+       }
+      else if (host)
+       {
+         mu_error ("server name already given: %s, new name %s?",
+                   host, argv[i]);
+         exit (1);
        }
       else
        host = argv[i];
@@ -209,20 +246,55 @@ main (int argc, char **argv)
        }
     }
   
+  MU_ASSERT (mu_smtp_mail_basic (smtp, from, NULL));
+  mu_list_do (rcpt_list, send_rcpt_command, 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_message_t msg;
+      mu_stream_t ostr, bstr;
+      mu_header_t hdr;
+      mu_iterator_t itr;
+      mu_body_t body;
+
+      if (skiphdr_list)
+       mu_list_set_comparator (skiphdr_list, headercmp);
+      
+      MU_ASSERT (mu_stream_to_message (instr, &msg));
+      MU_ASSERT (mu_smtp_data (smtp, &ostr));
+      MU_ASSERT (mu_message_get_header (msg, &hdr));
+      MU_ASSERT (mu_header_get_iterator (hdr, &itr));
+      for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+          mu_iterator_next (itr))
+       {
+         const char *name;
+         void *value;
+
+         mu_iterator_current_kv (itr, (void*) &name, &value);
+         if (mu_list_locate (skiphdr_list, (void*) name, NULL) == 0)
+           continue;
+
+         mu_stream_printf (ostr, "%s: %s\n", name, (char*)value);
+       }
+      mu_iterator_destroy (&itr);
+      MU_ASSERT (mu_stream_write (ostr, "\n", 1, NULL));
+      
+      MU_ASSERT (mu_message_get_body (msg, &body));
+      MU_ASSERT (mu_body_get_streamref (body, &bstr));
+      MU_ASSERT (mu_stream_copy (ostr, bstr, 0, NULL));
+      mu_stream_destroy (&bstr);
+      mu_stream_close (ostr);
+      mu_stream_destroy (&ostr);
     }
   
+  MU_ASSERT (mu_smtp_quit (smtp));
   
   mu_smtp_destroy (&smtp);
   mu_stream_close (instr);


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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