Skip to content

Pop & misc cleanup#113

Merged
theyoyojo merged 15 commits into
masterfrom
pop_n_misc_cleanup
May 21, 2024
Merged

Pop & misc cleanup#113
theyoyojo merged 15 commits into
masterfrom
pop_n_misc_cleanup

Conversation

@charliemirabile

Copy link
Copy Markdown
Contributor

Various fixes and cleanups including a substantial improvement for pop to remove duplicate code and various copy paste errors that came with it.

Fixes #17

Trolled yet again by local artifacts within the container >:(
Watchtower already had is own gitignore and each folder needs its own
dockerignore file. This also helps to avoid conflicts in the main one.

We should reserve the top level gitignore for stuff actually in the top
level directory or wildcards like the swap files.
Containers should be able to consume these programs separately. There
isn't really an relation between them except that they were developed
out of tree together at the same time using the same repo for convenience.
Even though the underlying file should be opened O_RDONLY we still want to
allow PROT_WRITE on the mapping of it so that the active field of the mail
can be updated in response to DELE or RSET commands.

Fixes: 710b051 ("pop: switch to caching email data in journal file")
The `send` function was originally imported wholesale from smtp and
so the comment refers to particulars of the smtp protocol that are
irrelevant to a pop implementation, though the gist is correct.
The original password code was copy pasted from the username code and
I forgot to change the string. The only important part is the `+OK` at
the beginning so this doesn't really matter, but I have been meaning to
fix it for ages.

Fixes: 76e03e6 ("Initial implementation using code from smtp server")
All commands want to consume a line of input whether or not they process
further, even if it might be marginally faster to skip reading the data
into the buffer when the command will just ignore it, cutting down on
repetition in each case is worth it.
some commands are valid in all states and can be processed first,
then we can filter based on states because for some states there is
really only one non generic command that is valid, and then the bulk
of the commands that are only valid once you are logged in can just
rely on the prior logic to block unauthenticated users from reaching
that point in the code.

Note: there is a single semicolon added to the beginning of the `stat`
command case. This is intentional because you cannot start a case label
with a declaration (at least not until C23 which is not fully supported
yet). This wasn't a problem previously because there were two conditions
checked before the decl, but now they are both gone so the error occurs.
This command will get refactored shortly, so that semicolon is not a long
term thing, just a stopgap to prevent this commit from breaking git-bisect
Handle the partial writes and error conditions in one place
All commands that take an argument take a single integer (except for top)
that refers to an email. We can try parsing that argument in all cases
if it exists and subsequent code can check whether or not it exists by
checking whether a pointer is null.
In order to be able to introduce an enumeration of commands, it is useful
we need to save the labels `QUIT` and `USER` for that purpose.
This will centralize the error checking so that an "invalid command"
message can properly be generated if the command is unrecognized
before further processing. The enumeration values being small and
sequential probably makes switching over them have better code-gen
(i.e. jump-tables instead of if else comparisons)
we can just use `dprintf` to send unbuffered data to `stdout` and let
libc deal with managing a buffer for storing the intermediate data.
Avoids replication of format strings. DRY.
This split allows a lot of the code to be deindented even though the
overall number of lines remains basically the same. It also helps to
conceptually separate the control flow so that it is easier to grok.
Comment thread pop/pop3.c

@theyoyojo theyoyojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@theyoyojo theyoyojo merged commit a7e9b40 into master May 21, 2024
@theyoyojo theyoyojo deleted the pop_n_misc_cleanup branch May 21, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor to improve code quality

2 participants