diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | include/mailutils/Makefile.am | 1 | ||||
-rw-r--r-- | include/mailutils/imapio.h | 52 | ||||
-rw-r--r-- | include/mailutils/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/mailutils/sys/imapio.h | 35 | ||||
-rw-r--r-- | include/mailutils/types.hin | 2 | ||||
-rw-r--r-- | libmailutils/Makefile.am | 3 | ||||
-rw-r--r-- | libmailutils/imapio/Makefile.am | 31 | ||||
-rw-r--r-- | libmailutils/imapio/create.c | 63 | ||||
-rw-r--r-- | libmailutils/imapio/getline.c | 114 | ||||
-rw-r--r-- | libmailutils/imapio/literal.c | 31 | ||||
-rw-r--r-- | libmailutils/imapio/printf.c | 35 | ||||
-rw-r--r-- | libmailutils/imapio/qstring.c | 72 | ||||
-rw-r--r-- | libmailutils/imapio/send.c | 29 | ||||
-rw-r--r-- | libmailutils/imapio/trace.c | 86 | ||||
-rw-r--r-- | libmailutils/imapio/words.c | 42 | ||||
-rw-r--r-- | libmailutils/imapio/xscript.c | 46 | ||||
-rw-r--r-- | libmailutils/tests/.gitignore | 1 | ||||
-rw-r--r-- | libmailutils/tests/Makefile.am | 1 | ||||
-rw-r--r-- | libmailutils/tests/imapio.c | 95 | ||||
-rw-r--r-- | libmailutils/tests/wsp.c | 5 |
21 files changed, 745 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 389800e0a..7251453cf 100644 --- a/configure.ac +++ b/configure.ac @@ -1469,12 +1469,13 @@ AC_CONFIG_FILES([ libmailutils/address/Makefile libmailutils/sockaddr/Makefile libmailutils/cidr/Makefile libmailutils/cfg/Makefile libmailutils/diag/Makefile libmailutils/filter/Makefile + libmailutils/imapio/Makefile libmailutils/mailbox/Makefile libmailutils/mailer/Makefile libmailutils/mime/Makefile libmailutils/property/Makefile libmailutils/server/Makefile libmailutils/string/Makefile diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am index 66828840d..27c1b5a42 100644 --- a/include/mailutils/Makefile.am +++ b/include/mailutils/Makefile.am @@ -49,12 +49,13 @@ pkginclude_HEADERS = \ folder.h\ gocs.h\ gsasl.h\ guile.h\ header.h\ imap.h\ + imapio.h\ io.h\ iterator.h\ kwd.h\ ldap.h\ libargp.h\ libcfg.h\ diff --git a/include/mailutils/imapio.h b/include/mailutils/imapio.h new file mode 100644 index 000000000..387e3dfb6 --- /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 e46a294ab..86412d0f3 100644 --- a/include/mailutils/sys/Makefile.am +++ b/include/mailutils/sys/Makefile.am @@ -28,12 +28,13 @@ sysinclude_HEADERS = \ filter.h\ folder.h\ gsasl-stream.h\ header_stream.h\ header.h\ imap.h\ + imapio.h\ iterator.h\ iostream.h\ list.h\ logstream.h\ mailbox.h\ mailer.h\ diff --git a/include/mailutils/sys/imapio.h b/include/mailutils/sys/imapio.h new file mode 100644 index 000000000..524c5beac --- /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 c1f4b4467..b98d617fb 100644 --- a/include/mailutils/types.hin +++ b/include/mailutils/types.hin @@ -73,12 +73,13 @@ struct _mu_url; struct _mu_wicket; struct _mu_assoc; 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 */ typedef _MU_OFF_TYPE_ mu_off_t; @@ -120,12 +121,13 @@ typedef struct _mu_ip_server *mu_ip_server_t; typedef struct _mu_m_server *mu_m_server_t; typedef struct _mu_opool *mu_opool_t; 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; typedef unsigned int mu_debug_level_t; #define MU_FOLDER_ATTRIBUTE_DIRECTORY 0x001 diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am index 5aef3382d..7c1c5c432 100644 --- a/libmailutils/Makefile.am +++ b/libmailutils/Makefile.am @@ -14,13 +14,13 @@ # # 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/>. 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 libmailutils_la_SOURCES = libmailutils_la_LIBADD = \ @@ -30,12 +30,13 @@ libmailutils_la_LIBADD = \ address/libaddress.la\ sockaddr/libsockaddr.la\ cidr/libcidr.la\ cfg/libcfg.la\ diag/libdiag.la\ filter/libfilter.la\ + imapio/libimapio.la\ mailbox/libmailbox.la\ mailer/libmailer.la\ mime/libmime.la\ property/libproperty.la\ server/libserver.la\ string/libstring.la\ diff --git a/libmailutils/imapio/Makefile.am b/libmailutils/imapio/Makefile.am new file mode 100644 index 000000000..74f36a2ec --- /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 000000000..4a3a9af59 --- /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 000000000..28c8d4b36 --- /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 000000000..e46d23e13 --- /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 000000000..801e82ade --- /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 000000000..f50c15c84 --- /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 000000000..11ee04930 --- /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 000000000..ae607452c --- /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 000000000..7fa1c81bf --- /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 000000000..ebb003b66 --- /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 0860f078e..444e39e91 100644 --- a/libmailutils/tests/.gitignore +++ b/libmailutils/tests/.gitignore @@ -9,12 +9,13 @@ addr argcv debugspec decode2047 encode2047 fltst fsaf +imapio listop mailcap prop url-comp url-parse wicket diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am index 66d83ca0e..0ac3ec16b 100644 --- a/libmailutils/tests/Makefile.am +++ b/libmailutils/tests/Makefile.am @@ -44,12 +44,13 @@ noinst_PROGRAMS = \ cidr\ debugspec\ decode2047\ encode2047\ fltst\ fsaf\ + imapio\ listop\ mailcap\ prop\ tempfile\ url-comp\ url-parse\ diff --git a/libmailutils/tests/imapio.c b/libmailutils/tests/imapio.c new file mode 100644 index 000000000..652f0d654 --- /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); |