diff --git a/Makefile b/Makefile index b7cb2c9..f6373a5 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,7 @@ dist: $(PACKAGE)-$(VERSION)/src/plugins/project.conf \ $(PACKAGE)-$(VERSION)/tests/date.c \ $(PACKAGE)-$(VERSION)/tests/email.c \ + $(PACKAGE)-$(VERSION)/tests/imap4.c \ $(PACKAGE)-$(VERSION)/tests/Makefile \ $(PACKAGE)-$(VERSION)/tests/tests.sh \ $(PACKAGE)-$(VERSION)/tests/project.conf \ diff --git a/src/account/imap4.c b/src/account/imap4.c index 73a2077..7dc276a 100644 --- a/src/account/imap4.c +++ b/src/account/imap4.c @@ -787,30 +787,48 @@ static int _context_status(IMAP4 * imap4, char const * answer) if(*p == ' ') /* skip spaces */ for(p++; *p != '\0' && *p == ' '; p++); if(*p == '(') + /* parse the data items */ for(p++; *p != '\0' && *p != ')'; p++) { if(strncmp(p, messages, sizeof(messages) - 1) == 0 && p[sizeof(messages) - 1] == ' ') { + /* number of messages in the mailbox */ p += sizeof(messages); sscanf(p, "%u", &u); /* FIXME really implement */ +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s() %u messages\n", + __func__, u); +#endif } - if(strncmp(p, recent, sizeof(recent) - 1) == 0 + else if(strncmp(p, recent, sizeof(recent) - 1) == 0 && p[sizeof(recent) - 1] == ' ') { + /* number of recent messages in the mailbox */ p += sizeof(recent); sscanf(p, "%u", &u); /* FIXME really implement */ +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s() %u recent\n", + __func__, u); +#endif } - if(strncmp(p, unseen, sizeof(unseen) - 1) == 0 + else if(strncmp(p, unseen, sizeof(unseen) - 1) == 0 && p[sizeof(unseen) - 1] == ' ') { + /* number of unseen messages in the mailbox */ p += sizeof(unseen); sscanf(p, "%u", &u); /* FIXME really implement */ +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s() %u unseen\n", + __func__, u); +#endif } - /* FIXME implement more */ + else + /* skip until the next space */ + for(; *p != '\0' && *p != ' '; p++); /* skip until the next space */ for(; *p != '\0' && *p != ' '; p++); } diff --git a/tests/Makefile b/tests/Makefile index 07b6bbc..b89327d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,13 +1,13 @@ -TARGETS = date email tests.log +TARGETS = date email imap4 tests.log PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin +SBINDIR = $(PREFIX)/sbin CC ?= cc CPPFLAGSF= -I ../include CPPFLAGS?= CFLAGSF = -W CFLAGS = -Wall -g -O2 -ffreestanding -LDFLAGSF= -L ../src -Wl,-rpath,../src -lMailer LDFLAGS = RM ?= rm -f LN ?= ln -f @@ -19,19 +19,26 @@ all: $(TARGETS) date_OBJS = date.o date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) -date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) +date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer date: $(date_OBJS) $(CC) -o date $(date_OBJS) $(date_LDFLAGS) email_OBJS = email.o email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) -email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) +email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer email: $(email_OBJS) $(CC) -o email $(email_OBJS) $(email_LDFLAGS) -tests.log: email +imap4_OBJS = imap4.o +imap4_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags glib-2.0 libSystem` `pkg-config --cflags openssl` +imap4_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs glib-2.0 libSystem` `pkg-config --libs openssl` -lssl + +imap4: $(imap4_OBJS) + $(CC) -o imap4 $(imap4_OBJS) $(imap4_LDFLAGS) + +tests.log: date email imap4 ./tests.sh -P "$(PREFIX)" -- "tests.log" date.o: date.c ../src/libMailer.a @@ -40,8 +47,11 @@ date.o: date.c ../src/libMailer.a email.o: email.c ../src/libMailer.a $(CC) $(email_CFLAGS) -c email.c +imap4.o: imap4.c ../src/account/imap4.c + $(CC) $(imap4_CFLAGS) -c imap4.c + clean: - $(RM) -- $(date_OBJS) $(email_OBJS) $(tests.log_OBJS) + $(RM) -- $(date_OBJS) $(email_OBJS) $(imap4_OBJS) $(tests.log_OBJS) distclean: clean $(RM) -- $(TARGETS) diff --git a/tests/imap4.c b/tests/imap4.c new file mode 100644 index 0000000..c783680 --- /dev/null +++ b/tests/imap4.c @@ -0,0 +1,45 @@ +/* $Id$ */ +/* Copyright (c) 2012 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Mailer */ +/* This program 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, version 3 of the License. + * + * This program 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 this program. If not, see . */ + + + +#include +#include "../src/account/imap4.c" + + +/* imap4 */ +static int _imap4_status(char const * progname, char const * title, + IMAP4 * imap4, char const * status) +{ + printf("%s: Testing %s\n", progname, title); + return _context_status(imap4, status); +} + + +/* main */ +int main(int argc, char * argv[]) +{ + int ret = 0; + IMAP4 imap4; + char const status[] = "STATUS \"folder\"" + " (MESSAGES 3 RECENT 2 UNSEEN 1)"; + + memset(&imap4, 0, sizeof(imap4)); + ret |= _imap4_status(argv[0], "STATUS (1/4)", &imap4, status); + ret |= _imap4_status(argv[0], "STATUS (2/4)", &imap4, "()"); + ret |= _imap4_status(argv[0], "STATUS (3/4)", &imap4, "( )"); + ret |= _imap4_status(argv[0], "STATUS (4/4)", &imap4, ""); + return (ret == 0) ? 0 : 2; +} diff --git a/tests/project.conf b/tests/project.conf index 1a0a6c9..8341115 100644 --- a/tests/project.conf +++ b/tests/project.conf @@ -1,14 +1,14 @@ -targets=date,email,tests.log +targets=date,email,imap4,tests.log cppflags_force=-I ../include cflags_force=-W cflags=-Wall -g -O2 -ffreestanding -ldflags_force=-L ../src -Wl,-rpath,../src -lMailer ldflags= dist=Makefile,tests.sh [date] type=binary sources=date.c +ldflags=-L ../src -Wl,-rpath,../src -lMailer [date.c] depends=../src/libMailer.a @@ -16,11 +16,21 @@ depends=../src/libMailer.a [email] type=binary sources=email.c +ldflags=-L ../src -Wl,-rpath,../src -lMailer [email.c] depends=../src/libMailer.a +[imap4] +type=binary +sources=imap4.c +cflags=`pkg-config --cflags glib-2.0 libSystem` `pkg-config --cflags openssl` +ldflags=`pkg-config --libs glib-2.0 libSystem` `pkg-config --libs openssl` -lssl + +[imap4.c] +depends=../src/account/imap4.c + [tests.log] type=script script=./tests.sh -depends=email +depends=date,email,imap4 diff --git a/tests/tests.sh b/tests/tests.sh index 5efee26..1bf8d05 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -47,6 +47,7 @@ target="$1" FAILED= ./date >> "$target" || FAILED="$FAILED date(error $?)" ./email >> "$target" || FAILED="$FAILED email(error $?)" +./imap4 >> "$target" || FAILED="$FAILED imap4(error $?)" [ -z "$FAILED" ] && exit 0 echo "Failed tests:$FAILED" 1>&2 #XXX ignore errors for now