From cfe5f7dbf431eee38cde62513aab59ddfbd058c8 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Wed, 11 Sep 2013 18:13:53 +0100 Subject: [PATCH] ftpserver.pl: Added support for IMAP CLOSE and EXPUNGE commands --- tests/ftpserver.pl | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl index 9c4d15372..ac52a496c 100755 --- a/tests/ftpserver.pl +++ b/tests/ftpserver.pl @@ -585,9 +585,11 @@ sub protocolsetup { 'APPEND' => \&APPEND_imap, 'CAPABILITY' => \&CAPABILITY_imap, 'CHECK' => \&CHECK_imap, + 'CLOSE' => \&CLOSE_imap, 'CREATE' => \&CREATE_imap, 'DELETE' => \&DELETE_imap, 'EXAMINE' => \&EXAMINE_imap, + 'EXPUNGE' => \&EXPUNGE_imap, 'FETCH' => \&FETCH_imap, 'LIST' => \&LIST_imap, 'LOGOUT' => \&LOGOUT_imap, @@ -1196,6 +1198,47 @@ sub CHECK_imap { return 0; } +sub CLOSE_imap { + if ($selected eq "") { + sendcontrol "$cmdid BAD Command received in Invalid state\r\n"; + } + elsif (!@deleted) { + sendcontrol "$cmdid BAD Command Argument\r\n"; + } + else { + sendcontrol "$cmdid OK CLOSE completed\r\n"; + + @deleted = (); + } + + return 0; +} + +sub EXPUNGE_imap { + if ($selected eq "") { + sendcontrol "$cmdid BAD Command received in Invalid state\r\n"; + } + else { + if (!@deleted) { + # Report the number of existing messages as per the SELECT + # command + sendcontrol "* 172 EXISTS\r\n"; + } + else { + # Report the message UIDs being deleted + for my $d (@deleted) { + sendcontrol "* $d EXPUNGE\r\n"; + } + + @deleted = (); + } + + sendcontrol "$cmdid OK EXPUNGE completed\r\n"; + } + + return 0; +} + sub LOGOUT_imap { sendcontrol "* BYE cURL IMAP server signing off\r\n"; sendcontrol "$cmdid OK LOGOUT completed\r\n";