Create a read_pop_response_sync() function

This factors out the socket reading code from get_message_hdrs() into
its own function. Which we then use in get_message_hdrs().

The sync in the name signifies that it reads from the socket
syncronously and only returns once it's read all it needs to.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
Use read_pop_response_sync() in get_message_list()

We need to modify the string we look for to know when to stop reading in
read_pop_response_sync() a little.

Previously we were looking for "\r\n\r\n.\r\n" which is fine for the
mail headers but for the message list, we get a response like

    1 1118
    2 1025
    3 1878
    4 1116
    5 39900
    6 1100
    .

If we relax the string slightly to "\r\n.\r\n", this catches both cases.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
Supply both arguments to the TOP command

The TOP command is used to display the headers and optionally some lines
from the body of the specified message. Usage is like; top n [l], where n
is the message number and l is the number of lines of the body to show.

We were just sending TOP n in get_message_hdrs()

It seems however that some POP servers, e.g The University of
Washington's, require the second argument to also be given.

So we now send; top n 0

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
Switch to proper program arguments

Use getopt() and the usage now becomes

    popx -h <host> -u <username> [-p <port>]

The port can now be optionally specified, it defaults to 110.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
In main(), move ret to where it's only used

Declare the ret variable only in the block it's actually used.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>