summaryrefslogtreecommitdiffabout
path: root/libmailutils
authorSergey Poznyakoff <gray@gnu.org.ua>2011-11-17 19:07:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-11-17 19:22:31 (GMT)
commit6f309ce61dcfb461c3fe1270efe2b23a7ac5d676 (patch) (side-by-side diff)
treeb692f47baf255d70eaec3eb2e68dec5a2812ac52 /libmailutils
parent2ec525acff5a090dcba8a0c7c166bbe745340902 (diff)
downloadmailutils-6f309ce61dcfb461c3fe1270efe2b23a7ac5d676.tar.gz
mailutils-6f309ce61dcfb461c3fe1270efe2b23a7ac5d676.tar.bz2
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
Diffstat (limited to 'libmailutils') (more/less context) (ignore whitespace changes)
-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
15 files changed, 653 insertions, 1 deletions
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.