-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.h
45 lines (34 loc) · 1.67 KB
/
Client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef CLIENT_H
#define CLIENT_H
#include <string>
#define POP3_PORT 110
// Size of 512 bytes is determined by RFC 1939 - "Responses may be up to 512 characters long, including the terminating CRLF"
#define BUFLEN 512
/**
* Simple POP3 client class
*
* It enables connecting to a POP3 server, login, receive a list of all messages and print message with a given ID number
* Messages are raw and unformatted
*/
class Client {
std::string host; /// host name
unsigned short port; /// port number (0-65535)
int sockfd; /// socket to connect
struct hostent *hostinfo; /// IP address + port
char buffer[BUFLEN+1]; /// buffer for receiving messages, 512 is max length of response message, +1 is for terminating '\0' byte
std::string username; /// username to log in, password won't be stored here, it's received interactively
bool shortMessage; /// if true prints full message with header, if false prints data part only
std::string sendReceive(const std::string& message); /// send a message and receive response message
void sendMessage(const std::string& message); /// send message to server
void receiveMessage(std::string& message); /// receive message from server
bool analyzeMessage(std::string& msg) const; /// check the response status
public:
Client(const std::string& ahostname, const unsigned short aport=POP3_PORT);
~Client();
void setShortMessage(const bool type=false) { shortMessage = type; } // set verbose type
void login(const std::string& user); // login with a given username
void listMails(); // list all emails
void getMail(const unsigned int i); // retrieve a given email
void quit(); // quit the POP3 server
};
#endif