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-444-g6f309ce


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-444-g6f309ce
Date: Thu, 17 Nov 2011 20:08:14 +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=6f309ce61dcfb461c3fe1270efe2b23a7ac5d676

The branch, master has been updated
       via  6f309ce61dcfb461c3fe1270efe2b23a7ac5d676 (commit)
      from  2ec525acff5a090dcba8a0c7c166bbe745340902 (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 6f309ce61dcfb461c3fe1270efe2b23a7ac5d676
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Nov 17 21:07:52 2011 +0200

    Implement IMAP I/O functions for client and server.
    
    * include/mailutils/imapio.h: New file.
    * include/mailutils/sys/imapio.h: New file.
    * libmailutils/imapio/create.c: New file.
    * libmailutils/imapio/getline.c: New file.
    * libmailutils/imapio/literal.c: New file.
    * libmailutils/imapio/printf.c: New file.
    * libmailutils/imapio/qstring.c: New file.
    * libmailutils/imapio/send.c: New file.
    * libmailutils/imapio/trace.c: New file.
    * libmailutils/imapio/words.c: New file.
    * libmailutils/imapio/xscript.c: New file.
    
    * configure.ac: Build libmailutils/imapio/Makefile
    * include/mailutils/Makefile.am (pkginclude_HEADERS): Add imapio.h.
    * include/mailutils/imapio.h: New file.
    * include/mailutils/sys/Makefile.am (sysinclude_HEADERS): Add imapio.h.
    * include/mailutils/sys/imapio.h: New file.
    * include/mailutils/types.hin (mu_imapio_t): New data type.
    * libmailutils/Makefile.am (SUBDIRS): Add imapio.
    
    * libmailutils/tests/Makefile.am: Build imapio
    * libmailutils/tests/imapio.c: New source.
    * libmailutils/tests/wsp.c: Handle escape argument

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

Summary of changes:
 configure.ac                                      |    1 +
 include/mailutils/Makefile.am                     |    1 +
 include/mailutils/imapio.h                        |   52 ++++++++++
 include/mailutils/sys/Makefile.am                 |    1 +
 mail/help.c => include/mailutils/sys/imapio.h     |   39 +++----
 include/mailutils/types.hin                       |    2 +
 libmailutils/Makefile.am                          |    3 +-
 libmailutils/{sockaddr => imapio}/Makefile.am     |   20 ++--
 libmailutils/imapio/create.c                      |   63 +++++++++++
 libmailutils/imapio/getline.c                     |  114 +++++++++++++++++++++
 mail/exit.c => libmailutils/imapio/literal.c      |   18 ++-
 mail/cd.c => libmailutils/imapio/printf.c         |   38 +++----
 libmailutils/imapio/qstring.c                     |   72 +++++++++++++
 mail/exit.c => libmailutils/imapio/send.c         |   16 ++-
 libmailutils/imapio/trace.c                       |   86 ++++++++++++++++
 examples/muemail.c => libmailutils/imapio/words.c |   47 ++++-----
 lib/tcpwrap.h => libmailutils/imapio/xscript.c    |   41 +++++---
 libmailutils/tests/.gitignore                     |    1 +
 libmailutils/tests/Makefile.am                    |    1 +
 libmailutils/tests/imapio.c                       |   95 +++++++++++++++++
 libmailutils/tests/wsp.c                          |    5 +
 21 files changed, 607 insertions(+), 109 deletions(-)
 create mode 100644 include/mailutils/imapio.h
 copy mail/help.c => include/mailutils/sys/imapio.h (62%)
 copy libmailutils/{sockaddr => imapio}/Makefile.am (85%)
 create mode 100644 libmailutils/imapio/create.c
 create mode 100644 libmailutils/imapio/getline.c
 copy mail/exit.c => libmailutils/imapio/literal.c (62%)
 copy mail/cd.c => libmailutils/imapio/printf.c (62%)
 create mode 100644 libmailutils/imapio/qstring.c
 copy mail/exit.c => libmailutils/imapio/send.c (67%)
 create mode 100644 libmailutils/imapio/trace.c
 copy examples/muemail.c => libmailutils/imapio/words.c (55%)
 copy lib/tcpwrap.h => libmailutils/imapio/xscript.c (51%)
 create mode 100644 libmailutils/tests/imapio.c

diff --git a/configure.ac b/configure.ac
index 389800e..7251453 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1472,6 +1472,7 @@ AC_CONFIG_FILES([
  libmailutils/cfg/Makefile
  libmailutils/diag/Makefile
  libmailutils/filter/Makefile
+ libmailutils/imapio/Makefile
  libmailutils/mailbox/Makefile
  libmailutils/mailer/Makefile
  libmailutils/mime/Makefile
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 6682884..27c1b5a 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -52,6 +52,7 @@ pkginclude_HEADERS = \
  guile.h\
  header.h\
  imap.h\
+ imapio.h\
  io.h\
  iterator.h\
  kwd.h\
diff --git a/include/mailutils/imapio.h b/include/mailutils/imapio.h
new file mode 100644
index 0000000..387e3df
--- /dev/null
+++ b/include/mailutils/imapio.h
@@ -0,0 +1,52 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _MAILUTILS_IMAPIO_H
+# define _MAILUTILS_IMAPIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+# include <mailutils/types.h>
+  
+int mu_imapio_create (mu_imapio_t *iop, mu_stream_t str);
+void mu_imapio_free (mu_imapio_t io);
+void mu_imapio_destroy (mu_imapio_t *pio);
+  
+int mu_imapio_getline (mu_imapio_t io);
+int mu_imapio_set_xscript_level (mu_imapio_t io, int xlev);  
+int mu_imapio_get_words (mu_imapio_t io, size_t *pwc, char ***pwv);
+
+int mu_imapio_send (mu_imapio_t io, const char *buf, size_t bytes);
+int mu_imapio_printf (mu_imapio_t io, const char *fmt, ...);
+int mu_imapio_send_literal (struct _mu_imapio *io, const char *buffer);
+int mu_imapio_send_qstring (struct _mu_imapio *io, const char *buffer);
+int mu_imapio_send_qstring_unfold (struct _mu_imapio *io, const char *buffer,
+                                  int unfold);
+
+int mu_imapio_trace_enable (mu_imapio_t io);
+int mu_imapio_trace_disable (mu_imapio_t io);
+int mu_imapio_get_trace (mu_imapio_t io);
+
+int mu_imapio_getbuf (mu_imapio_t io, char **pptr, size_t *psize);
+  
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAILUTILS_IMAPIO_H */
+  
diff --git a/include/mailutils/sys/Makefile.am 
b/include/mailutils/sys/Makefile.am
index e46a294..86412d0 100644
--- a/include/mailutils/sys/Makefile.am
+++ b/include/mailutils/sys/Makefile.am
@@ -31,6 +31,7 @@ sysinclude_HEADERS = \
  header_stream.h\
  header.h\
  imap.h\
+ imapio.h\
  iterator.h\
  iostream.h\
  list.h\
diff --git a/mail/help.c b/include/mailutils/sys/imapio.h
similarity index 62%
copy from mail/help.c
copy to include/mailutils/sys/imapio.h
index 16e873d..524c5be 100644
--- a/mail/help.c
+++ b/include/mailutils/sys/imapio.h
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2005, 2007, 2010, 2011 Free Software
-   Foundation, Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,26 +14,22 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "mail.h"
+#ifndef _MAILUTILS_SYS_IMAPIO_H
+# define _MAILUTILS_SYS_IMAPIO_H
 
-/*
- * hel[p] [command]
- * ? [command]
- */
+#include <mailutils/types.h>
+#include <mailutils/wordsplit.h>
 
-int
-mail_help (int argc, char **argv)
+struct _mu_imapio
 {
-  if (argc < 2)
-    return mail_command_help (NULL);
-  else
-    {
-      int status = 0;
-
-      while (--argc)
-       status |= mail_command_help (*++argv);
-
-      return status;
-    }
-  return 1;
-}
+  mu_stream_t _imap_stream;
+  char *_imap_buf_base;
+  size_t _imap_buf_size;
+  size_t _imap_buf_level;
+  struct mu_wordsplit _imap_ws;
+  int _imap_ws_flags;
+  int _imap_transcript:1;
+  int _imap_reply_ready:1;
+};
+  
+#endif
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index c1f4b44..b98d617 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -76,6 +76,7 @@ struct _mu_acl;
 struct _mu_server;
 struct _mu_tcp_server;
 struct _mu_dbm_file;
+struct _mu_imapio;
   
 struct mu_sockaddr; /* defined in mailutils/sockaddr.h */  
 struct mu_cidr;     /* defined in mailutils/cidr.h */  
@@ -123,6 +124,7 @@ typedef struct _mu_progmailer *mu_progmailer_t;
 typedef struct _mu_secret *mu_secret_t;
 typedef struct _mu_mime_io_buffer *mu_mime_io_buffer_t;
 typedef struct _mu_dbm_file *mu_dbm_file_t;
+typedef struct _mu_imapio *mu_imapio_t;
 
 typedef void (*mu_onexit_t) (void*);
 typedef unsigned int mu_debug_handle_t;
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 5aef338..7c1c5c4 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -17,7 +17,7 @@
 # <http://www.gnu.org/licenses/>.
 
 SUBDIRS = auth base address sockaddr cidr cfg diag filter mailbox mailer mime\
- server string stream stdstream property url . tests 
+ server string stream stdstream property url imapio . tests 
 
 lib_LTLIBRARIES = libmailutils.la
 
@@ -33,6 +33,7 @@ libmailutils_la_LIBADD = \
  cfg/libcfg.la\
  diag/libdiag.la\
  filter/libfilter.la\
+ imapio/libimapio.la\
  mailbox/libmailbox.la\
  mailer/libmailer.la\
  mime/libmime.la\
diff --git a/libmailutils/sockaddr/Makefile.am b/libmailutils/imapio/Makefile.am
similarity index 85%
copy from libmailutils/sockaddr/Makefile.am
copy to libmailutils/imapio/Makefile.am
index dcfb184..74f36a2 100644
--- a/libmailutils/sockaddr/Makefile.am
+++ b/libmailutils/imapio/Makefile.am
@@ -15,17 +15,17 @@
 # Public License along with this library.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-noinst_LTLIBRARIES = libsockaddr.la
+noinst_LTLIBRARIES = libimapio.la
 
-libsockaddr_la_SOURCES = \
- copy.c\
+libimapio_la_SOURCES = \
  create.c\
- free.c\
- fromnode.c\
- insert.c\
- ipaddr.c\
- str.c\
- unlink.c\
- url.c
+ getline.c\
+ literal.c\
+ printf.c\
+ qstring.c\
+ send.c\
+ trace.c\
+ words.c\
+ xscript.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/imapio/create.c b/libmailutils/imapio/create.c
new file mode 100644
index 0000000..4a3a9af
--- /dev/null
+++ b/libmailutils/imapio/create.c
@@ -0,0 +1,63 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdlib.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/imapio.h>
+
+int
+mu_imapio_create (mu_imapio_t *iop, mu_stream_t str)
+{
+  struct _mu_imapio *io = calloc (1, sizeof (*io));
+  if (!io)
+    return ENOMEM;
+  io->_imap_stream = str;
+  mu_stream_ref (str);
+  io->_imap_ws.ws_delim = " \t()";
+  io->_imap_ws.ws_escape = "\\\"";
+  io->_imap_ws_flags = MU_WRDSF_DELIM |
+                       MU_WRDSF_ESCAPE |
+                       MU_WRDSF_NOVAR |
+                       MU_WRDSF_NOCMD | 
+                       MU_WRDSF_QUOTE |
+                       MU_WRDSF_RETURN_DELIMS |
+                       MU_WRDSF_WS;
+  *iop = io;
+  return 0;
+}
+
+void
+mu_imapio_free (mu_imapio_t io)
+{
+  if (!io)
+    return;
+  if (io->_imap_ws_flags & MU_WRDSF_REUSE)
+    mu_wordsplit_free (&io->_imap_ws);
+  mu_stream_unref (io->_imap_stream);
+  free (io);
+}
+
+void
+mu_imapio_destroy (mu_imapio_t *pio)
+{
+  if (!pio)
+    return;
+  mu_imapio_free (*pio);
+  *pio = NULL;
+}
+
diff --git a/libmailutils/imapio/getline.c b/libmailutils/imapio/getline.c
new file mode 100644
index 0000000..28c8d4b
--- /dev/null
+++ b/libmailutils/imapio/getline.c
@@ -0,0 +1,114 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/cstr.h>
+#include <mailutils/cctype.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/imapio.h>
+
+int
+mu_imapio_getline (struct _mu_imapio *io)
+{
+  int rc;
+  char *last_arg;
+
+  io->_imap_ws_flags &= ~MU_WRDSF_APPEND;
+
+  if (io->_imap_reply_ready)
+    {
+      mu_wordsplit_free_words (&io->_imap_ws);
+      io->_imap_reply_ready = 0;
+    }
+  
+  for (;;)
+    {
+      rc = mu_stream_getline (io->_imap_stream,
+                             &io->_imap_buf_base, &io->_imap_buf_size,
+                             &io->_imap_buf_level);
+      if (rc)
+       return rc;
+      if (io->_imap_buf_level == 0)
+       break;
+      io->_imap_buf_level = mu_rtrim_class (io->_imap_buf_base,
+                                           MU_CTYPE_ENDLN);
+
+      if (mu_wordsplit_len (io->_imap_buf_base, io->_imap_buf_level,
+                           &io->_imap_ws, io->_imap_ws_flags))
+       return MU_ERR_PARSE;
+      io->_imap_ws_flags |= MU_WRDSF_REUSE|MU_WRDSF_APPEND;
+
+      last_arg = io->_imap_ws.ws_wordv[io->_imap_ws.ws_wordc - 1];
+      if (last_arg[0] == '{' && last_arg[strlen (last_arg)-1] == '}')
+       {
+         int rc;
+         unsigned long number;
+         char *sp = NULL;
+         int xlev = mu_imapio_set_xscript_level (io, MU_XSCRIPT_PAYLOAD);
+         
+         number = strtoul (last_arg + 1, &sp, 10);
+         /* Client can ask for non-synchronised literal,
+            if a '+' is appended to the octet count. */
+         if (*sp == '}')
+           mu_stream_printf (io->_imap_stream, "+ GO AHEAD\n");
+         else if (*sp != '+')
+           break;
+
+         if (number + 1 > io->_imap_buf_size)
+           {
+             size_t newsize = number + 1;
+             void *newp = realloc (&io->_imap_buf_base, newsize);
+             if (!newp)
+               return ENOMEM;
+             io->_imap_buf_base = newp;
+             io->_imap_buf_size = newsize;
+           }
+             
+          for (io->_imap_buf_level = 0; io->_imap_buf_level < number; )
+            {
+               size_t sz;
+              rc = mu_stream_read (io->_imap_stream,
+                                   io->_imap_buf_base + io->_imap_buf_level,
+                                   number - io->_imap_buf_level,
+                                   &sz);
+               if (rc || sz == 0)
+                 break;
+               io->_imap_buf_level += sz;
+            }
+         mu_imapio_set_xscript_level (io, xlev);
+         if (rc)
+           return rc;
+         io->_imap_buf_base[io->_imap_buf_level++] = 0;
+
+         free (last_arg);
+         io->_imap_ws.ws_wordv[--io->_imap_ws.ws_wordc] = NULL;
+         if (mu_wordsplit_len (io->_imap_buf_base, io->_imap_buf_level,
+                               &io->_imap_ws,
+                               io->_imap_ws_flags|MU_WRDSF_NOSPLIT))
+           return MU_ERR_PARSE;
+       }
+      else
+       break;
+    }
+
+  io->_imap_reply_ready = 1;
+  return 0;
+}
diff --git a/mail/exit.c b/libmailutils/imapio/literal.c
similarity index 62%
copy from mail/exit.c
copy to libmailutils/imapio/literal.c
index 888cfd6..e46d23e 100644
--- a/mail/exit.c
+++ b/libmailutils/imapio/literal.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2005, 2007, 2010, 2011 Free Software
-   Foundation, Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,11 +14,18 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "mail.h"
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/sys/imapio.h>
+#include <mailutils/stream.h>
 
 int
-mail_exit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
+mu_imapio_send_literal (struct _mu_imapio *io, const char *buffer)
 {
-  mu_mailbox_close (mbox);
-  exit (0);
+  return mu_stream_printf (io->_imap_stream,
+                          "{%lu}\n%s", (unsigned long) strlen (buffer),
+                          buffer);
 }
diff --git a/mail/cd.c b/libmailutils/imapio/printf.c
similarity index 62%
copy from mail/cd.c
copy to libmailutils/imapio/printf.c
index c8b078a..801e82a 100644
--- a/mail/cd.c
+++ b/libmailutils/imapio/printf.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2005, 2007, 2010, 2011 Free Software Foundation,
-   Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,29 +14,22 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "mail.h"
-
-/*
- * cd [directory]
- * ch[dir] [directory]
- */
+#include <config.h>
+#include <stdarg.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imapio.h>
 
 int
-mail_cd (int argc, char **argv)
+mu_imapio_printf (mu_imapio_t io, const char *fmt, ...)
 {
-  char *dir;
+  va_list ap;
+  int status;
   
-  if (argc > 2)
-    return 1;
-  else if (argc == 2)
-    dir = argv[1];
-  else 
-    dir = getenv ("HOME");
-
-  if (chdir (dir))
-    {
-      mu_diag_funcall (MU_DIAG_ERROR, "chdir", dir, errno);
-      return 1;
-    }
-  return 0;
+  va_start (ap, fmt);
+  status = mu_stream_vprintf (io->_imap_stream, fmt, ap);
+  va_end (ap);
+  return status;
 }
+    
diff --git a/libmailutils/imapio/qstring.c b/libmailutils/imapio/qstring.c
new file mode 100644
index 0000000..f50c15c
--- /dev/null
+++ b/libmailutils/imapio/qstring.c
@@ -0,0 +1,72 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imapio.h>
+
+/* Send NIL if empty string, change the quoted string to a literal if the
+   string contains: double quotes, CR, LF, or \. */
+
+int
+mu_imapio_send_qstring_unfold (struct _mu_imapio *io, const char *buffer,
+                              int unfold)
+{
+  if (buffer == NULL || *buffer == '\0')
+    return mu_imapio_printf (io, "NIL");
+  if (strchr (buffer, '"') ||
+      strchr (buffer, '\r') ||
+      strchr (buffer, '\n') ||
+      strchr (buffer, '\\'))
+    {
+      if (unfold)
+       {
+         int rc;
+         size_t len = strlen (buffer);
+
+         rc = mu_stream_printf (io->_imap_stream,
+                                "{%lu}\n", (unsigned long) strlen (buffer));
+         if (rc)
+           return rc;
+         for (;;)
+           {
+             size_t s = strcspn (buffer, "\r\n");
+             rc = mu_stream_write (io->_imap_stream, buffer, s, NULL);
+             if (rc)
+               return rc;
+             len -= s;
+             if (len == 0)
+               break;
+             buffer += s;
+             rc = mu_stream_write (io->_imap_stream, " ", 1, NULL);
+             if (rc)
+               return rc;
+           }
+       }
+      else
+       return mu_imapio_send_literal (io, buffer);
+    }
+  return mu_imapio_printf (io, "\"%s\"", buffer);
+}
+
+int
+mu_imapio_send_qstring (struct _mu_imapio *io, const char *buffer)
+{
+  return mu_imapio_send_qstring_unfold (io, buffer, 0);
+}
diff --git a/mail/exit.c b/libmailutils/imapio/send.c
similarity index 67%
copy from mail/exit.c
copy to libmailutils/imapio/send.c
index 888cfd6..11ee049 100644
--- a/mail/exit.c
+++ b/libmailutils/imapio/send.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2005, 2007, 2010, 2011 Free Software
-   Foundation, Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,11 +14,16 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "mail.h"
+#include <config.h>
+#include <stdarg.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imapio.h>
 
 int
-mail_exit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
+mu_imapio_send (mu_imapio_t io, const char *buf, size_t bytes)
 {
-  mu_mailbox_close (mbox);
-  exit (0);
+  return mu_stream_write (io->_imap_stream, buf, bytes, NULL);
 }
+    
diff --git a/libmailutils/imapio/trace.c b/libmailutils/imapio/trace.c
new file mode 100644
index 0000000..ae60745
--- /dev/null
+++ b/libmailutils/imapio/trace.c
@@ -0,0 +1,86 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <errno.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/nls.h>
+#include <mailutils/sys/imapio.h>
+
+static const char *imapio_prefix[] = {
+  "S: ", "C: "
+};
+
+int
+mu_imapio_trace_enable (mu_imapio_t io)
+{
+  int rc = 0;
+  mu_stream_t dstr, xstr;
+
+  if (io->_imap_transcript)
+    return MU_ERR_OPEN;
+  
+  rc = mu_dbgstream_create (&dstr, MU_DIAG_DEBUG);
+  if (rc)
+    mu_error (_("cannot create debug stream; transcript disabled: %s"),
+             mu_strerror (rc));
+  else
+    {
+      rc = mu_xscript_stream_create (&xstr, io->_imap_stream, dstr,
+                                    imapio_prefix);
+      if (rc)
+       mu_error (_("cannot create transcript stream: %s"),
+                 mu_strerror (rc));
+      else
+       {
+         mu_stream_unref (io->_imap_stream);
+         io->_imap_stream = xstr;
+         io->_imap_transcript = 1;
+       }
+    }
+
+  return rc;
+}
+
+int
+mu_imapio_trace_disable (mu_imapio_t io)
+{
+  mu_stream_t xstr = io->_imap_stream;
+  mu_stream_t stream[2];
+  int rc;
+
+  if (!io->_imap_transcript)
+    return MU_ERR_NOT_OPEN;
+  
+  rc = mu_stream_ioctl (xstr, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, stream);
+  if (rc)
+    return rc;
+
+  io->_imap_stream = stream[0];
+  mu_stream_destroy (&xstr);
+  io->_imap_transcript = 0;
+  return 0;
+}
+
+int
+mu_imapio_get_trace (mu_imapio_t io)
+{
+  return io ? io->_imap_transcript : 0; 
+}
diff --git a/examples/muemail.c b/libmailutils/imapio/words.c
similarity index 55%
copy from examples/muemail.c
copy to libmailutils/imapio/words.c
index 39a8099..7fa1c81 100644
--- a/examples/muemail.c
+++ b/libmailutils/imapio/words.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2007, 2010, 2011 Free Software
-   Foundation, Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,35 +14,29 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 #include <stdlib.h>
-#include <stdio.h>
-#include <mailutils/util.h>
-#include "mailutils/libargp.h"
-
-const char *capa[] = {
-  "address",
-  NULL
-};
+#include <mailutils/errno.h>
+#include <mailutils/imapio.h>
+#include <mailutils/sys/imapio.h>
 
 int
-main (int argc, char *argv[])
+mu_imapio_get_words (mu_imapio_t io, size_t *pwc, char ***pwv)
 {
-  int arg = 1;
-
-  if (mu_app_init (NULL, capa, NULL, argc, argv, 0, &arg, NULL))
-    exit (1);
-
-  if (!argv[arg])
-    printf ("current user -> %s\n", mu_get_user_email (0));
-  else
-    {
-      for (; argv[arg]; arg++)
-        printf ("%s -> %s\n", argv[arg], mu_get_user_email (argv[arg]));
-    }
-
+  if (!io->_imap_reply_ready)
+    return MU_ERR_INFO_UNAVAILABLE;
+  *pwc = io->_imap_ws.ws_wordc;
+  *pwv = io->_imap_ws.ws_wordv;
   return 0;
 }
 
+int
+mu_imapio_getbuf (mu_imapio_t io, char **pptr, size_t *psize)
+{
+  if (!io->_imap_reply_ready)
+    return MU_ERR_INFO_UNAVAILABLE;
+  *pptr  = io->_imap_buf_base;
+  *psize = io->_imap_buf_level;
+  return 0;
+}
+  
diff --git a/lib/tcpwrap.h b/libmailutils/imapio/xscript.c
similarity index 51%
copy from lib/tcpwrap.h
copy to libmailutils/imapio/xscript.c
index 939889a..ebb003b 100644
--- a/lib/tcpwrap.h
+++ b/libmailutils/imapio/xscript.c
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2010, 2011 Free Software Foundation, Inc.
+   2009, 2010, 2011 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,19 +15,32 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
+#include <config.h>
+#include <errno.h>
 #include <mailutils/types.h>
+#include <mailutils/stream.h>
+#include <mailutils/diag.h>
+#include <mailutils/imapio.h>
+#include <mailutils/sys/imapio.h>
 
-extern int mu_tcp_wrapper_enable;
-const char *mu_tcp_wrapper_daemon;
-extern int mu_tcpwrapper_access (int fd);
-extern void mu_tcpwrapper_cfg_init (void);
-extern int mu_tcp_wrapper_prefork (int fd, 
-                                  struct sockaddr *sa, int salen,
-                                  struct mu_srv_config *pconf,
-                                  void *data);
+int
+mu_imapio_set_xscript_level (struct _mu_imapio *io, int xlev)
+{
+  if (!io)
+    return EINVAL;
+  if (io->_imap_transcript)
+    {
+      if (xlev != MU_XSCRIPT_NORMAL)
+       {
+         if (mu_debug_level_p (MU_DEBCAT_REMOTE, 
+                               xlev == MU_XSCRIPT_SECURE ?
+                                 MU_DEBUG_TRACE6 : MU_DEBUG_TRACE7))
+           return MU_XSCRIPT_NORMAL;
+       }
 
-#ifdef WITH_LIBWRAP
-# define TCP_WRAPPERS_CONFIG { "tcp-wrappers", mu_cfg_section },
-#else
-# define TCP_WRAPPERS_CONFIG
-#endif
+      if (mu_stream_ioctl (io->_imap_stream, MU_IOCTL_XSCRIPTSTREAM,
+                           MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev) == 0)
+       return xlev;
+    }
+  return MU_XSCRIPT_NORMAL;
+}
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index 0860f07..444e39e 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -12,6 +12,7 @@ decode2047
 encode2047
 fltst
 fsaf
+imapio
 listop
 mailcap
 prop
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 66d83ca..0ac3ec1 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -47,6 +47,7 @@ noinst_PROGRAMS = \
  encode2047\
  fltst\
  fsaf\
+ imapio\
  listop\
  mailcap\
  prop\
diff --git a/libmailutils/tests/imapio.c b/libmailutils/tests/imapio.c
new file mode 100644
index 0000000..652f0d6
--- /dev/null
+++ b/libmailutils/tests/imapio.c
@@ -0,0 +1,95 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mailutils/imapio.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+#include <mailutils/stdstream.h>
+
+void
+usage ()
+{
+  mu_stream_printf (mu_strout, "usage: %s [debug=SPEC] [-transcript]\n",
+                   mu_program_name);
+  exit (0);
+}
+
+int
+main (int argc, char **argv)
+{
+  int i, rc;
+  int transcript = 0;
+  mu_imapio_t io;
+  mu_stream_t str;
+  
+  mu_set_program_name (argv[0]);
+  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+  
+  for (i = 1; i < argc; i++)
+    {
+      char *opt = argv[i];
+
+      if (strncmp (opt, "debug=", 6) == 0)
+       mu_debug_parse_spec (opt + 6);
+      else if (strcmp (opt, "-transcript") == 0)
+       transcript = 1;
+      else if (strcmp (opt, "-h") == 0)
+       usage ();
+      else
+       {
+         mu_error ("%s: unrecognized argument", opt);
+         exit (1);
+       }
+    }
+
+  MU_ASSERT (mu_iostream_create (&str, mu_strin, mu_strout));
+
+  
+  MU_ASSERT (mu_imapio_create (&io, str));
+
+  if (transcript)
+    mu_imapio_trace_enable (io);
+  mu_stream_unref (str);
+
+  while ((rc = mu_imapio_getline (io)) == 0)
+    {
+      size_t wc;
+      char **wv;
+
+      MU_ASSERT (mu_imapio_get_words (io, &wc, &wv));
+      if (wc == 0)
+       break;
+
+      mu_stream_printf (mu_strerr, "%d\n", wc);
+      for (i = 0; i < wc; i++)
+       {
+         mu_stream_printf (mu_strerr, "%d: '%s'\n", i, wv[i]);
+       }
+    }
+
+  if (rc)
+    mu_error ("mu_imap_getline: %s", mu_strerror (rc));
+
+  mu_imapio_free (io);
+  return 0;
+}
diff --git a/libmailutils/tests/wsp.c b/libmailutils/tests/wsp.c
index 0b8d622..47cd4ff 100644
--- a/libmailutils/tests/wsp.c
+++ b/libmailutils/tests/wsp.c
@@ -53,6 +53,7 @@ struct mu_kwd bool_keytab[] = {
 struct mu_kwd string_keytab[] = {
   { "delim",   MU_WRDSF_DELIM },
   { "comment", MU_WRDSF_COMMENT },
+  { "escape",  MU_WRDSF_ESCAPE },
   { NULL, 0 }
 };
 
@@ -239,6 +240,10 @@ main (int argc, char **argv)
                case MU_WRDSF_COMMENT:
                  ws.ws_comment = argv[i];
                  break;
+
+               case MU_WRDSF_ESCAPE:
+                 ws.ws_escape = argv[i];
+                 break;
                }
              
              wsflags |= flag;


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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