-
Notifications
You must be signed in to change notification settings - Fork 0
/
imap.hpp
114 lines (95 loc) · 2.26 KB
/
imap.hpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef IMAP_H
#define IMAP_H
#include "imaputils.hpp"
#include <libetpan/libetpan.h>
#include <string>
#include <functional>
namespace IMAP {
class Message;
class Session {
public:
/**
* Session constructor.
*/
Session(std::function<void()> updateUI);
/**
* Function pointer to be defined in constructor
*/
std::function<void()> reloadUI;
/**
* Get all messages in the INBOX mailbox terminated by a nullptr
*/
Message** getMessages();
/**
* connect to the specified server (143 is the standard imap port)
*/
void connect(std::string const& server, size_t port = 143);
/**
* log in to the server (connect first, then log in)
*/
void login(std::string const& userid, std::string const& password);
/**
* select a mailbox (only one can be selected at any given time)
*
* this can only be performed after login
*/
void selectMailbox(std::string const& mailbox);
/**
* Session destructor. Deletes dynamically allocated message array,
* logs out and frees the imap session.
*/
~Session();
friend Message;
private:
Message** set_of_messages;
mailimap* imap;
bool logged_in = false;
/**
* Counts the number of messages in the mailbox prior to full execution
* of getMessages().
*/
uint32_t count_mail();
/**
* Gets the unique identifier of message.
*/
uint32_t get_UID(mailimap_msg_att* msg_att);
};
class Message {
public:
/**
* Message constructor.
*/
Message(uint32_t uid, mailimap* imap, Session* session);
/**
* Get the body of the message. You may chose to either include the
* headers or not.
*/
std::string getBody();
/**
* Get one of the descriptor fields (subject, from, ...)
*/
std::string getField(std::string fieldname);
/**
* Remove this mail from its mailbox and reload the UI.
*/
void deleteFromMailbox();
private:
uint32_t uid;
mailimap* imap;
Session* session;
std::string body;
/**
* Retrieves body or header for getBody() and getField()
*/
char* get_msg_content(clist *fetch_result);
/**
* Retrieves content for get_msg_content
*/
char* get_msg_att_msg_content(mailimap_msg_att* msg_att);
/**
* Detects blank field and formats a given header for UI display.
*/
std::string format_field(char* header_content, std::string fieldname);
};
}
#endif /* IMAP_H */