Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/private/imap/status_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import 'response_parser.dart';
/// Parses status responses
class StatusParser extends ResponseParser<Mailbox> {
/// Creates a new parser
StatusParser(this.box) : _regex = RegExp(r'(STATUS "[^"]+?" )(.*)');
// Matches both a quoted ("INBOX") and an unquoted atom (INBOX) mailbox
// name: servers such as Dovecot return the atom form in STATUS responses.
StatusParser(this.box)
: _regex = RegExp(r'(STATUS (?:"[^"]+?"|[^ (]+) )(.*)');

/// The current mailbox
Mailbox box;
Expand Down
22 changes: 22 additions & 0 deletions test/src/imap/status_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:enough_mail/src/private/imap/all_parsers.dart';
import 'package:enough_mail/src/private/imap/imap_response.dart';
import 'package:enough_mail/src/private/imap/imap_response_line.dart';
import 'package:test/test.dart';

// cSpell:disable

void main() {
Expand Down Expand Up @@ -58,4 +59,25 @@ void main() {
expect(processed, true);
expect(box.messagesExists, 2);
});

test('Status with unquoted atom mailbox name', () {
// Dovecot answers `STATUS INBOX (...)` rather than `STATUS "INBOX" (...)`.
// The parser used to require the quotes, so the response never matched
// and every count stayed at its default of 0.
const responseText = 'STATUS INBOX (MESSAGES 231 UNSEEN 5 UIDNEXT 4392)';
final details = ImapResponse()..add(ImapResponseLine(responseText));
final box = Mailbox(
encodedName: 'INBOX',
encodedPath: 'INBOX',
flags: [MailboxFlag.inbox],
pathSeparator: '/',
);
final parser = StatusParser(box);
final response = Response<Mailbox>()..status = ResponseStatus.ok;
final processed = parser.parseUntagged(details, response);
expect(processed, true);
expect(box.messagesExists, 231);
expect(box.messagesUnseen, 5);
expect(box.uidNext, 4392);
});
}