Commit 6f309ce6 6f309ce61dcfb461c3fe1270efe2b23a7ac5d676 by Sergey Poznyakoff

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
1 parent 2ec525ac
......@@ -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
......
......@@ -52,6 +52,7 @@ pkginclude_HEADERS = \
guile.h\
header.h\
imap.h\
imapio.h\
io.h\
iterator.h\
kwd.h\
......
/* 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 */
......@@ -31,6 +31,7 @@ sysinclude_HEADERS = \
header_stream.h\
header.h\
imap.h\
imapio.h\
iterator.h\
iostream.h\
list.h\
......
/* 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
......@@ -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;
......
......@@ -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\
......
# 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
/* 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;
}
/* 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;
}
/* 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);
}
/* 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;
}
/* 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);
}
/* 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);
}
/* 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;
}
/* 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;
}
/* 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;
}
......@@ -12,6 +12,7 @@ decode2047
encode2047
fltst
fsaf
imapio
listop
mailcap
prop
......
......@@ -47,6 +47,7 @@ noinst_PROGRAMS = \
encode2047\
fltst\
fsaf\
imapio\
listop\
mailcap\
prop\
......
/* 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;
}
......@@ -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;
......