summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac1
-rw-r--r--include/mailutils/Makefile.am1
-rw-r--r--include/mailutils/imapio.h52
-rw-r--r--include/mailutils/sys/Makefile.am1
-rw-r--r--include/mailutils/sys/imapio.h35
-rw-r--r--include/mailutils/types.hin2
-rw-r--r--libmailutils/Makefile.am3
-rw-r--r--libmailutils/imapio/Makefile.am31
-rw-r--r--libmailutils/imapio/create.c63
-rw-r--r--libmailutils/imapio/getline.c114
-rw-r--r--libmailutils/imapio/literal.c31
-rw-r--r--libmailutils/imapio/printf.c35
-rw-r--r--libmailutils/imapio/qstring.c72
-rw-r--r--libmailutils/imapio/send.c29
-rw-r--r--libmailutils/imapio/trace.c86
-rw-r--r--libmailutils/imapio/words.c42
-rw-r--r--libmailutils/imapio/xscript.c46
-rw-r--r--libmailutils/tests/.gitignore1
-rw-r--r--libmailutils/tests/Makefile.am1
-rw-r--r--libmailutils/tests/imapio.c95
-rw-r--r--libmailutils/tests/wsp.c5
21 files changed, 745 insertions, 1 deletions
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
--- a/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/include/mailutils/sys/imapio.h b/include/mailutils/sys/imapio.h
new file mode 100644
index 0000000..524c5be
--- a/dev/null
+++ b/include/mailutils/sys/imapio.h
@@ -0,0 +1,35 @@
+/* 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_SYS_IMAPIO_H
+# define _MAILUTILS_SYS_IMAPIO_H
+
+#include <mailutils/types.h>
+#include <mailutils/wordsplit.h>
+
+struct _mu_imapio
+{
+ 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/imapio/Makefile.am b/libmailutils/imapio/Makefile.am
new file mode 100644
index 0000000..74f36a2
--- a/dev/null
+++ b/libmailutils/imapio/Makefile.am
@@ -0,0 +1,31 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2011 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 of the License, 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 this library. If not, see
+# <http://www.gnu.org/licenses/>.
+
+noinst_LTLIBRARIES = libimapio.la
+
+libimapio_la_SOURCES = \
+ create.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
--- a/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
--- a/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/libmailutils/imapio/literal.c b/libmailutils/imapio/literal.c
new file mode 100644
index 0000000..e46d23e
--- a/dev/null
+++ b/libmailutils/imapio/literal.c
@@ -0,0 +1,31 @@
+/* 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/sys/imapio.h>
+#include <mailutils/stream.h>
+
+int
+mu_imapio_send_literal (struct _mu_imapio *io, const char *buffer)
+{
+ return mu_stream_printf (io->_imap_stream,
+ "{%lu}\n%s", (unsigned long) strlen (buffer),
+ buffer);
+}
diff --git a/libmailutils/imapio/printf.c b/libmailutils/imapio/printf.c
new file mode 100644
index 0000000..801e82a
--- a/dev/null
+++ b/libmailutils/imapio/printf.c
@@ -0,0 +1,35 @@
+/* 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 <stdarg.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imapio.h>
+
+int
+mu_imapio_printf (mu_imapio_t io, const char *fmt, ...)
+{
+ va_list ap;
+ int status;
+
+ 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
--- a/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/libmailutils/imapio/send.c b/libmailutils/imapio/send.c
new file mode 100644
index 0000000..11ee049
--- a/dev/null
+++ b/libmailutils/imapio/send.c
@@ -0,0 +1,29 @@
+/* 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 <stdarg.h>
+#include <mailutils/types.h>
+#include <mailutils/imapio.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imapio.h>
+
+int
+mu_imapio_send (mu_imapio_t io, const char *buf, size_t bytes)
+{
+ 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
--- a/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/libmailutils/imapio/words.c b/libmailutils/imapio/words.c
new file mode 100644
index 0000000..7fa1c81
--- a/dev/null
+++ b/libmailutils/imapio/words.c
@@ -0,0 +1,42 @@
+/* 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/errno.h>
+#include <mailutils/imapio.h>
+#include <mailutils/sys/imapio.h>
+
+int
+mu_imapio_get_words (mu_imapio_t io, size_t *pwc, char ***pwv)
+{
+ 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/libmailutils/imapio/xscript.c b/libmailutils/imapio/xscript.c
new file mode 100644
index 0000000..ebb003b
--- a/dev/null
+++ b/libmailutils/imapio/xscript.c
@@ -0,0 +1,46 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ 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
+ 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/stream.h>
+#include <mailutils/diag.h>
+#include <mailutils/imapio.h>
+#include <mailutils/sys/imapio.h>
+
+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;
+ }
+
+ 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
--- a/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;

Return to:

Send suggestions and report system problems to the System administrator.