duesee / imap-codec

Rock-solid and complete codec for IMAP
Apache License 2.0
35 stars 13 forks source link

fix: Handle different line endings and EOF in examples #501

Closed HenningHolmDE closed 3 weeks ago

HenningHolmDE commented 3 weeks ago

The parse_* examples for imap-codec were not running on Windows due to an incorrect conversion of an already existing CRLF line ending to an erroneous CRCRLF line ending. This fixes the issue by ensuring a CRLF line ending in all possible cases.

Also, EOF of stdin is now handled and no longer results in an endless loop (e.g. echo -n "* OK Hello" | cargo run -p imap-codec --example parse_greeting).

duesee commented 3 weeks ago

Uhuuuu, good catch! I think we can do better: It's possible to require features for examples.

We could enable ...

https://github.com/duesee/imap-codec/blob/65e99b5b68bf1f015ec524ffae1452b23f2b9d29/imap-codec/Cargo.toml#L43

... to make the examples work w/o changing the data.

What do you think?

HenningHolmDE commented 3 weeks ago

Uhuuuu, good catch! I think we can do better: It's possible to require features for examples.

We could enable ...

https://github.com/duesee/imap-codec/blob/65e99b5b68bf1f015ec524ffae1452b23f2b9d29/imap-codec/Cargo.toml#L43

... to make the examples work w/o changing the data.

What do you think?

I don't think it the best way to fix an terminal input issue in the example by forcing the user to enable the quirk feature and relaxing the parser to deal with the input. We know what range of input to expect from Stdin::read_line in different situations and should be able to handle it locally in common::read_line.

duesee commented 3 weeks ago

I don't think it the best way to fix an terminal input issue in the example by forcing the user to enable the quirk feature and relaxing the parser to deal with the input.

I agree 👍🏻 It somehow happens too often that we "want" this quirk. But it's a lazy solution. Let's resist the temptation :-)