Commit 55cd448f 55cd448fe25f2e8b703b6847bb0b88c117697f0a by Sergey Poznyakoff

Improve IMAP I/O module. Add testcase.

* libmailutils/imapio/getline.c (initial_parse): New function.
(mu_imapio_getline): Use initial_parse.
* libmailutils/tests/imapio.c (main): Do not set progname.
* libmailutils/tests/imapio.at: New file.
* libmailutils/tests/Makefile.am: Add imapio.at.
* libmailutils/tests/testsuite.at: Include imapio.at
1 parent 342d2183
......@@ -96,12 +96,60 @@ get_response_code (struct _mu_imapio *io)
return 0;
}
#define IMAPIO_OK 0
#define IMAPIO_RESP 1
#define IMAPIO_ERR 2
static int
initial_parse (struct _mu_imapio *io)
{
int rc, type;
if ((rc = mu_wordsplit_len (io->_imap_buf_base, io->_imap_buf_level,
&io->_imap_ws,
io->_imap_ws_flags | MU_WRDSF_INCREMENTAL)))
{
if (rc == MU_WRDSE_NOINPUT)
return IMAPIO_OK;
return IMAPIO_ERR;
}
io->_imap_ws_flags |= MU_WRDSF_REUSE;
if ((rc = mu_wordsplit (NULL, &io->_imap_ws, MU_WRDSF_INCREMENTAL)))
{
if (rc == MU_WRDSE_NOINPUT)
return IMAPIO_OK;
return IMAPIO_ERR;
}
if ((type = is_status_response (io->_imap_ws.ws_wordv[1]))
&& (type == STATUS_RESPONSE ||
strcmp (io->_imap_ws.ws_wordv[0], "*") == 0))
{
rc = get_response_code (io);
if (rc)
return IMAPIO_ERR;
while (io->_imap_ws.ws_endp < io->_imap_ws.ws_len &&
mu_isblank (io->_imap_ws.ws_input[io->_imap_ws.ws_endp]))
io->_imap_ws.ws_endp++;
io->_imap_ws.ws_flags |= MU_WRDSF_NOSPLIT;
rc = mu_wordsplit (NULL, &io->_imap_ws, MU_WRDSF_INCREMENTAL);
io->_imap_ws.ws_flags &= ~MU_WRDSF_NOSPLIT;
if (rc)
{
if (rc != MU_WRDSE_NOINPUT)
return IMAPIO_ERR;
}
return IMAPIO_RESP;
}
return IMAPIO_OK;
}
int
mu_imapio_getline (struct _mu_imapio *io)
{
int rc;
char *last_arg;
int type;
if (io->_imap_reply_ready)
{
......@@ -120,52 +168,28 @@ mu_imapio_getline (struct _mu_imapio *io)
break;
io->_imap_buf_level = mu_rtrim_class (io->_imap_buf_base,
MU_CTYPE_ENDLN);
if ((rc = mu_wordsplit_len (io->_imap_buf_base, io->_imap_buf_level,
&io->_imap_ws,
io->_imap_ws_flags | MU_WRDSF_INCREMENTAL)))
{
if (rc == MU_WRDSE_NOINPUT)
break;
return MU_ERR_PARSE;
}
io->_imap_ws_flags |= MU_WRDSF_REUSE;
if ((rc = mu_wordsplit (NULL, &io->_imap_ws, MU_WRDSF_INCREMENTAL)))
rc = initial_parse (io);
if (rc == IMAPIO_ERR)
{
if (rc == MU_WRDSE_NOINPUT)
break;
return MU_ERR_PARSE;
rc = MU_ERR_PARSE;
break;
}
if ((type = is_status_response (io->_imap_ws.ws_wordv[1]))
&& (type == STATUS_RESPONSE ||
strcmp (io->_imap_ws.ws_wordv[0], "*") == 0))
else if (rc == IMAPIO_RESP)
{
rc = get_response_code (io);
if (rc)
return MU_ERR_PARSE;
while (io->_imap_ws.ws_endp < io->_imap_ws.ws_len &&
mu_isblank (io->_imap_ws.ws_input[io->_imap_ws.ws_endp]))
io->_imap_ws.ws_endp++;
io->_imap_ws.ws_flags |= MU_WRDSF_NOSPLIT;
rc = mu_wordsplit (NULL, &io->_imap_ws, MU_WRDSF_INCREMENTAL);
io->_imap_ws.ws_flags &= ~MU_WRDSF_NOSPLIT;
if (rc)
{
if (rc == MU_WRDSE_NOINPUT)
break;
return MU_ERR_PARSE;
}
rc = 0;
break;
}
rc = mu_wordsplit_len (io->_imap_buf_base + io->_imap_ws.ws_endp,
io->_imap_buf_level - io->_imap_ws.ws_endp,
&io->_imap_ws, io->_imap_ws_flags);
if (rc)
return MU_ERR_PARSE;
if (io->_imap_ws.ws_wordc == 0)
break;
last_arg = io->_imap_ws.ws_wordv[io->_imap_ws.ws_wordc - 1];
if (last_arg[0] == '{' && last_arg[strlen (last_arg)-1] == '}')
{
......
......@@ -75,6 +75,7 @@ TESTSUITE_AT = \
fromflt.at\
fsaf.at\
hdrflt.at\
imapio.at\
inline-comment.at\
linecon.at\
list.at\
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# 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/>.
AT_BANNER(IMAP IO)
dnl ------------------------------------------------------------
dnl IMAPIO([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'])
dnl
m4_pushdef([IMAPIO],[
m4_pushdef([MU_TEST_GROUP],[imapio])
m4_pushdef([MU_TEST_KEYWORDS],[imapio])
m4_pushdef([MU_TEST_COMMAND],[imapio])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
])
dnl ------------------------------------------------------------
dnl Tests
dnl ------------------------------------------------------------
IMAPIO([simple string],[],
[1 select INBOX
],
[],
[3
0: '1'
1: 'select'
2: 'INBOX'
])
IMAPIO([quoted string],[],
[1 select "Test mailbox"
],
[],
[3
0: '1'
1: 'select'
2: 'Test mailbox'
])
IMAPIO([server response],[],
[1 OK That's OK
],
[],
[3
0: '1'
1: 'OK'
2: 'That's OK'
])
IMAPIO([server response with code],[],
[* OK [[UIDNEXT 61]] Predicted next uid
],
[],
[7
0: '*'
1: 'OK'
[2: '['
3: 'UIDNEXT'
4: '61'
5: ']']
6: 'Predicted next uid'
])
IMAPIO([literals],[literal],
[A001 LOGIN {11}
FRED FOOBAR {7}
fat man
],
[+ GO AHEAD
+ GO AHEAD
],
[4
0: 'A001'
1: 'LOGIN'
2: 'FRED FOOBAR'
3: 'fat man'
])
dnl ------------------------------------------------------------
m4_popdef([IMAPIO])
......@@ -42,7 +42,6 @@ main (int argc, char **argv)
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++)
......
......@@ -80,4 +80,7 @@ m4_include([linecon.at])
AT_BANNER(Debug Specification)
m4_include([debugspec.at])
AT_BANNER([IMAP IO])
m4_include([imapio.at])
m4_include([fsaf.at])
\ No newline at end of file
......